@es-joy/jsoe 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintignore +7 -0
  3. package/.eslintrc.cjs +120 -0
  4. package/CHANGES.md +5 -0
  5. package/LICENSE-MIT.txt +22 -0
  6. package/README.md +82 -0
  7. package/package.json +101 -0
  8. package/rollup.config.js +29 -0
  9. package/server.js +25 -0
  10. package/src/deepEqual.js +72 -0
  11. package/src/formats/indexedDBKey.js +66 -0
  12. package/src/formats/json.js +64 -0
  13. package/src/formats/schemaAndArbitrary.js +20 -0
  14. package/src/formats/schemaOnly.js +529 -0
  15. package/src/formats/structuredCloning.js +372 -0
  16. package/src/formats.js +229 -0
  17. package/src/fundamentalTypes/BooleanObjectType.js +55 -0
  18. package/src/fundamentalTypes/NumberObjectType.js +41 -0
  19. package/src/fundamentalTypes/StringObjectType.js +37 -0
  20. package/src/fundamentalTypes/arrayReferenceType.js +203 -0
  21. package/src/fundamentalTypes/arrayType.js +898 -0
  22. package/src/fundamentalTypes/bigintType.js +53 -0
  23. package/src/fundamentalTypes/dateType.js +129 -0
  24. package/src/fundamentalTypes/nullType.js +33 -0
  25. package/src/fundamentalTypes/numberType.js +56 -0
  26. package/src/fundamentalTypes/objectReferenceType.js +51 -0
  27. package/src/fundamentalTypes/objectType.js +30 -0
  28. package/src/fundamentalTypes/regexpType.js +95 -0
  29. package/src/fundamentalTypes/sparseUndefinedType.js +43 -0
  30. package/src/fundamentalTypes/stringType.js +31 -0
  31. package/src/fundamentalTypes/undefinedType.js +37 -0
  32. package/src/index.js +7 -0
  33. package/src/subTypes/blobHTMLType.js +160 -0
  34. package/src/subTypes/falseType.js +42 -0
  35. package/src/subTypes/trueType.js +42 -0
  36. package/src/superTypes/InfinitiesSuperType.js +49 -0
  37. package/src/superTypes/SpecialNumberSuperType.js +62 -0
  38. package/src/typeChoices.js +125 -0
  39. package/src/types.js +665 -0
  40. package/src/utils/dialogs.js +115 -0
  41. package/src/utils/jsonPointer.js +89 -0
  42. package/src/utils/templateUtils.js +106 -0
  43. package/src/utils/types.js +6 -0
