@geonosis/document 0.9.1 → 0.9.3

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/core/actor.cjs +48 -0
  3. package/dist/core/actor.d.cts +3 -0
  4. package/dist/core/actor.d.ts +3 -0
  5. package/dist/core/actor.js +8 -0
  6. package/dist/core/body-version.cjs +75 -0
  7. package/dist/core/body-version.d.cts +25 -0
  8. package/dist/core/body-version.d.ts +25 -0
  9. package/dist/core/body-version.js +35 -0
  10. package/dist/core/canonical.cjs +55 -0
  11. package/dist/core/canonical.d.cts +5 -0
  12. package/dist/core/canonical.d.ts +5 -0
  13. package/dist/core/canonical.js +15 -0
  14. package/dist/core/document.cjs +136 -0
  15. package/dist/core/document.d.cts +137 -0
  16. package/dist/core/document.d.ts +137 -0
  17. package/dist/core/document.js +96 -0
  18. package/dist/core/entities.cjs +68 -0
  19. package/dist/core/entities.d.cts +42 -0
  20. package/dist/core/entities.d.ts +42 -0
  21. package/dist/core/entities.js +28 -0
  22. package/dist/core/naming.cjs +56 -0
  23. package/dist/core/naming.d.cts +17 -0
  24. package/dist/core/naming.d.ts +17 -0
  25. package/dist/core/naming.js +16 -0
  26. package/dist/core/numbering.cjs +41 -0
  27. package/dist/core/numbering.d.cts +12 -0
  28. package/dist/core/numbering.d.ts +12 -0
  29. package/dist/core/numbering.js +0 -0
  30. package/dist/core/ports.cjs +41 -0
  31. package/dist/core/ports.d.cts +29 -0
  32. package/dist/core/ports.d.ts +29 -0
  33. package/dist/core/ports.js +0 -0
  34. package/dist/core/schema.cjs +173 -0
  35. package/dist/core/schema.d.cts +33 -0
  36. package/dist/core/schema.d.ts +33 -0
  37. package/dist/{chunk-NA3DLROL.js → core/schema.js} +34 -72
  38. package/dist/core/status.cjs +47 -0
  39. package/dist/core/status.d.cts +8 -0
  40. package/dist/core/status.d.ts +8 -0
  41. package/dist/core/status.js +7 -0
  42. package/dist/index.cjs +70 -398
  43. package/dist/index.d.cts +11 -32
  44. package/dist/index.d.ts +11 -32
  45. package/dist/index.js +13 -25
  46. package/dist/store/ddl.cjs +209 -0
  47. package/dist/store/ddl.d.cts +56 -0
  48. package/dist/store/ddl.d.ts +56 -0
  49. package/dist/store/ddl.js +175 -0
  50. package/dist/store/hash.cjs +50 -0
  51. package/dist/store/hash.d.cts +2 -0
  52. package/dist/store/hash.d.ts +2 -0
  53. package/dist/store/hash.js +10 -0
  54. package/dist/store/store.cjs +606 -0
  55. package/dist/store/store.d.cts +169 -0
  56. package/dist/store/store.d.ts +169 -0
  57. package/dist/store/store.js +578 -0
  58. package/dist/store.cjs +51 -1358
  59. package/dist/store.d.cts +4 -277
  60. package/dist/store.d.ts +4 -277
  61. package/dist/store.js +17 -1114
  62. package/dist/surface/table.cjs +326 -0
  63. package/dist/surface/table.d.cts +70 -0
  64. package/dist/surface/table.d.ts +70 -0
  65. package/dist/surface/table.js +296 -0
  66. package/dist/workflows/document-workflows.cjs +314 -0
  67. package/dist/workflows/document-workflows.d.cts +112 -0
  68. package/dist/workflows/document-workflows.d.ts +112 -0
  69. package/dist/workflows/document-workflows.js +281 -0
  70. package/dist/workflows/effects.cjs +41 -0
  71. package/dist/workflows/effects.d.cts +68 -0
  72. package/dist/workflows/effects.d.ts +68 -0
  73. package/dist/workflows/effects.js +0 -0
  74. package/dist/workflows/ports.cjs +50 -0
  75. package/dist/workflows/ports.d.cts +72 -0
  76. package/dist/workflows/ports.d.ts +72 -0
  77. package/dist/workflows/ports.js +10 -0
  78. package/dist/workflows/refusals.cjs +80 -0
  79. package/dist/workflows/refusals.d.cts +59 -0
  80. package/dist/workflows/refusals.d.ts +59 -0
  81. package/dist/workflows/refusals.js +40 -0
  82. package/dist/workflows.cjs +52 -504
  83. package/dist/workflows.d.cts +4 -310
  84. package/dist/workflows.d.ts +4 -310
  85. package/dist/workflows.js +21 -368
  86. package/package.json +8 -8
  87. package/dist/chunk-A6ZU4QU3.js +0 -171
  88. package/dist/entities-DTNJMeVf.d.cts +0 -205
  89. package/dist/entities-DTNJMeVf.d.ts +0 -205
  90. package/dist/ports-C_OfflMQ.d.cts +0 -66
  91. package/dist/ports-C_OfflMQ.d.ts +0 -66
