@geonosis/document 0.6.0 → 0.8.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/index.cjs CHANGED
@@ -22,17 +22,31 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  BODY_VERSION_KEY: () => BODY_VERSION_KEY,
24
24
  Document: () => Document,
25
+ arrayOf: () => arrayOf,
26
+ booleanSchema: () => booleanSchema,
25
27
  canTransition: () => canTransition,
26
28
  canonicalOf: () => canonicalOf,
27
29
  documentBodyVersioning: () => documentBodyVersioning,
28
30
  documentEntities: () => documentEntities,
29
31
  documentIdentifiers: () => documentIdentifiers,
32
+ enumOf: () => enumOf,
30
33
  fieldPatterns: () => fieldPatterns,
31
34
  isSystemActor: () => isSystemActor,
32
35
  isTerminalStatus: () => isTerminalStatus,
36
+ literalOf: () => literalOf,
37
+ merge: () => merge,
33
38
  migrateBody: () => migrateBody,
39
+ nonEmptyString: () => nonEmptyString,
40
+ nullable: () => nullable,
41
+ numberSchema: () => numberSchema,
42
+ objectOf: () => objectOf,
43
+ optional: () => optional,
44
+ positiveInt: () => positiveInt,
34
45
  stampBody: () => stampBody,
46
+ stringSchema: () => stringSchema,
35
47
  systemActor: () => systemActor,
48
+ unknownSchema: () => unknownSchema,
49
+ validate: () => validate,
36
50
  validatorOf: () => validatorOf
37
51
  });
38
52
  module.exports = __toCommonJS(index_exports);
@@ -90,7 +104,7 @@ var FIELD_CHECKS = {
90
104
  text: { message: "a string", test: (value) => typeof value === "string" }
91
105
  };
