@latticecms/core 0.0.0 → 0.1.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.
Files changed (113) hide show
  1. package/README.md +1174 -2
  2. package/dist/access.d.ts +210 -0
  3. package/dist/access.d.ts.map +1 -0
  4. package/dist/access.js +225 -0
  5. package/dist/access.js.map +1 -0
  6. package/dist/build.d.ts +507 -0
  7. package/dist/build.d.ts.map +1 -0
  8. package/dist/build.js +598 -0
  9. package/dist/build.js.map +1 -0
  10. package/dist/collection.d.ts +480 -0
  11. package/dist/collection.d.ts.map +1 -0
  12. package/dist/collection.js +344 -0
  13. package/dist/collection.js.map +1 -0
  14. package/dist/crud.d.ts +30 -0
  15. package/dist/crud.d.ts.map +1 -0
  16. package/dist/crud.js +539 -0
  17. package/dist/crud.js.map +1 -0
  18. package/dist/describe.d.ts +89 -0
  19. package/dist/describe.d.ts.map +1 -0
  20. package/dist/describe.js +119 -0
  21. package/dist/describe.js.map +1 -0
  22. package/dist/errors.d.ts +179 -0
  23. package/dist/errors.d.ts.map +1 -0
  24. package/dist/errors.js +146 -0
  25. package/dist/errors.js.map +1 -0
  26. package/dist/family.d.ts +80 -0
  27. package/dist/family.d.ts.map +1 -0
  28. package/dist/family.js +231 -0
  29. package/dist/family.js.map +1 -0
  30. package/dist/index.d.ts +14 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +10 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/marker.d.ts +15 -0
  35. package/dist/marker.d.ts.map +1 -0
  36. package/dist/marker.js +28 -0
  37. package/dist/marker.js.map +1 -0
  38. package/dist/mask.d.ts +69 -0
  39. package/dist/mask.d.ts.map +1 -0
  40. package/dist/mask.js +255 -0
  41. package/dist/mask.js.map +1 -0
  42. package/dist/populate.d.ts +32 -0
  43. package/dist/populate.d.ts.map +1 -0
  44. package/dist/populate.js +73 -0
  45. package/dist/populate.js.map +1 -0
  46. package/dist/relations.d.ts +143 -0
  47. package/dist/relations.d.ts.map +1 -0
  48. package/dist/relations.js +128 -0
  49. package/dist/relations.js.map +1 -0
  50. package/dist/repo.d.ts +99 -0
  51. package/dist/repo.d.ts.map +1 -0
  52. package/dist/repo.js +83 -0
  53. package/dist/repo.js.map +1 -0
  54. package/dist/sort.d.ts +61 -0
  55. package/dist/sort.d.ts.map +1 -0
  56. package/dist/sort.js +145 -0
  57. package/dist/sort.js.map +1 -0
  58. package/dist/store/conformance.d.ts +15 -0
  59. package/dist/store/conformance.d.ts.map +1 -0
  60. package/dist/store/conformance.js +683 -0
  61. package/dist/store/conformance.js.map +1 -0
  62. package/dist/store/index.d.ts +9 -0
  63. package/dist/store/index.d.ts.map +1 -0
  64. package/dist/store/index.js +8 -0
  65. package/dist/store/index.js.map +1 -0
  66. package/dist/store.d.ts +113 -0
  67. package/dist/store.d.ts.map +1 -0
  68. package/dist/store.js +176 -0
  69. package/dist/store.js.map +1 -0
  70. package/dist/tenancy.d.ts +66 -0
  71. package/dist/tenancy.d.ts.map +1 -0
  72. package/dist/tenancy.js +69 -0
  73. package/dist/tenancy.js.map +1 -0
  74. package/dist/tracing.d.ts +12 -0
  75. package/dist/tracing.d.ts.map +1 -0
  76. package/dist/tracing.js +27 -0
  77. package/dist/tracing.js.map +1 -0
  78. package/dist/where.d.ts +95 -0
  79. package/dist/where.d.ts.map +1 -0
  80. package/dist/where.js +308 -0
  81. package/dist/where.js.map +1 -0
  82. package/package.json +79 -2
  83. package/skills/lattice/SKILL.md +106 -0
  84. package/skills/lattice/references/access.md +76 -0
  85. package/skills/lattice/references/cli.md +87 -0
  86. package/skills/lattice/references/collection.md +91 -0
  87. package/skills/lattice/references/event-handler.md +88 -0
  88. package/skills/lattice/references/masking.md +72 -0
  89. package/skills/lattice/references/method.md +85 -0
  90. package/skills/lattice/references/override.md +77 -0
  91. package/skills/lattice/references/relations.md +90 -0
  92. package/skills/lattice/references/tenancy.md +82 -0
  93. package/skills/lattice/references/testing.md +75 -0
  94. package/src/access.ts +429 -0
  95. package/src/build.ts +1722 -0
  96. package/src/collection.ts +1018 -0
  97. package/src/crud.ts +795 -0
  98. package/src/describe.ts +232 -0
  99. package/src/errors.ts +170 -0
  100. package/src/family.ts +334 -0
  101. package/src/index.ts +42 -0
  102. package/src/marker.ts +54 -0
  103. package/src/mask.ts +307 -0
  104. package/src/populate.ts +96 -0
  105. package/src/relations.ts +353 -0
  106. package/src/repo.ts +209 -0
  107. package/src/sort.ts +214 -0
  108. package/src/store/conformance.ts +1007 -0
  109. package/src/store/index.ts +16 -0
  110. package/src/store.ts +309 -0
  111. package/src/tenancy.ts +124 -0
  112. package/src/tracing.ts +29 -0
  113. package/src/where.ts +463 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mask.js","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAe,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAgBrC,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,KAAuB,EACvB,QAA2B;IAE3B,MAAM,MAAM,GAAoC,EAAE,GAAG,KAAK,EAAE,CAAC;IAC7D,MAAM,MAAM,GAAoC,EAAE,GAAG,KAAK,EAAE,CAAC;IAC7D,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,SAAS;YAAE,SAAS;QACnC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;QACrB,mEAAmE;QACnE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;aACd,QAAQ,CAAC,IAAI,CAAC;a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AAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAC1B,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO;YACpC,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;YACvD,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod';
