@kubohiroya/turbowarp-structured-data 0.6.1 → 0.6.2

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.
@@ -1,4 +1,3 @@
1
- import {compileSchemaBundle, validateSchemaInput} from '@kubohiroya/turbowarp-extension-data-editor/schema';
2
1
  import type {SchemaBundle, SchemaDocument, SchemaJsonValue, SourceBinding, SourceEditorOptions} from '@kubohiroya/turbowarp-extension-data-editor/schema';
3
2
 
4
3
  export function canonicalBundle(ownerId: string, contractId: string, document: SchemaDocument, ownerSource: {path: string; symbol: string}): SchemaBundle {
@@ -16,21 +15,25 @@ export function canonicalBundle(ownerId: string, contractId: string, document: S
16
15
  export function sourceBinding(argument: string, bundle: SchemaBundle,
17
16
  read: (source: string) => unknown, check: (source: string) => unknown = read,
18
17
  format: 'json' | 'yaml' = 'json', uiSchema?: SourceBinding['variants'][number]['uiSchema']): SourceBinding {
19
- const compiled = compileSchemaBundle(bundle);
20
18
  return {
21
19
  argument,
22
20
  variants: [{variantId: 'default', format, schemaBundle: bundle, ...(uiSchema ? {uiSchema} : {})}],
23
21
  decode(source) {return {source, format, variantId: 'default', data: read(source) as SchemaJsonValue};},
24
22
  validateSource(source, context) {
25
- if (compiled.kind !== 'compiled') return {source, result: {kind: 'schema-error', diagnostics: [{code: 'source-schema-invalid'}]}};
23
+ try {read(source);}
24
+ catch {return {source, result: {kind: 'invalid', diagnostics: [{code: 'source-decode-invalid'}]}};}
26
25
  try {
27
- const data = read(source) as SchemaJsonValue;
28
- return {source, result: validateSchemaInput(compiled.validator, data, {context,
29
- ownerValidate: () => {
30
- try {check(source); return {kind: 'valid', issues: []};}
31
- catch {return {kind: 'invalid', issues: [{dataPath: '', ruleId: 'source-owner-invalid'}]};}
32
- }})};
33
- } catch {return {source, result: {kind: 'invalid', diagnostics: [{code: 'source-decode-invalid'}]}};}
26
+ const descriptors = Object.getOwnPropertyDescriptors(context);
27
+ if (typeof descriptors.consumerId?.value !== 'string' ||
28
+ typeof descriptors.nowMs?.value !== 'number' || !Number.isFinite(descriptors.nowMs.value) ||
29
+ !descriptors.settings || !('value' in descriptors.settings)) {
30
+ return {source, result: {kind: 'execution-error', diagnostics: [{code: 'owner-context-invalid'}]}};
31
+ }
32
+ } catch {return {source, result: {kind: 'execution-error', diagnostics: [{code: 'owner-context-invalid'}]}};}
33
+ // The GUI checks Schema constraints; the owner checks the exact source without compiling.
34
+ try {check(source);}
35
+ catch {return {source, result: {kind: 'invalid', diagnostics: [{code: 'source-owner-invalid'}]}};}
36
+ return {source, result: {kind: 'valid', diagnostics: []}};
34
37
  }
35
38
  };
36
39
  }