92
106
  var validatorOf = (fields, options) => {
93
- const nullable = options?.nullable ?? false;
107
+ const nullable2 = options?.nullable ?? false;
94
108
  return {
95
109
  "~standard": {
96
110
  validate: (input) => {
@@ -103,7 +117,7 @@ var validatorOf = (fields, options) => {
103
117
  for (const [key, kind] of Object.entries(fields)) {
104
118
  const held = record[key];
105
119
  value[key] = held;
106
- if (nullable && held === null) continue;
120
+ if (nullable2 && held === null) continue;
107
121
  if (!FIELD_CHECKS[kind].test(held)) {
108
122
  issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
109
123
  }
@@ -177,23 +191,169 @@ var documentEntities = (map) => {
177
191
  entities: map,
178
192
  fold,
179
193
  instance: (name, parts) => ({ ...parts, entity: name, body: parts.body }),
194
+ keyed: (pick) => Object.fromEntries(names.map((name) => [name, pick(map[name], name)])),
180
195
  named: (name) => map[name],
181
196
  names,
182
197
  views: distinctBy((entity) => entity.view)
183
198
  };
184
199
  };
185
200
 
201
+ // src/core/schema.ts
202
+ var VENDOR = "geonosis-document";
203
+ var isString = (value) => typeof value === "string";
204
+ var isNumber = (value) => typeof value === "number";
205
+ var scalar = (test, message) => ({
206
+ "~standard": {
207
+ validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
208
+ vendor: VENDOR,
209
+ version: 1
210
+ }
211
+ });
212
+ var stringSchema = scalar(isString, "expected a string");
213
+ var numberSchema = scalar(isNumber, "expected a number");
214
+ var booleanSchema = scalar(
215
+ (value) => typeof value === "boolean",
216
+ "expected a boolean"
217
+ );
218
+ var literalOf = (literal) => scalar(
219
+ (value) => value === literal,
220
+ `expected exactly ${JSON.stringify(literal)}`
221
+ );
222
+ var unknownSchema = {
223
+ "~standard": { validate: (input) => ({ value: input }), vendor: VENDOR, version: 1 }
224
+ };
225
+ var syncResult = (schema, input) => {
226
+ const result = schema["~standard"].validate(input);
227
+ if (result instanceof Promise) {
228
+ throw new Error(
229
+ "a document surface schema validates synchronously; an async Standard Schema cannot back a row"
230
+ );
231
+ }
232
+ return result;
233
+ };
234
+ var optional = (inner) => ({
235
+ "~standard": {
236
+ validate: (input) => input === void 0 ? { value: void 0 } : syncResult(inner, input),
237
+ vendor: VENDOR,
238
+ version: 1
239
+ }
240
+ });
241
+ var nullable = (inner) => ({
242
+ "~standard": {
243
+ validate: (input) => input === null ? { value: null } : syncResult(inner, input),
244
+ vendor: VENDOR,
245
+ version: 1
246
+ }
247
+ });
248
+ var arrayOf = (item) => ({
249
+ "~standard": {
250
+ validate: (input) => {
251
+ if (!Array.isArray(input)) return { issues: [{ message: "expected an array" }] };
252
+ const value = [];
253
+ const issues = [];
254
+ input.forEach((one, at) => {
255
+ const result = syncResult(item, one);
256
+ if (result.issues !== void 0) {
257
+ issues.push(
258
+ ...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] }))
259
+ );
260
+ } else {
261
+ value.push(result.value);
262
+ }
263
+ });
264
+ return issues.length > 0 ? { issues } : { value };
265
+ },
266
+ vendor: VENDOR,
267
+ version: 1
268
+ }
269
+ });
270
+ var merge = (schemas) => ({
271
+ "~standard": {
272
+ validate: (input) => {
273
+ let value = {};
274
+ const issues = [];
275
+ for (const schema of schemas) {
276
+ const result = syncResult(schema, input);
277
+ if (result.issues !== void 0) issues.push(...result.issues);
278
+ else value = { ...value, ...result.value };
279
+ }
280
+ return issues.length > 0 ? { issues } : { value };
281
+ },
282
+ vendor: VENDOR,
283
+ version: 1
284
+ }
285
+ });
286
+ var nonEmptyString = scalar(
287
+ (value) => typeof value === "string" && value.length > 0,
288
+ "expected a non-empty string"
289
+ );
290
+ var positiveInt = scalar(
291
+ (value) => Number.isInteger(value) && value > 0,
292
+ "expected a positive integer"
293
+ );
294
+ var validate = async (schema, input) => {
295
+ const result = await schema["~standard"].validate(input);
296
+ if (result.issues !== void 0) {
297
+ throw new Error(
298
+ result.issues.map((issue) => {
299
+ const path = (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
300
+ return path === "" ? issue.message : `${path}: ${issue.message}`;
301
+ }).join("; ")
302
+ );
303
+ }
304
+ return result.value;
305
+ };
306
+ var enumOf = (values) => scalar(
307
+ (value) => typeof value === "string" && values.includes(value),
308
+ `expected one of ${values.map((value) => JSON.stringify(value)).join(", ")}`
309
+ );
310
+ var settle = (fields) => {
311
+ const value = {};
312
+ const issues = [];
313
+ for (const [key, result] of fields) {
314
+ if (result.issues !== void 0) {
315
+ issues.push(
316
+ ...result.issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] }))
317
+ );
318
+ } else if (result.value !== void 0) {
319
+ value[key] = result.value;
320
+ }
321
+ }
322
+ return issues.length > 0 ? { issues } : { value };
323
+ };
324
+ var objectOf = (shape) => ({
325
+ "~standard": {
326
+ validate: (input) => {
327
+ if (input === null || typeof input !== "object") {
328
+ return { issues: [{ message: "expected an object" }] };
329
+ }
330
+ const record = input;
331
+ const fields = Object.entries(shape).map(
332
+ ([key, schema]) => [key, schema["~standard"].validate(record[key])]
333
+ );
334
+ return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(
335
+ settle
336
+ ) : settle(fields);
337
+ },
338
+ vendor: VENDOR,
339
+ version: 1
340
+ }
341
+ });
342
+
186
343
  // src/core/actor.ts
187
344
  var SYSTEM_PREFIX = "system:";
188
345
  var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
189
346
  var isSystemActor = (actor) => actor.startsWith(SYSTEM_PREFIX);
190
347
 
191
348
  // src/core/canonical.ts
