@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.
- package/CHANGELOG.md +18 -0
- package/dist/core/actor.cjs +48 -0
- package/dist/core/actor.d.cts +3 -0
- package/dist/core/actor.d.ts +3 -0
- package/dist/core/actor.js +8 -0
- package/dist/core/body-version.cjs +75 -0
- package/dist/core/body-version.d.cts +25 -0
- package/dist/core/body-version.d.ts +25 -0
- package/dist/core/body-version.js +35 -0
- package/dist/core/canonical.cjs +55 -0
- package/dist/core/canonical.d.cts +5 -0
- package/dist/core/canonical.d.ts +5 -0
- package/dist/core/canonical.js +15 -0
- package/dist/core/document.cjs +136 -0
- package/dist/core/document.d.cts +137 -0
- package/dist/core/document.d.ts +137 -0
- package/dist/core/document.js +96 -0
- package/dist/core/entities.cjs +68 -0
- package/dist/core/entities.d.cts +42 -0
- package/dist/core/entities.d.ts +42 -0
- package/dist/core/entities.js +28 -0
- package/dist/core/naming.cjs +56 -0
- package/dist/core/naming.d.cts +17 -0
- package/dist/core/naming.d.ts +17 -0
- package/dist/core/naming.js +16 -0
- package/dist/core/numbering.cjs +41 -0
- package/dist/core/numbering.d.cts +12 -0
- package/dist/core/numbering.d.ts +12 -0
- package/dist/core/numbering.js +0 -0
- package/dist/core/ports.cjs +41 -0
- package/dist/core/ports.d.cts +29 -0
- package/dist/core/ports.d.ts +29 -0
- package/dist/core/ports.js +0 -0
- package/dist/core/schema.cjs +173 -0
- package/dist/core/schema.d.cts +33 -0
- package/dist/core/schema.d.ts +33 -0
- package/dist/{chunk-NA3DLROL.js → core/schema.js} +34 -72
- package/dist/core/status.cjs +47 -0
- package/dist/core/status.d.cts +8 -0
- package/dist/core/status.d.ts +8 -0
- package/dist/core/status.js +7 -0
- package/dist/index.cjs +70 -398
- package/dist/index.d.cts +11 -32
- package/dist/index.d.ts +11 -32
- package/dist/index.js +13 -25
- package/dist/store/ddl.cjs +209 -0
- package/dist/store/ddl.d.cts +56 -0
- package/dist/store/ddl.d.ts +56 -0
- package/dist/store/ddl.js +175 -0
- package/dist/store/hash.cjs +50 -0
- package/dist/store/hash.d.cts +2 -0
- package/dist/store/hash.d.ts +2 -0
- package/dist/store/hash.js +10 -0
- package/dist/store/store.cjs +606 -0
- package/dist/store/store.d.cts +169 -0
- package/dist/store/store.d.ts +169 -0
- package/dist/store/store.js +578 -0
- package/dist/store.cjs +51 -1358
- package/dist/store.d.cts +4 -277
- package/dist/store.d.ts +4 -277
- package/dist/store.js +17 -1114
- package/dist/surface/table.cjs +326 -0
- package/dist/surface/table.d.cts +70 -0
- package/dist/surface/table.d.ts +70 -0
- package/dist/surface/table.js +296 -0
- package/dist/workflows/document-workflows.cjs +314 -0
- package/dist/workflows/document-workflows.d.cts +112 -0
- package/dist/workflows/document-workflows.d.ts +112 -0
- package/dist/workflows/document-workflows.js +281 -0
- package/dist/workflows/effects.cjs +41 -0
- package/dist/workflows/effects.d.cts +68 -0
- package/dist/workflows/effects.d.ts +68 -0
- package/dist/workflows/effects.js +0 -0
- package/dist/workflows/ports.cjs +50 -0
- package/dist/workflows/ports.d.cts +72 -0
- package/dist/workflows/ports.d.ts +72 -0
- package/dist/workflows/ports.js +10 -0
- package/dist/workflows/refusals.cjs +80 -0
- package/dist/workflows/refusals.d.cts +59 -0
- package/dist/workflows/refusals.d.ts +59 -0
- package/dist/workflows/refusals.js +40 -0
- package/dist/workflows.cjs +52 -504
- package/dist/workflows.d.cts +4 -310
- package/dist/workflows.d.ts +4 -310
- package/dist/workflows.js +21 -368
- package/package.json +8 -8
- package/dist/chunk-A6ZU4QU3.js +0 -171
- package/dist/entities-DTNJMeVf.d.cts +0 -205
- package/dist/entities-DTNJMeVf.d.ts +0 -205
- package/dist/ports-C_OfflMQ.d.cts +0 -66
- package/dist/ports-C_OfflMQ.d.ts +0 -66
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @geonosis/document
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3d596f0]
|
|
8
|
+
- Updated dependencies [20bc769]
|
|
9
|
+
- @geonosis/workflows@0.7.0
|
|
10
|
+
|
|
11
|
+
## 0.9.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 1d51cae: Declarations are emitted by TypeScript's own compiler, one file per module with explicit extensions, where a bundler used to merge them. Three read differently with the same shape: `ErrorBoundary`'s `render` lists its return union in another order, and `documentSurface` and `DocumentSurfaceOptions` name their handle `DocumentStoreHandle`, the name the package already exported for `DrizzleHandle`.
|
|
16
|
+
|
|
17
|
+
TypeScript 7 infers and prints some of them differently. `SkeletonCard`, `SkeletonLine`, `SkeletonTable` and `SkeletonWidget` are typed as the `MemoExoticComponent` React's `memo` returns rather than a `NamedExoticComponent`; `documentWorkflows`, `jsonColumn`, `keyset` and `sqlFragments` read with their members in another order or an `& unknown` on a constraint, the same types.
|
|
18
|
+
- Updated dependencies [1d51cae]
|
|
19
|
+
- @geonosis/db@0.14.2
|
|
20
|
+
|
|
3
21
|
## 0.9.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,48 @@
|
|
|
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/actor.ts
|
|
40
|
+
var exports_actor = {};
|
|
41
|
+
__export(exports_actor, {
|
|
42
|
+
isSystemActor: () => isSystemActor,
|
|
43
|
+
systemActor: () => systemActor
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_actor);
|
|
46
|
+
var SYSTEM_PREFIX = "system:";
|
|
47
|
+
var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
|
|
48
|
+
var isSystemActor = (actor) => actor.startsWith(SYSTEM_PREFIX);
|
|
@@ -0,0 +1,75 @@
|
|
|
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/body-version.ts
|
|
40
|
+
var exports_body_version = {};
|
|
41
|
+
__export(exports_body_version, {
|
|
42
|
+
BODY_VERSION_KEY: () => BODY_VERSION_KEY,
|
|
43
|
+
documentBodyVersioning: () => documentBodyVersioning,
|
|
44
|
+
migrateBody: () => migrateBody,
|
|
45
|
+
stampBody: () => stampBody
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(exports_body_version);
|
|
48
|
+
var BODY_VERSION_KEY = "_v";
|
|
49
|
+
var versionOf = (body) => {
|
|
50
|
+
const stamped = body[BODY_VERSION_KEY];
|
|
51
|
+
return typeof stamped === "number" && Number.isInteger(stamped) ? stamped : 1;
|
|
52
|
+
};
|
|
53
|
+
var migrateBody = (definition, stored) => {
|
|
54
|
+
if (stored === null || typeof stored !== "object" || Array.isArray(stored))
|
|
55
|
+
return stored;
|
|
56
|
+
const target = definition.bodyVersion ?? 1;
|
|
57
|
+
const steps = definition.migrations ?? {};
|
|
58
|
+
let body = stored;
|
|
59
|
+
for (let version = versionOf(body);version < target; version += 1) {
|
|
60
|
+
const step = steps[version];
|
|
61
|
+
if (step === undefined)
|
|
62
|
+
break;
|
|
63
|
+
body = step(body);
|
|
64
|
+
}
|
|
65
|
+
const { [BODY_VERSION_KEY]: _stamp, ...withoutStamp } = body;
|
|
66
|
+
return withoutStamp;
|
|
67
|
+
};
|
|
68
|
+
var stampBody = (definition, body) => ({
|
|
69
|
+
...body,
|
|
70
|
+
[BODY_VERSION_KEY]: definition.bodyVersion ?? 1
|
|
71
|
+
});
|
|
72
|
+
var documentBodyVersioning = (definition) => ({
|
|
73
|
+
migrate: (stored) => migrateBody(definition, stored),
|
|
74
|
+
stamp: (body) => stampBody(definition, body)
|
|
75
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const BODY_VERSION_KEY = "_v";
|
|
2
|
+
type StoredBody = Record<string, unknown>;
|
|
3
|
+
/** A step declared for ONE entity's stored shape, keyed by the version it reads FROM. */
|
|
4
|
+
export type DocumentBodyMigrations<Body extends StoredBody = StoredBody> = Readonly<Record<number, (body: Body) => Body>>;
|
|
5
|
+
/**
|
|
6
|
+
* What an entity declares about its own body's history: the version it is at today, and the steps
|
|
7
|
+
* that bring an older stored body up to it. Absent, an entity is at version 1 with no steps —
|
|
8
|
+
* every field here is per-entity, so a step declared on one entity's `migrations` can never run on
|
|
9
|
+
* another's body, which is the gap a single shared step table left open.
|
|
10
|
+
*/
|
|
11
|
+
export type DocumentBodyVersion<Body extends StoredBody = StoredBody> = {
|
|
12
|
+
bodyVersion?: number;
|
|
13
|
+
migrations?: DocumentBodyMigrations<Body>;
|
|
14
|
+
};
|
|
15
|
+
/** Runs BEFORE the entity's schema parses: an older stored shape does not satisfy today's schema. */
|
|
16
|
+
export declare const migrateBody: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>, stored: unknown) => unknown;
|
|
17
|
+
export declare const stampBody: <Body>(definition: {
|
|
18
|
+
bodyVersion?: number;
|
|
19
|
+
}, body: Body) => unknown;
|
|
20
|
+
/** The migrate/stamp pair, bound to ONE entity's own declared version and steps. */
|
|
21
|
+
export declare const documentBodyVersioning: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>) => {
|
|
22
|
+
migrate: (stored: unknown) => unknown;
|
|
23
|
+
stamp: (body: Body) => unknown;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const BODY_VERSION_KEY = "_v";
|
|
2
|
+
type StoredBody = Record<string, unknown>;
|
|
3
|
+
/** A step declared for ONE entity's stored shape, keyed by the version it reads FROM. */
|
|
4
|
+
export type DocumentBodyMigrations<Body extends StoredBody = StoredBody> = Readonly<Record<number, (body: Body) => Body>>;
|
|
5
|
+
/**
|
|
6
|
+
* What an entity declares about its own body's history: the version it is at today, and the steps
|
|
7
|
+
* that bring an older stored body up to it. Absent, an entity is at version 1 with no steps —
|
|
8
|
+
* every field here is per-entity, so a step declared on one entity's `migrations` can never run on
|
|
9
|
+
* another's body, which is the gap a single shared step table left open.
|
|
10
|
+
*/
|
|
11
|
+
export type DocumentBodyVersion<Body extends StoredBody = StoredBody> = {
|
|
12
|
+
bodyVersion?: number;
|
|
13
|
+
migrations?: DocumentBodyMigrations<Body>;
|
|
14
|
+
};
|
|
15
|
+
/** Runs BEFORE the entity's schema parses: an older stored shape does not satisfy today's schema. */
|
|
16
|
+
export declare const migrateBody: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>, stored: unknown) => unknown;
|
|
17
|
+
export declare const stampBody: <Body>(definition: {
|
|
18
|
+
bodyVersion?: number;
|
|
19
|
+
}, body: Body) => unknown;
|
|
20
|
+
/** The migrate/stamp pair, bound to ONE entity's own declared version and steps. */
|
|
21
|
+
export declare const documentBodyVersioning: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>) => {
|
|
22
|
+
migrate: (stored: unknown) => unknown;
|
|
23
|
+
stamp: (body: Body) => unknown;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/core/body-version.ts
|
|
2
|
+
var BODY_VERSION_KEY = "_v";
|
|
3
|
+
var versionOf = (body) => {
|
|
4
|
+
const stamped = body[BODY_VERSION_KEY];
|
|
5
|
+
return typeof stamped === "number" && Number.isInteger(stamped) ? stamped : 1;
|
|
6
|
+
};
|
|
7
|
+
var migrateBody = (definition, stored) => {
|
|
8
|
+
if (stored === null || typeof stored !== "object" || Array.isArray(stored))
|
|
9
|
+
return stored;
|
|
10
|
+
const target = definition.bodyVersion ?? 1;
|
|
11
|
+
const steps = definition.migrations ?? {};
|
|
12
|
+
let body = stored;
|
|
13
|
+
for (let version = versionOf(body);version < target; version += 1) {
|
|
14
|
+
const step = steps[version];
|
|
15
|
+
if (step === undefined)
|
|
16
|
+
break;
|
|
17
|
+
body = step(body);
|
|
18
|
+
}
|
|
19
|
+
const { [BODY_VERSION_KEY]: _stamp, ...withoutStamp } = body;
|
|
20
|
+
return withoutStamp;
|
|
21
|
+
};
|
|
22
|
+
var stampBody = (definition, body) => ({
|
|
23
|
+
...body,
|
|
24
|
+
[BODY_VERSION_KEY]: definition.bodyVersion ?? 1
|
|
25
|
+
});
|
|
26
|
+
var documentBodyVersioning = (definition) => ({
|
|
27
|
+
migrate: (stored) => migrateBody(definition, stored),
|
|
28
|
+
stamp: (body) => stampBody(definition, body)
|
|
29
|
+
});
|
|
30
|
+
export {
|
|
31
|
+
BODY_VERSION_KEY,
|
|
32
|
+
documentBodyVersioning,
|
|
33
|
+
migrateBody,
|
|
34
|
+
stampBody
|
|
35
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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/canonical.ts
|
|
40
|
+
var exports_canonical = {};
|
|
41
|
+
__export(exports_canonical, {
|
|
42
|
+
canonicalOf: () => canonicalOf
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(exports_canonical);
|
|
45
|
+
var KEY_ORDER = new Intl.Collator("en-US");
|
|
46
|
+
var canonicalOf = (input) => {
|
|
47
|
+
if (input === null || typeof input !== "object")
|
|
48
|
+
return input;
|
|
49
|
+
const { toJSON } = input;
|
|
50
|
+
if (typeof toJSON === "function")
|
|
51
|
+
return canonicalOf(toJSON.call(input));
|
|
52
|
+
if (Array.isArray(input))
|
|
53
|
+
return input.map(canonicalOf);
|
|
54
|
+
return Object.fromEntries(Object.entries(input).toSorted(([a], [b]) => KEY_ORDER.compare(a, b)).map(([key, held]) => [key, canonicalOf(held)]));
|
|
55
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep, key-order-independent, and read as JSON writes it (a `Date` is its ISO string). The ONE
|
|
3
|
+
* canonicaliser both sides use — a consumer's archive recomputes `hashOf` over the identical form.
|
|
4
|
+
*/
|
|
5
|
+
export declare const canonicalOf: (input: unknown) => unknown;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep, key-order-independent, and read as JSON writes it (a `Date` is its ISO string). The ONE
|
|
3
|
+
* canonicaliser both sides use — a consumer's archive recomputes `hashOf` over the identical form.
|
|
4
|
+
*/
|
|
5
|
+
export declare const canonicalOf: (input: unknown) => unknown;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/core/canonical.ts
|
|
2
|
+
var KEY_ORDER = new Intl.Collator("en-US");
|
|
3
|
+
var canonicalOf = (input) => {
|
|
4
|
+
if (input === null || typeof input !== "object")
|
|
5
|
+
return input;
|
|
6
|
+
const { toJSON } = input;
|
|
7
|
+
if (typeof toJSON === "function")
|
|
8
|
+
return canonicalOf(toJSON.call(input));
|
|
9
|
+
if (Array.isArray(input))
|
|
10
|
+
return input.map(canonicalOf);
|
|
11
|
+
return Object.fromEntries(Object.entries(input).toSorted(([a], [b]) => KEY_ORDER.compare(a, b)).map(([key, held]) => [key, canonicalOf(held)]));
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
canonicalOf
|
|
15
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
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/document.ts
|
|
40
|
+
var exports_document = {};
|
|
41
|
+
__export(exports_document, {
|
|
42
|
+
Document: () => Document,
|
|
43
|
+
fieldPatterns: () => fieldPatterns,
|
|
44
|
+
headFields: () => headFields,
|
|
45
|
+
recordFields: () => recordFields,
|
|
46
|
+
validatorOf: () => validatorOf
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(exports_document);
|
|
49
|
+
var fieldPatterns = {
|
|
50
|
+
calendarDate: /^\d{4}-\d{2}-\d{2}$/,
|
|
51
|
+
decimal: /^-?\d+(?:\.\d+)?$/
|
|
52
|
+
};
|
|
53
|
+
var FIELD_CHECKS = {
|
|
54
|
+
calendarDate: {
|
|
55
|
+
message: "a calendar date is `YYYY-MM-DD`, never prose",
|
|
56
|
+
test: (value) => typeof value === "string" && fieldPatterns.calendarDate.test(value)
|
|
57
|
+
},
|
|
58
|
+
decimal: {
|
|
59
|
+
message: "an amount is a decimal string, never a float",
|
|
60
|
+
test: (value) => typeof value === "string" && fieldPatterns.decimal.test(value)
|
|
61
|
+
},
|
|
62
|
+
int: {
|
|
63
|
+
message: "an integer",
|
|
64
|
+
test: (value) => typeof value === "number" && Number.isInteger(value)
|
|
65
|
+
},
|
|
66
|
+
positiveInt: {
|
|
67
|
+
message: "a positive integer",
|
|
68
|
+
test: (value) => typeof value === "number" && Number.isInteger(value) && value > 0
|
|
69
|
+
},
|
|
70
|
+
text: { message: "a string", test: (value) => typeof value === "string" }
|
|
71
|
+
};
|
|
72
|
+
var validatorOf = (fields, options) => {
|
|
73
|
+
const nullable = options?.nullable ?? false;
|
|
74
|
+
return {
|
|
75
|
+
"~standard": {
|
|
76
|
+
validate: (input) => {
|
|
77
|
+
if (input === null || typeof input !== "object") {
|
|
78
|
+
return { issues: [{ message: "expected an object" }] };
|
|
79
|
+
}
|
|
80
|
+
const record = input;
|
|
81
|
+
const issues = [];
|
|
82
|
+
const value = {};
|
|
83
|
+
for (const [key, kind] of Object.entries(fields)) {
|
|
84
|
+
const held = record[key];
|
|
85
|
+
value[key] = held;
|
|
86
|
+
if (nullable && held === null)
|
|
87
|
+
continue;
|
|
88
|
+
if (!FIELD_CHECKS[kind].test(held)) {
|
|
89
|
+
issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return issues.length > 0 ? { issues } : { value };
|
|
93
|
+
},
|
|
94
|
+
vendor: "geonosis-document",
|
|
95
|
+
version: 1
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
var parseWith = (schema, input) => {
|
|
100
|
+
const result = schema["~standard"].validate(input);
|
|
101
|
+
if (result instanceof Promise) {
|
|
102
|
+
throw new Error("Document.head and Document.record parse synchronously; an async Standard Schema cannot back them");
|
|
103
|
+
}
|
|
104
|
+
if (result.issues !== undefined) {
|
|
105
|
+
throw new Error(result.issues.map((issue) => issue.message).join("; "));
|
|
106
|
+
}
|
|
107
|
+
return result.value;
|
|
108
|
+
};
|
|
109
|
+
var headFields = {
|
|
110
|
+
status: "text",
|
|
111
|
+
issueDate: "calendarDate",
|
|
112
|
+
dueDate: "calendarDate",
|
|
113
|
+
counterparty: "text",
|
|
114
|
+
externalRef: "text",
|
|
115
|
+
revision: "text",
|
|
116
|
+
total: "decimal"
|
|
117
|
+
};
|
|
118
|
+
var recordFields = {
|
|
119
|
+
version: "positiveInt",
|
|
120
|
+
createdAt: "int",
|
|
121
|
+
updatedAt: "int"
|
|
122
|
+
};
|
|
123
|
+
var headValidator = validatorOf(headFields, { nullable: true });
|
|
124
|
+
var recordValidator = validatorOf(recordFields);
|
|
125
|
+
var Document = {
|
|
126
|
+
head: headValidator,
|
|
127
|
+
headFields,
|
|
128
|
+
record: recordValidator,
|
|
129
|
+
recordFields,
|
|
130
|
+
extend: (definition) => ({
|
|
131
|
+
...definition,
|
|
132
|
+
headOf: (body) => parseWith(headValidator, definition.headOf(body)),
|
|
133
|
+
is: (document) => document.entity === definition.name,
|
|
134
|
+
view: definition.view ?? definition.body
|
|
135
|
+
})
|
|
136
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { DocumentBodyMigrations } from './body-version.cjs';
|
|
3
|
+
import type { DocumentNumbering } from './numbering.cjs';
|
|
4
|
+
import type { DocumentStatusMachine } from './status.cjs';
|
|
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 {};
|