@@ -0,0 +1,137 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { DocumentBodyMigrations } from './body-version.js';
3
+ import type { DocumentNumbering } from './numbering.js';
4
+ import type { DocumentStatusMachine } from './status.js';
5
+ /** The five checks `Document.head` and `Document.record` are built from — never a sixth kind. */
6
+ export type FieldKind = 'calendarDate' | 'decimal' | 'int' | 'positiveInt' | 'text';
7
+ /** The two `FieldKind`s a consumer's own schema library validates by pattern — `validatorOf`'s own regexes, on the door, so a fold names one pattern once (#409). */
8
+ export declare const fieldPatterns: Record<'calendarDate' | 'decimal', RegExp>;
9
+ /**
10
+ * A `StandardSchemaV1` derived from a declarative field spec — one small checker per `FieldKind`,
11
+ * never a second listing of the fields `Document.head`/`Document.record` already carry.
12
+ */
13
+ export declare const validatorOf: <Output>(fields: Readonly<Record<string, FieldKind>>, options?: {
14
+ nullable?: boolean;
15
+ }) => StandardSchemaV1<unknown, Output>;
16
+ /**
17
+ * What every document has before anything knows what kind it is — the indexed facts a list sorts
18
+ * and filters by. Every entity derives these from its own body (`headOf`).
19
+ */
20
+ export declare const headFields: {
21
+ readonly status: 'text';
22
+ readonly issueDate: 'calendarDate';
23
+ readonly dueDate: 'calendarDate';
24
+ readonly counterparty: 'text';
25
+ readonly externalRef: 'text';
26
+ readonly revision: 'text';
27
+ readonly total: 'decimal';
28
+ };
29
+ /** What storage adds: the version a history counts, and the two clocks. */
30
+ export declare const recordFields: {
31
+ readonly version: 'positiveInt';
32
+ readonly createdAt: 'int';
33
+ readonly updatedAt: 'int';
34
+ };
35
+ export type DocumentHead = {
36
+ status: string | null;
37
+ issueDate: string | null;
38
+ dueDate: string | null;
39
+ counterparty: string | null;
40
+ externalRef: string | null;
41
+ revision: string | null;
42
+ total: string | null;
43
+ };
44
+ export type DocumentRecord = {
45
+ version: number;
46
+ createdAt: number;
47
+ updatedAt: number;
48
+ };
49
+ /** What an entity decides when it extends `Document`; every side effect is written once over these. */
50
+ export type DocumentDefinition<Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema> = {
51
+ name: Name;
52
+ noun: string;
53
+ basePath: Path;
54
+ body: BodySchema;
55
+ draft: DraftSchema;
56
+ incoming: IncomingSchema;
57
+ statuses: DocumentStatusMachine<Status>;
58
+ numbering: DocumentNumbering<StandardSchemaV1.InferOutput<DraftSchema>>;
59
+ /** The version this entity's stored body is at today — absent, it is 1. */
60
+ bodyVersion?: number;
61
+ /** Steps that bring an older stored body up to `bodyVersion`, keyed by the version they read. */
62
+ migrations?: DocumentBodyMigrations<Record<string, unknown>>;
63
+ /** `number` is the MINTED number — read off the numbering before the counter moves, never a series. */
64
+ fromDraft: (draft: StandardSchemaV1.InferOutput<DraftSchema>, number: string) => StandardSchemaV1.InferOutput<BodySchema>;
65
+ headOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => DocumentHead;
66
+ searchText: (body: StandardSchemaV1.InferOutput<BodySchema>) => {
67
+ body: string;
68
+ };
69
+ statusOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => Status;
70
+ withStatus: (body: StandardSchemaV1.InferOutput<BodySchema>, status: Status, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
71
+ prepare: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
72
+ merge: (stored: StandardSchemaV1.InferOutput<BodySchema>, incoming: StandardSchemaV1.InferOutput<IncomingSchema>, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
73
+ onSent: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
74
+ copy: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
75
+ removable: boolean;
76
+ card: {
77
+ schema: CardSchema;
78
+ of: (document: DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>, names: {
79
+ counterpartyName: string;
80
+ }) => StandardSchemaV1.InferOutput<CardSchema>;
81
+ };
82
+ /** What a single-document read RENDERS — absent, the body a consumer already declared. */
83
+ view?: ViewSchema;
84
+ };
85
+ /** A stored document of one entity: the head every document has, the record's clocks, its body. */
86
+ export type DocumentInstance<Name extends string, Body> = DocumentHead & DocumentRecord & {
87
+ entity: Name;
88
+ number: string;
89
+ body: Body;
90
+ };
91
+ export type DocumentEntity<Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema> = DocumentDefinition<Name, BodySchema, DraftSchema, IncomingSchema, Status, CardSchema, Path, ViewSchema> & {
92
+ is: (document: {
93
+ entity: string;
94
+ }) => document is DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>;
95
+ view: ViewSchema;
96
+ };
97
+ /**
98
+ * The abstract Document. Never stored as itself — a consumer's entities extend it, and everything
99
+ * written against `Document` runs for every one of them.
100
+ */
101
+ export declare const Document: {
102
+ head: StandardSchemaV1<unknown, DocumentHead>;
103
+ headFields: {
104
+ readonly status: 'text';
105
+ readonly issueDate: 'calendarDate';
106
+ readonly dueDate: 'calendarDate';
107
+ readonly counterparty: 'text';
108
+ readonly externalRef: 'text';
109
+ readonly revision: 'text';
110
+ readonly total: 'decimal';
111
+ };
112
+ record: StandardSchemaV1<unknown, DocumentRecord>;
113
+ recordFields: {
114
+ readonly version: 'positiveInt';
115
+ readonly createdAt: 'int';
116
+ readonly updatedAt: 'int';
117
+ };
118
+ extend: <Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema>(definition: DocumentDefinition<Name, BodySchema, DraftSchema, IncomingSchema, Status, CardSchema, Path, ViewSchema>) => DocumentEntity<Name, BodySchema, DraftSchema, IncomingSchema, Status, CardSchema, Path, ViewSchema>;
119
+ };
120
+ type Parts<Entity> = Entity extends DocumentDefinition<infer Name, infer BodySchema, infer DraftSchema, infer IncomingSchema, infer Status, infer CardSchema, infer _Path, infer ViewSchema> ? {
121
+ name: Name;
122
+ body: StandardSchemaV1.InferOutput<BodySchema>;
123
+ draft: StandardSchemaV1.InferOutput<DraftSchema>;
124
+ incoming: StandardSchemaV1.InferOutput<IncomingSchema>;
125
+ status: Status;
126
+ card: StandardSchemaV1.InferOutput<CardSchema>;
127
+ view: StandardSchemaV1.InferOutput<ViewSchema>;
128
+ } : never;
129
+ export type NameOf<Entity> = Parts<Entity>['name'];
130
+ export type BodyOf<Entity> = Parts<Entity>['body'];
131
+ export type DraftOf<Entity> = Parts<Entity>['draft'];
132
+ export type IncomingOf<Entity> = Parts<Entity>['incoming'];
133
+ export type StatusOf<Entity> = Parts<Entity>['status'];
134
+ export type CardOf<Entity> = Parts<Entity>['card'];
135
+ export type ViewOf<Entity> = Parts<Entity>['view'];
136
+ export type InstanceOf<Entity> = DocumentInstance<NameOf<Entity>, BodyOf<Entity>>;
137
+ export {};
@@ -0,0 +1,96 @@
1
+ // src/core/document.ts
2
+ var fieldPatterns = {
3
+ calendarDate: /^\d{4}-\d{2}-\d{2}$/,
4
+ decimal: /^-?\d+(?:\.\d+)?$/
5
+ };
6
+ var FIELD_CHECKS = {
7
+ calendarDate: {
8
+ message: "a calendar date is `YYYY-MM-DD`, never prose",
9
+ test: (value) => typeof value === "string" && fieldPatterns.calendarDate.test(value)
10
+ },
11
+ decimal: {
12
+ message: "an amount is a decimal string, never a float",
13
+ test: (value) => typeof value === "string" && fieldPatterns.decimal.test(value)
14
+ },
15
+ int: {
16
+ message: "an integer",
17
+ test: (value) => typeof value === "number" && Number.isInteger(value)
18
+ },
19
+ positiveInt: {
20
+ message: "a positive integer",
21
+ test: (value) => typeof value === "number" && Number.isInteger(value) && value > 0
22
+ },
23
+ text: { message: "a string", test: (value) => typeof value === "string" }
24
+ };
25
+ var validatorOf = (fields, options) => {
26
+ const nullable = options?.nullable ?? false;
27
+ return {
28
+ "~standard": {
29
+ validate: (input) => {
30
+ if (input === null || typeof input !== "object") {
31
+ return { issues: [{ message: "expected an object" }] };
32
+ }
33
+ const record = input;
34
+ const issues = [];
35
+ const value = {};
36
+ for (const [key, kind] of Object.entries(fields)) {
37
+ const held = record[key];
38
+ value[key] = held;
39
+ if (nullable && held === null)
40
+ continue;
41
+ if (!FIELD_CHECKS[kind].test(held)) {
42
+ issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
43
+ }
44
+ }
45
+ return issues.length > 0 ? { issues } : { value };
46
+ },
47
+ vendor: "geonosis-document",
48
+ version: 1
49
+ }
50
+ };
51
+ };
52
+ var parseWith = (schema, input) => {
53
+ const result = schema["~standard"].validate(input);
54
+ if (result instanceof Promise) {
55
+ throw new Error("Document.head and Document.record parse synchronously; an async Standard Schema cannot back them");
56
+ }
57
+ if (result.issues !== undefined) {
58
+ throw new Error(result.issues.map((issue) => issue.message).join("; "));
59
+ }
60
+ return result.value;
61
+ };
62
+ var headFields = {
63
+ status: "text",
64
+ issueDate: "calendarDate",
65
+ dueDate: "calendarDate",
66
+ counterparty: "text",
67
+ externalRef: "text",
68
+ revision: "text",
69
+ total: "decimal"
70
+ };
71
+ var recordFields = {
72
+ version: "positiveInt",
73
+ createdAt: "int",
74
+ updatedAt: "int"
75
+ };
76
+ var headValidator = validatorOf(headFields, { nullable: true });
77
+ var recordValidator = validatorOf(recordFields);
78
+ var Document = {
79
+ head: headValidator,
80
+ headFields,
81
+ record: recordValidator,
82
+ recordFields,
83
+ extend: (definition) => ({
84
+ ...definition,
85
+ headOf: (body) => parseWith(headValidator, definition.headOf(body)),
86
+ is: (document) => document.entity === definition.name,
87
+ view: definition.view ?? definition.body
88
+ })
89
+ };
90
+ export {
91
+ Document,
92
+ fieldPatterns,
93
+ headFields,
94
+ recordFields,
95
+ validatorOf
96
+ };
@@ -0,0 +1,68 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/core/entities.ts
40
+ var exports_entities = {};
41
+ __export(exports_entities, {
42
+ documentEntities: () => documentEntities
43
+ });
44
+ module.exports = __toCommonJS(exports_entities);
45
+ var documentEntities = (map) => {
46
+ for (const [key, entity] of Object.entries(map)) {
47
+ if (entity.name !== key) {
48
+ throw new Error(`documentEntities was handed "${key}" for an entity whose own name is "${entity.name}": the map's key is what a row's \`entity\` column carries, and a mismatch here is a row nothing can find again`);
49
+ }
50
+ }
51
+ const names = Object.keys(map);
52
+ const values = Object.values(map);
53
+ const fold = (pick) => values.map(pick);
54
+ const distinctBy = (pick) => [
55
+ ...new Set(fold(pick))
56
+ ];
57
+ return {
58
+ bodies: distinctBy((entity) => entity.body),
59
+ cards: distinctBy((entity) => entity.card.schema),
60
+ entities: map,
61
+ fold,
62
+ instance: (name, parts) => ({ ...parts, entity: name, body: parts.body }),
63
+ keyed: (pick) => Object.fromEntries(names.map((name) => [name, pick(map[name], name)])),
64
+ named: (name) => map[name],
65
+ names,
66
+ views: distinctBy((entity) => entity.view)
67
+ };
68
+ };
@@ -0,0 +1,42 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { DocumentInstance, InstanceOf } from './document.cjs';
3
+ /**
4
+ * The least a map's value has to be for `documentEntities` to do its own work: a name to check
5
+ * against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
6
+ * caller passed — this is a constraint bound, not the type inference reads back — because a status
7
+ * machine typed to its own narrow union is not assignable to one held at `string`, and widening it
8
+ * here would break every entity's own `withStatus` the moment two of them met in one map.
9
+ *
10
+ * Exported for a layer that composes over the registry's OWN values generically (the store): the
11
+ * same minimal bound, never a second one.
12
+ */
13
+ export type AnyDocumentEntity = {
14
+ body: StandardSchemaV1;
15
+ card: {
16
+ schema: StandardSchemaV1;
17
+ };
18
+ name: string;
19
+ view: StandardSchemaV1;
20
+ };
21
+ /**
22
+ * `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
23
+ *
24
+ * A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
25
+ * every entity the registry holds, in one place, typed over the union of the map's own values.
26
+ * Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
27
+ * `names` union is DERIVED from the map's own keys.
28
+ */
29
+ export declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
30
+ bodies: StandardSchemaV1[];
31
+ cards: StandardSchemaV1[];
32
+ entities: Map;
33
+ fold: <Result>(pick: (entity: Map[keyof Map]) => Result) => Result[];
34
+ instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, 'entity' | 'body'> & {
35
+ body: unknown;
36
+ }) => DocumentInstance<Name, InstanceOf<Map[Name]>['body']>;
37
+ /** One answer per entity, keyed by the name its rows carry — total by construction. */
38
+ keyed: <Result>(pick: (entity: Map[keyof Map], name: keyof Map & string) => Result) => { [Name in keyof Map & string]: Result; };
39
+ named: <Name extends keyof Map & string>(name: Name) => Map[Name];
40
+ names: readonly (keyof Map & string)[];
41
+ views: StandardSchemaV1[];
42
+ };
@@ -0,0 +1,42 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { DocumentInstance, InstanceOf } from './document.js';
3
+ /**
4
+ * The least a map's value has to be for `documentEntities` to do its own work: a name to check
5
+ * against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
6
+ * caller passed — this is a constraint bound, not the type inference reads back — because a status
7
+ * machine typed to its own narrow union is not assignable to one held at `string`, and widening it
8
+ * here would break every entity's own `withStatus` the moment two of them met in one map.
9
+ *
10
+ * Exported for a layer that composes over the registry's OWN values generically (the store): the
11
+ * same minimal bound, never a second one.
12
+ */
13
+ export type AnyDocumentEntity = {
14
+ body: StandardSchemaV1;
15
+ card: {
16
+ schema: StandardSchemaV1;
17
+ };
18
+ name: string;
19
+ view: StandardSchemaV1;
20
+ };
21
+ /**
22
+ * `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
23
+ *
24
+ * A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
25
+ * every entity the registry holds, in one place, typed over the union of the map's own values.
26
+ * Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
27
+ * `names` union is DERIVED from the map's own keys.
28
+ */
29
+ export declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
30
+ bodies: StandardSchemaV1[];
31
+ cards: StandardSchemaV1[];
32
+ entities: Map;
33
+ fold: <Result>(pick: (entity: Map[keyof Map]) => Result) => Result[];
34
+ instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, 'entity' | 'body'> & {
35
+ body: unknown;
36
+ }) => DocumentInstance<Name, InstanceOf<Map[Name]>['body']>;
37
+ /** One answer per entity, keyed by the name its rows carry — total by construction. */
38
+ keyed: <Result>(pick: (entity: Map[keyof Map], name: keyof Map & string) => Result) => { [Name in keyof Map & string]: Result; };
39
+ named: <Name extends keyof Map & string>(name: Name) => Map[Name];
40
+ names: readonly (keyof Map & string)[];
41
+ views: StandardSchemaV1[];
42
+ };
@@ -0,0 +1,28 @@
1
+ // src/core/entities.ts
2
+ var documentEntities = (map) => {
3
+ for (const [key, entity] of Object.entries(map)) {
4
+ if (entity.name !== key) {
5
+ throw new Error(`documentEntities was handed "${key}" for an entity whose own name is "${entity.name}": the map's key is what a row's \`entity\` column carries, and a mismatch here is a row nothing can find again`);
6
+ }
7
+ }
8
+ const names = Object.keys(map);
9
+ const values = Object.values(map);
10
+ const fold = (pick) => values.map(pick);
11
+ const distinctBy = (pick) => [
12
+ ...new Set(fold(pick))
13
+ ];
14
+ return {
15
+ bodies: distinctBy((entity) => entity.body),
16
+ cards: distinctBy((entity) => entity.card.schema),
17
+ entities: map,
18
+ fold,
19
+ instance: (name, parts) => ({ ...parts, entity: name, body: parts.body }),
20
+ keyed: (pick) => Object.fromEntries(names.map((name) => [name, pick(map[name], name)])),
21
+ named: (name) => map[name],
22
+ names,
23
+ views: distinctBy((entity) => entity.view)
24
+ };
25
+ };
26
+ export {
27
+ documentEntities
28
+ };
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/core/naming.ts
40
+ var exports_naming = {};
41
+ __export(exports_naming, {
42
+ documentIdentifiers: () => documentIdentifiers
43
+ });
44
+ module.exports = __toCommonJS(exports_naming);
45
+ var camelOf = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
46
+ var documentIdentifiers = (name) => {
47
+ const camel = camelOf(name);
48
+ return {
49
+ camel,
50
+ pascal: `${camel[0]?.toUpperCase() ?? ""}${camel.slice(1)}`,
51
+ pluralCamel: `${camel}s`,
52
+ snake: name.replaceAll("-", "_"),
53
+ snakePlural: `${name.replaceAll("-", "_")}s`,
54
+ path: `/${name}s`
55
+ };
56
+ };
@@ -0,0 +1,17 @@
1
+ /** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
2
+ export type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
3
+ type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
4
+ /**
5
+ * Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
6
+ * a consumer keys a router map or a path table by them without a cast.
7
+ */
8
+ export type DocumentIdentifiers<Name extends string> = {
9
+ camel: CamelOf<Name>;
10
+ pascal: Capitalize<CamelOf<Name>>;
11
+ pluralCamel: `${CamelOf<Name>}s`;
12
+ snake: SnakeOf<Name>;
13
+ snakePlural: `${SnakeOf<Name>}s`;
14
+ path: `/${Name}s`;
15
+ };
16
+ export declare const documentIdentifiers: <Name extends string>(name: Name) => DocumentIdentifiers<Name>;
17
+ export {};
@@ -0,0 +1,17 @@
1
+ /** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
2
+ export type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
3
+ type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
4
+ /**
5
+ * Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
6
+ * a consumer keys a router map or a path table by them without a cast.
7
+ */
8
+ export type DocumentIdentifiers<Name extends string> = {
9
+ camel: CamelOf<Name>;
10
+ pascal: Capitalize<CamelOf<Name>>;
11
+ pluralCamel: `${CamelOf<Name>}s`;
12
+ snake: SnakeOf<Name>;
13
+ snakePlural: `${SnakeOf<Name>}s`;
14
+ path: `/${Name}s`;
15
+ };
16
+ export declare const documentIdentifiers: <Name extends string>(name: Name) => DocumentIdentifiers<Name>;
17
+ export {};
@@ -0,0 +1,16 @@
1
+ // src/core/naming.ts
2
+ var camelOf = (name) => name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
3
+ var documentIdentifiers = (name) => {
4
+ const camel = camelOf(name);
5
+ return {
6
+ camel,
7
+ pascal: `${camel[0]?.toUpperCase() ?? ""}${camel.slice(1)}`,
8
+ pluralCamel: `${camel}s`,
9
+ snake: name.replaceAll("-", "_"),
10
+ snakePlural: `${name.replaceAll("-", "_")}s`,
11
+ path: `/${name}s`
12
+ };
13
+ };
14
+ export {
15
+ documentIdentifiers
16
+ };
@@ -0,0 +1,41 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/core/numbering.ts
40
+ var exports_numbering = {};
41
+ module.exports = __toCommonJS(exports_numbering);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Given by the caller, or minted from a counter. The series is read off the draft BEFORE the
3
+ * counter moves, so a draft that cannot be numbered burns nothing.
4
+ */
5
+ export type DocumentNumbering<Draft> = {
6
+ mode: 'given';
7
+ } | {
8
+ mode: 'counter';
9
+ counter: string;
10
+ series: (draft: Draft) => string;
11
+ format: (series: string, sequence: number) => string;
12
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Given by the caller, or minted from a counter. The series is read off the draft BEFORE the
3
+ * counter moves, so a draft that cannot be numbered burns nothing.
4
+ */
5
+ export type DocumentNumbering<Draft> = {
6
+ mode: 'given';
7
+ } | {
8
+ mode: 'counter';
9
+ counter: string;
10
+ series: (draft: Draft) => string;
11
+ format: (series: string, sequence: number) => string;
12
+ };
File without changes
@@ -0,0 +1,41 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/core/ports.ts
40
+ var exports_ports = {};
41
+ module.exports = __toCommonJS(exports_ports);
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
3
+ * revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
4
+ * collides with the one it replaced.
5
+ */
6
+ export type ArchivePort = {
7
+ head: (key: string) => Promise<{
8
+ hash: string;
9
+ } | null>;
10
+ put: (key: string, bytes: Uint8Array, meta: {
11
+ hash: string;
12
+ immutable: true;
13
+ }) => Promise<void>;
14
+ };
15
+ /** A trusted third party's timestamp over a hash — never implemented here, only declared. */
16
+ export type TimestampPort = {
17
+ stamp: (hash: string) => Promise<{
18
+ at: number;
19
+ token: Uint8Array;
20
+ }>;
21
+ };
22
+ export type LinkVerifierPort = {
23
+ verify: (token: string) => Promise<{
24
+ entity: string;
25
+ exp: number;
26
+ org: string;
27
+ ref: string;
28
+ } | null>;
29
+ };