349
+ var KEY_ORDER = new Intl.Collator("en-US");
192
350
  var canonicalOf = (input) => {
193
351
  if (input === null || typeof input !== "object") return input;
352
+ const { toJSON } = input;
353
+ if (typeof toJSON === "function") return canonicalOf(toJSON.call(input));
194
354
  if (Array.isArray(input)) return input.map(canonicalOf);
195
355
  return Object.fromEntries(
196
- Object.entries(input).toSorted(([a], [b]) => a.localeCompare(b)).map(([key, held]) => [key, canonicalOf(held)])
356
+ Object.entries(input).toSorted(([a], [b]) => KEY_ORDER.compare(a, b)).map(([key, held]) => [key, canonicalOf(held)])
197
357
  );
198
358
  };
199
359
 
@@ -218,16 +378,30 @@ var isTerminalStatus = (machine, status) => machine.transitions[status].length =
218
378
  0 && (module.exports = {
219
379
  BODY_VERSION_KEY,
220
380
  Document,
381
+ arrayOf,
382
+ booleanSchema,
221
383
  canTransition,
222
384
  canonicalOf,
223
385
  documentBodyVersioning,
224
386
  documentEntities,
225
387
  documentIdentifiers,
388
+ enumOf,
226
389
  fieldPatterns,
227
390
  isSystemActor,
228
391
  isTerminalStatus,
392
+ literalOf,
393
+ merge,
229
394
  migrateBody,
395
+ nonEmptyString,
396
+ nullable,
397
+ numberSchema,
398
+ objectOf,
399
+ optional,
400
+ positiveInt,
230
401
  stampBody,
402
+ stringSchema,
231
403
  systemActor,
404
+ unknownSchema,
405
+ validate,
232
406
  validatorOf
233
407
  });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- export { A as AnyDocumentEntity, a as ArchivePort, B as BODY_VERSION_KEY, b as BodyOf, C as CardOf, D as Document, c as DocumentBodyMigrations, d as DocumentBodyVersion, e as DocumentDefinition, f as DocumentEntity, g as DocumentHead, h as DocumentInstance, i as DocumentNumbering, j as DocumentRecord, k as DocumentStatusMachine, l as DraftOf, F as FieldKind, I as IncomingOf, m as InstanceOf, L as LinkVerifierPort, N as NameOf, S as StatusOf, T as TimestampPort, V as ViewOf, n as canTransition, o as documentBodyVersioning, p as documentEntities, q as fieldPatterns, r as isTerminalStatus, s as migrateBody, t as stampBody, v as validatorOf } from './ports-D0NtPwAO.cjs';
1
+ export { A as AnyDocumentEntity, B as BODY_VERSION_KEY, a as BodyOf, C as CardOf, D as Document, b as DocumentBodyMigrations, c as DocumentBodyVersion, d as DocumentDefinition, e as DocumentEntity, f as DocumentHead, g as DocumentInstance, h as DocumentNumbering, i as DocumentRecord, j as DocumentStatusMachine, k as DraftOf, F as FieldKind, I as IncomingOf, l as InstanceOf, N as NameOf, S as StatusOf, V as ViewOf, m as canTransition, n as documentBodyVersioning, o as documentEntities, p as fieldPatterns, q as isTerminalStatus, r as migrateBody, s as stampBody, v as validatorOf } from './entities-DTNJMeVf.cjs';
2
+ export { A as ArchivePort, L as LinkVerifierPort, S as SchemaAdapter, T as TimestampPort, a as arrayOf, b as booleanSchema, e as enumOf, l as literalOf, m as merge, n as nonEmptyString, c as nullable, d as numberSchema, o as objectOf, f as optional, p as positiveInt, s as stringSchema, u as unknownSchema, v as validate } from './ports-C_OfflMQ.cjs';
2
3
  export { StandardSchemaV1 } from '@standard-schema/spec';
3
4
 
4
5
  /** An unattended write's principal — `systemActor('recurring.generate')` — never a bare `'system'`. */
@@ -6,20 +7,26 @@ declare const systemActor: (name: string) => string;
6
7
  declare const isSystemActor: (actor: string) => boolean;
7
8
 
