@stonecrop/stonecrop 0.13.14 → 0.15.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/README.md +6 -3
- package/dist/src/doctype.d.ts +42 -7
- package/dist/src/doctype.d.ts.map +1 -1
- package/dist/src/doctype.js +77 -18
- package/dist/src/index.d.ts +5 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/registry.d.ts +1 -1
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +46 -38
- package/dist/src/schema-validator.d.ts.map +1 -1
- package/dist/src/schema-validator.js +44 -47
- package/dist/src/stonecrop.d.ts +0 -6
- package/dist/src/stonecrop.d.ts.map +1 -1
- package/dist/src/stores/index.d.ts +2 -0
- package/dist/src/stores/index.d.ts.map +1 -1
- package/dist/src/stores/index.js +1 -0
- package/dist/src/stores/operation-log.d.ts +0 -6
- package/dist/src/stores/operation-log.d.ts.map +1 -1
- package/dist/src/stores/operation-log.js +0 -1
- package/dist/src/stores/validation.d.ts +83 -0
- package/dist/src/stores/validation.d.ts.map +1 -0
- package/dist/src/stores/validation.js +104 -0
- package/dist/src/types/doctype.d.ts +1 -1
- package/dist/src/types/doctype.d.ts.map +1 -1
- package/dist/src/types/operation-log.d.ts +0 -2
- package/dist/src/types/operation-log.d.ts.map +1 -1
- package/dist/stonecrop.d.ts +166 -22
- package/dist/stonecrop.js +5235 -1950
- package/dist/stonecrop.js.map +1 -1
- package/package.json +23 -23
- package/src/client-handler.ts +55 -0
- package/src/doctype.ts +83 -22
- package/src/index.ts +12 -0
- package/src/registry.ts +45 -40
- package/src/schema-validator.ts +52 -48
- package/src/stores/index.ts +2 -0
- package/src/stores/operation-log.ts +0 -1
- package/src/stores/validation.ts +138 -0
- package/src/types/doctype.ts +1 -1
- package/src/types/operation-log.ts +0 -3
- package/dist/composable.js +0 -1
- package/dist/composables/lazy-link.js +0 -125
- package/dist/composables/operation-log.js +0 -224
- package/dist/composables/stonecrop.js +0 -504
- package/dist/composables/use-lazy-link-state.js +0 -125
- package/dist/composables/use-stonecrop.js +0 -476
- package/dist/doctype.js +0 -242
- package/dist/exceptions.js +0 -16
- package/dist/field-triggers.js +0 -575
- package/dist/index.js +0 -27
- package/dist/operation-log-DB-dGNT9.js +0 -593
- package/dist/operation-log-DB-dGNT9.js.map +0 -1
- package/dist/plugins/index.js +0 -99
- package/dist/registry.js +0 -423
- package/dist/schema-validator.js +0 -407
- package/dist/src/composable.d.ts +0 -11
- package/dist/src/composable.d.ts.map +0 -1
- package/dist/src/composable.js +0 -477
- package/dist/src/composables/use-lazy-link-state.d.ts +0 -25
- package/dist/src/composables/use-lazy-link-state.d.ts.map +0 -1
- package/dist/src/composables/use-stonecrop.d.ts +0 -93
- package/dist/src/composables/use-stonecrop.d.ts.map +0 -1
- package/dist/src/composables/useNestedSchema.d.ts +0 -110
- package/dist/src/composables/useNestedSchema.d.ts.map +0 -1
- package/dist/src/composables/useNestedSchema.js +0 -155
- package/dist/src/stores/data.d.ts +0 -11
- package/dist/src/stores/data.d.ts.map +0 -1
- package/dist/src/stores/xstate.d.ts +0 -31
- package/dist/src/stores/xstate.d.ts.map +0 -1
- package/dist/src/tsdoc-metadata.json +0 -11
- package/dist/src/utils.d.ts +0 -24
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/stonecrop.css +0 -1
- package/dist/stonecrop.umd.cjs +0 -6
- package/dist/stonecrop.umd.cjs.map +0 -1
- package/dist/stores/data.js +0 -7
- package/dist/stores/hst.js +0 -496
- package/dist/stores/index.js +0 -12
- package/dist/stores/operation-log.js +0 -580
- package/dist/stores/xstate.js +0 -29
- package/dist/tests/setup.d.ts +0 -5
- package/dist/tests/setup.d.ts.map +0 -1
- package/dist/tests/setup.js +0 -15
- package/dist/types/composable.js +0 -0
- package/dist/types/doctype.js +0 -0
- package/dist/types/field-triggers.js +0 -4
- package/dist/types/hst.js +0 -0
- package/dist/types/index.js +0 -10
- package/dist/types/operation-log.js +0 -0
- package/dist/types/plugin.js +0 -0
- package/dist/types/registry.js +0 -0
- package/dist/types/schema-validator.js +0 -13
- package/dist/types/stonecrop.js +0 -0
- package/dist/utils.js +0 -46
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Validates Stonecrop schemas for integrity and consistency
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
|
+
import { componentLinkExpansion } from '@stonecrop/schema';
|
|
6
7
|
import { getGlobalTriggerEngine } from './field-triggers';
|
|
7
8
|
import { ValidationSeverity } from './types/schema-validator';
|
|
8
9
|
/**
|
|
@@ -40,7 +41,7 @@ export class SchemaValidator {
|
|
|
40
41
|
const schemaArray = schema ? (Array.isArray(schema) ? schema : schema.toArray()) : [];
|
|
41
42
|
// Validate required properties
|
|
42
43
|
if (this.options.validateRequiredProperties) {
|
|
43
|
-
issues.push(...this.validateRequiredProperties(doctype, schemaArray));
|
|
44
|
+
issues.push(...this.validateRequiredProperties(doctype, schemaArray, links));
|
|
44
45
|
}
|
|
45
46
|
// Validate Link field targets
|
|
46
47
|
if (this.options.validateLinkTargets && this.options.registry) {
|
|
@@ -76,7 +77,7 @@ export class SchemaValidator {
|
|
|
76
77
|
* Validates that required schema properties are present
|
|
77
78
|
* @internal
|
|
78
79
|
*/
|
|
79
|
-
validateRequiredProperties(doctype, schema) {
|
|
80
|
+
validateRequiredProperties(doctype, schema, links) {
|
|
80
81
|
const issues = [];
|
|
81
82
|
for (const field of schema) {
|
|
82
83
|
// Check for fieldname
|
|
@@ -90,19 +91,37 @@ export class SchemaValidator {
|
|
|
90
91
|
});
|
|
91
92
|
continue;
|
|
92
93
|
}
|
|
93
|
-
//
|
|
94
|
-
|
|
94
|
+
// A value field renders through its component and has no other rendering axis;
|
|
95
|
+
// fieldset/table have their own structural requirements.
|
|
96
|
+
if (field.kind === 'field' && !field.component) {
|
|
95
97
|
issues.push({
|
|
96
98
|
severity: ValidationSeverity.ERROR,
|
|
97
|
-
rule: 'required-component
|
|
98
|
-
message: `Field "${field.fieldname}" must have
|
|
99
|
+
rule: 'required-component',
|
|
100
|
+
message: `Field "${field.fieldname}" must have a component property`,
|
|
101
|
+
doctype,
|
|
102
|
+
fieldname: field.fieldname,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// A link component with nothing to point at renders an empty picker, which looks exactly
|
|
106
|
+
// like a record that has no value — so this fails silently at runtime rather than loudly.
|
|
107
|
+
// Link-ness comes from `doctype` or a `links` declaration, so this is a field that named
|
|
108
|
+
// a link component and gave it neither.
|
|
109
|
+
if (field.kind === 'field' &&
|
|
110
|
+
componentLinkExpansion(field.component) &&
|
|
111
|
+
!field.doctype &&
|
|
112
|
+
!links?.[field.fieldname]) {
|
|
113
|
+
issues.push({
|
|
114
|
+
severity: ValidationSeverity.ERROR,
|
|
115
|
+
rule: 'link-component-without-doctype',
|
|
116
|
+
message: `Field "${field.fieldname}" renders with "${field.component}", which is a link component, ` +
|
|
117
|
+
`but has no \`doctype\` to name its target`,
|
|
99
118
|
doctype,
|
|
100
119
|
fieldname: field.fieldname,
|
|
101
120
|
});
|
|
102
121
|
}
|
|
103
122
|
// Validate nested schemas recursively (fieldset only; table columns are ColumnSchema not DoctypeField)
|
|
104
123
|
if (field.kind === 'fieldset') {
|
|
105
|
-
issues.push(...this.validateRequiredProperties(doctype, field.schema));
|
|
124
|
+
issues.push(...this.validateRequiredProperties(doctype, field.schema, links));
|
|
106
125
|
}
|
|
107
126
|
}
|
|
108
127
|
return issues;
|
|
@@ -114,29 +133,14 @@ export class SchemaValidator {
|
|
|
114
133
|
validateLinkFields(doctype, schema, registry) {
|
|
115
134
|
const issues = [];
|
|
116
135
|
for (const field of schema) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
fieldname: field.fieldname,
|
|
126
|
-
});
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const targetDoctype = typeof options === 'string' ? options : '';
|
|
130
|
-
if (!targetDoctype) {
|
|
131
|
-
issues.push({
|
|
132
|
-
severity: ValidationSeverity.ERROR,
|
|
133
|
-
rule: 'link-invalid-options',
|
|
134
|
-
message: `Link field "${field.fieldname}" has invalid options format (expected string doctype name)`,
|
|
135
|
-
doctype,
|
|
136
|
-
fieldname: field.fieldname,
|
|
137
|
-
});
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
136
|
+
// `doctype` is both the link marker and its target, and the schema types it as a
|
|
137
|
+
// non-empty string — so there is no "missing target" or "malformed target" state left
|
|
138
|
+
// to check here. The rules that did (`link-missing-options`, `link-invalid-options`)
|
|
139
|
+
// were removed with the `options`-as-link-target convention; the case they actually
|
|
140
|
+
// guarded — a link component with no target — is now `link-component-without-doctype`,
|
|
141
|
+
// which fires in validateRequiredProperties whether or not a registry is configured.
|
|
142
|
+
if (field.kind === 'field' && field.doctype) {
|
|
143
|
+
const targetDoctype = field.doctype;
|
|
140
144
|
const targetMeta = registry.registry[targetDoctype] || registry.registry[targetDoctype.toLowerCase()];
|
|
141
145
|
if (!targetMeta) {
|
|
142
146
|
issues.push({
|
|
@@ -162,10 +166,10 @@ export class SchemaValidator {
|
|
|
162
166
|
*/
|
|
163
167
|
validateLinkDeclarations(doctype, links, schema, registry) {
|
|
164
168
|
const issues = [];
|
|
165
|
-
// Build a map of
|
|
169
|
+
// Build a map of link fields by fieldname for quick lookup
|
|
166
170
|
const linkFieldsByFieldname = new Map();
|
|
167
171
|
for (const field of schema) {
|
|
168
|
-
if (field.kind === 'field' && field.
|
|
172
|
+
if (field.kind === 'field' && field.doctype) {
|
|
169
173
|
linkFieldsByFieldname.set(field.fieldname, field);
|
|
170
174
|
}
|
|
171
175
|
}
|
|
@@ -223,7 +227,8 @@ export class SchemaValidator {
|
|
|
223
227
|
if (link.fieldname) {
|
|
224
228
|
const linkField = linkFieldsByFieldname.get(link.fieldname);
|
|
225
229
|
if (linkField && linkField.kind === 'field') {
|
|
226
|
-
|
|
230
|
+
// Map membership implies `doctype` is set — that is the map's build condition.
|
|
231
|
+
const linkFieldTarget = linkField.doctype;
|
|
227
232
|
if (linkFieldTarget && linkFieldTarget !== link.target) {
|
|
228
233
|
issues.push({
|
|
229
234
|
severity: ValidationSeverity.ERROR,
|
|
@@ -237,20 +242,12 @@ export class SchemaValidator {
|
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
severity: ValidationSeverity.ERROR,
|
|
247
|
-
rule: 'link-field-without-declaration',
|
|
248
|
-
message: `Link field "${fieldname}" has no corresponding link declaration`,
|
|
249
|
-
doctype,
|
|
250
|
-
fieldname,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
245
|
+
// NOTE: there is deliberately no "every link field needs a declaration" rule. A plain foreign
|
|
246
|
+
// key is a link with no `links` entry — the map is additive, carrying expansion metadata
|
|
247
|
+
// (backlink/fetch/cardinality), and is not required. Such a rule would contradict
|
|
248
|
+
// `Registry.resolveFields`, which resolves undeclared links to inline pickers, and would flag
|
|
249
|
+
// every doctype that mixes an expanded relation with a plain FK (e.g. `country`: a `links`
|
|
250
|
+
// map for states/languages/subdivisions plus a plain `continent` picker).
|
|
254
251
|
return issues;
|
|
255
252
|
}
|
|
256
253
|
/**
|
package/dist/src/stonecrop.d.ts
CHANGED
|
@@ -108,7 +108,6 @@ export declare class Stonecrop {
|
|
|
108
108
|
config: import("vue").Ref<{
|
|
109
109
|
maxOperations?: number | undefined;
|
|
110
110
|
enableCrossTabSync?: boolean | undefined;
|
|
111
|
-
autoSyncInterval?: number | undefined;
|
|
112
111
|
enablePersistence?: boolean | undefined;
|
|
113
112
|
persistenceKeyPrefix?: string | undefined;
|
|
114
113
|
userId?: string | undefined;
|
|
@@ -116,7 +115,6 @@ export declare class Stonecrop {
|
|
|
116
115
|
}, OperationLogConfig | {
|
|
117
116
|
maxOperations?: number | undefined;
|
|
118
117
|
enableCrossTabSync?: boolean | undefined;
|
|
119
|
-
autoSyncInterval?: number | undefined;
|
|
120
118
|
enablePersistence?: boolean | undefined;
|
|
121
119
|
persistenceKeyPrefix?: string | undefined;
|
|
122
120
|
userId?: string | undefined;
|
|
@@ -194,7 +192,6 @@ export declare class Stonecrop {
|
|
|
194
192
|
config: import("vue").Ref<{
|
|
195
193
|
maxOperations?: number | undefined;
|
|
196
194
|
enableCrossTabSync?: boolean | undefined;
|
|
197
|
-
autoSyncInterval?: number | undefined;
|
|
198
195
|
enablePersistence?: boolean | undefined;
|
|
199
196
|
persistenceKeyPrefix?: string | undefined;
|
|
200
197
|
userId?: string | undefined;
|
|
@@ -202,7 +199,6 @@ export declare class Stonecrop {
|
|
|
202
199
|
}, OperationLogConfig | {
|
|
203
200
|
maxOperations?: number | undefined;
|
|
204
201
|
enableCrossTabSync?: boolean | undefined;
|
|
205
|
-
autoSyncInterval?: number | undefined;
|
|
206
202
|
enablePersistence?: boolean | undefined;
|
|
207
203
|
persistenceKeyPrefix?: string | undefined;
|
|
208
204
|
userId?: string | undefined;
|
|
@@ -280,7 +276,6 @@ export declare class Stonecrop {
|
|
|
280
276
|
config: import("vue").Ref<{
|
|
281
277
|
maxOperations?: number | undefined;
|
|
282
278
|
enableCrossTabSync?: boolean | undefined;
|
|
283
|
-
autoSyncInterval?: number | undefined;
|
|
284
279
|
enablePersistence?: boolean | undefined;
|
|
285
280
|
persistenceKeyPrefix?: string | undefined;
|
|
286
281
|
userId?: string | undefined;
|
|
@@ -288,7 +283,6 @@ export declare class Stonecrop {
|
|
|
288
283
|
}, OperationLogConfig | {
|
|
289
284
|
maxOperations?: number | undefined;
|
|
290
285
|
enableCrossTabSync?: boolean | undefined;
|
|
291
|
-
autoSyncInterval?: number | undefined;
|
|
292
286
|
enablePersistence?: boolean | undefined;
|
|
293
287
|
persistenceKeyPrefix?: string | undefined;
|
|
294
288
|
userId?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEzD;;;GAGG;AACH,qBAAa,SAAS;IACrB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,CAAA;IAEvB,2DAA2D;IAC3D,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,kBAAkB,CAAC,CAAyC;IACpE,OAAO,CAAC,mBAAmB,CAAC,CAA6B;IACzD,OAAO,CAAC,OAAO,CAAC,CAAY;IAE5B,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAG,QAAQ,CAAA;IAE5B;;;;;OAKG;gBACS,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAoB5G;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAInC;;;OAGG;IACH,SAAS,IAAI,UAAU,GAAG,SAAS;IAInC;;;OAGG;IACH,oBAAoB
|
|
1
|
+
{"version":3,"file":"stonecrop.d.ts","sourceRoot":"","sources":["../../src/stonecrop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,OAAO,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;OASG;IACG,cAAc,CACnB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,EAAE,GACd,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAWrE;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;;;OAIG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAOlD;;;OAGG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IA6BnE;;;;;;OAMG;IACH,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IA+B7E;;;;;;;;;OASG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAoB1D;;;;;;;;;;;;;OAaG;IACG,eAAe,CACpB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;KAAE,GAC9C,OAAO,CAAC,IAAI,CAAC;IAgChB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;CA2BzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,IAAI,SAAS,GAAG,SAAS,CAEpD"}
|
|
@@ -3,5 +3,7 @@ declare const hst: HST;
|
|
|
3
3
|
declare const pinia: import("pinia").Pinia;
|
|
4
4
|
export { hst, pinia };
|
|
5
5
|
export { useOperationLogStore } from './operation-log';
|
|
6
|
+
export { useValidationStore } from './validation';
|
|
7
|
+
export type { ValidationError } from './validation';
|
|
6
8
|
export type { HSTNode } from './hst';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,QAAA,MAAM,GAAG,KAAoB,CAAA;AAC7B,QAAA,MAAM,KAAK,uBAAgB,CAAA;AAU3B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,QAAA,MAAM,GAAG,KAAoB,CAAA;AAC7B,QAAA,MAAM,KAAK,uBAAgB,CAAA;AAU3B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,YAAY,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA"}
|
package/dist/src/stores/index.js
CHANGED
|
@@ -60,7 +60,6 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
|
|
|
60
60
|
config: import("vue").Ref<{
|
|
61
61
|
maxOperations?: number | undefined;
|
|
62
62
|
enableCrossTabSync?: boolean | undefined;
|
|
63
|
-
autoSyncInterval?: number | undefined;
|
|
64
63
|
enablePersistence?: boolean | undefined;
|
|
65
64
|
persistenceKeyPrefix?: string | undefined;
|
|
66
65
|
userId?: string | undefined;
|
|
@@ -68,7 +67,6 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
|
|
|
68
67
|
}, OperationLogConfig | {
|
|
69
68
|
maxOperations?: number | undefined;
|
|
70
69
|
enableCrossTabSync?: boolean | undefined;
|
|
71
|
-
autoSyncInterval?: number | undefined;
|
|
72
70
|
enablePersistence?: boolean | undefined;
|
|
73
71
|
persistenceKeyPrefix?: string | undefined;
|
|
74
72
|
userId?: string | undefined;
|
|
@@ -146,7 +144,6 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
|
|
|
146
144
|
config: import("vue").Ref<{
|
|
147
145
|
maxOperations?: number | undefined;
|
|
148
146
|
enableCrossTabSync?: boolean | undefined;
|
|
149
|
-
autoSyncInterval?: number | undefined;
|
|
150
147
|
enablePersistence?: boolean | undefined;
|
|
151
148
|
persistenceKeyPrefix?: string | undefined;
|
|
152
149
|
userId?: string | undefined;
|
|
@@ -154,7 +151,6 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
|
|
|
154
151
|
}, OperationLogConfig | {
|
|
155
152
|
maxOperations?: number | undefined;
|
|
156
153
|
enableCrossTabSync?: boolean | undefined;
|
|
157
|
-
autoSyncInterval?: number | undefined;
|
|
158
154
|
enablePersistence?: boolean | undefined;
|
|
159
155
|
persistenceKeyPrefix?: string | undefined;
|
|
160
156
|
userId?: string | undefined;
|
|
@@ -232,7 +228,6 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
|
|
|
232
228
|
config: import("vue").Ref<{
|
|
233
229
|
maxOperations?: number | undefined;
|
|
234
230
|
enableCrossTabSync?: boolean | undefined;
|
|
235
|
-
autoSyncInterval?: number | undefined;
|
|
236
231
|
enablePersistence?: boolean | undefined;
|
|
237
232
|
persistenceKeyPrefix?: string | undefined;
|
|
238
233
|
userId?: string | undefined;
|
|
@@ -240,7 +235,6 @@ export declare const useOperationLogStore: import("pinia").StoreDefinition<"hst-
|
|
|
240
235
|
}, OperationLogConfig | {
|
|
241
236
|
maxOperations?: number | undefined;
|
|
242
237
|
enableCrossTabSync?: boolean | undefined;
|
|
243
|
-
autoSyncInterval?: number | undefined;
|
|
244
238
|
enablePersistence?: boolean | undefined;
|
|
245
239
|
persistenceKeyPrefix?: string | undefined;
|
|
246
240
|
userId?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-log.d.ts","sourceRoot":"","sources":["../../../src/stores/operation-log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,KAAK,EAEX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,MAAM,wBAAwB,CAAA;AA8F/B;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB
|
|
1
|
+
{"version":3,"file":"operation-log.d.ts","sourceRoot":"","sources":["../../../src/stores/operation-log.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,KAAK,EAEX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,MAAM,wBAAwB,CAAA;AA8F/B;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAyDJ,OAAO,CAAC,kBAAkB,CAAC;8BAkBtB,iBAAiB,WAAU,eAAe;;gCA0DxC,MAAM,KAAG,MAAM,GAAG,IAAI;;kBA2EpC,OAAO,KAAG,OAAO;kBAiDjB,OAAO,KAAG,OAAO;;gCAkEH,MAAM,aAAa,MAAM,KAAG,YAAY,EAAE;uBA1BrD,oBAAoB;oCAmCL,MAAM,UAAU,MAAM;yBAmBnD,MAAM,cACH,MAAM,cACN,MAAM,EAAE,WACZ,SAAS,GAAG,SAAS,GAAG,SAAS,UACjC,MAAM,KACZ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA3SmB,OAAO,CAAC,kBAAkB,CAAC;8BAkBtB,iBAAiB,WAAU,eAAe;;gCA0DxC,MAAM,KAAG,MAAM,GAAG,IAAI;;kBA2EpC,OAAO,KAAG,OAAO;kBAiDjB,OAAO,KAAG,OAAO;;gCAkEH,MAAM,aAAa,MAAM,KAAG,YAAY,EAAE;uBA1BrD,oBAAoB;oCAmCL,MAAM,UAAU,MAAM;yBAmBnD,MAAM,cACH,MAAM,cACN,MAAM,EAAE,WACZ,SAAS,GAAG,SAAS,GAAG,SAAS,UACjC,MAAM,KACZ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA3SmB,OAAO,CAAC,kBAAkB,CAAC;8BAkBtB,iBAAiB,WAAU,eAAe;;gCA0DxC,MAAM,KAAG,MAAM,GAAG,IAAI;;kBA2EpC,OAAO,KAAG,OAAO;kBAiDjB,OAAO,KAAG,OAAO;;gCAkEH,MAAM,aAAa,MAAM,KAAG,YAAY,EAAE;uBA1BrD,oBAAoB;oCAmCL,MAAM,UAAU,MAAM;yBAmBnD,MAAM,cACH,MAAM,cACN,MAAM,EAAE,WACZ,SAAS,GAAG,SAAS,GAAG,SAAS,UACjC,MAAM,KACZ,MAAM;oLA6MR,CAAA"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { TriggerDefinition } from '@stonecrop/schema';
|
|
2
|
+
/**
|
|
3
|
+
* A single validation error contributed by a trigger, displayed on a field.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ValidationError {
|
|
7
|
+
/** The trigger that produced this error — the namespace a re-run clears before repopulating */
|
|
8
|
+
trigger: string;
|
|
9
|
+
/** The fieldname the error displays on (the `setError` target, not necessarily a fired field) */
|
|
10
|
+
field: string;
|
|
11
|
+
/** The message to display */
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reactive per-field validation error store + the advisory field-validation trigger engine.
|
|
16
|
+
*
|
|
17
|
+
* Holds the errors produced by field-validation triggers (see `TriggerDefinition` in
|
|
18
|
+
* `@stonecrop/schema`) and runs a trigger's `clientHandler` on demand. Errors are **namespaced
|
|
19
|
+
* by trigger**: re-running a trigger clears its own prior contributions before repopulating, so a
|
|
20
|
+
* corrected value clears its stale error without disturbing other triggers.
|
|
21
|
+
*
|
|
22
|
+
* The engine is **advisory** and does **no rollback** — an invalid value stays in the record so the
|
|
23
|
+
* user can fix it; validity is reported separately via `isValid` (read by the save gate) and
|
|
24
|
+
* the per-field messages are surfaced via `errorsByField` / `errorsFor` for display.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare const useValidationStore: import("pinia").StoreDefinition<"stonecrop-validation", Pick<{
|
|
29
|
+
errors: import("vue").Ref<{
|
|
30
|
+
trigger: string;
|
|
31
|
+
field: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}[], ValidationError[] | {
|
|
34
|
+
trigger: string;
|
|
35
|
+
field: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}[]>;
|
|
38
|
+
isValid: import("vue").ComputedRef<boolean>;
|
|
39
|
+
errorsByField: import("vue").ComputedRef<Record<string, string[]>>;
|
|
40
|
+
errorsFor: (field: string) => string[];
|
|
41
|
+
setError: (trigger: string, field: string, message: string) => void;
|
|
42
|
+
clearTrigger: (trigger: string) => void;
|
|
43
|
+
clearAll: () => void;
|
|
44
|
+
validateField: (triggers: Record<string, TriggerDefinition>, changedField: string, record: Record<string, unknown>) => Promise<void>;
|
|
45
|
+
validateRecord: (triggers: Record<string, TriggerDefinition>, record: Record<string, unknown>) => Promise<void>;
|
|
46
|
+
}, "errors">, Pick<{
|
|
47
|
+
errors: import("vue").Ref<{
|
|
48
|
+
trigger: string;
|
|
49
|
+
field: string;
|
|
50
|
+
message: string;
|
|
51
|
+
}[], ValidationError[] | {
|
|
52
|
+
trigger: string;
|
|
53
|
+
field: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}[]>;
|
|
56
|
+
isValid: import("vue").ComputedRef<boolean>;
|
|
57
|
+
errorsByField: import("vue").ComputedRef<Record<string, string[]>>;
|
|
58
|
+
errorsFor: (field: string) => string[];
|
|
59
|
+
setError: (trigger: string, field: string, message: string) => void;
|
|
60
|
+
clearTrigger: (trigger: string) => void;
|
|
61
|
+
clearAll: () => void;
|
|
62
|
+
validateField: (triggers: Record<string, TriggerDefinition>, changedField: string, record: Record<string, unknown>) => Promise<void>;
|
|
63
|
+
validateRecord: (triggers: Record<string, TriggerDefinition>, record: Record<string, unknown>) => Promise<void>;
|
|
64
|
+
}, "isValid" | "errorsByField">, Pick<{
|
|
65
|
+
errors: import("vue").Ref<{
|
|
66
|
+
trigger: string;
|
|
67
|
+
field: string;
|
|
68
|
+
message: string;
|
|
69
|
+
}[], ValidationError[] | {
|
|
70
|
+
trigger: string;
|
|
71
|
+
field: string;
|
|
72
|
+
message: string;
|
|
73
|
+
}[]>;
|
|
74
|
+
isValid: import("vue").ComputedRef<boolean>;
|
|
75
|
+
errorsByField: import("vue").ComputedRef<Record<string, string[]>>;
|
|
76
|
+
errorsFor: (field: string) => string[];
|
|
77
|
+
setError: (trigger: string, field: string, message: string) => void;
|
|
78
|
+
clearTrigger: (trigger: string) => void;
|
|
79
|
+
clearAll: () => void;
|
|
80
|
+
validateField: (triggers: Record<string, TriggerDefinition>, changedField: string, record: Record<string, unknown>) => Promise<void>;
|
|
81
|
+
validateRecord: (triggers: Record<string, TriggerDefinition>, record: Record<string, unknown>) => Promise<void>;
|
|
82
|
+
}, "errorsFor" | "setError" | "clearTrigger" | "clearAll" | "validateField" | "validateRecord">>;
|
|
83
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @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9GP,MAAM;eAER,MAAM;iBAEJ,MAAM;;iBAJN,MAAM;eAER,MAAM;iBAEJ,MAAM;;;;uBAkCW,MAAM,KAAG,MAAM,EAAE;wBAKhB,MAAM,SAAS,MAAM,WAAW,MAAM;4BAKlC,MAAM;;8BA0C1B,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,gBAC7B,MAAM,UACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;+BAeL,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,UACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC;gGAef,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { defineStore } from 'pinia';
|
|
2
|
+
import { ref, computed } from 'vue';
|
|
3
|
+
import { executeClientHandler } from '../client-handler';
|
|
4
|
+
/**
|
|
5
|
+
* Reactive per-field validation error store + the advisory field-validation trigger engine.
|
|
6
|
+
*
|
|
7
|
+
* Holds the errors produced by field-validation triggers (see `TriggerDefinition` in
|
|
8
|
+
* `@stonecrop/schema`) and runs a trigger's `clientHandler` on demand. Errors are **namespaced
|
|
9
|
+
* by trigger**: re-running a trigger clears its own prior contributions before repopulating, so a
|
|
10
|
+
* corrected value clears its stale error without disturbing other triggers.
|
|
11
|
+
*
|
|
12
|
+
* The engine is **advisory** and does **no rollback** — an invalid value stays in the record so the
|
|
13
|
+
* user can fix it; validity is reported separately via `isValid` (read by the save gate) and
|
|
14
|
+
* the per-field messages are surfaced via `errorsByField` / `errorsFor` for display.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export const useValidationStore = defineStore('stonecrop-validation', () => {
|
|
19
|
+
const errors = ref([]);
|
|
20
|
+
/** True when no field currently carries a validation error. */
|
|
21
|
+
const isValid = computed(() => errors.value.length === 0);
|
|
22
|
+
/** Errors grouped by field — the shape a renderer consumes (e.g. AForm `:errors`). */
|
|
23
|
+
const errorsByField = computed(() => {
|
|
24
|
+
const map = {};
|
|
25
|
+
for (const e of errors.value) {
|
|
26
|
+
if (!map[e.field])
|
|
27
|
+
map[e.field] = [];
|
|
28
|
+
map[e.field].push(e.message);
|
|
29
|
+
}
|
|
30
|
+
return map;
|
|
31
|
+
});
|
|
32
|
+
/** Messages currently displayed on `field`. */
|
|
33
|
+
function errorsFor(field) {
|
|
34
|
+
return errors.value.filter(e => e.field === field).map(e => e.message);
|
|
35
|
+
}
|
|
36
|
+
/** Record an error contributed by `trigger`, displayed on `field`. */
|
|
37
|
+
function setError(trigger, field, message) {
|
|
38
|
+
errors.value.push({ trigger, field, message });
|
|
39
|
+
}
|
|
40
|
+
/** Remove every error contributed by `trigger` (its namespace). */
|
|
41
|
+
function clearTrigger(trigger) {
|
|
42
|
+
errors.value = errors.value.filter(e => e.trigger !== trigger);
|
|
43
|
+
}
|
|
44
|
+
/** Remove every validation error. */
|
|
45
|
+
function clearAll() {
|
|
46
|
+
errors.value = [];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Run a single trigger against a read-only snapshot of `record`. Clears the trigger's prior
|
|
50
|
+
* errors, then executes its `clientHandler` with `{ record, value, setError }`. Fails **open** —
|
|
51
|
+
* a throwing validator warns and records nothing, so a broken validator never blocks the user.
|
|
52
|
+
*/
|
|
53
|
+
async function runTrigger(name, def, record, value) {
|
|
54
|
+
clearTrigger(name);
|
|
55
|
+
// Shallow-frozen copy: the validator reads siblings but can neither mutate the record nor
|
|
56
|
+
// reassign fields (advisory reads only) — and mutation can't leak back to the caller.
|
|
57
|
+
const frozen = Object.freeze({ ...record });
|
|
58
|
+
const boundSetError = (field, message) => setError(name, field, message);
|
|
59
|
+
try {
|
|
60
|
+
await executeClientHandler(def.clientHandler, { record: frozen, value, setError: boundSetError });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// Advisory by design: a broken validator must never block save (a bug in one trigger must
|
|
64
|
+
// not trap the user, especially in production). It fails OPEN — but a throw is an error in
|
|
65
|
+
// the author's code, so surface it loudly (error severity, trigger named) rather than
|
|
66
|
+
// silently: a broken validator that just "does nothing" is the real footgun here.
|
|
67
|
+
if (typeof console !== 'undefined') {
|
|
68
|
+
console.error(`Validation trigger "${name}" threw and was ignored (advisory — save is not blocked). ` +
|
|
69
|
+
`Fix its clientHandler:`, error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Run every trigger whose `on` set includes `changedField`, passing that field's current value.
|
|
75
|
+
* Call on the edit path (desktop-driven) so editing either bound field re-validates the pair.
|
|
76
|
+
*/
|
|
77
|
+
async function validateField(triggers, changedField, record) {
|
|
78
|
+
const runs = [];
|
|
79
|
+
for (const [name, def] of Object.entries(triggers)) {
|
|
80
|
+
if (def.on.includes(changedField)) {
|
|
81
|
+
runs.push(runTrigger(name, def, record, record[changedField]));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
await Promise.all(runs);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run **all** triggers (no fired-field filter) — the authoritative client gate at save-attempt,
|
|
88
|
+
* covering triggers whose fields were never edited. `value` is undefined (no single changed field).
|
|
89
|
+
*/
|
|
90
|
+
async function validateRecord(triggers, record) {
|
|
91
|
+
await Promise.all(Object.entries(triggers).map(([name, def]) => runTrigger(name, def, record, undefined)));
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
errors,
|
|
95
|
+
isValid,
|
|
96
|
+
errorsByField,
|
|
97
|
+
errorsFor,
|
|
98
|
+
setError,
|
|
99
|
+
clearTrigger,
|
|
100
|
+
clearAll,
|
|
101
|
+
validateField,
|
|
102
|
+
validateRecord,
|
|
103
|
+
};
|
|
104
|
+
});
|
|
@@ -21,7 +21,7 @@ export type DoctypeConfig = {
|
|
|
21
21
|
name: string;
|
|
22
22
|
/** URL-friendly slug (kebab-case) */
|
|
23
23
|
slug?: string;
|
|
24
|
-
/** Field definitions (
|
|
24
|
+
/** Field definitions (a link field is one carrying `doctype`) */
|
|
25
25
|
fields?: DoctypeField[];
|
|
26
26
|
/** Relationship links to other doctypes */
|
|
27
27
|
links?: Record<string, LinkDeclaration>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/types/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,YAAY,CAAA;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CACxC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,
|
|
1
|
+
{"version":3,"file":"doctype.d.ts","sourceRoot":"","sources":["../../../src/types/doctype.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACpF,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAEtE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,kBAAkB,GAAG,YAAY,CAAA;IAC5E,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CACxC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iEAAiE;IACjE,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACvC,oEAAoE;IACpE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,YAAY,CAAA;IAC9C,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAClC,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
|
|
@@ -94,8 +94,6 @@ export interface OperationLogConfig {
|
|
|
94
94
|
maxOperations?: number;
|
|
95
95
|
/** Enable cross-tab synchronization (default: true) */
|
|
96
96
|
enableCrossTabSync?: boolean;
|
|
97
|
-
/** Auto-sync interval in milliseconds (default: 30000) */
|
|
98
|
-
autoSyncInterval?: number;
|
|
99
97
|
/** Enable operation persistence to localStorage (default: false) */
|
|
100
98
|
enablePersistence?: boolean;
|
|
101
99
|
/** Persistence key prefix */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation-log.d.ts","sourceRoot":"","sources":["../../../src/types/operation-log.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GA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