small-tech / jsdb

A transparent, in-memory, streaming write-on-update JavaScript database for Small Web applications that persists to a JavaScript transaction log.
Other
237 stars 8 forks source link

Serialization error when object property name starts with @ #4

Closed DJSundog closed 3 years ago

DJSundog commented 3 years ago

Assuming a JSDB table called local_people has been initialized, the following code:

db.local_people.push({
          id: id,
          actor: {
            "@context": ["https://www.w3.org/ns/activitystreams"],  
          }
});

results in creating the following local_people.js:

globalThis._ = [  ];
(function () { if (typeof define === 'function' && define.amd) { define([], globalThis._); } else if (typeof module === 'object' && module.exports) { module.exports = globalThis._ } else { globalThis.local_people = globalThis._ } })();
_[0] = { id: `REDACTED`, actor: { @context: [ `https://www.w3.org/ns/activitystreams` ] } };

upon stopping the site.js server and restarting it, it fails to reload the data into memory:

_[0] = { id: `REDACTED`, actor: { @context: [ `https://www.w3.org/ns/activitystreams` ] } };
                                  ^

SyntaxError: Invalid or unexpected token
    at wrapSafe (internal/modules/cjs/loader.js:1070:16)
    at Module._compile (internal/modules/cjs/loader.js:1120:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at JSTable.load (/usr/local/bin/node_modules/@small-tech/jsdb/lib/JSTable.js:161:20)
    at new JSTable (/usr/local/bin/node_modules/@small-tech/jsdb/lib/JSTable.js:58:12)
    at /usr/local/bin/node_modules/@small-tech/jsdb/lib/JSDB.js:113:30
aral commented 3 years ago

Thanks for the report, @DJSundog. Going to look into this now. Will report back shortly.

aral commented 3 years ago

Reproduced. Tracking internally here.

Will be fixed in the next release.

aral commented 3 years ago

Fixed in https://github.com/small-tech/jsdb/commit/e8c2e787b6d923c2dccef0b35064be4693e3f104

DJSundog commented 3 years ago

Awesome - thanks!