package/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ ; EditorConfig file: https://EditorConfig.org
2
+ ; Install the "EditorConfig" plugin into your editor to use
3
+
4
+ root = true
5
+
6
+ [*]
7
+ charset = utf-8
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ indent_style = space
11
+ indent_size = 2
12
+ trim_trailing_whitespace = true
13
+
14
+ [*.md]
15
+ indent_size = 4
package/.eslintignore ADDED
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ coverage
3
+ instrumented
4
+ ignore
5
+ src/deepEqual.js
6
+ src/main-pages.js
7
+ !.*.js
package/.eslintrc.cjs ADDED
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ extends: ['ash-nazg/sauron-node-overrides', 'plugin:cypress/recommended'],
5
+ parserOptions: {
6
+ ecmaVersion: 2021
7
+ },
8
+ settings: {
9
+ jsdoc: {
10
+ mode: 'typescript'
11
+ },
12
+ polyfills: [
13
+ 'Array.isArray',
14
+ 'Array.filter',
15
+ 'Array.forEach',
16
+ 'Array.from',
17
+ 'Array.includes',
18
+ 'Array.map',
19
+ 'Array.reduce',
20
+ 'ArrayBuffer',
21
+ 'BigInt',
22
+ 'Blob',
23
+ 'btoa',
24
+ 'console',
25
+ 'Date.toISOString',
26
+ 'document.body',
27
+ 'document.querySelector',
28
+ 'document.querySelectorAll',
29
+ 'Error',
30
+ 'fetch',
31
+ 'FileReader',
32
+ 'history',
33
+ 'IDBKeyRange',
34
+ 'indexedDB',
35
+ 'JSON',
36
+ 'location.hash',
37
+ 'location.href',
38
+ 'location.pathname',
39
+ 'MutationObserver',
40
+ 'Number.isNaN',
41
+ 'Number.parseFloat',
42
+ 'Number.parseInt',
43
+ 'Object.assign',
44
+ 'Object.keys',
45
+ 'Object.entries',
46
+ 'Object.values',
47
+ 'Promise',
48
+ 'Set',
49
+ 'Uint8Array',
50
+ 'URL',
51
+ 'URLSearchParams',
52
+ 'WeakMap'
53
+ ],
54
+ coverage: true
55
+ },
56
+ env: {
57
+ node: false,
58
+ browser: true
59
+ },
60
+ overrides: [
61
+ {
62
+ files: '*.md/*.js',
63
+ rules: {
64
+ 'import/unambiguous': 'off'
65
+ }
66
+ },
67
+ {
68
+ files: 'cypress/**',
69
+ rules: {
70
+ 'import/unambiguous': 'off'
71
+ }
72
+ }
73
+ ],
74
+ rules: {
75
+ 'no-console': 0,
76
+ 'no-shadow': 0,
77
+ // 'jsdoc/require-jsdoc': ['error', {
78
+ // require: {
79
+ // ArrowFunctionExpression: true,
80
+ // ClassDeclaration: true,
81
+ // ClassExpression: true,
82
+ // FunctionDeclaration: true,
83
+ // FunctionExpression: true,
84
+ // MethodDefinition: true
85
+ // }
86
+ // }],
87
+ quotes: ['error', 'single', {
88
+ avoidEscape: true, allowTemplateLiterals: true
89
+ }],
90
+
91
+ 'jsdoc/require-jsdoc': ['warn', {
92
+ contexts: [
93
+ 'Program > VariableDeclaration > ' +
94
+ 'VariableDeclarator > ArrowFunctionExpression',
95
+ 'Program > VariableDeclaration > ' +
96
+ 'VariableDeclarator > FunctionExpression',
97
+ 'ExportNamedDeclaration > VariableDeclaration > ' +
98
+ 'VariableDeclarator > ArrowFunctionExpression',
99
+ 'ExportNamedDeclaration > VariableDeclaration > ' +
100
+ 'VariableDeclarator > FunctionExpression',
101
+ 'ExportDefaultDeclaration > ArrowFunctionExpression',
102
+ 'ExportDefaultDeclaration > FunctionExpression',
103
+
104
+ 'ClassDeclaration',
105
+ 'ClassExpression',
106
+ 'FunctionDeclaration', // Default is true
107
+ 'MethodDefinition'
108
+ ]
109
+ }],
110
+
111
+ // Disable until find time
112
+ 'prefer-named-capture-group': 0,
113
+ 'eslint-comments/require-description': 0,
114
+ // Disable until rule improved?
115
+ 'require-atomic-updates': 0,
116
+ // Disable; waiting on https://github.com/mysticatea/eslint-plugin-node/issues/162
117
+ 'n/no-unpublished-import': 0,
118
+ 'unicorn/no-this-assignment': 0
119
+ }
120
+ };
package/CHANGES.md ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGES TO `@es-joy/jsoe`
2
+
3
+ ## 0.0.1
4
+
5
+ - initial commit
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2023 Brett Zamir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @es-joy/jsoe
2
+
3
+ JavaScript Object Editor.
4
+
5
+ Editing of arbitrary JavaScript objects.
6
+
7
+ ## Formats
8
+
9
+ Formats are a collection of allowed types.
10
+
11
+ - Structured Cloning (using [typeson](https://github.com/dfahlander/typeson)) (e.g., IndexedDB)
12
+ - JSON
13
+ - IndexedDB keys
14
+
15
+ ## Fundamental types
16
+
17
+ These are generally atomic types which correlate to JavaScript language structures.
18
+
19
+ - Array reference (for cyclic arrays)
20
+ - Array
21
+ - `BigInt`
22
+ - `Boolean` object
23
+ - `Date`
24
+ - `null`
25
+ - `Number` object
26
+ - number
27
+ - Object reference (for cyclic objects)
28
+ - Object
29
+ - `RegExp`
30
+ - `String` object
31
+ - string
32
+ - `undefined`
33
+
34
+ ## Subtypes
35
+
36
+ These map to a subset of JavaScript language structures. Note that false and true were common and limited enough in number to justify their own subtype for the sake of having a quick pull-down entry.
37
+
38
+ - Blob (text/html)
39
+ - `false`
40
+ - `true`
41
+
42
+ ## Supertypes
43
+
44
+ These are collections of individual types, justified by the subitems not being so frequent as to necessitate their own
45
+ separate enumeration.
46
+
47
+ - Infinities (`Infinity`, `-Infinity`) - Used with IndexedDB keys
48
+ - Special Number (`Infinity`, `-Infinity`, `NaN`) - Used with Structured Cloning values
49
+
50
+ ## To-dos
51
+
52
+ 1. Create demo
53
+ 1. Add tests of demo (lower priority as have tests in `idb-manager`)
54
+ 1. Support Schemas based on a JSON serialization of Zod
55
+ 1. Expand fundamental types
56
+ 1. Not in typeson-registry
57
+ 1. Structured Cloning
58
+ 1. arraybufferview
59
+ 1. Already in typeson-registry
60
+ 1. Structured Cloning
61
+ 1. map, set,
62
+ 1. blob, file, filelist
63
+ 1. arraybuffer
64
+ 1. dataview, imagedata, imagebitmap
65
+ 1. error, errors
66
+ 1. Typed Arrays
67
+ 1. int8array
68
+ 1. uint8array
69
+ 1. uint8clampedarray
70
+ 1. int16array
71
+ 1. uint16array
72
+ 1. int32array
73
+ 1. uint32array
74
+ 1. float32array
75
+ 1. float64array
76
+ 1. Intl (imperfect)
77
+ 1. IntlCollator
78
+ 1. IntlDateTimeFormat
79
+ 1. IntlNumberFormat
80
+ 1. Expand subtypes
81
+ 1. As supported by Zod, JSON Schema, etc. (e.g., email addresses as
82
+ subtype of `string`)
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@es-joy/jsoe",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.js"
7
+ },
8
+ "description": "Editing of arbitrary JavaScript objects",
9
+ "browserslist": [
10
+ "cover 100%"
11
+ ],
12
+ "nyc": {
13
+ "exclude": [
14
+ "node_modules/**"
15
+ ]
16
+ },
17
+ "dependencies": {
18
+ "@brettz9/node-static": "^0.1.1",
19
+ "jamilih": "0.55.0",
20
+ "sceditor": "3.2.0",
21
+ "typeson-registry": "5.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@babel/core": "^7.21.4",
25
+ "@babel/plugin-transform-modules-commonjs": "^7.21.2",
26
+ "@babel/preset-env": "^7.21.4",
27
+ "@babel/register": "^7.21.0",
28
+ "@brettz9/eslint-plugin": "^1.0.4",
29
+ "@cypress/code-coverage": "^3.10.4",
30
+ "@rollup/plugin-babel": "^6.0.3",
31
+ "@rollup/plugin-commonjs": "^24.1.0",
32
+ "@rollup/plugin-node-resolve": "^15.0.2",
33
+ "axe-core": "^4.6.3",
34
+ "cypress": "^12.9.0",
35
+ "cypress-axe": "^1.4.0",
36
+ "eslint": "^8.38.0",
37
+ "eslint-config-ash-nazg": "^34.10.0",
38
+ "eslint-config-standard": "^17.0.0",
39
+ "eslint-plugin-array-func": "^3.1.8",
40
+ "eslint-plugin-compat": "^4.1.4",
41
+ "eslint-plugin-cypress": "^2.13.2",
42
+ "eslint-plugin-eslint-comments": "^3.2.0",
43
+ "eslint-plugin-html": "^7.1.0",
44
+ "eslint-plugin-import": "^2.27.5",
45
+ "eslint-plugin-jsdoc": "^41.1.1",
46
+ "eslint-plugin-markdown": "^3.0.0",
47
+ "eslint-plugin-n": "^15.7.0",
48
+ "eslint-plugin-no-unsanitized": "^4.0.2",
49
+ "eslint-plugin-no-use-extend-native": "^0.5.0",
50
+ "eslint-plugin-promise": "^6.1.1",
51
+ "eslint-plugin-sonarjs": "^0.19.0",
52
+ "eslint-plugin-standard": "^4.1.0",
53
+ "eslint-plugin-unicorn": "^46.0.0",
54
+ "fast-deep-equal": "^3.1.3",
55
+ "npm-run-all": "^4.1.5",
56
+ "nyc": "^15.1.0",
57
+ "open-cli": "^7.2.0",
58
+ "rimraf": "^5.0.0",
59
+ "rollup": "3.20.2",
60
+ "rollup-plugin-istanbul": "^4.0.0",
61
+ "rollup-plugin-node-builtins": "^2.1.2"
62
+ },
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "git@github.com:es-joy/jsoe.git"
66
+ },
67
+ "keywords": [
68
+ "JSON",
69
+ "structured-cloning",
70
+ "indexeddb"
71
+ ],
72
+ "author": "Brett Zamir",
73
+ "contributors": [],
74
+ "engines": {
75
+ "node": ">=14.0.0"
76
+ },
77
+ "bugs": "https://github.com/es-joy/jsoe/issues",
78
+ "license": "MIT",
79
+ "homepage": "https://github.com/es-joy/jsoe#readme",
80
+ "scripts": {
81
+ "eslint": "eslint --ext=js,cjs,md,html .",
82
+ "lint": "npm run eslint --",
83
+ "coverage": "open-cli http://localhost:8086/coverage/lcov-report/",
84
+ "open": "open-cli http://localhost:8086/",
85
+ "start": "node server 8086",
86
+ "start-instrumented": "node server 8086 instrumented",
87
+ "cypress:open": "cypress open",
88
+ "rollup": "rollup -c",
89
+ "instrument-add": "nyc instrument src instrumented",
90
+ "instrument-remove-cache": "rimraf node_modules/.cache",
91
+ "instrument-remove-instrumented": "rimraf instrumented",
92
+ "instrument-remove": "run-p -c instrument-remove-cache instrument-remove-instrumented",
93
+ "copy-pages": "cp node_modules/sceditor/minified/themes/default.min.css vendor/sceditor/minified/themes/default.min.css && cp node_modules/sceditor/minified/sceditor.min.js vendor/sceditor/minified/sceditor.min.js && cp node_modules/sceditor/minified/formats/bbcode.js vendor/sceditor/minified/formats/bbcode.js && cp node_modules/sceditor/minified/formats/xhtml.js vendor/sceditor/minified/formats/xhtml.js",
94
+ "copy-index": "cp src/index-instrumented.html instrumented/index.html",
95
+ "copy": "run-p copy-pages copy-index",
96
+ "instrument": "run-s -c instrument-remove instrument-add copy-index",
97
+ "cypress:log": "ELECTRON_ENABLE_LOGGING=1 cypress run; nyc report",
98
+ "cypress": "cypress run; nyc report",
99
+ "test": "npm run eslint && npm run rollup && npm run cypress"
100
+ }
101
+ }
@@ -0,0 +1,29 @@
1
+ import builtins from 'rollup-plugin-node-builtins';
2
+ import {nodeResolve} from '@rollup/plugin-node-resolve';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+ // import babel from 'rollup-plugin-babel';
5
+ // import {terser} from 'rollup-plugin-terser';
6
+
7
+ export default {
8
+ input: 'node_modules/fast-deep-equal/es6/index.js',
9
+ output: {
10
+ file: 'src/deepEqual.js',
11
+ format: 'es',
12
+ name: 'deepEqual'
13
+ },
14
+ plugins: [
15
+ /*
16
+ babel(),
17
+ terser({
18
+ // Needed for Typeson's `Undefined` and other constructor detection
19
+ keep_fnames: true,
20
+ keep_classnames: true // Keep in case implementing above as classes
21
+ }),
22
+ */
23
+ builtins(),
24
+ nodeResolve(),
25
+ commonjs({
26
+ include: 'node_modules/**'
27
+ })
28
+ ]
29
+ };
package/server.js ADDED
@@ -0,0 +1,25 @@
1
+ import http from 'http';
2
+ import statik from '@brettz9/node-static';
3
+
4
+ const port = process.argv[2];
5
+
6
+ const instrumented = process.argv[3];
7
+
8
+ const fileServer = new statik.Server();
9
+
10
+ http.createServer(function (request, response) {
11
+ request.addListener('end', function () {
12
+ fileServer.serve(request, response, function (e, res) {
13
+ if (e && (e.status === 404)) { // If the file wasn't found
14
+ fileServer.serveFile(
15
+ instrumented === 'instrumented'
16
+ ? '/instrumented/index.html'
17
+ : '/index.html',
18
+ 200, {}, request, response
19
+ );
20
+ }
21
+ });
22
+ }).resume();
23
+ }).listen(port);
24
+
25
+ console.log(`Listening on port ${port}`);
@@ -0,0 +1,72 @@
1
+ function getDefaultExportFromCjs (x) {
2
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3
+ }
4
+
5
+ var es6 = function equal(a, b) {
6
+ if (a === b) return true;
7
+
8
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
9
+ if (a.constructor !== b.constructor) return false;
10
+
11
+ var length, i, keys;
12
+ if (Array.isArray(a)) {
13
+ length = a.length;
14
+ if (length != b.length) return false;
15
+ for (i = length; i-- !== 0;)
16
+ if (!equal(a[i], b[i])) return false;
17
+ return true;
18
+ }
19
+
20
+
21
+ if ((a instanceof Map) && (b instanceof Map)) {
22
+ if (a.size !== b.size) return false;
23
+ for (i of a.entries())
24
+ if (!b.has(i[0])) return false;
25
+ for (i of a.entries())
26
+ if (!equal(i[1], b.get(i[0]))) return false;
27
+ return true;
28
+ }
29
+
30
+ if ((a instanceof Set) && (b instanceof Set)) {
31
+ if (a.size !== b.size) return false;
32
+ for (i of a.entries())
33
+ if (!b.has(i[0])) return false;
34
+ return true;
35
+ }
36
+
37
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
38
+ length = a.length;
39
+ if (length != b.length) return false;
40
+ for (i = length; i-- !== 0;)
41
+ if (a[i] !== b[i]) return false;
42
+ return true;
43
+ }
44
+
45
+
46
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
47
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
48
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
49
+
50
+ keys = Object.keys(a);
51
+ length = keys.length;
52
+ if (length !== Object.keys(b).length) return false;
53
+
54
+ for (i = length; i-- !== 0;)
55
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
56
+
57
+ for (i = length; i-- !== 0;) {
58
+ var key = keys[i];
59
+
60
+ if (!equal(a[key], b[key])) return false;
61
+ }
62
+
63
+ return true;
64
+ }
65
+
66
+ // true if both NaN, false otherwise
67
+ return a!==a && b!==b;
68
+ };
69
+
70
+ var index = /*@__PURE__*/getDefaultExportFromCjs(es6);
71
+
72
+ export { index as default };
@@ -0,0 +1,66 @@
1
+ import * as structuredCloning from './structuredCloning.js';
2
+
3
+ // Todo (low): Support ArrayBuffer
4
+ /**
5
+ * @returns {string[]}
6
+ */
7
+ export const types = () => [
8
+ 'number', 'Infinities', 'string', 'ValidDate', 'array'
9
+ ];
10
+
11
+ // A hack until we simply pass in our own types or do own parsing
12
+
13
+ /**
14
+ * @param {string} newType
15
+ * @param {Date|GenericArray} value
16
+ * @returns {boolean}
17
+ */
18
+ export const testInvalid = (newType, value) => {
19
+ switch (newType) {
20
+ /* istanbul ignore next -- Shouldn't occur as it is a preset */
21
+ case 'Infinities':
22
+ /* istanbul ignore next -- Shouldn't occur as it is a preset */
23
+ return Number.isNaN(value);
24
+ case 'ValidDate':
25
+ return Number.isNaN(value.getTime());
26
+ case 'array':
27
+ return Object.keys(value).length !== value.length;
28
+ /* istanbul ignore next -- Shouldn't occur */
29
+ default:
30
+ /* istanbul ignore next -- Shouldn't occur */
31
+ return undefined; // Todo: Should this throw?
32
+ }
33
+ };
34
+
35
+ /**
36
+ * @param {string} typesonType
37
+ * @returns {string}
38
+ */
39
+ export const convertFromTypeson = (typesonType) => {
40
+ return {
41
+ SpecialNumber: 'Infinities', // This shouldn't occur as it is a preset
42
+ date: 'ValidDate',
43
+ // sparseArrays: 'array',
44
+ arrayNonindexKeys: 'array'
45
+ }[typesonType];
46
+ };
47
+
48
+ /**
49
+ * @type {FormatIterator}
50
+ */
51
+ export const iterate = (records, stateObj) => {
52
+ stateObj.format = 'indexedDBKey';
53
+ return structuredCloning.iterate(records, stateObj);
54
+ };
55
+
56
+ /**
57
+ * @param {"array"|undefined} state
58
+ * @returns {undefined|string[]}
59
+ */
60
+ export const getTypesForState = function (state) {
61
+ if (!state || ['array'].includes(state)) {
62
+ return this.types();
63
+ }
64
+ /* istanbul ignore next -- Can't be object, so shouldn't reach here */
65
+ return undefined; // Todo: Should this throw?
66
+ };
@@ -0,0 +1,64 @@
1
+ import * as structuredCloning from './structuredCloning.js';
2
+
3
+ /**
4
+ * @returns {string[]}
5
+ */
6
+ export const types = () => [
7
+ 'null', 'true', 'false', 'number', 'string', 'array', 'object'
8
+ ];
9
+
10
+ /**
11
+ * @type {FormatIterator}
12
+ */
13
+ export const iterate = (records, stateObj) => {
14
+ // Todo (low): Add a more optimal (`JSON.stringify`-based iterator)
15
+ const recs = records;
16
+ // I believe this escaping should be by Typeson itself
17
+ // if (records && typeof records === 'object' && records.$types) {
18
+ // recs = {$: records, $types: true};
19
+ // }
20
+ stateObj.format = 'json';
21
+ return structuredCloning.iterate(recs, stateObj);
22
+ };
23
+
24
+ // A hack until we simply pass in our own types or do own parsing
25
+ /**
26
+ * @param {string} typesonType
27
+ * @returns {string}
28
+ */
29
+ export const convertFromTypeson = (typesonType) => {
30
+ return {
31
+ // sparseArrays: 'array',
32
+ arrayNonindexKeys: 'array'
33
+ }[typesonType];
34
+ };
35
+
36
+ /**
37
+ * @param {string} newType
38
+ * @param {GenericArray} value
39
+ * @returns {boolean|undefined}
40
+ */
41
+ export const testInvalid = (newType, value) => {
42
+ switch (newType) {
43
+ case 'array':
44
+ return Object.keys(value).length !== value.length;
45
+ /* istanbul ignore next -- Shouldn't occur */
46
+ default:
47
+ /* istanbul ignore next -- Shouldn't occur */
48
+ return undefined; // Todo: Fix?
49
+ }
50
+ };
51
+
52
+ /**
53
+ * @param {string} state
54
+ * @returns {string[]|undefined}
55
+ */
56
+ export const getTypesForState = function (state) {
57
+ /* istanbul ignore else -- No other states apparently */
58
+ if (!state || ['array', 'object'].includes(state)) {
59
+ return this.types();
60
+ }
61
+ // Todo: Should this throw?
62
+ /* istanbul ignore next -- No other states apparently */
63
+ return undefined;
64
+ };
@@ -0,0 +1,20 @@
1
+ import * as structuredCloning from './structuredCloning.js';
2
+
3
+ /**
4
+ * @type {FormatIterator}
5
+ */
6
+ export const iterate = (records, stateObj) => {
7
+ console.log('records', records, stateObj);
8
+ stateObj.format = 'schemaAndArbitrary';
9
+ return structuredCloning.iterate(records, stateObj);
10
+ };
11
+
12
+ /**
13
+ * @param {string} state
14
+ * @returns {string[]}
15
+ */
16
+ export const getTypesForState = (state) => {
17
+ return structuredCloning.getTypesForState.call(
18
+ this, state
19
+ );
20
+ };