@sequenceholdings/orm 2.4.0 → 2.6.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 +23 -0
- package/dist/authoring.cjs +53 -7
- package/dist/authoring.cjs.map +1 -1
- package/dist/authoring.d.cts +10 -6
- package/dist/authoring.d.ts +10 -6
- package/dist/authoring.js +53 -7
- package/dist/authoring.js.map +1 -1
- package/dist/canonical.cjs +48 -2
- package/dist/canonical.cjs.map +1 -1
- package/dist/canonical.d.cts +1 -1
- package/dist/canonical.d.ts +1 -1
- package/dist/canonical.js +48 -2
- package/dist/canonical.js.map +1 -1
- package/dist/cli.cjs +260 -31
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +260 -31
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +11 -6
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +38 -31
- package/dist/client.d.ts +38 -31
- package/dist/client.js +11 -7
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +513 -23
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +39 -3
- package/dist/compiler.d.ts +39 -3
- package/dist/compiler.js +510 -24
- package/dist/compiler.js.map +1 -1
- package/dist/{constants-C6EG6Wq7.d.cts → constants-Dou1RkTo.d.cts} +7 -2
- package/dist/{constants-C6EG6Wq7.d.ts → constants-Dou1RkTo.d.ts} +7 -2
- package/dist/dynamic-input.d.cts +1 -1
- package/dist/dynamic-input.d.ts +1 -1
- package/dist/index.cjs +461 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -4
- package/dist/index.d.ts +34 -4
- package/dist/index.js +460 -141
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +55 -4
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +1 -1
- package/dist/ir.d.ts +1 -1
- package/dist/ir.js +55 -4
- package/dist/ir.js.map +1 -1
- package/dist/predicate-v2.cjs +55 -4
- package/dist/predicate-v2.cjs.map +1 -1
- package/dist/predicate-v2.d.cts +1 -1
- package/dist/predicate-v2.d.ts +1 -1
- package/dist/predicate-v2.js +55 -4
- package/dist/predicate-v2.js.map +1 -1
- package/dist/sdl.cjs +60 -4
- package/dist/sdl.cjs.map +1 -1
- package/dist/sdl.d.cts +3 -1
- package/dist/sdl.d.ts +3 -1
- package/dist/sdl.js +60 -4
- package/dist/sdl.js.map +1 -1
- package/package.json +1 -1
package/dist/predicate-v2.cjs
CHANGED
|
@@ -31,9 +31,11 @@ var PolicyCompileError = class extends Error {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// src/constants.ts
|
|
34
|
+
var NAMESPACE_PATTERN = /^(?!(?:events|native_sources)$)[a-z][a-z0-9_]{0,40}$/;
|
|
34
35
|
var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
|
|
35
36
|
var MAX_IDENTIFIER_LENGTH = 63;
|
|
36
37
|
var CAPABILITY_KEY_PATTERN = /^(?:org\/|app\/[a-z][a-z0-9-]{0,63}\/)?[a-z0-9-]{1,64}$/;
|
|
38
|
+
var MAX_PERSISTED_READ_ROWS = 50001;
|
|
37
39
|
var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
|
|
38
40
|
var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
|
|
39
41
|
var CELL_PART_SUFFIX = {
|
|
@@ -383,6 +385,7 @@ function validateResolvedView({ view, tables, views = [] }) {
|
|
|
383
385
|
function validateSource({ scope, source, table }) {
|
|
384
386
|
const { fail } = scope;
|
|
385
387
|
if (source.kind === "etl" && table.source === void 0) fail(`etl source '${source.name}' must reference a synced table`);
|
|
388
|
+
if (source.kind === "etl" && table.primaryKey?.length === 0) fail(`etl source '${source.name}' cannot use an unkeyed synced table for resolved row identity`);
|
|
386
389
|
if (source.kind !== "etl" && (table.internal !== true || table.cellMetadata !== true)) {
|
|
387
390
|
fail(`${source.kind} source '${source.name}' must reference an internal table with cell metadata`);
|
|
388
391
|
}
|
|
@@ -674,7 +677,7 @@ var canonicalTableSchema = zod.z.object({
|
|
|
674
677
|
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
675
678
|
source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
676
679
|
columns: zod.z.array(canonicalColumnSchema).default([]),
|
|
677
|
-
primaryKey: zod.z.array(columnIdentifier).
|
|
680
|
+
primaryKey: zod.z.array(columnIdentifier).max(8).optional(),
|
|
678
681
|
links: zod.z.array(canonicalLinkSchema).default([]),
|
|
679
682
|
indexes: zod.z.array(canonicalIndexSchema).default([]),
|
|
680
683
|
/** Omitted by old definitions, preserving their existing content hashes. */
|
|
@@ -710,6 +713,29 @@ var canonicalTableSchema = zod.z.object({
|
|
|
710
713
|
* data plane. Omitted otherwise.
|
|
711
714
|
*/
|
|
712
715
|
materializes: identifier2.optional()
|
|
716
|
+
}).superRefine((table, ctx) => {
|
|
717
|
+
if (table.primaryKey?.length !== 0) return;
|
|
718
|
+
const fail = (message, path = ["primaryKey"]) => ctx.addIssue({ code: "custom", path, message: `unkeyed table '${table.table}' ${message}` });
|
|
719
|
+
if (table.source === void 0 || table.columns.length === 0) {
|
|
720
|
+
fail("requires a typed synced source");
|
|
721
|
+
}
|
|
722
|
+
if ([table.policies.write, table.policies.insert, table.policies.update].some((policy) => policy !== void 0)) {
|
|
723
|
+
fail("is read-only and cannot declare write policies", ["policies"]);
|
|
724
|
+
}
|
|
725
|
+
const ownedCollections = [table.indexes, table.actions, table.checks, table.foreignKeys, table.cowMutations];
|
|
726
|
+
const ownedMetadata = [table.cellMetadata, table.internal, table.materializes, table.renamedFrom];
|
|
727
|
+
if (ownedCollections.some((items) => items !== void 0 && items.length > 0) || ownedMetadata.some((value) => value !== void 0)) {
|
|
728
|
+
fail("cannot declare owned storage, constraints or identity operations");
|
|
729
|
+
}
|
|
730
|
+
for (const [index, column] of table.columns.entries()) {
|
|
731
|
+
const ownedColumnMetadata = [column.default, column.defaultFn, column.onUpdateFn, column.renamedFrom, column.cast, column.cell];
|
|
732
|
+
if (column.unique || ownedColumnMetadata.some((value) => value !== void 0)) {
|
|
733
|
+
fail("cannot declare column uniqueness, mutation defaults or migration metadata", ["columns", index]);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
for (const [index, link] of table.links.entries()) {
|
|
737
|
+
if (link.enforce || link.kind === "toMany") fail("cannot provide an identity for this link", ["links", index]);
|
|
738
|
+
}
|
|
713
739
|
});
|
|
714
740
|
var MAX_VIEW_QUERY = 1e5;
|
|
715
741
|
var MAX_RESOLVED_VIEW_QUERY = 5e6;
|
|
@@ -766,6 +792,26 @@ var canonicalViewSchema = zod.z.object({
|
|
|
766
792
|
}
|
|
767
793
|
}
|
|
768
794
|
});
|
|
795
|
+
function validateUnkeyedLinkIdentities({ definition, ctx }) {
|
|
796
|
+
const tables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
797
|
+
const relations = [
|
|
798
|
+
...definition.tables.map((table, index) => ({ kind: "tables", index, links: table.links })),
|
|
799
|
+
...(definition.views ?? []).map((view, index) => ({ kind: "views", index, links: view.links }))
|
|
800
|
+
];
|
|
801
|
+
for (const relation of relations) {
|
|
802
|
+
for (const [linkIndex, link] of relation.links.entries()) {
|
|
803
|
+
if (link.kind !== "toOne" || link.namespace !== void 0 && link.namespace !== definition.namespace) continue;
|
|
804
|
+
const target = link.target === void 0 ? void 0 : tables.get(link.target);
|
|
805
|
+
if (target?.source !== void 0 && target.primaryKey?.length === 0) {
|
|
806
|
+
ctx.addIssue({
|
|
807
|
+
code: "custom",
|
|
808
|
+
path: [relation.kind, relation.index, "links", linkIndex],
|
|
809
|
+
message: `link '${link.name}' cannot use unkeyed table '${target.table}' as a to-one identity`
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
769
815
|
var CELL_PART_TYPES = {
|
|
770
816
|
at: "timestamptz",
|
|
771
817
|
by: "text",
|
|
@@ -829,7 +875,7 @@ var exportGateSchema = zod.z.union([zod.z.literal(true), zod.z.object({ capabili
|
|
|
829
875
|
var relationExportSchema = zod.z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
|
|
830
876
|
var localDefinitionSchema = zod.z.object({
|
|
831
877
|
definition_format: zod.z.literal(CANONICAL_FORMAT),
|
|
832
|
-
namespace: identifier2.max(41),
|
|
878
|
+
namespace: identifier2.max(41).regex(NAMESPACE_PATTERN, "invalid or reserved ORM namespace"),
|
|
833
879
|
description: zod.z.string().max(2e3).optional(),
|
|
834
880
|
enums: zod.z.array(canonicalEnumSchema).default([]),
|
|
835
881
|
tables: zod.z.array(canonicalTableSchema).min(0).max(500),
|
|
@@ -863,6 +909,7 @@ var localDefinitionSchema = zod.z.object({
|
|
|
863
909
|
}
|
|
864
910
|
}
|
|
865
911
|
const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
912
|
+
validateUnkeyedLinkIdentities({ definition, ctx });
|
|
866
913
|
const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
|
|
867
914
|
for (const name of Object.keys(definition.exports ?? {})) {
|
|
868
915
|
if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
|
|
@@ -1047,6 +1094,9 @@ localDefinitionSchema.safeExtend({
|
|
|
1047
1094
|
imports: zod.z.array(localDefinitionSchema).max(32).optional()
|
|
1048
1095
|
});
|
|
1049
1096
|
|
|
1097
|
+
// src/client/sql.ts
|
|
1098
|
+
var BUILTIN_SQL_READ_HASH = "sha256:a50c477c952a5e0fe68ed158a4530e4aab573c09bcbb1a8ac454dc88a39a6258";
|
|
1099
|
+
|
|
1050
1100
|
// src/ir/index.ts
|
|
1051
1101
|
var LEGACY_IR_VERSION = 1;
|
|
1052
1102
|
var GUARDED_IR_VERSION = 2;
|
|
@@ -1126,7 +1176,7 @@ var limitIrSchema = zod.z.object({
|
|
|
1126
1176
|
variable: zod.z.string().optional(),
|
|
1127
1177
|
value: zod.z.number().int().positive().optional(),
|
|
1128
1178
|
default: zod.z.number().int().positive(),
|
|
1129
|
-
max: zod.z.number().int().positive()
|
|
1179
|
+
max: zod.z.number().int().positive().max(MAX_PERSISTED_READ_ROWS)
|
|
1130
1180
|
});
|
|
1131
1181
|
var selectionIrSchema = zod.z.lazy(
|
|
1132
1182
|
() => zod.z.object({
|
|
@@ -1371,7 +1421,8 @@ var compiledOperationSchema = zod.z.object({
|
|
|
1371
1421
|
}).superRefine((operation, ctx) => {
|
|
1372
1422
|
if (operation.language === "sql") {
|
|
1373
1423
|
const validPlan = operation.sqlQuery ? !operation.sql && operation.irVersion === RUNTIME_SQL_IR_VERSION : !!operation.sql && operation.irVersion === SQL_IR_VERSION;
|
|
1374
|
-
|
|
1424
|
+
const builtin = operation.name === "BuiltinSqlRead" && operation.opHash === BUILTIN_SQL_READ_HASH && operation.requires === null;
|
|
1425
|
+
if (!validPlan || operation.kind !== "query" || operation.roots.length !== 0 || !builtin && !operation.requires?.capability) {
|
|
1375
1426
|
ctx.addIssue({ code: "custom", message: "SQL operations require a query-only v4 plan or v5 runtime contract, capability, and no GraphQL roots" });
|
|
1376
1427
|
}
|
|
1377
1428
|
} else if (operation.sql || operation.sqlQuery || operation.roots.length === 0) {
|