Serialization error when object property name starts with @
Original issue by DJSundog on JSDB GitHub mirror.
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