2
+ import type { AnyCollection, AnyRelation } from './collection.js';
3
+ /**
4
+ * A populated document the caller may not read, or one that no longer
5
+ * exists: its id only (0022). A UI can still show the row.
6
+ */
7
+ declare const withheld: z.ZodObject<{
8
+ id: z.ZodString;
9
+ }, z.core.$strip>;
10
+ export type Withheld = z.output<typeof withheld>;
11
+ /** The `populate` input field for `keys`, or no field when there are none. */
12
+ export declare function populateShape(keys: readonly string[]): z.core.$ZodShape;
13
+ /**
14
+ * What `populate` may name on a read of `collection`: its ref fields, and
15
+ * on `get` its `many()` relations. `find` populates refs only, so a page
16
+ * cannot fetch up to 1000 links for each of its documents.
17
+ */
18
+ export declare function populateKeys(collection: AnyCollection, read: 'get' | 'find'): string[];
19
+ /** The fields a link of `relation` carries, beside its two refs. */
20
+ export declare function linkFields(relation: AnyRelation): string[];
21
+ /**
22
+ * The schemas of a populated read of `collection`, by the client output
23
+ * schema of each collection: `fields` holds each ref field's expanded schema (its
24
+ * target document or `Withheld`, element-wise for a list of ids), and `wide`
25
+ * is the document as a read sends it, with each ref field plain or expanded.
26
+ */
27
+ export declare function expansionOf(collection: AnyCollection, outputs: ReadonlyMap<string, z.ZodType>, read: 'get' | 'find'): {
28
+ readonly fields: Readonly<Record<string, z.ZodType>>;
29
+ readonly wide: z.ZodObject;
30
+ };
31
+ export {};
32
+ //# sourceMappingURL=populate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"populate.d.ts","sourceRoot":"","sources":["../src/populate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAElE;;;GAGG;AACH,QAAA,MAAM,QAAQ;;iBAA+B,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEjD,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAKvE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,KAAK,GAAG,MAAM,GACnB,MAAM,EAAE,CAKV;AAED,oEAAoE;AACpE,wBAAgB,UAAU,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,EAAE,CAI1D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,aAAa,EACzB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EACvC,IAAI,EAAE,KAAK,GAAG,MAAM,GACnB;IACD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC;CAC5B,CAyCA"}
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * A populated document the caller may not read, or one that no longer
4
+ * exists: its id only (0022). A UI can still show the row.
5
+ */
6
+ const withheld = z.object({ id: z.string() });
7
+ /** The `populate` input field for `keys`, or no field when there are none. */
8
+ export function populateShape(keys) {
9
+ const [first, ...rest] = keys;
10
+ return first === undefined
11
+ ? {}
12
+ : { populate: z.array(z.enum([first, ...rest])).optional() };
13
+ }
14
+ /**
15
+ * What `populate` may name on a read of `collection`: its ref fields, and
16
+ * on `get` its `many()` relations. `find` populates refs only, so a page
17
+ * cannot fetch up to 1000 links for each of its documents.
18
+ */
19
+ export function populateKeys(collection, read) {
20
+ return [
21
+ ...collection.refs.map((ref) => ref.field),
22
+ ...(read === 'get' ? Object.keys(collection.relations) : []),
23
+ ];
24
+ }
25
+ /** The fields a link of `relation` carries, beside its two refs. */
26
+ export function linkFields(relation) {
27
+ return Object.keys(relation.through.schema.shape).filter((field) => field !== relation.parentField && field !== relation.targetField);
28
+ }
29
+ /**
30
+ * The schemas of a populated read of `collection`, by the client output
31
+ * schema of each collection: `fields` holds each ref field's expanded schema (its
32
+ * target document or `Withheld`, element-wise for a list of ids), and `wide`
33
+ * is the document as a read sends it, with each ref field plain or expanded.
34
+ */
35
+ export function expansionOf(collection, outputs, read) {
36
+ const fields = {};
37
+ const wide = {};
38
+ const targetOf = (slug) => {
39
+ const target = outputs.get(slug);
40
+ if (target === undefined) {
41
+ throw new Error(`Lattice: "${slug}" is not a collection of this framework, so ${collection.slug} cannot populate it`);
42
+ }
43
+ return z.union([target, withheld]);
44
+ };
45
+ for (const { field, slug, array } of collection.refs) {
46
+ const one = targetOf(slug);
47
+ const plain = collection.clientOutput.shape[field];
48
+ if (plain === undefined) {
49
+ throw new Error(`Lattice: ${collection.slug} has no field "${field}"`);
50
+ }
51
+ const expanded = array ? z.array(one) : one;
52
+ fields[field] = expanded;
53
+ wide[field] = z.union([plain, expanded]);
54
+ }
55
+ if (read === 'get') {
56
+ // A relation is in the output only when populated: its links, each
57
+ // with its fields and its target document.
58
+ for (const [name, relation] of Object.entries(collection.relations)) {
59
+ const { shape } = relation.through.clientOutput;
60
+ const link = z.object({
61
+ ...Object.fromEntries(linkFields(relation).flatMap((field) => {
62
+ const schema = shape[field];
63
+ return schema === undefined ? [] : [[field, schema]];
64
+ })),
65
+ doc: targetOf(relation.target),
66
+ });
67
+ fields[name] = z.array(link);
68
+ wide[name] = z.array(link).optional();
69
+ }
70
+ }
71
+ return { fields, wide: collection.clientOutput.extend(wide) };
72
+ }
73
+ //# sourceMappingURL=populate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"populate.js","sourceRoot":"","sources":["../src/populate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAI9C,8EAA8E;AAC9E,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9B,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,UAAyB,EACzB,IAAoB;IAEpB,OAAO;QACL,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;QAC1C,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC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UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;AAChE,CAAC"}
@@ -0,0 +1,143 @@
1
+ import { z } from 'zod';
2
+ import type { AnyCollection } from './collection.js';
3
+ /**
4
+ * What happens to the documents that refer to one being deleted:
5
+ * `restrict` refuses the delete, `cascade` deletes them too, and `nullify`
6
+ * clears the reference (0028).
7
+ */
8
+ export type OnDelete = 'restrict' | 'cascade' | 'nullify';
9
+ /** A reference as Lattice reads it: the target collection's slug and its onDelete. */
10
+ type RefInfo<Slug extends string = string, D extends OnDelete = OnDelete> = {
11
+ readonly slug: Slug;
12
+ readonly onDelete: D;
13
+ };
14
+ /**
15
+ * A string field that holds the id of a document in collection `Slug`.
16
+ * `'~ref'` is a type-only brand; at runtime the reference is a no-op check,
17
+ * so a clone such as `.min(1)` keeps it.
18
+ */
19
+ export type Ref<Slug extends string, D extends OnDelete> = z.ZodString & {
20
+ readonly '~ref'?: RefInfo<Slug, D>;
21
+ };
22
+ /**
23
+ * Marks a string field as the id of a document in collection `slug`. The
24
+ * slug, not the collection, so collections can refer to each other.
25
+ * `z.array(ref(slug))` is a list of ids. The marker is what Lattice reads;
26
+ * `x-lattice-ref` is what the field's JSON Schema says, so a client such as
27
+ * the admin knows where an id points. Both come from `slug`, here.
28
+ */
29
+ export declare function ref<const Slug extends string, const D extends OnDelete = 'restrict'>(slug: Slug, options?: {
30
+ readonly onDelete?: D;
31
+ }): Ref<Slug, D>;
32
+ /** What deleting a target does to its links: refuse, or delete them. */
33
+ export type ManyOnDelete = 'restrict' | 'cascade';
34
+ /** A many-to-many relation, through a join collection Lattice derives. */
35
+ export type Many<Target extends string, Through extends string, Fields extends z.core.$ZodShape, D extends ManyOnDelete> = {
36
+ readonly kind: 'many';
37
+ readonly target: Target;
38
+ /** The join collection's slug. */
39
+ readonly through: Through;
40
+ /** Fields each link carries, such as `sortOrder`. */
41
+ readonly fields: z.ZodObject<Fields, z.core.$strip> | undefined;
42
+ /** What deleting a target does to its links. Undefined is restrict. */
43
+ readonly onDelete: D | undefined;
44
+ };
45
+ export type AnyMany = Many<string, string, z.core.$ZodShape, ManyOnDelete>;
46
+ /**
47
+ * Relates each document to many of `target`, through a join collection
48
+ * `through` with `<parent>Id`, `<target>Id` and `fields`. Lattice derives
49
+ * that collection; its slug is `through`.
50
+ */
51
+ export declare function many<const Target extends string, const Through extends string, Fields extends z.core.$ZodShape = Record<never, never>, const D extends ManyOnDelete = 'restrict'>(target: Target, options: {
52
+ readonly through: Through;
53
+ readonly fields?: z.ZodObject<Fields, z.core.$strip>;
54
+ readonly onDelete?: D;
55
+ }): Many<Target, Through, NoInfer<Fields>, NoInfer<D>>;
56
+ /** The join collection's shape: the two refs, then the link fields. */
57
+ export type JoinShape<P extends string, T extends string, D extends ManyOnDelete, F extends z.core.$ZodShape> = {
58
+ [K in `${P}Id` | `${T}Id` | keyof F]: K extends `${P}Id` ? Ref<P, 'cascade'> : K extends `${T}Id` ? Ref<T, D> : F[K];
59
+ };
60
+ /** What `set` takes per link: the target's id and the link fields. */
61
+ export type LinkShape<T extends string, D extends ManyOnDelete, F extends z.core.$ZodShape> = {
62
+ [K in `${T}Id` | keyof F]: K extends `${T}Id` ? Ref<T, D> : F[K];
63
+ };
64
+ /**
65
+ * The join collection's schema, and the link schema `set` takes. Untyped:
66
+ * `relationsOf` in collection.ts states their types.
67
+ */
68
+ export declare function joinSchemas(parent: string, relation: AnyMany): {
69
+ readonly join: z.ZodObject<z.core.$ZodShape, z.core.$strip>;
70
+ readonly link: z.ZodObject<z.core.$ZodShape, z.core.$strip>;
71
+ readonly parentField: string;
72
+ readonly targetField: string;
73
+ };
74
+ /** The reference a field schema holds, through optional, nullable, default and array. */
75
+ type RefIn<F> = F extends {
76
+ readonly '~ref'?: infer R extends RefInfo;
77
+ } ? R : F extends z.ZodOptional<infer I> | z.ZodNullable<infer I> | z.ZodDefault<infer I> | z.ZodArray<infer I> ? RefIn<I> : never;
78
+ /** Each ref field of `Shape`, and the slug it refers to. */
79
+ export type RefSlugs<Shape extends z.core.$ZodShape> = {
80
+ [K in keyof Shape as [RefIn<Shape[K]>] extends [never] ? never : K]: RefIn<Shape[K]>['slug'];
81
+ };
82
+ /** The fields of `Shape` whose ref cascades. */
83
+ export type CascadeFields<Shape extends z.core.$ZodShape> = {
84
+ [K in keyof Shape]: [RefIn<Shape[K]>] extends [never] ? never : RefIn<Shape[K]>['onDelete'] extends 'cascade' ? K : never;
85
+ }[keyof Shape];
86
+ /** A field whose own schema is a ref with `nullify`: nothing wraps it optional or nullable. */
87
+ type RequiredNullify<Shape extends z.core.$ZodShape> = {
88
+ [K in keyof Shape]: Shape[K] extends {
89
+ readonly '~ref'?: RefInfo<string, 'nullify'>;
90
+ } ? K : never;
91
+ }[keyof Shape];
92
+ /** A list of ids, possibly wrapped, with `cascade`. */
93
+ type ArrayCascade<F> = F extends z.ZodArray<infer I> ? [RefIn<I>] extends [never] ? false : RefIn<I>['onDelete'] extends 'cascade' ? true : false : F extends z.ZodOptional<infer I> | z.ZodNullable<infer I> | z.ZodDefault<infer I> ? ArrayCascade<I> : false;
94
+ type CascadeArrays<Shape extends z.core.$ZodShape> = {
95
+ [K in keyof Shape]: ArrayCascade<Shape[K]> extends true ? K : never;
96
+ }[keyof Shape];
97
+ /**
98
+ * The definition-time rules of refs. A rejected schema adds a key the
99
+ * options lack, so the error names the field.
100
+ */
101
+ export type RefCheck<Shape extends z.core.$ZodShape> = [
102
+ RequiredNullify<Shape>
103
+ ] extends [never] ? [CascadeArrays<Shape>] extends [never] ? unknown : {
104
+ readonly '~error': `"${CascadeArrays<Shape> & string}" is a list of ids; it cannot cascade (use restrict or nullify)`;
105
+ } : {
106
+ readonly '~error': `"${RequiredNullify<Shape> & string}" is required; nullify needs it .optional() or .nullable()`;
107
+ };
108
+ /** One ref field of a collection, as the generated delete reads it. */
109
+ export type RefField = {
110
+ readonly field: string;
111
+ readonly slug: string;
112
+ readonly onDelete: OnDelete;
113
+ /** A list of ids: nullify pulls the id, and a lookup uses `has`. */
114
+ readonly array: boolean;
115
+ /** What nullify writes: undefined to unset, or null. */
116
+ readonly cleared: null | undefined;
117
+ };
118
+ /**
119
+ * The ref fields of a schema. Throws on the rules `RefCheck` states, for
120
+ * the forms the types do not catch.
121
+ */
122
+ export declare function refsOf(slug: string, shape: z.core.$ZodShape): RefField[];
123
+ /** A relation as REFERENCED names it: its parent collection and its name. */
124
+ export type RelationName = {
125
+ readonly collection: string;
126
+ readonly name: string;
127
+ };
128
+ /**
129
+ * A collection that refers to another one, through one of its ref fields.
130
+ * A join collection's refs carry the relation that derived it, since the
131
+ * join is not in the catalog.
132
+ */
133
+ export type Referrer = {
134
+ readonly collection: AnyCollection;
135
+ readonly ref: RefField;
136
+ readonly relation: RelationName | undefined;
137
+ };
138
+ /** The referrers of each collection, by its slug. */
139
+ export type Referrers = ReadonlyMap<string, readonly Referrer[]>;
140
+ /** Who refers to each collection among `collections`. */
141
+ export declare function referrersOf(collections: readonly AnyCollection[]): Referrers;
142
+ export {};
143
+ //# sourceMappingURL=relations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../src/relations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AAE1D,sFAAsF;AACtF,KAAK,OAAO,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI;IAC1E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,GAAG,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,SAAS,QAA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ACvB,QAAQ,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;CAC7C,CAAC;AAEF,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,CAAC,CAAC;AAEjE,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,GAAG,SAAS,CAqB5E"}
@@ -0,0 +1,128 @@
1
+ import { z } from 'zod';
2
+ import { innerOf } from './where.js';
3
+ function isMarker(check) {
4
+ return typeof check === 'object' && check !== null && '~lattice' in check;
5
+ }
6
+ /**
7
+ * Marks a string field as the id of a document in collection `slug`. The
8
+ * slug, not the collection, so collections can refer to each other.
9
+ * `z.array(ref(slug))` is a list of ids. The marker is what Lattice reads;
10
+ * `x-lattice-ref` is what the field's JSON Schema says, so a client such as
11
+ * the admin knows where an id points. Both come from `slug`, here.
12
+ */
13
+ export function ref(slug, options) {
14
+ const info = { slug, onDelete: options?.onDelete ?? 'restrict' };
15
+ const marker = Object.assign(z.check(() => { }), { '~lattice': info });
16
+ return z.string().check(marker).meta({ 'x-lattice-ref': slug });
17
+ }
18
+ /**
19
+ * Relates each document to many of `target`, through a join collection
20
+ * `through` with `<parent>Id`, `<target>Id` and `fields`. Lattice derives
21
+ * that collection; its slug is `through`.
22
+ */
23
+ export function many(target, options) {
24
+ return {
25
+ kind: 'many',
26
+ target,
27
+ through: options.through,
28
+ fields: options.fields,
29
+ onDelete: options.onDelete,
30
+ };
31
+ }
32
+ /**
33
+ * The join collection's schema, and the link schema `set` takes. Untyped:
34
+ * `relationsOf` in collection.ts states their types.
35
+ */
36
+ export function joinSchemas(parent, relation) {
37
+ const parentField = `${parent}Id`;
38
+ const targetField = `${relation.target}Id`;
39
+ const fields = relation.fields?.shape ?? {};
40
+ const target = {
41
+ [targetField]: ref(relation.target, {
42
+ onDelete: relation.onDelete ?? 'restrict',
43
+ }),
44
+ };
45
+ return {
46
+ join: z.object({
47
+ [parentField]: ref(parent, { onDelete: 'cascade' }),
48
+ ...target,
49
+ ...fields,
50
+ }),
51
+ link: z.object({ ...target, ...fields }),
52
+ parentField,
53
+ targetField,
54
+ };
55
+ }
56
+ /** The ref a field schema holds, unwrapping as `RefIn` does. */
57
+ function refIn(schema) {
58
+ let current = schema;
59
+ let optional = false;
60
+ let nullable = false;
61
+ let array = false;
62
+ for (;;) {
63
+ if (current instanceof z.core.$ZodOptional)
64
+ optional = true;
65
+ if (current instanceof z.core.$ZodNullable)
66
+ nullable = true;
67
+ const inner = innerOf(current);
68
+ if (inner !== undefined) {
69
+ current = inner;
70
+ continue;
71
+ }
72
+ if (current instanceof z.core.$ZodArray && !array) {
73
+ array = true;
74
+ current = current._zod.def.element;
75
+ continue;
76
+ }
77
+ break;
78
+ }
79
+ const marker = (current._zod.def.checks ?? []).find(isMarker);
80
+ return marker === undefined
81
+ ? undefined
82
+ : { info: marker['~lattice'], array, optional, nullable };
83
+ }
84
+ /**
85
+ * The ref fields of a schema. Throws on the rules `RefCheck` states, for
86
+ * the forms the types do not catch.
87
+ */
88
+ export function refsOf(slug, shape) {
89
+ const refs = [];
90
+ for (const [field, schema] of Object.entries(shape)) {
91
+ const found = refIn(schema);
92
+ if (found === undefined)
93
+ continue;
94
+ const { info, array, optional, nullable } = found;
95
+ if (array && info.onDelete === 'cascade') {
96
+ throw new Error(`Lattice: "${slug}.${field}" is a list of ids; it cannot cascade (use restrict or nullify)`);
97
+ }
98
+ if (!array && info.onDelete === 'nullify' && !optional && !nullable) {
99
+ throw new Error(`Lattice: "${slug}.${field}" is required; nullify needs it .optional() or .nullable()`);
100
+ }
101
+ refs.push({
102
+ field,
103
+ slug: info.slug,
104
+ onDelete: info.onDelete,
105
+ array,
106
+ cleared: optional ? undefined : null,
107
+ });
108
+ }
109
+ return refs;
110
+ }
111
+ /** Who refers to each collection among `collections`. */
112
+ export function referrersOf(collections) {
113
+ const relations = new Map(collections.flatMap((parent) => Object.entries(parent.relations).map(([name, relation]) => [
114
+ relation.through.slug,
115
+ { collection: parent.slug, name },
116
+ ])));
117
+ const referrers = new Map();
118
+ for (const collection of collections) {
119
+ const relation = relations.get(collection.slug);
120
+ for (const ref of collection.refs) {
121
+ const list = referrers.get(ref.slug) ?? [];
122
+ list.push({ collection, ref, relation });
123
+ referrers.set(ref.slug, list);
124
+ }
125
+ }
126
+ return referrers;
127
+ }
128
+ //# sourceMappingURL=relations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relations.js","sourceRoot":"","sources":["../src/relations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA2BrC,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,UAAU,IAAI,KAAK,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAGjB,IAAU,EAAE,OAAmC;IAC/C,MAAM,IAAI,GAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,CAAC;IAC1E,MAAM,MAAM,GAAc,MAAM,CAAC,MAAM,CACrC,CAAC,CAAC,KAAK,CAAS,GAAG,EAAE,GAAE,CAAC,CAAC,EACzB,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAC;IACF,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC;AA0BD;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAMlB,MAAc,EACd,OAIC;IAKD,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,MAAM;QACN,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QA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AG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/dist/repo.d.ts ADDED
@@ -0,0 +1,99 @@
1
+ import type { z } from 'zod';
2
+ import { unscoped } from './access.js';
3
+ import type { AnyCollection } from './collection.js';
4
+ import { type Sort } from './sort.js';
5
+ import type { CollectionStore, FindQuery, Patch } from './store.js';
6
+ import { type Scope, type TenantField } from './tenancy.js';
7
+ import { type AnyWhere, type Where } from './where.js';
8
+ /** A collection's stored document: its schema plus `id`, `createdAt` and `updatedAt`. */
9
+ export type Doc<C extends {
10
+ readonly output: z.ZodType;
11
+ }> = z.output<C['output']>;
12
+ /**
13
+ * A collection's document as a client receives it: `Doc`, with each
14
+ * maskable field optional, since the caller's rules may withhold it.
15
+ */
16
+ export type ClientDoc<C extends {
17
+ readonly clientOutput: z.ZodType;
18
+ }> = z.output<C['clientOutput']>;
19
+ /** A query of `Repo.find`. Each key is optional; the defaults are find's. */
20
+ export type RepoQuery<D> = {
21
+ readonly where?: Where<D>;
22
+ readonly sort?: Sort<D>;
23
+ readonly limit?: number;
24
+ /** The `next` cursor of the previous page. */
25
+ readonly after?: string;
26
+ };
27
+ /**
28
+ * What a `Repo` call runs under: the call's scope for this collection, from
29
+ * `ctx.access.scope()`, or `unscoped` for trusted code that acts for no
30
+ * caller. Required, so a forgotten filter cannot read every row (0023).
31
+ */
32
+ export type RepoScope<C extends AnyCollection> = Scope<C['slug']> | typeof unscoped;
33
+ /**
34
+ * What `insert` runs under. A tenanted collection's new row needs its
35
+ * tenant, so `unscoped` cannot insert into it: use the call's scope, or
36
+ * `tenancy.scope(C, tenantId)`.
37
+ */
38
+ export type InsertScope<C extends AnyCollection> = [TenantField<C>] extends [
39
+ never
40
+ ] ? RepoScope<C> : Scope<C['slug']>;
41
+ /**
42
+ * A typed view of the `CollectionStore` for one collection, for hand-written
43
+ * use cases and event handlers. It is trusted: no hooks, no events and no
44
+ * access. `insert` parses its data with the schema, as create does; `update`
45
+ * writes its typed patch as given. Each call runs under
46
+ * the scope it is given: a row outside it acts as missing. A tenant bypass
47
+ * scope reads only: a write through it on a tenanted collection is
48
+ * FORBIDDEN.
49
+ */
50
+ export interface Repo<C extends AnyCollection> {
51
+ get(id: string, scope: RepoScope<C>): Promise<Doc<C> | null>;
52
+ /** The docs that exist and are in scope, in the order of `ids`. */
53
+ getMany(ids: readonly string[], scope: RepoScope<C>): Promise<Doc<C>[]>;
54
+ find(query: RepoQuery<Doc<C>>, scope: RepoScope<C>): Promise<{
55
+ docs: Doc<C>[];
56
+ next: string | null;
57
+ }>;
58
+ /** How many documents in scope match `where`. */
59
+ count(where: Where<Doc<C>>, scope: RepoScope<C>): Promise<number>;
60
+ /**
61
+ * Parses `data` with the collection's schema, as create does: defaults
62
+ * apply, unknown keys are dropped, and a failed check is VALIDATION. Then
63
+ * stores it with a new `id`, `createdAt`, `updatedAt` and the scope's
64
+ * tenant.
65
+ */
66
+ insert(data: z.input<C['schema']>, scope: InsertScope<C>): Promise<Doc<C>>;
67
+ /**
68
+ * Writes the fields in `patch` and bumps `updatedAt`; null when no doc in
69
+ * scope has `id`. It never writes the tenant field.
70
+ */
71
+ update(id: string, patch: Partial<z.output<C['schema']>>, scope: RepoScope<C>): Promise<Doc<C> | null>;
72
+ /** The removed doc, or null when no doc in scope has `id`. */
73
+ remove(id: string, scope: RepoScope<C>): Promise<Doc<C> | null>;
74
+ }
75
+ /** A new document: `data` with an `id`, `createdAt` and `updatedAt`. */
76
+ export declare function stamped<D extends object>(data: D): D & {
77
+ id: `${string}-${string}-${string}-${string}-${string}`;
78
+ createdAt: string;
79
+ updatedAt: string;
80
+ };
81
+ /** A patch that also bumps `updatedAt`. */
82
+ export declare function touched<P extends Patch>(patch: P): P & {
83
+ updatedAt: string;
84
+ };
85
+ /** A store query with find's default sort and limit. */
86
+ export declare function findQuery(collection: string, query: {
87
+ readonly where?: AnyWhere | undefined;
88
+ readonly sort?: readonly string[] | undefined;
89
+ readonly limit?: number | undefined;
90
+ readonly after?: string | undefined;
91
+ }): FindQuery;
92
+ /**
93
+ * The repo of `collection`. The store holds untyped documents (`StoredDoc`); a
94
+ * repo trusts that each one has its collection's type, as the writes that
95
+ * put it there did. The overload states that type; the implementation is
96
+ * typed for any collection, so no value is cast.
97
+ */
98
+ export declare function repo<C extends AnyCollection>(store: CollectionStore, collection: C): Repo<C>;
99
+ //# sourceMappingURL=repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../src/repo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAW,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAA6B,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAa,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAiB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,KAAK,QAAQ,EAAQ,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAE7D,yFAAyF;AACzF,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAA;CAAE,IAAI,CAAC,CAAC,MAAM,CAClE,CAAC,CAAC,QAAQ,CAAC,CACZ,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,OAAO,CAAA;CAAE,IAClE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;AAE9B,6EAA6E;AAC7E,MAAM,MAAM,SAAS,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MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,GACA,SAAS,CASX;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,aAAa,EAC1C,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,CAAC,GACZ,IAAI,CAAC,CAAC,CAAC,CAAC"}
package/dist/repo.js ADDED
@@ -0,0 +1,83 @@
1
+ import { unscoped, whereOf } from './access.js';
2
+ import { LatticeError, parse } from './errors.js';
3
+ import { defaultLimit, defaultSort } from './sort.js';
4
+ import { withoutTenant } from './tenancy.js';
5
+ import { both } from './where.js';
6
+ /**
7
+ * The filter of a write. A bypass scope has no tenant, so it cannot write a
8
+ * tenanted collection.
9
+ */
10
+ function writable(collection, scope) {
11
+ const where = whereOf(collection.slug, scope);
12
+ if (collection.tenant !== undefined &&
13
+ scope !== unscoped &&
14
+ scope.tenantId === undefined) {
15
+ throw LatticeError.FORBIDDEN();
16
+ }
17
+ return where;
18
+ }
19
+ /** A new document: `data` with an `id`, `createdAt` and `updatedAt`. */
20
+ export function stamped(data) {
21
+ const now = new Date().toISOString();
22
+ return { ...data, id: crypto.randomUUID(), createdAt: now, updatedAt: now };
23
+ }
24
+ /** A patch that also bumps `updatedAt`. */
25
+ export function touched(patch) {
26
+ return { ...patch, updatedAt: new Date().toISOString() };
27
+ }
28
+ /** A store query with find's default sort and limit. */
29
+ export function findQuery(collection, query) {
30
+ const { where, sort, limit, after } = query;
31
+ return {
32
+ collection,
33
+ sort: sort ?? defaultSort,
34
+ limit: limit ?? defaultLimit,
35
+ ...(where === undefined ? {} : { where }),
36
+ ...(after === undefined ? {} : { after }),
37
+ };
38
+ }
39
+ export function repo(store, collection) {
40
+ const { slug } = collection;
41
+ // Each method is async, so a scope for another collection rejects, as a
42
+ // store failure would, rather than throwing before a promise exists.
43
+ return {
44
+ async get(id, scope) {
45
+ return store.get(slug, id, whereOf(slug, scope));
46
+ },
47
+ async getMany(ids, scope) {
48
+ return store.getMany(slug, ids, whereOf(slug, scope));
49
+ },
50
+ async find(query, scope) {
51
+ const where = both(query.where, whereOf(slug, scope));
52
+ return store.find(findQuery(slug, { ...query, where }));
53
+ },
54
+ async count(where, scope) {
55
+ return store.count(slug, both(where, whereOf(slug, scope)));
56
+ },
57
+ async insert(data, scope) {
58
+ // A new row has no filter to meet, but a scope for another collection
59
+ // is still refused.
60
+ writable(collection, scope);
61
+ const { tenant } = collection;
62
+ if (tenant !== undefined && scope === unscoped) {
63
+ throw new Error(`Lattice: "${slug}" is tenanted, so insert needs a scope with a tenant, such as tenancy.scope()`);
64
+ }
65
+ // The tenant comes from the scope, after the parse: the schema has none.
66
+ const parsed = parse(collection.schema, data);
67
+ const doc = stamped(tenant === undefined || scope === unscoped
68
+ ? parsed
69
+ : { ...parsed, [tenant]: scope.tenantId });
70
+ await store.insert(slug, doc);
71
+ return doc;
72
+ },
73
+ async update(id, patch, scope) {
74
+ const where = writable(collection, scope);
75
+ const changes = touched(withoutTenant(collection, patch));
76
+ return store.update(slug, id, changes, where);
77
+ },
78
+ async remove(id, scope) {
79
+ return store.remove(slug, id, writable(collection, scope));
80
+ },
81
+ };
82
+ }
83
+ //# sourceMappingURL=repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo.js","sourceRoot":"","sources":["../src/repo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAgC,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAiB,IAAI,EAAc,MAAM,YAAY,CAAC;AAqF7D;;;GAGG;AACH,SAAS,QAAQ,CACf,UAAyB,EACzB,KAA8B;IAE9B,MAAM,KAAK,GA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