@pixerate/editor 0.153.0 → 0.155.0
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.
- package/dist/animation-editor/index.cjs +2 -3
- package/dist/animation-editor/index.js +1 -2
- package/dist/canvas/editorDocument.d.cts +59 -0
- package/dist/canvas/editorDocument.d.ts +59 -0
- package/dist/canvas/index.cjs +125 -16
- package/dist/canvas/index.d.cts +1 -0
- package/dist/canvas/index.d.ts +1 -0
- package/dist/canvas/index.js +112 -3
- package/dist/chart/index.cjs +2 -3
- package/dist/chart/index.js +1 -2
- package/dist/chunk-M4MIZPQI.cjs +393 -0
- package/dist/chunk-NHLYK3AX.js +393 -0
- package/dist/{chunk-XFDQEAOS.cjs → chunk-RQCMSEM5.cjs} +2 -2
- package/dist/{chunk-BCY22GBH.js → chunk-SDHZG5TF.js} +1 -1
- package/dist/{chunk-HVX35M2I.cjs → chunk-WI7QJA7A.cjs} +2 -2
- package/dist/{chunk-4J4MC3F5.js → chunk-YXOW456B.js} +1 -1
- package/dist/diagram/index.cjs +2 -3
- package/dist/diagram/index.js +1 -2
- package/dist/image-editor/controller.d.cts +8 -0
- package/dist/image-editor/controller.d.ts +8 -0
- package/dist/image-editor/editorDocument.d.cts +16 -0
- package/dist/image-editor/editorDocument.d.ts +16 -0
- package/dist/image-editor/index.cjs +102 -52
- package/dist/image-editor/index.d.cts +1 -0
- package/dist/image-editor/index.d.ts +1 -0
- package/dist/image-editor/index.js +51 -1
- package/dist/index.cjs +4 -5
- package/dist/index.js +2 -3
- package/dist/paint-editor/controller.d.cts +8 -0
- package/dist/paint-editor/controller.d.ts +8 -0
- package/dist/paint-editor/editorDocument.d.cts +17 -0
- package/dist/paint-editor/editorDocument.d.ts +17 -0
- package/dist/paint-editor/index.cjs +74 -18
- package/dist/paint-editor/index.d.cts +1 -0
- package/dist/paint-editor/index.d.ts +1 -0
- package/dist/paint-editor/index.js +58 -2
- package/dist/parameters/index.cjs +2 -3
- package/dist/parameters/index.js +1 -2
- package/dist/persistence/assets.d.cts +51 -0
- package/dist/persistence/assets.d.ts +51 -0
- package/dist/persistence/editorDocument.d.cts +12 -0
- package/dist/persistence/editorDocument.d.ts +12 -0
- package/dist/persistence/index.cjs +32 -8
- package/dist/persistence/index.d.cts +1 -0
- package/dist/persistence/index.d.ts +1 -0
- package/dist/persistence/index.js +34 -10
- package/dist/spreadsheet/index.cjs +3 -4
- package/dist/spreadsheet/index.js +2 -3
- package/dist/tokens/index.cjs +3 -4
- package/dist/tokens/index.js +2 -3
- package/dist/vector/index.cjs +2 -3
- package/dist/vector/index.js +1 -2
- package/dist/video-editor/index.cjs +2 -3
- package/dist/video-editor/index.js +1 -2
- package/package.json +1 -1
- package/skills/pixerate-canvas/SKILL.md +14 -0
- package/skills/pixerate-image-editor/SKILL.md +16 -24
- package/skills/pixerate-image-editor/references/smart-objects.md +28 -0
- package/skills/pixerate-paint-editor/SKILL.md +17 -5
- package/dist/chunk-5H2C3QSF.cjs +0 -134
- package/dist/chunk-GNV54DLO.js +0 -134
- package/dist/chunk-L5OWG2NA.cjs +0 -135
- package/dist/chunk-WHKNYFM2.js +0 -135
package/dist/chunk-5H2C3QSF.cjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkL5OWG2NAcjs = require('./chunk-L5OWG2NA.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _chunk2BSBFBOAcjs = require('./chunk-2BSBFBOA.cjs');
|
|
8
|
-
|
|
9
|
-
// src/persistence/editorDocument.ts
|
|
10
|
-
var EditorDocumentLoadError = class extends Error {
|
|
11
|
-
/** The `LoadReport` when the input was a file that could not be migrated. */
|
|
12
|
-
|
|
13
|
-
constructor(message, report) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "EditorDocumentLoadError";
|
|
16
|
-
this.report = report;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var EDITOR_DOCUMENT_FORMAT = "pixerate.editor-document";
|
|
20
|
-
var KIND = /^[a-z][a-z0-9_]*$/;
|
|
21
|
-
function isEditorDocumentFile(value) {
|
|
22
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
23
|
-
const v = value;
|
|
24
|
-
return v.format === EDITOR_DOCUMENT_FORMAT && typeof v.kind === "string" && typeof v.formatVersion === "number" && "document" in v;
|
|
25
|
-
}
|
|
26
|
-
function toEditorDocumentFile(doc, name) {
|
|
27
|
-
return {
|
|
28
|
-
format: EDITOR_DOCUMENT_FORMAT,
|
|
29
|
-
kind: doc.kind,
|
|
30
|
-
formatVersion: doc.formatVersion,
|
|
31
|
-
...name ? { name } : {},
|
|
32
|
-
document: doc.getDocument()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function serializeEditorDocument(doc, options = {}) {
|
|
36
|
-
return JSON.stringify(toEditorDocumentFile(doc, options.name), null, options.space);
|
|
37
|
-
}
|
|
38
|
-
function parseEditorDocument(text, options = {}) {
|
|
39
|
-
let value;
|
|
40
|
-
try {
|
|
41
|
-
value = _chunk2BSBFBOAcjs.stripPrototypeKeys.call(void 0, JSON.parse(text));
|
|
42
|
-
} catch (error) {
|
|
43
|
-
throw new EditorDocumentLoadError(`The file is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
|
-
}
|
|
45
|
-
if (!isEditorDocumentFile(value)) {
|
|
46
|
-
throw new EditorDocumentLoadError(`The file is not a saved editor document (expected "format": "${EDITOR_DOCUMENT_FORMAT}").`);
|
|
47
|
-
}
|
|
48
|
-
if (options.kind && value.kind !== options.kind) {
|
|
49
|
-
throw new EditorDocumentLoadError(`The file is a ${value.kind} document, not a ${options.kind} document.`);
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
function defineEditorDocument(spec) {
|
|
54
|
-
if (!KIND.test(spec.kind)) throw new Error(`Editor document kind "${spec.kind}" must match ${KIND}.`);
|
|
55
|
-
const formatVersion = _nullishCoalesce(spec.formatVersion, () => ( 1));
|
|
56
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
57
|
-
let revision = 0;
|
|
58
|
-
let unsubscribe = null;
|
|
59
|
-
let connected = false;
|
|
60
|
-
const connect = () => {
|
|
61
|
-
if (unsubscribe) return;
|
|
62
|
-
if (connected) revision++;
|
|
63
|
-
connected = true;
|
|
64
|
-
unsubscribe = spec.subscribe(() => {
|
|
65
|
-
revision++;
|
|
66
|
-
listeners.forEach((listener) => {
|
|
67
|
-
try {
|
|
68
|
-
listener();
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(`[${spec.kind} document] Error in change listener:`, error);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
connect();
|
|
76
|
-
const unwrap = (input) => {
|
|
77
|
-
if (!isEditorDocumentFile(input)) return { document: input, report: _chunkL5OWG2NAcjs.createLoadReport.call(void 0, { version: formatVersion }) };
|
|
78
|
-
if (input.kind !== spec.kind) throw new EditorDocumentLoadError(`This is a ${input.kind} document; it cannot be opened in the ${spec.kind} editor.`);
|
|
79
|
-
const steps = Object.fromEntries(
|
|
80
|
-
Object.entries(_nullishCoalesce(spec.migrations, () => ( {}))).map(([v, step]) => [v, (w) => ({ ...w, document: step(w.document) })])
|
|
81
|
-
);
|
|
82
|
-
const { doc, report } = _chunkL5OWG2NAcjs.migrateDocument.call(void 0,
|
|
83
|
-
{ formatVersion: input.formatVersion, document: input.document },
|
|
84
|
-
{ currentVersion: formatVersion, versionKey: "formatVersion", steps }
|
|
85
|
-
);
|
|
86
|
-
if (report.readOnly) throw new EditorDocumentLoadError(`Cannot open the ${spec.kind} document: ${report.readOnly.message}.`, report);
|
|
87
|
-
return { document: doc.document, report };
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
kind: spec.kind,
|
|
91
|
-
formatVersion,
|
|
92
|
-
recordsLoads: spec.recordsLoads !== false,
|
|
93
|
-
getDocument: () => spec.get(),
|
|
94
|
-
loadDocument(input, options = {}) {
|
|
95
|
-
const { document, report } = unwrap(input);
|
|
96
|
-
if (document === void 0 || document === null) throw new EditorDocumentLoadError(`No ${spec.kind} document was given.`);
|
|
97
|
-
try {
|
|
98
|
-
const result = spec.load(document, { history: _nullishCoalesce(options.history, () => ( "reset")) });
|
|
99
|
-
if (_optionalChain([result, 'optionalAccess', _ => _.problems, 'optionalAccess', _2 => _2.length])) report.problems.push(...result.problems);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (error instanceof EditorDocumentLoadError) throw error;
|
|
102
|
-
throw new EditorDocumentLoadError(error instanceof Error ? error.message : String(error));
|
|
103
|
-
}
|
|
104
|
-
return report;
|
|
105
|
-
},
|
|
106
|
-
revision: () => {
|
|
107
|
-
connect();
|
|
108
|
-
return revision;
|
|
109
|
-
},
|
|
110
|
-
subscribe(listener) {
|
|
111
|
-
connect();
|
|
112
|
-
listeners.add(listener);
|
|
113
|
-
return () => {
|
|
114
|
-
listeners.delete(listener);
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
history: spec.history,
|
|
118
|
-
readOnly: () => _nullishCoalesce(_optionalChain([spec, 'access', _3 => _3.readOnly, 'optionalCall', _4 => _4()]), () => ( false)),
|
|
119
|
-
destroy() {
|
|
120
|
-
_optionalChain([unsubscribe, 'optionalCall', _5 => _5()]);
|
|
121
|
-
unsubscribe = null;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
exports.EditorDocumentLoadError = EditorDocumentLoadError; exports.EDITOR_DOCUMENT_FORMAT = EDITOR_DOCUMENT_FORMAT; exports.isEditorDocumentFile = isEditorDocumentFile; exports.toEditorDocumentFile = toEditorDocumentFile; exports.serializeEditorDocument = serializeEditorDocument; exports.parseEditorDocument = parseEditorDocument; exports.defineEditorDocument = defineEditorDocument;
|
package/dist/chunk-GNV54DLO.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createLoadReport,
|
|
3
|
-
migrateDocument
|
|
4
|
-
} from "./chunk-WHKNYFM2.js";
|
|
5
|
-
import {
|
|
6
|
-
stripPrototypeKeys
|
|
7
|
-
} from "./chunk-HF5QZS7Z.js";
|
|
8
|
-
|
|
9
|
-
// src/persistence/editorDocument.ts
|
|
10
|
-
var EditorDocumentLoadError = class extends Error {
|
|
11
|
-
/** The `LoadReport` when the input was a file that could not be migrated. */
|
|
12
|
-
report;
|
|
13
|
-
constructor(message, report) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "EditorDocumentLoadError";
|
|
16
|
-
this.report = report;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var EDITOR_DOCUMENT_FORMAT = "pixerate.editor-document";
|
|
20
|
-
var KIND = /^[a-z][a-z0-9_]*$/;
|
|
21
|
-
function isEditorDocumentFile(value) {
|
|
22
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
23
|
-
const v = value;
|
|
24
|
-
return v.format === EDITOR_DOCUMENT_FORMAT && typeof v.kind === "string" && typeof v.formatVersion === "number" && "document" in v;
|
|
25
|
-
}
|
|
26
|
-
function toEditorDocumentFile(doc, name) {
|
|
27
|
-
return {
|
|
28
|
-
format: EDITOR_DOCUMENT_FORMAT,
|
|
29
|
-
kind: doc.kind,
|
|
30
|
-
formatVersion: doc.formatVersion,
|
|
31
|
-
...name ? { name } : {},
|
|
32
|
-
document: doc.getDocument()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function serializeEditorDocument(doc, options = {}) {
|
|
36
|
-
return JSON.stringify(toEditorDocumentFile(doc, options.name), null, options.space);
|
|
37
|
-
}
|
|
38
|
-
function parseEditorDocument(text, options = {}) {
|
|
39
|
-
let value;
|
|
40
|
-
try {
|
|
41
|
-
value = stripPrototypeKeys(JSON.parse(text));
|
|
42
|
-
} catch (error) {
|
|
43
|
-
throw new EditorDocumentLoadError(`The file is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
44
|
-
}
|
|
45
|
-
if (!isEditorDocumentFile(value)) {
|
|
46
|
-
throw new EditorDocumentLoadError(`The file is not a saved editor document (expected "format": "${EDITOR_DOCUMENT_FORMAT}").`);
|
|
47
|
-
}
|
|
48
|
-
if (options.kind && value.kind !== options.kind) {
|
|
49
|
-
throw new EditorDocumentLoadError(`The file is a ${value.kind} document, not a ${options.kind} document.`);
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
function defineEditorDocument(spec) {
|
|
54
|
-
if (!KIND.test(spec.kind)) throw new Error(`Editor document kind "${spec.kind}" must match ${KIND}.`);
|
|
55
|
-
const formatVersion = spec.formatVersion ?? 1;
|
|
56
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
57
|
-
let revision = 0;
|
|
58
|
-
let unsubscribe = null;
|
|
59
|
-
let connected = false;
|
|
60
|
-
const connect = () => {
|
|
61
|
-
if (unsubscribe) return;
|
|
62
|
-
if (connected) revision++;
|
|
63
|
-
connected = true;
|
|
64
|
-
unsubscribe = spec.subscribe(() => {
|
|
65
|
-
revision++;
|
|
66
|
-
listeners.forEach((listener) => {
|
|
67
|
-
try {
|
|
68
|
-
listener();
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(`[${spec.kind} document] Error in change listener:`, error);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
connect();
|
|
76
|
-
const unwrap = (input) => {
|
|
77
|
-
if (!isEditorDocumentFile(input)) return { document: input, report: createLoadReport({ version: formatVersion }) };
|
|
78
|
-
if (input.kind !== spec.kind) throw new EditorDocumentLoadError(`This is a ${input.kind} document; it cannot be opened in the ${spec.kind} editor.`);
|
|
79
|
-
const steps = Object.fromEntries(
|
|
80
|
-
Object.entries(spec.migrations ?? {}).map(([v, step]) => [v, (w) => ({ ...w, document: step(w.document) })])
|
|
81
|
-
);
|
|
82
|
-
const { doc, report } = migrateDocument(
|
|
83
|
-
{ formatVersion: input.formatVersion, document: input.document },
|
|
84
|
-
{ currentVersion: formatVersion, versionKey: "formatVersion", steps }
|
|
85
|
-
);
|
|
86
|
-
if (report.readOnly) throw new EditorDocumentLoadError(`Cannot open the ${spec.kind} document: ${report.readOnly.message}.`, report);
|
|
87
|
-
return { document: doc.document, report };
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
kind: spec.kind,
|
|
91
|
-
formatVersion,
|
|
92
|
-
recordsLoads: spec.recordsLoads !== false,
|
|
93
|
-
getDocument: () => spec.get(),
|
|
94
|
-
loadDocument(input, options = {}) {
|
|
95
|
-
const { document, report } = unwrap(input);
|
|
96
|
-
if (document === void 0 || document === null) throw new EditorDocumentLoadError(`No ${spec.kind} document was given.`);
|
|
97
|
-
try {
|
|
98
|
-
const result = spec.load(document, { history: options.history ?? "reset" });
|
|
99
|
-
if (result?.problems?.length) report.problems.push(...result.problems);
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (error instanceof EditorDocumentLoadError) throw error;
|
|
102
|
-
throw new EditorDocumentLoadError(error instanceof Error ? error.message : String(error));
|
|
103
|
-
}
|
|
104
|
-
return report;
|
|
105
|
-
},
|
|
106
|
-
revision: () => {
|
|
107
|
-
connect();
|
|
108
|
-
return revision;
|
|
109
|
-
},
|
|
110
|
-
subscribe(listener) {
|
|
111
|
-
connect();
|
|
112
|
-
listeners.add(listener);
|
|
113
|
-
return () => {
|
|
114
|
-
listeners.delete(listener);
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
history: spec.history,
|
|
118
|
-
readOnly: () => spec.readOnly?.() ?? false,
|
|
119
|
-
destroy() {
|
|
120
|
-
unsubscribe?.();
|
|
121
|
-
unsubscribe = null;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export {
|
|
127
|
-
EditorDocumentLoadError,
|
|
128
|
-
EDITOR_DOCUMENT_FORMAT,
|
|
129
|
-
isEditorDocumentFile,
|
|
130
|
-
toEditorDocumentFile,
|
|
131
|
-
serializeEditorDocument,
|
|
132
|
-
parseEditorDocument,
|
|
133
|
-
defineEditorDocument
|
|
134
|
-
};
|
package/dist/chunk-L5OWG2NA.cjs
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunk2BSBFBOAcjs = require('./chunk-2BSBFBOA.cjs');
|
|
5
|
-
|
|
6
|
-
// src/persistence/migrate.ts
|
|
7
|
-
function hasLoadProblems(report) {
|
|
8
|
-
return report.problems.length > 0 || report.readOnly !== null;
|
|
9
|
-
}
|
|
10
|
-
function createLoadReport(partial = {}) {
|
|
11
|
-
return {
|
|
12
|
-
migratedFrom: null,
|
|
13
|
-
version: null,
|
|
14
|
-
problems: [],
|
|
15
|
-
readOnly: null,
|
|
16
|
-
unknownKeys: [],
|
|
17
|
-
...partial
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
-
var deepClone = (value) => typeof structuredClone === "function" ? structuredClone(value) : JSON.parse(JSON.stringify(value));
|
|
22
|
-
function toObject(json) {
|
|
23
|
-
let value = json;
|
|
24
|
-
if (typeof json === "string") {
|
|
25
|
-
try {
|
|
26
|
-
value = JSON.parse(json);
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return isObject(value) ? _chunk2BSBFBOAcjs.stripPrototypeKeys.call(void 0, deepClone(value)) : void 0;
|
|
32
|
-
}
|
|
33
|
-
function migrateDocument(json, options) {
|
|
34
|
-
const versionKey = _nullishCoalesce(options.versionKey, () => ( "version"));
|
|
35
|
-
const target = options.currentVersion;
|
|
36
|
-
const original = toObject(json);
|
|
37
|
-
if (!original) {
|
|
38
|
-
return {
|
|
39
|
-
doc: { [versionKey]: target },
|
|
40
|
-
report: createLoadReport({
|
|
41
|
-
readOnly: { kind: "invalid", message: "document is not a JSON object" }
|
|
42
|
-
})
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const raw = original[versionKey];
|
|
46
|
-
const found = typeof raw === "number" && Number.isInteger(raw) && raw >= 0 ? raw : null;
|
|
47
|
-
const from = _nullishCoalesce(_nullishCoalesce(found, () => ( options.missingVersion)), () => ( target));
|
|
48
|
-
const report = createLoadReport({ version: found });
|
|
49
|
-
if (from > target) {
|
|
50
|
-
report.readOnly = {
|
|
51
|
-
kind: "newerVersion",
|
|
52
|
-
version: from,
|
|
53
|
-
supported: target,
|
|
54
|
-
message: `document has version ${from}, newer than the supported ${target}`
|
|
55
|
-
};
|
|
56
|
-
return { doc: original, report };
|
|
57
|
-
}
|
|
58
|
-
if (from === target) {
|
|
59
|
-
original[versionKey] = target;
|
|
60
|
-
return { doc: original, report };
|
|
61
|
-
}
|
|
62
|
-
let doc = deepClone(original);
|
|
63
|
-
for (let step = from; step < target; step++) {
|
|
64
|
-
const fn = _optionalChain([options, 'access', _ => _.steps, 'optionalAccess', _2 => _2[step]]);
|
|
65
|
-
if (!fn) {
|
|
66
|
-
report.readOnly = {
|
|
67
|
-
kind: "migrationFailed",
|
|
68
|
-
from: step,
|
|
69
|
-
message: `no migration step from version ${step}`
|
|
70
|
-
};
|
|
71
|
-
return { doc: original, report };
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
doc = _nullishCoalesce(fn(doc), () => ( doc));
|
|
75
|
-
} catch (error) {
|
|
76
|
-
report.readOnly = {
|
|
77
|
-
kind: "migrationFailed",
|
|
78
|
-
from: step,
|
|
79
|
-
message: `migration from version ${step} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
80
|
-
};
|
|
81
|
-
return { doc: original, report };
|
|
82
|
-
}
|
|
83
|
-
doc[versionKey] = step + 1;
|
|
84
|
-
}
|
|
85
|
-
report.migratedFrom = from;
|
|
86
|
-
return { doc, report };
|
|
87
|
-
}
|
|
88
|
-
function loadSections(doc, sections, options = {}) {
|
|
89
|
-
const source = isObject(doc) ? doc : {};
|
|
90
|
-
const ignore = new Set(_nullishCoalesce(options.ignore, () => ( ["version"])));
|
|
91
|
-
const value = {};
|
|
92
|
-
const problems = [];
|
|
93
|
-
for (const key of Object.keys(sections)) {
|
|
94
|
-
const spec = sections[key];
|
|
95
|
-
const fallback = () => typeof spec.defaults === "function" ? spec.defaults() : spec.defaults;
|
|
96
|
-
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
|
97
|
-
value[key] = fallback();
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
const parsed = spec.parse(source[key]);
|
|
102
|
-
if (parsed === void 0) throw new Error("invalid value");
|
|
103
|
-
value[key] = parsed;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
problems.push({
|
|
106
|
-
section: key,
|
|
107
|
-
message: error instanceof Error ? error.message : String(error)
|
|
108
|
-
});
|
|
109
|
-
value[key] = fallback();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const unknown = {};
|
|
113
|
-
for (const key of Object.keys(source)) {
|
|
114
|
-
if (!(key in sections) && !ignore.has(key) && !_chunk2BSBFBOAcjs.isUnsafeJsonKey.call(void 0, key)) unknown[key] = source[key];
|
|
115
|
-
}
|
|
116
|
-
return { value, problems, unknown };
|
|
117
|
-
}
|
|
118
|
-
function loadDocument(json, sections, options) {
|
|
119
|
-
const { doc, report } = migrateDocument(json, options);
|
|
120
|
-
const ignore = _nullishCoalesce(options.ignore, () => ( [_nullishCoalesce(options.versionKey, () => ( "version"))]));
|
|
121
|
-
const result = loadSections(_optionalChain([report, 'access', _3 => _3.readOnly, 'optionalAccess', _4 => _4.kind]) === "invalid" ? {} : doc, sections, {
|
|
122
|
-
ignore
|
|
123
|
-
});
|
|
124
|
-
report.problems = result.problems;
|
|
125
|
-
report.unknownKeys = Object.keys(result.unknown);
|
|
126
|
-
return { ...result, report };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
exports.hasLoadProblems = hasLoadProblems; exports.createLoadReport = createLoadReport; exports.migrateDocument = migrateDocument; exports.loadSections = loadSections; exports.loadDocument = loadDocument;
|
package/dist/chunk-WHKNYFM2.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isUnsafeJsonKey,
|
|
3
|
-
stripPrototypeKeys
|
|
4
|
-
} from "./chunk-HF5QZS7Z.js";
|
|
5
|
-
|
|
6
|
-
// src/persistence/migrate.ts
|
|
7
|
-
function hasLoadProblems(report) {
|
|
8
|
-
return report.problems.length > 0 || report.readOnly !== null;
|
|
9
|
-
}
|
|
10
|
-
function createLoadReport(partial = {}) {
|
|
11
|
-
return {
|
|
12
|
-
migratedFrom: null,
|
|
13
|
-
version: null,
|
|
14
|
-
problems: [],
|
|
15
|
-
readOnly: null,
|
|
16
|
-
unknownKeys: [],
|
|
17
|
-
...partial
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21
|
-
var deepClone = (value) => typeof structuredClone === "function" ? structuredClone(value) : JSON.parse(JSON.stringify(value));
|
|
22
|
-
function toObject(json) {
|
|
23
|
-
let value = json;
|
|
24
|
-
if (typeof json === "string") {
|
|
25
|
-
try {
|
|
26
|
-
value = JSON.parse(json);
|
|
27
|
-
} catch {
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return isObject(value) ? stripPrototypeKeys(deepClone(value)) : void 0;
|
|
32
|
-
}
|
|
33
|
-
function migrateDocument(json, options) {
|
|
34
|
-
const versionKey = options.versionKey ?? "version";
|
|
35
|
-
const target = options.currentVersion;
|
|
36
|
-
const original = toObject(json);
|
|
37
|
-
if (!original) {
|
|
38
|
-
return {
|
|
39
|
-
doc: { [versionKey]: target },
|
|
40
|
-
report: createLoadReport({
|
|
41
|
-
readOnly: { kind: "invalid", message: "document is not a JSON object" }
|
|
42
|
-
})
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const raw = original[versionKey];
|
|
46
|
-
const found = typeof raw === "number" && Number.isInteger(raw) && raw >= 0 ? raw : null;
|
|
47
|
-
const from = found ?? options.missingVersion ?? target;
|
|
48
|
-
const report = createLoadReport({ version: found });
|
|
49
|
-
if (from > target) {
|
|
50
|
-
report.readOnly = {
|
|
51
|
-
kind: "newerVersion",
|
|
52
|
-
version: from,
|
|
53
|
-
supported: target,
|
|
54
|
-
message: `document has version ${from}, newer than the supported ${target}`
|
|
55
|
-
};
|
|
56
|
-
return { doc: original, report };
|
|
57
|
-
}
|
|
58
|
-
if (from === target) {
|
|
59
|
-
original[versionKey] = target;
|
|
60
|
-
return { doc: original, report };
|
|
61
|
-
}
|
|
62
|
-
let doc = deepClone(original);
|
|
63
|
-
for (let step = from; step < target; step++) {
|
|
64
|
-
const fn = options.steps?.[step];
|
|
65
|
-
if (!fn) {
|
|
66
|
-
report.readOnly = {
|
|
67
|
-
kind: "migrationFailed",
|
|
68
|
-
from: step,
|
|
69
|
-
message: `no migration step from version ${step}`
|
|
70
|
-
};
|
|
71
|
-
return { doc: original, report };
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
doc = fn(doc) ?? doc;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
report.readOnly = {
|
|
77
|
-
kind: "migrationFailed",
|
|
78
|
-
from: step,
|
|
79
|
-
message: `migration from version ${step} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
80
|
-
};
|
|
81
|
-
return { doc: original, report };
|
|
82
|
-
}
|
|
83
|
-
doc[versionKey] = step + 1;
|
|
84
|
-
}
|
|
85
|
-
report.migratedFrom = from;
|
|
86
|
-
return { doc, report };
|
|
87
|
-
}
|
|
88
|
-
function loadSections(doc, sections, options = {}) {
|
|
89
|
-
const source = isObject(doc) ? doc : {};
|
|
90
|
-
const ignore = new Set(options.ignore ?? ["version"]);
|
|
91
|
-
const value = {};
|
|
92
|
-
const problems = [];
|
|
93
|
-
for (const key of Object.keys(sections)) {
|
|
94
|
-
const spec = sections[key];
|
|
95
|
-
const fallback = () => typeof spec.defaults === "function" ? spec.defaults() : spec.defaults;
|
|
96
|
-
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
|
97
|
-
value[key] = fallback();
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
try {
|
|
101
|
-
const parsed = spec.parse(source[key]);
|
|
102
|
-
if (parsed === void 0) throw new Error("invalid value");
|
|
103
|
-
value[key] = parsed;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
problems.push({
|
|
106
|
-
section: key,
|
|
107
|
-
message: error instanceof Error ? error.message : String(error)
|
|
108
|
-
});
|
|
109
|
-
value[key] = fallback();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const unknown = {};
|
|
113
|
-
for (const key of Object.keys(source)) {
|
|
114
|
-
if (!(key in sections) && !ignore.has(key) && !isUnsafeJsonKey(key)) unknown[key] = source[key];
|
|
115
|
-
}
|
|
116
|
-
return { value, problems, unknown };
|
|
117
|
-
}
|
|
118
|
-
function loadDocument(json, sections, options) {
|
|
119
|
-
const { doc, report } = migrateDocument(json, options);
|
|
120
|
-
const ignore = options.ignore ?? [options.versionKey ?? "version"];
|
|
121
|
-
const result = loadSections(report.readOnly?.kind === "invalid" ? {} : doc, sections, {
|
|
122
|
-
ignore
|
|
123
|
-
});
|
|
124
|
-
report.problems = result.problems;
|
|
125
|
-
report.unknownKeys = Object.keys(result.unknown);
|
|
126
|
-
return { ...result, report };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export {
|
|
130
|
-
hasLoadProblems,
|
|
131
|
-
createLoadReport,
|
|
132
|
-
migrateDocument,
|
|
133
|
-
loadSections,
|
|
134
|
-
loadDocument
|
|
135
|
-
};
|