8
9
  /**
9
- * Deep, key-order-independent: two payloads that hold the same facts hash the same. The ONE
10
- * canonicaliser both sides use — a consumer's archive recomputes `hashOf` over the identical form,
11
- * so a second implementation of this function is a second chain that silently stops agreeing.
10
+ * Deep, key-order-independent, and read as JSON writes it (a `Date` is its ISO string). The ONE
11
+ * canonicaliser both sides use — a consumer's archive recomputes `hashOf` over the identical form.
12
12
  */
13
13
  declare const canonicalOf: (input: unknown) => unknown;
14
14
 
15
- /** The identifiers a surface spells an entity with, all derived from its one hyphenated name. */
16
- declare const documentIdentifiers: (name: string) => {
17
- camel: string;
18
- pascal: string;
19
- pluralCamel: string;
20
- snake: string;
21
- snakePlural: string;
22
- path: string;
15
+ /** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
16
+ type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
17
+ type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
18
+ /**
19
+ * Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
20
+ * a consumer keys a router map or a path table by them without a cast.
21
+ */
22
+ type DocumentIdentifiers<Name extends string> = {
23
+ camel: CamelOf<Name>;
24
+ pascal: Capitalize<CamelOf<Name>>;
25
+ pluralCamel: `${CamelOf<Name>}s`;
26
+ snake: SnakeOf<Name>;
27
+ snakePlural: `${SnakeOf<Name>}s`;
28
+ path: `/${Name}s`;
23
29
  };
30
+ declare const documentIdentifiers: <Name extends string>(name: Name) => DocumentIdentifiers<Name>;
24
31
 
25
- export { canonicalOf, documentIdentifiers, isSystemActor, systemActor };
32
+ export { type CamelOf, type DocumentIdentifiers, canonicalOf, documentIdentifiers, isSystemActor, systemActor };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { A as AnyDocumentEntity, a as ArchivePort, B as BODY_VERSION_KEY, b as BodyOf, C as CardOf, D as Document, c as DocumentBodyMigrations, d as DocumentBodyVersion, e as DocumentDefinition, f as DocumentEntity, g as DocumentHead, h as DocumentInstance, i as DocumentNumbering, j as DocumentRecord, k as DocumentStatusMachine, l as DraftOf, F as FieldKind, I as IncomingOf, m as InstanceOf, L as LinkVerifierPort, N as NameOf, S as StatusOf, T as TimestampPort, V as ViewOf, n as canTransition, o as documentBodyVersioning, p as documentEntities, q as fieldPatterns, r as isTerminalStatus, s as migrateBody, t as stampBody, v as validatorOf } from './ports-D0NtPwAO.js';
1
+ export { A as AnyDocumentEntity, B as BODY_VERSION_KEY, a as BodyOf, C as CardOf, D as Document, b as DocumentBodyMigrations, c as DocumentBodyVersion, d as DocumentDefinition, e as DocumentEntity, f as DocumentHead, g as DocumentInstance, h as DocumentNumbering, i as DocumentRecord, j as DocumentStatusMachine, k as DraftOf, F as FieldKind, I as IncomingOf, l as InstanceOf, N as NameOf, S as StatusOf, V as ViewOf, m as canTransition, n as documentBodyVersioning, o as documentEntities, p as fieldPatterns, q as isTerminalStatus, r as migrateBody, s as stampBody, v as validatorOf } from './entities-DTNJMeVf.js';
2
+ export { A as ArchivePort, L as LinkVerifierPort, S as SchemaAdapter, T as TimestampPort, a as arrayOf, b as booleanSchema, e as enumOf, l as literalOf, m as merge, n as nonEmptyString, c as nullable, d as numberSchema, o as objectOf, f as optional, p as positiveInt, s as stringSchema, u as unknownSchema, v as validate } from './ports-C_OfflMQ.js';
2
3
  export { StandardSchemaV1 } from '@standard-schema/spec';
3
4
 
4
5
  /** An unattended write's principal — `systemActor('recurring.generate')` — never a bare `'system'`. */
@@ -6,20 +7,26 @@ declare const systemActor: (name: string) => string;
6
7
  declare const isSystemActor: (actor: string) => boolean;
7
8
 
8
9
  /**
9
- * Deep, key-order-independent: two payloads that hold the same facts hash the same. The ONE
10
- * canonicaliser both sides use — a consumer's archive recomputes `hashOf` over the identical form,
11
- * so a second implementation of this function is a second chain that silently stops agreeing.
10
+ * Deep, key-order-independent, and read as JSON writes it (a `Date` is its ISO string). The ONE
11
+ * canonicaliser both sides use — a consumer's archive recomputes `hashOf` over the identical form.
12
12
  */
13
13
  declare const canonicalOf: (input: unknown) => unknown;
14
14
 
15
- /** The identifiers a surface spells an entity with, all derived from its one hyphenated name. */
16
- declare const documentIdentifiers: (name: string) => {
17
- camel: string;
18
- pascal: string;
19
- pluralCamel: string;
20
- snake: string;
21
- snakePlural: string;
22
- path: string;
15
+ /** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
16
+ type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
17
+ type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
18
+ /**
19
+ * Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
20
+ * a consumer keys a router map or a path table by them without a cast.
21
+ */
22
+ type DocumentIdentifiers<Name extends string> = {
23
+ camel: CamelOf<Name>;
24
+ pascal: Capitalize<CamelOf<Name>>;
25
+ pluralCamel: `${CamelOf<Name>}s`;
26
+ snake: SnakeOf<Name>;
27
+ snakePlural: `${SnakeOf<Name>}s`;
28
+ path: `/${Name}s`;
23
29
  };
30
+ declare const documentIdentifiers: <Name extends string>(name: Name) => DocumentIdentifiers<Name>;
24
31
 
25
- export { canonicalOf, documentIdentifiers, isSystemActor, systemActor };
32
+ export { type CamelOf, type DocumentIdentifiers, canonicalOf, documentIdentifiers, isSystemActor, systemActor };
package/dist/index.js CHANGED
@@ -1,18 +1,34 @@
1
1
  import {
2
2
  BODY_VERSION_KEY,
3
3
  Document,
4
- canTransition,
5
4
  canonicalOf,
6
5
  documentBodyVersioning,
7
6
  documentEntities,
8
7
  fieldPatterns,
9
- isSystemActor,
10
- isTerminalStatus,
11
8
  migrateBody,
12
9
  stampBody,
13
- systemActor,
14
10
  validatorOf
15
- } from "./chunk-WWP7MNI7.js";
11
+ } from "./chunk-A6ZU4QU3.js";
12
+ import {
13
+ arrayOf,
14
+ booleanSchema,
15
+ canTransition,
16
+ enumOf,
17
+ isSystemActor,
18
+ isTerminalStatus,
19
+ literalOf,
20
+ merge,
21
+ nonEmptyString,
22
+ nullable,
23
+ numberSchema,
24
+ objectOf,
25
+ optional,
26
+ positiveInt,
27
+ stringSchema,
28
+ systemActor,
29
+ unknownSchema,
30
+ validate
31
+ } from "./chunk-NA3DLROL.js";
16
32
 
17
33
  // src/core/naming.ts
18
34
  var camelOf = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -30,16 +46,30 @@ var documentIdentifiers = (name) => {
30
46
  export {
31
47
  BODY_VERSION_KEY,
32
48
  Document,
49
+ arrayOf,
50
+ booleanSchema,
33
51
  canTransition,
34
52
  canonicalOf,
35
53
  documentBodyVersioning,
36
54
  documentEntities,
37
55
  documentIdentifiers,
56
+ enumOf,
38
57
  fieldPatterns,
39
58
  isSystemActor,
40
59
  isTerminalStatus,
60
+ literalOf,
61
+ merge,
41
62
  migrateBody,
63
+ nonEmptyString,
64
+ nullable,
65
+ numberSchema,
66
+ objectOf,
67
+ optional,
68
+ positiveInt,
42
69
  stampBody,
70
+ stringSchema,
43
71
  systemActor,
72
+ unknownSchema,
73
+ validate,
44
74
  validatorOf
45
75
  };
@@ -0,0 +1,66 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+
3
+ /**
4
+ * The three builders a validator library supplies so the surface and the workflows stay library-free
5
+ * (#383) while the union/enum/object they derive are still real schemas of THAT library — the one
6
+ * place a consumer's zod enters `@geonosis/document` is through this adapter, never a dependency.
7
+ */
8
+ type SchemaAdapter = {
9
+ enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
10
+ object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
11
+ union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
12
+ };
13
+ declare const stringSchema: StandardSchemaV1<unknown, string>;
14
+ declare const numberSchema: StandardSchemaV1<unknown, number>;
15
+ declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
16
+ declare const literalOf: <Value extends boolean | string>(literal: Value) => StandardSchemaV1<unknown, Value>;
17
+ /** A passthrough for a shape this ticket declares but does not itself narrow further. */
18
+ declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
19
+ declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
20
+ declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
21
+ declare const arrayOf: <Output>(item: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output[]>;
22
+ /** Every schema's own issues, folded into one — the merged VALUE is every schema's fields, spread. */
23
+ declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
24
+ declare const nonEmptyString: StandardSchemaV1<unknown, string>;
25
+ declare const positiveInt: StandardSchemaV1<unknown, number>;
26
+ /** One value through one schema, whichever library wrote it; the issues are the refusal's text. */
27
+ declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
28
+ declare const enumOf: <Value extends string>(values: readonly Value[]) => StandardSchemaV1<unknown, Value>;
29
+ /**
30
+ * An object of named fields, each through its own schema — the one builder a workflow input needs
31
+ * that the adapter is not asked for, since a run's input is refused by the engine and never rendered
32
+ * by a host's own library. Async when a field's schema is; unknown keys are dropped.
33
+ */
34
+ declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
35
+
36
+ /**
37
+ * The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
38
+ * revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
39
+ * collides with the one it replaced.
40
+ */
41
+ type ArchivePort = {
42
+ head: (key: string) => Promise<{
43
+ hash: string;
44
+ } | null>;
45
+ put: (key: string, bytes: Uint8Array, meta: {
46
+ hash: string;
47
+ immutable: true;
48
+ }) => Promise<void>;
49
+ };
50
+ /** A trusted third party's timestamp over a hash — never implemented here, only declared. */
51
+ type TimestampPort = {
52
+ stamp: (hash: string) => Promise<{
53
+ at: number;
54
+ token: Uint8Array;
55
+ }>;
56
+ };
57
+ type LinkVerifierPort = {
58
+ verify: (token: string) => Promise<{
59
+ entity: string;
60
+ exp: number;
61
+ org: string;
62
+ ref: string;
63
+ } | null>;
64
+ };
65
+
66
+ export { type ArchivePort as A, type LinkVerifierPort as L, type SchemaAdapter as S, type TimestampPort as T, arrayOf as a, booleanSchema as b, nullable as c, numberSchema as d, enumOf as e, optional as f, literalOf as l, merge as m, nonEmptyString as n, objectOf as o, positiveInt as p, stringSchema as s, unknownSchema as u, validate as v };
@@ -0,0 +1,66 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+
3
+ /**
4
+ * The three builders a validator library supplies so the surface and the workflows stay library-free
5
+ * (#383) while the union/enum/object they derive are still real schemas of THAT library — the one
6
+ * place a consumer's zod enters `@geonosis/document` is through this adapter, never a dependency.
7
+ */
8
+ type SchemaAdapter = {
9
+ enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
10
+ object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
11
+ union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
12
+ };
13
+ declare const stringSchema: StandardSchemaV1<unknown, string>;
14
+ declare const numberSchema: StandardSchemaV1<unknown, number>;
15
+ declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
16
+ declare const literalOf: <Value extends boolean | string>(literal: Value) => StandardSchemaV1<unknown, Value>;
17
+ /** A passthrough for a shape this ticket declares but does not itself narrow further. */
18
+ declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
19
+ declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
20
+ declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
21
+ declare const arrayOf: <Output>(item: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output[]>;
22
+ /** Every schema's own issues, folded into one — the merged VALUE is every schema's fields, spread. */
23
+ declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
24
+ declare const nonEmptyString: StandardSchemaV1<unknown, string>;
25
+ declare const positiveInt: StandardSchemaV1<unknown, number>;
26
+ /** One value through one schema, whichever library wrote it; the issues are the refusal's text. */
27
+ declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
28
+ declare const enumOf: <Value extends string>(values: readonly Value[]) => StandardSchemaV1<unknown, Value>;
29
+ /**
30
+ * An object of named fields, each through its own schema — the one builder a workflow input needs
31
+ * that the adapter is not asked for, since a run's input is refused by the engine and never rendered
32
+ * by a host's own library. Async when a field's schema is; unknown keys are dropped.
33
+ */
34
+ declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
35
+
36
+ /**
37
+ * The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
38
+ * revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
39
+ * collides with the one it replaced.
40
+ */
41
+ type ArchivePort = {
42
+ head: (key: string) => Promise<{
43
+ hash: string;
44
+ } | null>;
45
+ put: (key: string, bytes: Uint8Array, meta: {
46
+ hash: string;
47
+ immutable: true;
48
+ }) => Promise<void>;
49
+ };
50
+ /** A trusted third party's timestamp over a hash — never implemented here, only declared. */
51
+ type TimestampPort = {
52
+ stamp: (hash: string) => Promise<{
53
+ at: number;
54
+ token: Uint8Array;
55
+ }>;
56
+ };
57
+ type LinkVerifierPort = {
58
+ verify: (token: string) => Promise<{
59
+ entity: string;
60
+ exp: number;
61
+ org: string;
62
+ ref: string;
63
+ } | null>;
64
+ };
65
+
66
+ export { type ArchivePort as A, type LinkVerifierPort as L, type SchemaAdapter as S, type TimestampPort as T, arrayOf as a, booleanSchema as b, nullable as c, numberSchema as d, enumOf as e, optional as f, literalOf as l, merge as m, nonEmptyString as n, objectOf as o, positiveInt as p, stringSchema as s, unknownSchema as u, validate as v };
package/dist/store.cjs CHANGED
@@ -39,11 +39,14 @@ module.exports = __toCommonJS(store_exports);
39
39
  var import_node_crypto = require("crypto");
40
40
 
41
41
  // src/core/canonical.ts
42
+ var KEY_ORDER = new Intl.Collator("en-US");
42
43
  var canonicalOf = (input) => {
43
44
  if (input === null || typeof input !== "object") return input;
45
+ const { toJSON } = input;
46
+ if (typeof toJSON === "function") return canonicalOf(toJSON.call(input));
44
47
  if (Array.isArray(input)) return input.map(canonicalOf);
45
48
  return Object.fromEntries(
46
- Object.entries(input).toSorted(([a], [b]) => a.localeCompare(b)).map(([key, held]) => [key, canonicalOf(held)])
49
+ Object.entries(input).toSorted(([a], [b]) => KEY_ORDER.compare(a, b)).map(([key, held]) => [key, canonicalOf(held)])
47
50
  );
48
51
  };
49
52
 
@@ -141,11 +144,8 @@ var Document = {
141
144
  })
142
145
  };
143
146
 
144
- // src/core/status.ts
145
- var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
146
-
147
- // src/surface/table.ts
148
- var VENDOR = "geonosis-document-surface";
147
+ // src/core/schema.ts
148
+ var VENDOR = "geonosis-document";
149
149
  var isString = (value) => typeof value === "string";
150
150
  var isNumber = (value) => typeof value === "number";
151
151
  var scalar = (test, message) => ({
@@ -229,6 +229,19 @@ var merge = (schemas) => ({
229
229
  version: 1
230
230
  }
231
231
  });
232
+ var nonEmptyString = scalar(
233
+ (value) => typeof value === "string" && value.length > 0,
234
+ "expected a non-empty string"
235
+ );
236
+ var positiveInt = scalar(
237
+ (value) => Number.isInteger(value) && value > 0,
238
+ "expected a positive integer"
239
+ );
240
+
241
+ // src/core/status.ts
242
+ var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
243
+
244
+ // src/surface/table.ts
232
245
  var doorFor = (store, name) => {
233
246
  const door = store[name];
234
247
  if (door === void 0) {