@lunora/server 1.0.0-alpha.30 → 1.0.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-model.mjs +0 -1
- package/dist/drizzle.mjs +1 -1
- package/dist/index.d.mts +105 -8
- package/dist/index.d.ts +105 -8
- package/dist/index.mjs +1 -29
- package/dist/packem_shared/LunoraEnvError-CgpI2Mm_.mjs +3 -0
- package/dist/packem_shared/LunoraError-LVhdU0Lo.mjs +1 -0
- package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-CF_9uiu1.mjs +1 -0
- package/dist/packem_shared/allowAll-BnyNbJZT.mjs +1 -0
- package/dist/packem_shared/asBucketStorage-1pFfH-Tn.mjs +1 -0
- package/dist/packem_shared/bindOrm-Bp9hsM2q.mjs +1 -0
- package/dist/packem_shared/buildRlsReadRegistry-WdiqSj87.mjs +1 -0
- package/dist/packem_shared/composePluginMiddleware-COr09CXA.mjs +1 -0
- package/dist/packem_shared/createPolicyDsl-sV1swpkD.mjs +1 -0
- package/dist/packem_shared/createSecrets-CgVPiW2C.mjs +1 -0
- package/dist/packem_shared/defineAggregateIndex-CYuH6IbJ.mjs +1 -0
- package/dist/packem_shared/defineIdentity-B7gfAgxx.mjs +1 -0
- package/dist/packem_shared/defineMigration-Bfpwxv2f.mjs +1 -0
- package/dist/packem_shared/defineMutator-8Kz0j1Kt.mjs +1 -0
- package/dist/packem_shared/defineShape-CyuRfwHz.mjs +1 -0
- package/dist/packem_shared/defineStorageRule-BDu01PUn.mjs +1 -0
- package/dist/packem_shared/functions-CDC08CWY.mjs +1 -0
- package/dist/packem_shared/httpAction-C14NuF3V.mjs +4 -0
- package/dist/packem_shared/initLunora-CHh1EmR4.mjs +1 -0
- package/dist/packem_shared/mask-C6Bi78qj.mjs +1 -0
- package/dist/packem_shared/onConnect-CEtRmUpJ.mjs +1 -0
- package/dist/packem_shared/policy-tag-Dprt9JWo.mjs +1 -0
- package/dist/packem_shared/protectPublic-BhKewPqm.mjs +1 -0
- package/dist/packem_shared/rls-_iVsPvhX.mjs +1 -0
- package/dist/packem_shared/run-middleware-BeEEqmdE.mjs +1 -0
- package/dist/packem_shared/storageRules-BptPZbi8.mjs +1 -0
- package/dist/rls/testing.mjs +1 -49
- package/dist/types.d.mts +76 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.mjs +1 -31
- package/package.json +4 -4
- package/dist/packem_shared/LunoraEnvError-BGmd1Qs0.mjs +0 -187
- package/dist/packem_shared/LunoraError-WbxmrpxR.mjs +0 -9
- package/dist/packem_shared/PRESENCE_DEFAULT_TTL_MS-Cr0i4mTv.mjs +0 -114
- package/dist/packem_shared/asBucketStorage-Cnxd9y2q.mjs +0 -11
- package/dist/packem_shared/bindOrm-CaY7Wq9Z.mjs +0 -147
- package/dist/packem_shared/buildRlsReadRegistry-2uk_GfiH.mjs +0 -107
- package/dist/packem_shared/composePluginMiddleware-z62dttBo.mjs +0 -103
- package/dist/packem_shared/createPolicyDsl-By3QB4he.mjs +0 -32
- package/dist/packem_shared/createSecrets-DwaR2rNG.mjs +0 -58
- package/dist/packem_shared/defineAggregateIndex-cdo0g-un.mjs +0 -349
- package/dist/packem_shared/defineIdentity-DiX4zM9x.mjs +0 -35
- package/dist/packem_shared/defineMigration-Hx01yIht.mjs +0 -10
- package/dist/packem_shared/defineMutator-EIXAWhs9.mjs +0 -11
- package/dist/packem_shared/defineShape-C5scNOrf.mjs +0 -18
- package/dist/packem_shared/defineStorageRule-B5nL4Z1P.mjs +0 -23
- package/dist/packem_shared/functions-Di9FUNkf.mjs +0 -5
- package/dist/packem_shared/httpAction-DCXoYPIk.mjs +0 -355
- package/dist/packem_shared/initLunora-D0Wuki7S.mjs +0 -115
- package/dist/packem_shared/mask-BepaW7YN.mjs +0 -334
- package/dist/packem_shared/onConnect-CIPXKPyw.mjs +0 -13
- package/dist/packem_shared/policy-tag-DvpVH2tv.mjs +0 -13
- package/dist/packem_shared/protectPublic-BlcGpiRc.mjs +0 -15
- package/dist/packem_shared/rls-BaDQf7MG.mjs +0 -595
- package/dist/packem_shared/run-middleware-I6EiQfxL.mjs +0 -20
- package/dist/packem_shared/storageRules-6QxzDOcx.mjs +0 -88
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
import { LunoraError as LunoraError$1 } from '@lunora/errors';
|
|
2
|
-
import { isOrWrapsFromValidator, v } from '@lunora/values';
|
|
3
|
-
import { mergeSchemaExtension } from './composePluginMiddleware-z62dttBo.mjs';
|
|
4
|
-
|
|
5
|
-
const relationBuilder = {
|
|
6
|
-
many: (table, options) => {
|
|
7
|
-
return { field: options.field, kind: "many", references: options.references ?? "_id", table };
|
|
8
|
-
},
|
|
9
|
-
one: (table, options) => {
|
|
10
|
-
return { field: options.field, kind: "one", onDelete: options.onDelete, references: options.references ?? "_id", table };
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const makeTrigger = (timing, op, handler) => {
|
|
14
|
-
return { handler, op, timing };
|
|
15
|
-
};
|
|
16
|
-
const createTriggerBuilder = () => {
|
|
17
|
-
return {
|
|
18
|
-
afterDelete: (handler) => makeTrigger("after", "delete", handler),
|
|
19
|
-
afterInsert: (handler) => makeTrigger("after", "insert", handler),
|
|
20
|
-
afterUpdate: (handler) => makeTrigger("after", "update", handler),
|
|
21
|
-
beforeDelete: (handler) => makeTrigger("before", "delete", handler),
|
|
22
|
-
beforeInsert: (handler) => makeTrigger("before", "insert", handler),
|
|
23
|
-
beforeUpdate: (handler) => makeTrigger("before", "update", handler)
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const defineTable = (inputShape) => {
|
|
27
|
-
const shape = { ...inputShape };
|
|
28
|
-
for (const [columnName, validator] of Object.entries(shape)) {
|
|
29
|
-
if (isOrWrapsFromValidator(validator)) {
|
|
30
|
-
throw new LunoraError$1("INTERNAL", `defineTable: column "${columnName}" uses v.from() which is args-only — table columns need a concrete v.* type`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const aggregateIndexes = [];
|
|
34
|
-
const geoIndexes = [];
|
|
35
|
-
const indexes = [];
|
|
36
|
-
const rankIndexes = [];
|
|
37
|
-
const relations = {};
|
|
38
|
-
const searchIndexes = [];
|
|
39
|
-
const triggers = {};
|
|
40
|
-
const triggerBuilder = createTriggerBuilder();
|
|
41
|
-
const vectorIndexes = [];
|
|
42
|
-
let shardMode = { kind: "root" };
|
|
43
|
-
let isExternallyManaged = false;
|
|
44
|
-
let isPublic = false;
|
|
45
|
-
let softDelete;
|
|
46
|
-
let ttl;
|
|
47
|
-
let externalSource;
|
|
48
|
-
const builder = {
|
|
49
|
-
aggregateIndex(name, options) {
|
|
50
|
-
const op = options?.op ?? "count";
|
|
51
|
-
if (op !== "count" && !options?.field) {
|
|
52
|
-
throw new LunoraError$1("INTERNAL", `aggregateIndex "${name}": op "${op}" requires a "field"`);
|
|
53
|
-
}
|
|
54
|
-
aggregateIndexes.push({
|
|
55
|
-
by: options?.by,
|
|
56
|
-
field: options?.field,
|
|
57
|
-
name,
|
|
58
|
-
// `on` is filled in by `defineSchema` once the table is keyed; we
|
|
59
|
-
// stash the placeholder so the AggregateIndexDefinition shape stays
|
|
60
|
-
// straightforward for D1/DO consumers (who read `on`).
|
|
61
|
-
on: "",
|
|
62
|
-
op,
|
|
63
|
-
where: options?.where
|
|
64
|
-
});
|
|
65
|
-
return builder;
|
|
66
|
-
},
|
|
67
|
-
get aggregateIndexes() {
|
|
68
|
-
return aggregateIndexes;
|
|
69
|
-
},
|
|
70
|
-
get externalSource() {
|
|
71
|
-
return externalSource;
|
|
72
|
-
},
|
|
73
|
-
externallyManaged() {
|
|
74
|
-
isExternallyManaged = true;
|
|
75
|
-
return builder;
|
|
76
|
-
},
|
|
77
|
-
geoIndex(name, options) {
|
|
78
|
-
geoIndexes.push({ field: options.field, name, precision: options.precision });
|
|
79
|
-
return builder;
|
|
80
|
-
},
|
|
81
|
-
get geoIndexes() {
|
|
82
|
-
return geoIndexes;
|
|
83
|
-
},
|
|
84
|
-
global(options) {
|
|
85
|
-
shardMode = { backend: options?.backend ?? "d1", kind: "global" };
|
|
86
|
-
return builder;
|
|
87
|
-
},
|
|
88
|
-
get isExternallyManaged() {
|
|
89
|
-
return isExternallyManaged;
|
|
90
|
-
},
|
|
91
|
-
get isPublic() {
|
|
92
|
-
return isPublic;
|
|
93
|
-
},
|
|
94
|
-
index(name, fields, options) {
|
|
95
|
-
indexes.push({ fields, name, unique: options?.unique ?? false });
|
|
96
|
-
return builder;
|
|
97
|
-
},
|
|
98
|
-
get indexes() {
|
|
99
|
-
return indexes;
|
|
100
|
-
},
|
|
101
|
-
public() {
|
|
102
|
-
isPublic = true;
|
|
103
|
-
return builder;
|
|
104
|
-
},
|
|
105
|
-
rankIndex(name, options) {
|
|
106
|
-
if (!options.sortBy || options.sortBy.length === 0) {
|
|
107
|
-
throw new LunoraError$1("INTERNAL", `rankIndex "${name}": "sortBy" is required and must list at least one key`);
|
|
108
|
-
}
|
|
109
|
-
const sortBy = options.sortBy.map((key) => {
|
|
110
|
-
return {
|
|
111
|
-
direction: key.direction ?? "asc",
|
|
112
|
-
field: key.field
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
rankIndexes.push({
|
|
116
|
-
name,
|
|
117
|
-
// `on` is filled in by `defineSchema` once the table is keyed —
|
|
118
|
-
// same pattern as `aggregateIndex`.
|
|
119
|
-
on: "",
|
|
120
|
-
partitionBy: options.partitionBy,
|
|
121
|
-
sortBy,
|
|
122
|
-
where: options.where
|
|
123
|
-
});
|
|
124
|
-
return builder;
|
|
125
|
-
},
|
|
126
|
-
get rankIndexes() {
|
|
127
|
-
return rankIndexes;
|
|
128
|
-
},
|
|
129
|
-
get relationMap() {
|
|
130
|
-
return relations;
|
|
131
|
-
},
|
|
132
|
-
relations(build) {
|
|
133
|
-
Object.assign(relations, build(relationBuilder));
|
|
134
|
-
return builder;
|
|
135
|
-
},
|
|
136
|
-
searchIndex(name, options) {
|
|
137
|
-
searchIndexes.push({ field: options.field, filterFields: options.filterFields, name });
|
|
138
|
-
return builder;
|
|
139
|
-
},
|
|
140
|
-
get searchIndexes() {
|
|
141
|
-
return searchIndexes;
|
|
142
|
-
},
|
|
143
|
-
shape,
|
|
144
|
-
shardBy(field) {
|
|
145
|
-
shardMode = { field, kind: "shardBy" };
|
|
146
|
-
return builder;
|
|
147
|
-
},
|
|
148
|
-
get shardMode() {
|
|
149
|
-
return shardMode;
|
|
150
|
-
},
|
|
151
|
-
get softDeleteMode() {
|
|
152
|
-
return softDelete;
|
|
153
|
-
},
|
|
154
|
-
source(definition) {
|
|
155
|
-
if (!definition.binding) {
|
|
156
|
-
throw new LunoraError$1("INTERNAL", "source: `binding` is required (the wrangler Hyperdrive binding name)");
|
|
157
|
-
}
|
|
158
|
-
if (!definition.query) {
|
|
159
|
-
throw new LunoraError$1("INTERNAL", "source: `query` is required (the tenant-membership SQL)");
|
|
160
|
-
}
|
|
161
|
-
externalSource = definition;
|
|
162
|
-
isExternallyManaged = true;
|
|
163
|
-
return builder;
|
|
164
|
-
},
|
|
165
|
-
softDelete(options) {
|
|
166
|
-
const field = options?.field ?? "deletedAt";
|
|
167
|
-
softDelete = { field };
|
|
168
|
-
if (!(field in shape)) {
|
|
169
|
-
shape[field] = v.optional(v.number().nullable());
|
|
170
|
-
}
|
|
171
|
-
return builder;
|
|
172
|
-
},
|
|
173
|
-
get triggerMap() {
|
|
174
|
-
return triggers;
|
|
175
|
-
},
|
|
176
|
-
triggers(build) {
|
|
177
|
-
Object.assign(triggers, build(triggerBuilder));
|
|
178
|
-
return builder;
|
|
179
|
-
},
|
|
180
|
-
ttl(field, options) {
|
|
181
|
-
ttl = { after: options?.after, field };
|
|
182
|
-
return builder;
|
|
183
|
-
},
|
|
184
|
-
get ttlPolicy() {
|
|
185
|
-
return ttl;
|
|
186
|
-
},
|
|
187
|
-
get vectorIndexes() {
|
|
188
|
-
return vectorIndexes;
|
|
189
|
-
},
|
|
190
|
-
vectorize(field, options) {
|
|
191
|
-
vectorIndexes.push({
|
|
192
|
-
dimensions: options.dimensions,
|
|
193
|
-
embed: options.embed,
|
|
194
|
-
field,
|
|
195
|
-
metadata: options.metadata,
|
|
196
|
-
metric: options.metric,
|
|
197
|
-
name: options.index
|
|
198
|
-
});
|
|
199
|
-
return builder;
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
return builder;
|
|
203
|
-
};
|
|
204
|
-
const defineVectorIndex = (options) => {
|
|
205
|
-
return {
|
|
206
|
-
dimensions: options.dimensions,
|
|
207
|
-
embed: options.embed,
|
|
208
|
-
kind: "vectorIndex",
|
|
209
|
-
metadata: options.metadata,
|
|
210
|
-
metric: options.metric,
|
|
211
|
-
select: options.source.select,
|
|
212
|
-
table: options.source.table
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
const defineAggregateIndex = (name, options) => {
|
|
216
|
-
const op = options.op ?? "count";
|
|
217
|
-
if (op !== "count" && !options.field) {
|
|
218
|
-
throw new LunoraError$1("INTERNAL", `aggregateIndex "${name}": op "${op}" requires a "field"`);
|
|
219
|
-
}
|
|
220
|
-
return { by: options.by, field: options.field, name, on: options.on, op, where: options.where };
|
|
221
|
-
};
|
|
222
|
-
const defineRankIndex = (name, options) => {
|
|
223
|
-
if (!options.sortBy || options.sortBy.length === 0) {
|
|
224
|
-
throw new LunoraError$1("INTERNAL", `rankIndex "${name}": "sortBy" is required and must list at least one key`);
|
|
225
|
-
}
|
|
226
|
-
const sortBy = options.sortBy.map((key) => {
|
|
227
|
-
return {
|
|
228
|
-
direction: key.direction ?? "asc",
|
|
229
|
-
field: key.field
|
|
230
|
-
};
|
|
231
|
-
});
|
|
232
|
-
return { name, on: options.table, partitionBy: options.partitionBy, sortBy, where: options.where };
|
|
233
|
-
};
|
|
234
|
-
const withExtend = (schema) => {
|
|
235
|
-
return {
|
|
236
|
-
...schema,
|
|
237
|
-
extend(extension) {
|
|
238
|
-
return withExtend(mergeSchemaExtension(schema, extension));
|
|
239
|
-
},
|
|
240
|
-
jurisdiction(_jurisdiction) {
|
|
241
|
-
return withExtend(schema);
|
|
242
|
-
},
|
|
243
|
-
rls(mode) {
|
|
244
|
-
return withExtend({ ...schema, rlsMode: mode });
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
const fillIndexTableNames = (tables) => {
|
|
249
|
-
for (const [tableName, table] of Object.entries(tables)) {
|
|
250
|
-
for (const index of table.aggregateIndexes) {
|
|
251
|
-
if (index.on === "") {
|
|
252
|
-
index.on = tableName;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
for (const index of table.rankIndexes) {
|
|
256
|
-
if (index.on === "") {
|
|
257
|
-
index.on = tableName;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
const attachStandaloneIndexes = (tables, aggregateIndexes, rankIndexes) => {
|
|
263
|
-
for (const index of Object.values(aggregateIndexes)) {
|
|
264
|
-
const table = tables[index.on];
|
|
265
|
-
if (!table) {
|
|
266
|
-
throw new LunoraError$1("INTERNAL", `defineAggregateIndex "${index.name}": unknown table "${index.on}"`);
|
|
267
|
-
}
|
|
268
|
-
table.aggregateIndexes.push(index);
|
|
269
|
-
}
|
|
270
|
-
for (const index of Object.values(rankIndexes)) {
|
|
271
|
-
const table = tables[index.on];
|
|
272
|
-
if (!table) {
|
|
273
|
-
throw new LunoraError$1("INTERNAL", `defineRankIndex "${index.name}": unknown table "${index.on}"`);
|
|
274
|
-
}
|
|
275
|
-
table.rankIndexes.push(index);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
const strayIncrementalKnob = (source) => {
|
|
279
|
-
if (source.cursor) {
|
|
280
|
-
return "cursor";
|
|
281
|
-
}
|
|
282
|
-
if (source.reconcileEveryMs !== void 0) {
|
|
283
|
-
return "reconcileEveryMs";
|
|
284
|
-
}
|
|
285
|
-
if (source.softDeleteColumn !== void 0) {
|
|
286
|
-
return "softDeleteColumn";
|
|
287
|
-
}
|
|
288
|
-
return void 0;
|
|
289
|
-
};
|
|
290
|
-
const validateExternalSourceMode = (name, source) => {
|
|
291
|
-
const isIncremental = source.mode === "incremental";
|
|
292
|
-
if (source.mode !== void 0 && source.mode !== "full-pull" && !isIncremental) {
|
|
293
|
-
throw new LunoraError$1(
|
|
294
|
-
"INTERNAL",
|
|
295
|
-
`defineSchema: table "${name}" uses \`mode: ${JSON.stringify(source.mode)}\` — supported modes are "full-pull" (default) and "incremental".`
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
if (!isIncremental) {
|
|
299
|
-
const strayKnob = strayIncrementalKnob(source);
|
|
300
|
-
if (strayKnob) {
|
|
301
|
-
throw new LunoraError$1(
|
|
302
|
-
"INTERNAL",
|
|
303
|
-
`defineSchema: table "${name}" sets \`${strayKnob}\` but is not \`mode: "incremental"\` — that knob only applies to incremental ingest. Set \`mode: "incremental"\` or remove \`${strayKnob}\`.`
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
if (!source.cursor?.column || !source.cursor.query) {
|
|
309
|
-
throw new LunoraError$1(
|
|
310
|
-
"INTERNAL",
|
|
311
|
-
`defineSchema: table "${name}" is \`mode: "incremental"\` but has no \`cursor\` — add \`cursor: { column: "updated_at", query: "… WHERE … > $N" }\` binding the watermark as the trailing parameter.`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
if (source.reconcileEveryMs === void 0 && source.softDeleteColumn === void 0) {
|
|
315
|
-
throw new LunoraError$1(
|
|
316
|
-
"INTERNAL",
|
|
317
|
-
`defineSchema: table "${name}" is \`mode: "incremental"\` with no delete-visibility path — an incremental pull never sees upstream deletes, so it would accumulate phantom rows. Add \`reconcileEveryMs\` (a periodic full-pull sweep) or \`softDeleteColumn\` (an upstream tombstone column).`
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
const validateExternalSources = (tables) => {
|
|
322
|
-
for (const [name, table] of Object.entries(tables)) {
|
|
323
|
-
const source = table.externalSource;
|
|
324
|
-
if (!source) {
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
if (table.shardMode.kind === "global") {
|
|
328
|
-
throw new LunoraError$1(
|
|
329
|
-
"INTERNAL",
|
|
330
|
-
`defineSchema: table "${name}" cannot be both .source() and .global() — a sourced table materializes into a shard DO's SQLite, a global table lives in the external tier`
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
if (table.shardMode.kind === "shardBy" && !source.tenantBy) {
|
|
334
|
-
throw new LunoraError$1(
|
|
335
|
-
"INTERNAL",
|
|
336
|
-
`defineSchema: sourced + .shardBy() table "${name}" needs a \`tenantBy\` mapper — without it every tenant's DO would run the same unscoped query and replicate the whole multitenant table (a cross-tenant leak). Add \`tenantBy: (shardKey) => [shardKey]\` binding the shard key into the query's parameters.`
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
validateExternalSourceMode(name, source);
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
const defineSchema = (tables, vectorIndexes = {}, aggregateIndexes = {}, rankIndexes = {}) => {
|
|
343
|
-
fillIndexTableNames(tables);
|
|
344
|
-
attachStandaloneIndexes(tables, aggregateIndexes, rankIndexes);
|
|
345
|
-
validateExternalSources(tables);
|
|
346
|
-
return withExtend({ tables, vectorIndexes });
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
export { defineAggregateIndex, defineRankIndex, defineSchema, defineTable, defineVectorIndex };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { LunoraError as LunoraError$1 } from '@lunora/errors';
|
|
2
|
-
import { parseValidatorMap, ValidationError } from '@lunora/values';
|
|
3
|
-
|
|
4
|
-
const NON_STRING_USER_ID_KINDS = /* @__PURE__ */ new Set([
|
|
5
|
-
"array",
|
|
6
|
-
"bigint",
|
|
7
|
-
"boolean",
|
|
8
|
-
"bytes",
|
|
9
|
-
"date",
|
|
10
|
-
"null",
|
|
11
|
-
"number",
|
|
12
|
-
"object",
|
|
13
|
-
"optional",
|
|
14
|
-
"record",
|
|
15
|
-
"timestamp"
|
|
16
|
-
]);
|
|
17
|
-
const defineIdentity = (claims, options = {}) => {
|
|
18
|
-
const map = claims;
|
|
19
|
-
const userIdValidator = map["userId"];
|
|
20
|
-
if (userIdValidator === void 0 || NON_STRING_USER_ID_KINDS.has(userIdValidator.kind)) {
|
|
21
|
-
throw new LunoraError$1("INTERNAL", "defineIdentity: the claim map must declare a required string `userId` validator (e.g. `v.string()` or `v.id(...)`)");
|
|
22
|
-
}
|
|
23
|
-
const onInvalid = options.onInvalid ?? "anonymous";
|
|
24
|
-
const validate = (identity) => {
|
|
25
|
-
try {
|
|
26
|
-
parseValidatorMap(map, identity, "identity");
|
|
27
|
-
return { ok: true };
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return { error: error instanceof ValidationError ? error.message : String(error), ok: false };
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
return { __lunoraIdentity: true, claims: map, onInvalid, validate };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export { defineIdentity };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { LunoraError as LunoraError$1 } from '@lunora/errors';
|
|
2
|
-
|
|
3
|
-
const defineMigration = (definition) => {
|
|
4
|
-
if (definition.id.trim() === "") {
|
|
5
|
-
throw new LunoraError$1("INTERNAL", "defineMigration: `id` must be a non-empty string");
|
|
6
|
-
}
|
|
7
|
-
return { __lunoraMigration: true, ...definition };
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export { defineMigration };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { v as validateArgs } from './functions-Di9FUNkf.mjs';
|
|
2
|
-
|
|
3
|
-
const defineMutator = (definition) => {
|
|
4
|
-
const handler = async (context, rawArgs) => {
|
|
5
|
-
const parsed = validateArgs(definition.args ?? {}, rawArgs);
|
|
6
|
-
return definition.server(context, parsed);
|
|
7
|
-
};
|
|
8
|
-
return { __lunoraMutator: true, ...definition, handler, kind: "mutation" };
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { defineMutator };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { LunoraError as LunoraError$1 } from '@lunora/errors';
|
|
2
|
-
import { v as validateArgs } from './functions-Di9FUNkf.mjs';
|
|
3
|
-
|
|
4
|
-
const defineShape = (definition) => {
|
|
5
|
-
if (definition.table.trim() === "") {
|
|
6
|
-
throw new LunoraError$1("INTERNAL", "defineShape: `table` must be a non-empty string");
|
|
7
|
-
}
|
|
8
|
-
if (definition.columns?.length === 0) {
|
|
9
|
-
throw new LunoraError$1("INTERNAL", "defineShape: `columns` must list at least one column when provided");
|
|
10
|
-
}
|
|
11
|
-
const compileWhere = (context, rawArgs) => {
|
|
12
|
-
const parsed = validateArgs(definition.args ?? {}, rawArgs);
|
|
13
|
-
return definition.where(context, parsed);
|
|
14
|
-
};
|
|
15
|
-
return { __lunoraShape: true, ...definition, compileWhere };
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { defineShape };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { LunoraError as LunoraError$1 } from '@lunora/errors';
|
|
2
|
-
|
|
3
|
-
const defineStorageRule = (input) => {
|
|
4
|
-
return { bucket: input.bucket, on: input.on, prefix: input.prefix, when: input.when };
|
|
5
|
-
};
|
|
6
|
-
const defineStorageRules = (rules) => {
|
|
7
|
-
const seenWhenByKey = /* @__PURE__ */ new Map();
|
|
8
|
-
for (const rule of rules) {
|
|
9
|
-
const key = JSON.stringify([rule.bucket, rule.on, rule.prefix]);
|
|
10
|
-
const whens = seenWhenByKey.get(key) ?? /* @__PURE__ */ new Set();
|
|
11
|
-
if (whens.has(rule.when)) {
|
|
12
|
-
throw new LunoraError$1(
|
|
13
|
-
"INTERNAL",
|
|
14
|
-
`defineStorageRules: duplicate rule for (bucket "${rule.bucket}", on "${rule.on}"${rule.prefix === void 0 ? "" : `, prefix "${rule.prefix}"`}) — the same decision function is registered more than once. Multiple distinct rules per (bucket, on) are allowed (they OR); remove the duplicate.`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
whens.add(rule.when);
|
|
18
|
-
seenWhenByKey.set(key, whens);
|
|
19
|
-
}
|
|
20
|
-
return rules;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { defineStorageRule, defineStorageRules };
|