yarramate 1.15.3 → 1.16.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.
@@ -1,15 +1,5 @@
1
- import Ajv2020Module from 'ajv/dist/2020.js';
2
1
  import { diagnosticOrder, loadSourceDocument, locateSourcePath, } from './source-document.js';
3
- import { compileValidator } from './schema-validation.js';
4
- import adapterMappingSchema from '../schema/yarramate-adapter-mapping.schema.json' with { type: 'json'
5
- };
6
- // `.default ?? module`, not a bare `.default`: NodeNext sees the raw CJS
7
- // `module.exports` and a bundler the unwrapped class. One shape for all of
8
- // them, so which modules a browser happens to reach is not a thing anyone has
9
- // to keep track of (#252).
10
- const ajv2020Module = Ajv2020Module;
11
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
12
- const validateSchema = compileValidator(adapterMappingSchema);
2
+ import { validateAdapterMapping as validateSchema } from './schema-validation.js';
13
3
  const mappingLocations = new WeakMap();
14
4
  export function loadAdapterMapping(source) {
15
5
  const loaded = loadSourceDocument(source, validateSchema, 'Adapter mapping');
@@ -1,5 +1,4 @@
1
1
  import { isMap, isScalar, isSeq, parseDocument, } from 'yaml';
2
- import Ajv2020Module from 'ajv/dist/2020.js';
3
2
  import { loadAdapterMapping } from './adapter-mapping.js';
4
3
  import { compileWorkspace, withDiagnosticSubjects, } from './compiler.js';
5
4
  import { evaluateEvidence, loadEvidence } from './evidence.js';
@@ -20,19 +19,9 @@ export const posixDirectoryOf = (path) => {
20
19
  const cut = normalised.lastIndexOf('/');
21
20
  return cut === -1 ? '' : normalised.slice(0, cut);
22
21
  };
23
- import operationsSchema from '../schema/yarramate-operations.schema.json' with { type: 'json'
24
- };
25
- import { compileValidatorWith } from './schema-validation.js';
26
- // `.default ?? module`, not a bare `.default`: NodeNext sees the raw CJS
27
- // `module.exports` and a bundler sees the unwrapped class, and this file is
28
- // reachable from a browser through `./apply-operations.js` (#252).
29
- const ajv2020Module = Ajv2020Module;
30
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
22
+ import { validateOperations } from './schema-validation.js';
31
23
  // `discriminator` routes a batch entry to the single branch its `op` names, so
32
24
  // one malformed operation reports one fault instead of ten near-misses.
33
- // Keeps its own Ajv instance: `discriminator` changes how a schema compiles,
34
- // so it cannot share one with the nine that do not set it.
35
- const validateOperations = compileValidatorWith({ allErrors: true, discriminator: true }, operationsSchema);
36
25
  // Scalar fields replace; list fields append; `remove` retracts (ADR 0062).
37
26
  // An answer enriches what is there and may explicitly take back what it
38
27
  // asserted — it never silently shrinks anything.
package/dist/compiler.js CHANGED
@@ -1,23 +1,11 @@
1
- import Ajv2020Import from 'ajv/dist/2020.js';
2
1
  import { LineCounter, parse, parseDocument } from 'yaml';
3
2
  import { conceptKinds, relationshipPolicies, } from './profile.js';
4
3
  import { isCoreConceptKindId, matrixEndpointAspects, permittedRelationshipKinds as tablePermittedKinds, } from './relationship-matrix.js';
5
4
  import { closestCandidate, describeSchemaViolation, } from './source-document.js';
6
- import documentSchema from '../schema/yarramate-document.schema.json' with { type: 'json'
7
- };
8
- import profileSchema from '../schema/yarramate-profile.schema.json' with { type: 'json'
9
- };
10
- import patternSchema from '../schema/yarramate-pattern.schema.json' with { type: 'json'
11
- };
12
5
  import { ATTESTATION_PREDICATE_PREFIX, attestationClaimValue } from './graph-claims.js';
13
6
  import { shippedPolicyIdentity, shippedPolicySource, } from './shipped-profile.js';
14
- import { compileValidator } from './schema-validation.js';
7
+ import { validateDocument, validateProfile, validatePattern } from './schema-validation.js';
15
8
  const coreProfile = 'yarramate/core@0.1';
16
- const ajv2020Module = Ajv2020Import;
17
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
18
- const validateDocument = compileValidator(documentSchema);
19
- const validateProfile = compileValidator(profileSchema);
20
- const validatePattern = compileValidator(patternSchema);
21
9
  const immutableMap = (entries) => {
22
10
  const backing = new Map(entries);
23
11
  const facade = {
@@ -1,16 +1,6 @@
1
- import Ajv2020Module from 'ajv/dist/2020.js';
2
1
  import { LineCounter, parseDocument } from 'yaml';
3
2
  import { diagnosticOrder, loadSourceDocument, locateSourcePath, } from './source-document.js';
4
- import { compileValidator } from './schema-validation.js';
5
- import coreContractSchema from '../schema/yarramate-core-contract.schema.json' with { type: 'json'
6
- };
7
- // `.default ?? module`, not a bare `.default`: NodeNext sees the raw CJS
8
- // `module.exports` and a bundler the unwrapped class. One shape for all of
9
- // them, so which modules a browser happens to reach is not a thing anyone has
10
- // to keep track of (#252).
11
- const ajv2020Module = Ajv2020Module;
12
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
13
- const validateCoreContract = compileValidator(coreContractSchema);
3
+ import { validateCoreContract } from './schema-validation.js';
14
4
  export function loadCoreContract(source) {
15
5
  const loaded = loadSourceDocument(source, validateCoreContract, 'Core contract');
16
6
  if (!loaded.ok)
package/dist/evidence.js CHANGED
@@ -1,15 +1,5 @@
1
- import Ajv2020Module from 'ajv/dist/2020.js';
2
1
  import { diagnosticOrder, loadSourceDocument, locateSourcePath, } from './source-document.js';
3
- import evidenceSchema from '../schema/yarramate-evidence.schema.json' with { type: 'json'
4
- };
5
- // `.default ?? module`, not a bare `.default`: NodeNext sees the raw CJS
6
- // `module.exports` and a bundler the unwrapped class. One shape for all of
7
- // them, so which modules a browser happens to reach is not a thing anyone has
8
- // to keep track of (#252).
9
- const ajv2020Module = Ajv2020Module;
10
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
11
- import { compileValidator } from './schema-validation.js';
12
- const validateEvidenceSchema = compileValidator(evidenceSchema);
2
+ import { validateEvidence as validateEvidenceSchema } from './schema-validation.js';
13
3
  const evidenceLocations = new WeakMap();
14
4
  const observationTarget = (observation) => 'subject' in observation ? observation.subject : observation.claim;
15
5
  export function loadEvidence(source) {
@@ -1,17 +1,7 @@
1
- import Ajv2020Module from 'ajv/dist/2020.js';
2
1
  import { loadSourceDocument, locateSourcePath, } from './source-document.js';
3
2
  import { nearDuplicateIndex } from './subject-identity.js';
4
3
  import { sourceKindsPermitting, tableKnowsConceptKind, tableKnowsRelationshipKind, targetKindsPermitting, } from './relationship-matrix.js';
5
- import catalogueSchema from '../schema/yarramate-question-catalogue.schema.json' with { type: 'json'
6
- };
7
- // `.default ?? module`, not a bare `.default`: NodeNext sees the raw CJS
8
- // `module.exports` and a bundler the unwrapped class. One shape for all of
9
- // them, so which modules a browser happens to reach is not a thing anyone has
10
- // to keep track of (#252).
11
- const ajv2020Module = Ajv2020Module;
12
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
13
- import { compileValidator } from './schema-validation.js';
14
- const validateCatalogue = compileValidator(catalogueSchema);
4
+ import { validateCatalogue } from './schema-validation.js';
15
5
  /**
16
6
  * The version of condition evaluation itself, not of the package.
17
7
  *
@@ -1,12 +1,6 @@
1
- import Ajv2020Import from 'ajv/dist/2020.js';
2
1
  import { isDeclaredNonGoal } from './brief.js';
3
2
  import { loadSourceDocument } from './source-document.js';
4
3
  import { similarity } from './subject-identity.js';
5
- import projectionSchema from '../schema/yarramate-projection.schema.json' with { type: 'json'
6
- };
7
- const ajv2020Module = Ajv2020Import;
8
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
9
- const validateProjection = compileValidator(projectionSchema);
10
4
  /**
11
5
  * A relationship kind a view may draw as nesting, and the default. Defined in
12
6
  * `./nesting.js`, which imports nothing, and re-exported here so a consumer
@@ -20,7 +14,7 @@ export { DEFAULT_NESTING } from './nesting.js';
20
14
  * nesting vocabulary above, and re-exported here on the same terms (ADR 0121).
21
15
  */
22
16
  export { DEFAULT_DIRECTION } from './layout-direction.js';
23
- import { compileValidator } from './schema-validation.js';
17
+ import { validateProjection } from './schema-validation.js';
24
18
  export function loadProjection(source) {
25
19
  const loaded = loadSourceDocument(source, validateProjection, 'Projection');
26
20
  return loaded.ok
@@ -1,12 +1,42 @@
1
- import Ajv2020Module from 'ajv/dist/2020.js';
2
1
  import type { ValidateFunction } from 'ajv';
3
- declare const Ajv2020: typeof Ajv2020Module & typeof Ajv2020Module.Ajv2020;
4
- /** Compiles on the shared `allErrors` instance. */
5
- export declare const compileValidator: <T = unknown>(schema: object) => ValidateFunction<T>;
6
2
  /**
7
- * For a schema needing options the shared instance does not carry. Only
8
- * `apply-command` uses it: `discriminator` changes how a schema compiles, so
9
- * it cannot ride on an instance that does not set it.
3
+ * The package's JSON Schema validators, precompiled at BUILD time.
4
+ *
5
+ * Ajv normally compiles a schema by generating source and calling
6
+ * `new Function`, and where that happens decided two releases:
7
+ *
8
+ * - Cloudflare's `workerd` **permits** code generation during module
9
+ * evaluation and **forbids** it at request time. 1.15.2 deferred compilation
10
+ * to first use to save startup CPU, which put it inside a request, and every
11
+ * request that validated anything threw `EvalError`.
12
+ * - 1.15.3 moved compilation back to import, where it is allowed, but that
13
+ * only avoids the forbidden context. The codegen still ran, and Workers
14
+ * budget startup CPU separately (400ms) and refuse a Worker that exceeds it.
15
+ * An adopter's deploy came back at 439ms against that line.
16
+ *
17
+ * Precompiling removes the question instead of answering it: there is no
18
+ * compile step left to put in the wrong place, and no amount of future
19
+ * refactoring can move one back. `schema-validators.generated.js` is committed
20
+ * and regenerated by `pnpm generate:validators`;
21
+ * `test/generated-validators.test.ts` regenerates and compares byte for byte,
22
+ * so a schema edited without regenerating fails there rather than shipping a
23
+ * validator that checks the old shape.
24
+ *
25
+ * Behaviour is unchanged: same `allErrors` collection, same messages, same
26
+ * `errors` property on each validator. `validateOperations` is emitted from an
27
+ * instance with `discriminator` enabled, which is compiled into it.
28
+ *
29
+ * Ajv's COMPILER is a build dependency now rather than a runtime one. Two pure
30
+ * helpers - a deep-equal and a UCS-2 string length - are still imported from
31
+ * `ajv/dist/runtime` by the generated module, which is the accurate claim.
10
32
  */
11
- export declare const compileValidatorWith: <T = unknown>(options: ConstructorParameters<typeof Ajv2020>[0], schema: object) => ValidateFunction<T>;
12
- export {};
33
+ export declare const validateDocument: ValidateFunction;
34
+ export declare const validateProfile: ValidateFunction;
35
+ export declare const validatePattern: ValidateFunction;
36
+ export declare const validateWorkspace: ValidateFunction;
37
+ export declare const validateProjection: ValidateFunction;
38
+ export declare const validateEvidence: ValidateFunction;
39
+ export declare const validateCoreContract: ValidateFunction;
40
+ export declare const validateAdapterMapping: ValidateFunction;
41
+ export declare const validateCatalogue: ValidateFunction;
42
+ export declare const validateOperations: ValidateFunction;
@@ -1,46 +1,43 @@
1
- import Ajv2020Module from 'ajv/dist/2020.js';
2
- // The published dual-export dance every other module here does; see the
3
- // comment in `compiler.ts` for why (#252).
4
- const ajv2020Module = Ajv2020Module;
5
- const Ajv2020 = ajv2020Module.default ?? ajv2020Module;
1
+ import * as generatedOperations from './schema-validators-operations.generated.js';
2
+ import * as generated from './schema-validators.generated.js';
6
3
  /**
7
- * Compiles a JSON Schema AT MODULE SCOPE, on an instance shared with every
8
- * other schema that wants the same options.
4
+ * The package's JSON Schema validators, precompiled at BUILD time.
9
5
  *
10
- * **Compilation must happen at import, and this is not a preference.** Ajv
11
- * compiles a schema by generating source and calling `new Function`.
12
- * Cloudflare's `workerd` permits code generation during module evaluation and
13
- * FORBIDS it at request time - measured on the real runtime binary:
6
+ * Ajv normally compiles a schema by generating source and calling
7
+ * `new Function`, and where that happens decided two releases:
14
8
  *
15
- * ```
16
- * {"atStartup":"ALLOWED",
17
- * "atRequest":"EvalError: Code generation from strings disallowed for this context"}
18
- * ```
9
+ * - Cloudflare's `workerd` **permits** code generation during module
10
+ * evaluation and **forbids** it at request time. 1.15.2 deferred compilation
11
+ * to first use to save startup CPU, which put it inside a request, and every
12
+ * request that validated anything threw `EvalError`.
13
+ * - 1.15.3 moved compilation back to import, where it is allowed, but that
14
+ * only avoids the forbidden context. The codegen still ran, and Workers
15
+ * budget startup CPU separately (400ms) and refuse a Worker that exceeds it.
16
+ * An adopter's deploy came back at 439ms against that line.
19
17
  *
20
- * 1.15.2 deferred these compiles to first use to keep startup CPU down, which
21
- * moved them into the one context that cannot run them: every request that
22
- * validated anything threw. The startup budget was real, but a package that
23
- * cannot serve a request is not a fix for it. Deferral is therefore not an
24
- * option here, and `test/schema-validation-eagerness.test.ts` asserts the
25
- * opposite of what its predecessor did - that importing the package compiles
26
- * every validator, so no request has to.
18
+ * Precompiling removes the question instead of answering it: there is no
19
+ * compile step left to put in the wrong place, and no amount of future
20
+ * refactoring can move one back. `schema-validators.generated.js` is committed
21
+ * and regenerated by `pnpm generate:validators`;
22
+ * `test/generated-validators.test.ts` regenerates and compares byte for byte,
23
+ * so a schema edited without regenerating fails there rather than shipping a
24
+ * validator that checks the old shape.
27
25
  *
28
- * The cost is paid down by SHARING one Ajv instance rather than building ten.
29
- * Each instance compiles the 2020-12 meta-schema again, and that dominates:
30
- * ten instances cost 81.6ms against 35.0ms for one, a 57% reduction with no
31
- * change to when anything runs. Sharing is safe here because no schema
32
- * registers formats and all 39 ship distinct `$id`s, so nothing collides.
26
+ * Behaviour is unchanged: same `allErrors` collection, same messages, same
27
+ * `errors` property on each validator. `validateOperations` is emitted from an
28
+ * instance with `discriminator` enabled, which is compiled into it.
33
29
  *
34
- * The real ceiling-lifter is precompiled standalone validators (Ajv's
35
- * `code: { source: true }`), which remove Ajv from the runtime altogether and
36
- * satisfy both constraints at once. This is the shape that is correct today.
30
+ * Ajv's COMPILER is a build dependency now rather than a runtime one. Two pure
31
+ * helpers - a deep-equal and a UCS-2 string length - are still imported from
32
+ * `ajv/dist/runtime` by the generated module, which is the accurate claim.
37
33
  */
38
- const sharedAjv = new Ajv2020({ allErrors: true });
39
- /** Compiles on the shared `allErrors` instance. */
40
- export const compileValidator = (schema) => sharedAjv.compile(schema);
41
- /**
42
- * For a schema needing options the shared instance does not carry. Only
43
- * `apply-command` uses it: `discriminator` changes how a schema compiles, so
44
- * it cannot ride on an instance that does not set it.
45
- */
46
- export const compileValidatorWith = (options, schema) => new Ajv2020(options).compile(schema);
34
+ export const validateDocument = generated.validateDocument;
35
+ export const validateProfile = generated.validateProfile;
36
+ export const validatePattern = generated.validatePattern;
37
+ export const validateWorkspace = generated.validateWorkspace;
38
+ export const validateProjection = generated.validateProjection;
39
+ export const validateEvidence = generated.validateEvidence;
40
+ export const validateCoreContract = generated.validateCoreContract;
41
+ export const validateAdapterMapping = generated.validateAdapterMapping;
42
+ export const validateCatalogue = generated.validateCatalogue;
43
+ export const validateOperations = generatedOperations.validateOperations;
@@ -0,0 +1,7 @@
1
+ export declare const validateOperations: typeof validate20;
2
+ declare function validate20(data: any, { instancePath, parentData, parentDataProperty, rootData, dynamicAnchors }?: {
3
+ dynamicAnchors?: {} | undefined;
4
+ instancePath?: string | undefined;
5
+ rootData?: any;
6
+ }): boolean;
7
+ export {};