@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.
- package/README.md +1174 -2
- package/dist/access.d.ts +210 -0
- package/dist/access.d.ts.map +1 -0
- package/dist/access.js +225 -0
- package/dist/access.js.map +1 -0
- package/dist/build.d.ts +507 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +598 -0
- package/dist/build.js.map +1 -0
- package/dist/collection.d.ts +480 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/collection.js +344 -0
- package/dist/collection.js.map +1 -0
- package/dist/crud.d.ts +30 -0
- package/dist/crud.d.ts.map +1 -0
- package/dist/crud.js +539 -0
- package/dist/crud.js.map +1 -0
- package/dist/describe.d.ts +89 -0
- package/dist/describe.d.ts.map +1 -0
- package/dist/describe.js +119 -0
- package/dist/describe.js.map +1 -0
- package/dist/errors.d.ts +179 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +146 -0
- package/dist/errors.js.map +1 -0
- package/dist/family.d.ts +80 -0
- package/dist/family.d.ts.map +1 -0
- package/dist/family.js +231 -0
- package/dist/family.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/marker.d.ts +15 -0
- package/dist/marker.d.ts.map +1 -0
- package/dist/marker.js +28 -0
- package/dist/marker.js.map +1 -0
- package/dist/mask.d.ts +69 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +255 -0
- package/dist/mask.js.map +1 -0
- package/dist/populate.d.ts +32 -0
- package/dist/populate.d.ts.map +1 -0
- package/dist/populate.js +73 -0
- package/dist/populate.js.map +1 -0
- package/dist/relations.d.ts +143 -0
- package/dist/relations.d.ts.map +1 -0
- package/dist/relations.js +128 -0
- package/dist/relations.js.map +1 -0
- package/dist/repo.d.ts +99 -0
- package/dist/repo.d.ts.map +1 -0
- package/dist/repo.js +83 -0
- package/dist/repo.js.map +1 -0
- package/dist/sort.d.ts +61 -0
- package/dist/sort.d.ts.map +1 -0
- package/dist/sort.js +145 -0
- package/dist/sort.js.map +1 -0
- package/dist/store/conformance.d.ts +15 -0
- package/dist/store/conformance.d.ts.map +1 -0
- package/dist/store/conformance.js +683 -0
- package/dist/store/conformance.js.map +1 -0
- package/dist/store/index.d.ts +9 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +8 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store.d.ts +113 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +176 -0
- package/dist/store.js.map +1 -0
- package/dist/tenancy.d.ts +66 -0
- package/dist/tenancy.d.ts.map +1 -0
- package/dist/tenancy.js +69 -0
- package/dist/tenancy.js.map +1 -0
- package/dist/tracing.d.ts +12 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +27 -0
- package/dist/tracing.js.map +1 -0
- package/dist/where.d.ts +95 -0
- package/dist/where.d.ts.map +1 -0
- package/dist/where.js +308 -0
- package/dist/where.js.map +1 -0
- package/package.json +79 -2
- package/skills/lattice/SKILL.md +106 -0
- package/skills/lattice/references/access.md +76 -0
- package/skills/lattice/references/cli.md +87 -0
- package/skills/lattice/references/collection.md +91 -0
- package/skills/lattice/references/event-handler.md +88 -0
- package/skills/lattice/references/masking.md +72 -0
- package/skills/lattice/references/method.md +85 -0
- package/skills/lattice/references/override.md +77 -0
- package/skills/lattice/references/relations.md +90 -0
- package/skills/lattice/references/tenancy.md +82 -0
- package/skills/lattice/references/testing.md +75 -0
- package/src/access.ts +429 -0
- package/src/build.ts +1722 -0
- package/src/collection.ts +1018 -0
- package/src/crud.ts +795 -0
- package/src/describe.ts +232 -0
- package/src/errors.ts +170 -0
- package/src/family.ts +334 -0
- package/src/index.ts +42 -0
- package/src/marker.ts +54 -0
- package/src/mask.ts +307 -0
- package/src/populate.ts +96 -0
- package/src/relations.ts +353 -0
- package/src/repo.ts +209 -0
- package/src/sort.ts +214 -0
- package/src/store/conformance.ts +1007 -0
- package/src/store/index.ts +16 -0
- package/src/store.ts +309 -0
- package/src/tenancy.ts +124 -0
- package/src/tracing.ts +29 -0
- package/src/where.ts +463 -0
package/dist/build.js
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { INVALID_SPAN_CONTEXT, context as otel, SpanKind, trace, } from '@opentelemetry/api';
|
|
2
|
+
import { isContractProcedure, procedure, router, } from '@ts-pf/contract';
|
|
3
|
+
import { isPFError, isUnexpectedError } from '@ts-pf/protocol';
|
|
4
|
+
import { createImplementer, } from '@ts-pf/server';
|
|
5
|
+
import { validate } from 'hexok';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { CallAccess, CollectionAccess, familyContext, } from './access.js';
|
|
8
|
+
import { operations, } from './collection.js';
|
|
9
|
+
import { generated, generatedRelation, } from './crud.js';
|
|
10
|
+
import { generatedMeta, methodMeta } from './describe.js';
|
|
11
|
+
import { declaredErrors, latticeCodes, refusal, toClientError, } from './errors.js';
|
|
12
|
+
import { callerFields, loggedByFamily, } from './family.js';
|
|
13
|
+
import { applyMask, maskedCollections, maskPlan, } from './mask.js';
|
|
14
|
+
import { expansionOf, populateKeys, populateShape, } from './populate.js';
|
|
15
|
+
import { referrersOf } from './relations.js';
|
|
16
|
+
import { repo } from './repo.js';
|
|
17
|
+
import { failed, tracer } from './tracing.js';
|
|
18
|
+
const actions = [
|
|
19
|
+
'find',
|
|
20
|
+
'count',
|
|
21
|
+
'get',
|
|
22
|
+
'create',
|
|
23
|
+
'update',
|
|
24
|
+
'delete',
|
|
25
|
+
];
|
|
26
|
+
/** The effects `@ts-pf/mcp` knows, which a method's `effect` must be one of. */
|
|
27
|
+
const effects = ['read', 'write', 'destructive'];
|
|
28
|
+
/**
|
|
29
|
+
* Names a collection slug, a relation or a method cannot take: ts-pf
|
|
30
|
+
* `Implementer` keys, whose members they would shadow in the router.
|
|
31
|
+
*/
|
|
32
|
+
export const reservedNames = [
|
|
33
|
+
'$context',
|
|
34
|
+
'use',
|
|
35
|
+
'useAfter',
|
|
36
|
+
'middleware',
|
|
37
|
+
'router',
|
|
38
|
+
];
|
|
39
|
+
/** The relation operations Lattice generates. */
|
|
40
|
+
const relationOps = ['list', 'set'];
|
|
41
|
+
/** Whether a slice's node is a procedure, not a relation's node. */
|
|
42
|
+
function isProcedure(node) {
|
|
43
|
+
return isContractProcedure(node);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An app's definition: its family, its error map and its collections, with
|
|
47
|
+
* the methods and overrides attached to them. It holds no ports, so its
|
|
48
|
+
* `contract` needs no store and no publisher. `build()` wires it.
|
|
49
|
+
*/
|
|
50
|
+
export class Framework {
|
|
51
|
+
family;
|
|
52
|
+
errors;
|
|
53
|
+
entries;
|
|
54
|
+
#contract;
|
|
55
|
+
constructor(family, errors, entries) {
|
|
56
|
+
this.family = family;
|
|
57
|
+
this.errors = errors;
|
|
58
|
+
this.entries = entries;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Adds a collection, and the methods and overrides attached to it. Its slug
|
|
62
|
+
* becomes its contract slice.
|
|
63
|
+
*/
|
|
64
|
+
collection(collection, options) {
|
|
65
|
+
const { slug } = collection;
|
|
66
|
+
if (collection.tenant !== undefined && this.family.tenantOf === undefined) {
|
|
67
|
+
throw new Error(`Lattice: "${slug}" is tenanted, but the family has no tenantOf`);
|
|
68
|
+
}
|
|
69
|
+
if (reservedNames.some((key) => key === slug)) {
|
|
70
|
+
throw new Error(`Lattice: "${slug}" is a ts-pf implementer key`);
|
|
71
|
+
}
|
|
72
|
+
if (this.entries.some((entry) => entry.collection.slug === slug)) {
|
|
73
|
+
throw new Error(`Lattice: "${slug}" is already a collection`);
|
|
74
|
+
}
|
|
75
|
+
const relations = Object.entries(collection.relations);
|
|
76
|
+
const joins = relations.map(([, relation]) => relation.through);
|
|
77
|
+
for (const join of joins) {
|
|
78
|
+
if (join.slug === slug ||
|
|
79
|
+
this.entries.some((entry) => entry.collection.slug === join.slug) ||
|
|
80
|
+
joins.filter((other) => other.slug === join.slug).length > 1) {
|
|
81
|
+
throw new Error(`Lattice: the join collection "${join.slug}" is already a collection`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const [name] of relations) {
|
|
85
|
+
if (reservedNames.some((key) => key === name)) {
|
|
86
|
+
throw new Error(`Lattice: relation "${slug}.${name}" is a ts-pf implementer key`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const methods = options.methods ?? {};
|
|
90
|
+
for (const name of Object.keys(methods)) {
|
|
91
|
+
if ([...reservedNames, ...actions, 'read'].some((key) => key === name) ||
|
|
92
|
+
relations.some(([relation]) => relation === name) ||
|
|
93
|
+
name.includes('.')) {
|
|
94
|
+
throw new Error(`Lattice: "${slug}.${name}" cannot be a method name`);
|
|
95
|
+
}
|
|
96
|
+
// Its summary is the tool description MCP sends a model, and the
|
|
97
|
+
// admin's label for the action. Its effect gives MCP its hints. A
|
|
98
|
+
// JavaScript caller, or a widened class, reaches here unchecked.
|
|
99
|
+
const summary = methods[name]?.summary;
|
|
100
|
+
const effect = methods[name]?.effect;
|
|
101
|
+
if (typeof summary !== 'string' ||
|
|
102
|
+
summary.trim() === '' ||
|
|
103
|
+
!effects.some((known) => known === effect)) {
|
|
104
|
+
throw new Error(`Lattice: method "${slug}.${name}" needs a summary and an effect: one sentence on what it does, and whether it is 'read', 'write' or 'destructive'`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const overrides = options.overrides ?? {};
|
|
108
|
+
for (const [action, override] of Object.entries(overrides)) {
|
|
109
|
+
const classes = typeof override === 'function'
|
|
110
|
+
? [[action, override]]
|
|
111
|
+
: Object.entries(override).map(([op, cls]) => [`${action}.${op}`, cls]);
|
|
112
|
+
for (const [name, cls] of classes) {
|
|
113
|
+
if ('summary' in cls || 'effect' in cls) {
|
|
114
|
+
throw new Error(`Lattice: override "${slug}.${name}" keeps the generated summary and effect; remove its summary and effect statics`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const fields = options.fields ?? {};
|
|
119
|
+
const given = Object.keys(fields);
|
|
120
|
+
const { maskable } = collection;
|
|
121
|
+
if (given.length !== maskable.length ||
|
|
122
|
+
!maskable.every((field) => Object.hasOwn(fields, field))) {
|
|
123
|
+
throw new Error(`Lattice: ${slug} needs exactly one fields rule for each maskable field (${maskable.join(', ') || 'none'}); it has ${given.join(', ') || 'none'}`);
|
|
124
|
+
}
|
|
125
|
+
const cascading = collection.refs.find((ref) => ref.onDelete === 'cascade');
|
|
126
|
+
if (overrides.delete !== undefined && cascading !== undefined) {
|
|
127
|
+
throw new Error(`Lattice: ${slug} overrides delete, so ${slug}.${cascading.field} cannot cascade; use restrict or nullify`);
|
|
128
|
+
}
|
|
129
|
+
// A relation's list runs the parent's read, and its set the parent's
|
|
130
|
+
// update (0028).
|
|
131
|
+
const declared = options.access;
|
|
132
|
+
const access = Object.fromEntries([
|
|
133
|
+
...Object.entries(declared),
|
|
134
|
+
...relations.flatMap(([name]) => [
|
|
135
|
+
...(declared.read === undefined
|
|
136
|
+
? []
|
|
137
|
+
: [
|
|
138
|
+
[`${name}.list`, declared.read],
|
|
139
|
+
]),
|
|
140
|
+
...(declared.update === undefined
|
|
141
|
+
? []
|
|
142
|
+
: [
|
|
143
|
+
[`${name}.set`, declared.update],
|
|
144
|
+
]),
|
|
145
|
+
]),
|
|
146
|
+
]);
|
|
147
|
+
for (const action of Object.keys(overrides)) {
|
|
148
|
+
if (!actions.some((key) => key === action) &&
|
|
149
|
+
!relations.some(([relation]) => relation === action)) {
|
|
150
|
+
throw new Error(`Lattice: "${slug}.${action}" is not a generated operation or a relation`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return new Framework(this.family, this.errors, [
|
|
154
|
+
...this.entries,
|
|
155
|
+
{ collection, access, fields, methods, overrides, join: false },
|
|
156
|
+
...joins.map((join) => ({
|
|
157
|
+
collection: join,
|
|
158
|
+
access: {},
|
|
159
|
+
fields: {},
|
|
160
|
+
methods: {},
|
|
161
|
+
overrides: {},
|
|
162
|
+
join: true,
|
|
163
|
+
})),
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The ts-pf contract: one slice per collection. Built on first read and
|
|
168
|
+
* the same object after, so clients and codegen import it with no ports.
|
|
169
|
+
*/
|
|
170
|
+
get contract() {
|
|
171
|
+
checkSlugs(this.entries);
|
|
172
|
+
this.#contract ??= contractOf(this.entries, this.errors.declared);
|
|
173
|
+
return this.#contract;
|
|
174
|
+
}
|
|
175
|
+
build(options) {
|
|
176
|
+
checkSlugs(this.entries);
|
|
177
|
+
const { store, events } = options;
|
|
178
|
+
const referrers = referrersOf(this.entries.map((entry) => entry.collection));
|
|
179
|
+
const collections = new Map(this.entries.map(({ collection }) => [collection.slug, collection]));
|
|
180
|
+
const access = options.access ??
|
|
181
|
+
new CollectionAccess(new Map(this.entries.map((entry) => [entry.collection.slug, entry.access])), new Map(this.entries.map((entry) => [entry.collection.slug, entry.fields])));
|
|
182
|
+
const context = (base) => familyContext(access, base, this.family);
|
|
183
|
+
const repos = Object.fromEntries(this.entries.map(({ collection }) => [
|
|
184
|
+
collection.slug,
|
|
185
|
+
repo(store, collection),
|
|
186
|
+
]));
|
|
187
|
+
const methodInstances = options.methods?.({ repos });
|
|
188
|
+
const overrideInstances = options.overrides?.({ repos });
|
|
189
|
+
// Each operation and method's use case, and each relation operation's,
|
|
190
|
+
// by slug: the procedures of a slice and its nested relation nodes.
|
|
191
|
+
const operationUseCases = {};
|
|
192
|
+
const relationUseCases = {};
|
|
193
|
+
for (const { collection, methods, overrides, join } of this.entries) {
|
|
194
|
+
if (join)
|
|
195
|
+
continue;
|
|
196
|
+
const { slug } = collection;
|
|
197
|
+
const sliceUseCases = {};
|
|
198
|
+
const ops = operations(collection.schema, collection.output);
|
|
199
|
+
for (const action of actions) {
|
|
200
|
+
const declared = overrides[action];
|
|
201
|
+
sliceUseCases[action] =
|
|
202
|
+
typeof declared === 'function'
|
|
203
|
+
? instanceOf('override', [slug, action], declared, overrideInstances)
|
|
204
|
+
: generated(this.family, store, events, collection, ops, action, referrers, collections);
|
|
205
|
+
}
|
|
206
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
207
|
+
sliceUseCases[name] = instanceOf('method', [slug, name], method, methodInstances);
|
|
208
|
+
}
|
|
209
|
+
operationUseCases[slug] = sliceUseCases;
|
|
210
|
+
const sliceRelations = {};
|
|
211
|
+
for (const [name, relation] of Object.entries(collection.relations)) {
|
|
212
|
+
const declared = overrides[name];
|
|
213
|
+
const opUseCases = {};
|
|
214
|
+
for (const op of relationOps) {
|
|
215
|
+
const override = declared === undefined || typeof declared === 'function'
|
|
216
|
+
? undefined
|
|
217
|
+
: declared[op];
|
|
218
|
+
opUseCases[op] =
|
|
219
|
+
override === undefined
|
|
220
|
+
? generatedRelation(this.family, store, events, collection, name, relation, op, collections)
|
|
221
|
+
: instanceOf('override', [slug, name, op], override, overrideInstances);
|
|
222
|
+
}
|
|
223
|
+
sliceRelations[name] = opUseCases;
|
|
224
|
+
}
|
|
225
|
+
relationUseCases[slug] = sliceRelations;
|
|
226
|
+
}
|
|
227
|
+
// One implementer per slice and per relation node, each typed by its own
|
|
228
|
+
// procedures: ts-pf's types read a node that may be a procedure or a
|
|
229
|
+
// router as a procedure. The root router places each procedure at its
|
|
230
|
+
// path and checks the tree against the whole contract.
|
|
231
|
+
const contract = this.contract;
|
|
232
|
+
// Masking reads each output schema once, here. With no maskable field
|
|
233
|
+
// in the app, nothing can be masked, so no schema needs reading.
|
|
234
|
+
const masking = this.entries.some(({ collection }) => collection.maskable.length > 0);
|
|
235
|
+
const maskOf = (path, procedure) => {
|
|
236
|
+
if (!masking)
|
|
237
|
+
return undefined;
|
|
238
|
+
const where = path.join('.');
|
|
239
|
+
const { output } = procedure['~pf'];
|
|
240
|
+
if (!(output instanceof z.core.$ZodType)) {
|
|
241
|
+
throw new Error(`Lattice: the output of "${where}" is not a Zod schema, which Lattice cannot see through to mask a field`);
|
|
242
|
+
}
|
|
243
|
+
const plan = maskPlan(output, where);
|
|
244
|
+
if (plan === undefined)
|
|
245
|
+
return undefined;
|
|
246
|
+
return {
|
|
247
|
+
plan,
|
|
248
|
+
collections: [...maskedCollections(plan)].flatMap((slug) => {
|
|
249
|
+
const found = collections.get(slug);
|
|
250
|
+
return found === undefined ? [] : [found];
|
|
251
|
+
}),
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const tree = {};
|
|
255
|
+
const implement = (path, procedures, useCasesOf) => {
|
|
256
|
+
const impl = createImplementer(procedures).$context();
|
|
257
|
+
const node = {};
|
|
258
|
+
for (const [name, procedure] of Object.entries(procedures)) {
|
|
259
|
+
const builder = impl[name];
|
|
260
|
+
const useCase = useCasesOf?.[name];
|
|
261
|
+
if (builder === undefined || useCase === undefined) {
|
|
262
|
+
throw new Error(`Lattice: no procedure "${[...path, name].join('.')}"`);
|
|
263
|
+
}
|
|
264
|
+
const mask = maskOf([...path, name], procedure);
|
|
265
|
+
// A fresh context per call: a createLocalClient context object is
|
|
266
|
+
// shared by every call, and access answers are kept on the context.
|
|
267
|
+
// Every procedure's output is masked here, generated or not, so an
|
|
268
|
+
// override or a method cannot skip it.
|
|
269
|
+
node[name] = builder.handler(async ({ input, context: base }) => {
|
|
270
|
+
const ctx = context(base);
|
|
271
|
+
const output = await useCase.execute(ctx, input);
|
|
272
|
+
return mask === undefined ? output : masked(mask, output, ctx);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return node;
|
|
276
|
+
};
|
|
277
|
+
for (const [slug, slice] of Object.entries(contract)) {
|
|
278
|
+
const procedures = {};
|
|
279
|
+
const nodes = {};
|
|
280
|
+
for (const [name, node] of Object.entries(slice)) {
|
|
281
|
+
if (isProcedure(node))
|
|
282
|
+
procedures[name] = node;
|
|
283
|
+
else
|
|
284
|
+
nodes[name] = node;
|
|
285
|
+
}
|
|
286
|
+
const sliceTree = implement([slug], procedures, operationUseCases[slug]);
|
|
287
|
+
for (const [name, node] of Object.entries(nodes)) {
|
|
288
|
+
sliceTree[name] = implement([slug, name], node, relationUseCases[slug]?.[name]);
|
|
289
|
+
}
|
|
290
|
+
tree[slug] = sliceTree;
|
|
291
|
+
}
|
|
292
|
+
const useCases = Object.fromEntries(Object.entries(operationUseCases).map(([slug, sliceUseCases]) => [
|
|
293
|
+
slug,
|
|
294
|
+
{ ...sliceUseCases, ...relationUseCases[slug] },
|
|
295
|
+
]));
|
|
296
|
+
const errors = clientCalls(this.family, this.errors.map);
|
|
297
|
+
return {
|
|
298
|
+
app: rootRouter(createImplementer(contract).$context().use(errors), tree),
|
|
299
|
+
useCases,
|
|
300
|
+
repos,
|
|
301
|
+
onError: unexpectedErrors,
|
|
302
|
+
ensure: async () => {
|
|
303
|
+
for (const { collection } of this.entries) {
|
|
304
|
+
if (collection.indexes.length === 0)
|
|
305
|
+
continue;
|
|
306
|
+
await store.ensure(collection.slug, collection.indexes);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
context,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** Throws on a ref whose slug is not a collection of `entries`. */
|
|
314
|
+
function checkSlugs(entries) {
|
|
315
|
+
const slugs = new Set(entries.map((entry) => entry.collection.slug));
|
|
316
|
+
for (const { collection } of entries) {
|
|
317
|
+
for (const { field, slug } of collection.refs) {
|
|
318
|
+
if (!slugs.has(slug)) {
|
|
319
|
+
throw new Error(`Lattice: ${collection.slug}.${field} refers to "${slug}", which is not a collection of this framework`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function contractOf(entries, declared) {
|
|
325
|
+
const call = procedure.errors({ ...declaredErrors, ...declared });
|
|
326
|
+
// What a client receives of each collection's documents: each maskable
|
|
327
|
+
// field optional. Where and sort stay on the stored output, so a caller
|
|
328
|
+
// allowed to read a field can filter by it.
|
|
329
|
+
const outputs = new Map(entries.map(({ collection }) => [collection.slug, collection.clientOutput]));
|
|
330
|
+
/** A page of `doc`s, as find and list return them. */
|
|
331
|
+
const page = (doc) => z.object({ docs: z.array(doc), next: z.string().nullable() });
|
|
332
|
+
const slices = {};
|
|
333
|
+
for (const { collection, methods, overrides, join } of entries) {
|
|
334
|
+
if (join)
|
|
335
|
+
continue;
|
|
336
|
+
const slice = {};
|
|
337
|
+
const ops = operations(collection.schema, collection.output);
|
|
338
|
+
const doc = collection.clientOutput;
|
|
339
|
+
const { slug, label } = collection;
|
|
340
|
+
for (const action of actions) {
|
|
341
|
+
const output = action === 'count'
|
|
342
|
+
? ops.count.output
|
|
343
|
+
: action === 'find'
|
|
344
|
+
? page(doc)
|
|
345
|
+
: doc;
|
|
346
|
+
slice[action] = call
|
|
347
|
+
.meta(generatedMeta({ slug, label, op: action, populate: [] }))
|
|
348
|
+
.input(ops[action].input)
|
|
349
|
+
.output(output);
|
|
350
|
+
}
|
|
351
|
+
// A read's output follows its `populate` list, through ts-pf's
|
|
352
|
+
// expandable outputs (0022): the output is the wide document.
|
|
353
|
+
// An overridden read is plain: Lattice populates in the generated one.
|
|
354
|
+
if (overrides.get === undefined &&
|
|
355
|
+
populateKeys(collection, 'get').length > 0) {
|
|
356
|
+
const { fields, wide } = expansionOf(collection, outputs, 'get');
|
|
357
|
+
slice.get = call
|
|
358
|
+
.meta(generatedMeta({
|
|
359
|
+
slug,
|
|
360
|
+
label,
|
|
361
|
+
op: 'get',
|
|
362
|
+
populate: populateKeys(collection, 'get'),
|
|
363
|
+
}))
|
|
364
|
+
.input(ops.get.input.extend(populateShape(populateKeys(collection, 'get'))))
|
|
365
|
+
.output(wide)
|
|
366
|
+
.expand({ key: 'populate', fields });
|
|
367
|
+
}
|
|
368
|
+
if (overrides.find === undefined &&
|
|
369
|
+
populateKeys(collection, 'find').length > 0) {
|
|
370
|
+
const { fields, wide } = expansionOf(collection, outputs, 'find');
|
|
371
|
+
slice.find = call
|
|
372
|
+
.meta(generatedMeta({
|
|
373
|
+
slug,
|
|
374
|
+
label,
|
|
375
|
+
op: 'find',
|
|
376
|
+
populate: populateKeys(collection, 'find'),
|
|
377
|
+
}))
|
|
378
|
+
.input(ops.find.input.extend(populateShape(populateKeys(collection, 'find'))))
|
|
379
|
+
.output(page(wide))
|
|
380
|
+
.expand({ key: 'populate', at: ['docs'], fields });
|
|
381
|
+
}
|
|
382
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
383
|
+
const { summary, effect } = method;
|
|
384
|
+
slice[name] = call
|
|
385
|
+
.meta(methodMeta({ slug, label, name, summary, effect }))
|
|
386
|
+
.input(method.input)
|
|
387
|
+
.output(method.output);
|
|
388
|
+
}
|
|
389
|
+
for (const [name, relation] of Object.entries(collection.relations)) {
|
|
390
|
+
const declared = overrides[name];
|
|
391
|
+
const { fields, wide } = expansionOf(relation.through, outputs, 'find');
|
|
392
|
+
const listed = typeof declared === 'object' && declared.list !== undefined;
|
|
393
|
+
const list = call.meta(generatedMeta({
|
|
394
|
+
slug,
|
|
395
|
+
label,
|
|
396
|
+
op: 'list',
|
|
397
|
+
relation: name,
|
|
398
|
+
target: relation.target,
|
|
399
|
+
populate: listed ? [] : Object.keys(fields),
|
|
400
|
+
}));
|
|
401
|
+
slice[name] = {
|
|
402
|
+
list: listed
|
|
403
|
+
? list.input(relation.list.input).output(relation.list.output)
|
|
404
|
+
: list
|
|
405
|
+
.input(relation.list.input)
|
|
406
|
+
.output(page(wide))
|
|
407
|
+
.expand({ key: 'populate', at: ['docs'], fields }),
|
|
408
|
+
set: call
|
|
409
|
+
.meta(generatedMeta({
|
|
410
|
+
slug,
|
|
411
|
+
label,
|
|
412
|
+
op: 'set',
|
|
413
|
+
relation: name,
|
|
414
|
+
target: relation.target,
|
|
415
|
+
populate: [],
|
|
416
|
+
}))
|
|
417
|
+
.input(relation.set.input)
|
|
418
|
+
.output(relation.set.output),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
slices[collection.slug] = slice;
|
|
422
|
+
}
|
|
423
|
+
return router(slices);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* The edge's `onError`, such as `FetchHandler`'s: it logs each unexpected
|
|
427
|
+
* error (ts-pf's `isUnexpectedError`) that no family logged as a failure. A
|
|
428
|
+
* throw inside `execute` reaches the edge unchanged, and the family has
|
|
429
|
+
* logged it once already. Logged here: a throw the family never saw, such as
|
|
430
|
+
* the context factory's or ts-pf's output check, and a refusal the app's
|
|
431
|
+
* map keeps from clients, which the family logged only at info. Typed
|
|
432
|
+
* structurally, so core needs no `@ts-pf/server-http`: it fits
|
|
433
|
+
* `FetchHandlerOnError`, which also passes the request.
|
|
434
|
+
*/
|
|
435
|
+
function unexpectedErrors(logger) {
|
|
436
|
+
return (error) => {
|
|
437
|
+
if (!isUnexpectedError(error) || loggedByFamily(error) === 'failed') {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (error instanceof Error)
|
|
441
|
+
logger.error(error);
|
|
442
|
+
else
|
|
443
|
+
logger.error('Unexpected error', { thrown: error });
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* The instance passed to `build()` for one declared class. The type check is
|
|
448
|
+
* structural, so it accepts a different class with the same members;
|
|
449
|
+
* `instanceof` catches that here.
|
|
450
|
+
*/
|
|
451
|
+
function instanceOf(kind, path, declared, instances) {
|
|
452
|
+
const [slug, name, op] = path;
|
|
453
|
+
const found = instances?.[slug]?.[name];
|
|
454
|
+
// A relation's instances are one more level down, by operation.
|
|
455
|
+
const instance = op === undefined || found === undefined || isExecutable(found)
|
|
456
|
+
? found
|
|
457
|
+
: found[op];
|
|
458
|
+
const at = path.join('.');
|
|
459
|
+
if (instance === undefined || !isExecutable(instance)) {
|
|
460
|
+
throw new Error(`Lattice: no instance for ${kind} "${at}"`);
|
|
461
|
+
}
|
|
462
|
+
if (!(instance instanceof declared)) {
|
|
463
|
+
throw new Error(`Lattice: "${at}" instance is not an instance of ${declared.name}`);
|
|
464
|
+
}
|
|
465
|
+
return instance;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Whether a value is an implementer node, which has `router()`. The
|
|
469
|
+
* predicate claims that `router()` returns the implemented router, as its
|
|
470
|
+
* signature in ts-pf says, but checks only that `router` is a function.
|
|
471
|
+
* The claim is not left unguarded: ts-pf's `router()` checks the tree
|
|
472
|
+
* against the whole contract at runtime, and throws on a missing or extra
|
|
473
|
+
* implementation (build.test.ts proves it). The predicate goes with
|
|
474
|
+
* `rootRouter()`.
|
|
475
|
+
*/
|
|
476
|
+
function hasRouter(value) {
|
|
477
|
+
return 'router' in value && typeof value.router === 'function';
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* The finished root router. The runtime contract's slice node is
|
|
481
|
+
* `RuntimeProcedure | RuntimeRelation`, and ts-pf (1.0) types a node that
|
|
482
|
+
* may be a procedure as one: `IsContractProcedure` of the union is true, so
|
|
483
|
+
* `RouterImplCheck` wants an implemented procedure where a relation's
|
|
484
|
+
* router sits. The root implementer's `router()` is therefore called
|
|
485
|
+
* through its runtime shape, and its result typed by `hasRouter`. At
|
|
486
|
+
* runtime ts-pf still checks the tree against the whole contract, sets each
|
|
487
|
+
* procedure's path and adds the root middleware. This function and
|
|
488
|
+
* `hasRouter` go when ts-pf ships a `RouterImplCheck` that decides a mixed
|
|
489
|
+
* node by the implementation's node, or a public guard for an implemented
|
|
490
|
+
* router. Exported for its test only; it is not in index.ts.
|
|
491
|
+
*/
|
|
492
|
+
export function rootRouter(implementer, tree) {
|
|
493
|
+
if (!hasRouter(implementer)) {
|
|
494
|
+
throw new Error('Lattice: the ts-pf implementer has no router()');
|
|
495
|
+
}
|
|
496
|
+
return implementer.router(tree);
|
|
497
|
+
}
|
|
498
|
+
/** Whether an instance entry is a use case, not a relation's map of them. */
|
|
499
|
+
function isExecutable(value) {
|
|
500
|
+
return 'execute' in value && typeof value.execute === 'function';
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* The middleware on every procedure, and the only one, so the outermost.
|
|
504
|
+
*
|
|
505
|
+
* - It traces the call: one span per procedure, active while the procedure
|
|
506
|
+
* runs, so the use case's span and the store's spans nest under it. Its
|
|
507
|
+
* outcome is what the client receives.
|
|
508
|
+
* - It replaces a thrown error with the one the client receives
|
|
509
|
+
* (`toClientError`).
|
|
510
|
+
* - It logs each refusal no family logged, once, at info: a guard's, and
|
|
511
|
+
* ts-pf's own input check, which runs after `.use()` middleware. An error
|
|
512
|
+
* sent as INTERNAL is the edge's `onError` to log.
|
|
513
|
+
*
|
|
514
|
+
* One middleware, because the span and the log both read the error the
|
|
515
|
+
* client receives.
|
|
516
|
+
*/
|
|
517
|
+
function clientCalls(family, map) {
|
|
518
|
+
return async ({ context, next, path }) => {
|
|
519
|
+
const span = tracer.startSpan(path.join('/'), { kind: SpanKind.SERVER });
|
|
520
|
+
// A real span, sampled or not, is made active, so the use case's span
|
|
521
|
+
// and the store's nest under it and share its sampling. The no-op API's
|
|
522
|
+
// span has no context to pass on, so without an SDK the call makes none.
|
|
523
|
+
const recording = span.isRecording();
|
|
524
|
+
// By identity: the no-op span carries the API's one invalid context.
|
|
525
|
+
const active = span.spanContext() !== INVALID_SPAN_CONTEXT;
|
|
526
|
+
if (recording) {
|
|
527
|
+
span.setAttributes({
|
|
528
|
+
'rpc.system': 'ts-pf',
|
|
529
|
+
'rpc.service': path[0] ?? '',
|
|
530
|
+
'rpc.method': path.slice(1).join('/'),
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
const output = await (active
|
|
535
|
+
? otel.with(trace.setSpan(otel.active(), span), next)
|
|
536
|
+
: next());
|
|
537
|
+
if (recording)
|
|
538
|
+
span.setAttribute('lattice.outcome', 'ok');
|
|
539
|
+
return output;
|
|
540
|
+
}
|
|
541
|
+
catch (error) {
|
|
542
|
+
const sent = toClientError(error, map);
|
|
543
|
+
if (!isPFError(sent) || sent.code === 'INTERNAL') {
|
|
544
|
+
failed(span, error);
|
|
545
|
+
throw sent;
|
|
546
|
+
}
|
|
547
|
+
// A refusal is the caller's, not a failure: the status stays UNSET.
|
|
548
|
+
if (recording) {
|
|
549
|
+
span.setAttributes({
|
|
550
|
+
'lattice.outcome': 'refused',
|
|
551
|
+
'lattice.code': sent.code,
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
if (loggedByFamily(error) === undefined) {
|
|
555
|
+
const [collection, action] = path;
|
|
556
|
+
// The guards may not have checked the actor yet.
|
|
557
|
+
const actor = validate(family.actor, context.actor);
|
|
558
|
+
context.logger.info(path.join('.'), {
|
|
559
|
+
collection,
|
|
560
|
+
action,
|
|
561
|
+
...(actor.ok ? callerFields(family, actor.value) : {}),
|
|
562
|
+
outcome: 'refused',
|
|
563
|
+
...(refusal(error) ?? { code: sent.code }),
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
throw sent;
|
|
567
|
+
}
|
|
568
|
+
finally {
|
|
569
|
+
span.end();
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Starts an app's definition: the family every generated and hand-written
|
|
575
|
+
* use case extends, and the app's client errors. It takes no ports;
|
|
576
|
+
* `build()` does.
|
|
577
|
+
*/
|
|
578
|
+
export function framework(options) {
|
|
579
|
+
const errors = options.errors ?? { declared: {}, map: (error) => error };
|
|
580
|
+
for (const code of Object.keys(errors.declared)) {
|
|
581
|
+
if (latticeCodes.includes(code)) {
|
|
582
|
+
throw new Error(`Lattice: "${code}" is a Lattice error code`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return new Framework(options.family, errors, []);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* `output` without the fields the caller's rules withhold, asked once per
|
|
589
|
+
* call per collection. A field of a collection outside the app is withheld.
|
|
590
|
+
*/
|
|
591
|
+
async function masked(mask, output, ctx) {
|
|
592
|
+
const withheld = new Map(await Promise.all(mask.collections.map(async (collection) => [
|
|
593
|
+
collection.slug,
|
|
594
|
+
await CallAccess.withheld(ctx.access, collection),
|
|
595
|
+
])));
|
|
596
|
+
return applyMask(mask.plan, output, ({ collection, field }) => withheld.get(collection)?.has(field) ?? true);
|
|
597
|
+
}
|
|
598
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,OAAO,IAAI,IAAI,EACf,QAAQ,EACR,KAAK,GACN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EASL,mBAAmB,EACnB,SAAS,EACT,MAAM,GACP,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EACL,iBAAiB,GAIlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAML,UAAU,EACV,gBAAgB,EAEhB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGL,SAAS,EACT,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAiB,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,cAAc,EAEd,YAAY,EACZ,OAAO,EACP,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,YAAY,EAGZ,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,SAAS,EAET,iBAAiB,EACjB,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,GAEd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAqC,WAAW,EAAE,MAAM,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