@sequenceholdings/orm 2.1.1 → 2.3.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 +3 -1
- package/dist/authoring.cjs +284 -99
- package/dist/authoring.cjs.map +1 -1
- package/dist/authoring.d.cts +31 -8
- package/dist/authoring.d.ts +31 -8
- package/dist/authoring.js +282 -100
- package/dist/authoring.js.map +1 -1
- package/dist/canonical.cjs +51 -3
- package/dist/canonical.cjs.map +1 -1
- package/dist/canonical.d.cts +838 -12
- package/dist/canonical.d.ts +838 -12
- package/dist/canonical.js +47 -4
- package/dist/canonical.js.map +1 -1
- package/dist/cli.cjs +5876 -4198
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +5876 -4198
- package/dist/cli.js.map +1 -1
- package/dist/client.cjs +49 -32
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +49 -6
- package/dist/client.d.ts +49 -6
- package/dist/client.js +49 -32
- package/dist/client.js.map +1 -1
- package/dist/compiler.cjs +1275 -264
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +57 -3
- package/dist/compiler.d.ts +57 -3
- package/dist/compiler.js +1268 -265
- package/dist/compiler.js.map +1 -1
- package/dist/{constants-YoFGjIBM.d.cts → constants-C6EG6Wq7.d.cts} +1 -1
- package/dist/{constants-YoFGjIBM.d.ts → constants-C6EG6Wq7.d.ts} +1 -1
- package/dist/definition-DjfC7Lll.d.cts +91 -0
- package/dist/definition-DjfC7Lll.d.ts +91 -0
- package/dist/dynamic-input.cjs +2 -1
- package/dist/dynamic-input.cjs.map +1 -1
- package/dist/dynamic-input.d.cts +9 -2
- package/dist/dynamic-input.d.ts +9 -2
- package/dist/dynamic-input.js +2 -1
- package/dist/dynamic-input.js.map +1 -1
- package/dist/index.cjs +1103 -322
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +479 -19
- package/dist/index.d.ts +479 -19
- package/dist/index.js +1090 -323
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +93 -11
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +226 -15
- package/dist/ir.d.ts +226 -15
- package/dist/ir.js +88 -12
- package/dist/ir.js.map +1 -1
- package/dist/predicate-v2.cjs +116 -10
- package/dist/predicate-v2.cjs.map +1 -1
- package/dist/predicate-v2.d.cts +11 -3
- package/dist/predicate-v2.d.ts +11 -3
- package/dist/predicate-v2.js +116 -10
- package/dist/predicate-v2.js.map +1 -1
- package/dist/sdl.cjs +158 -22
- package/dist/sdl.cjs.map +1 -1
- package/dist/sdl.d.cts +8 -1
- package/dist/sdl.d.ts +8 -1
- package/dist/sdl.js +158 -22
- package/dist/sdl.js.map +1 -1
- package/package.json +5 -4
- package/src/codegen-gql/server-fns.cjs +2 -2
- package/templates/orm-namespace/AGENTS.md +10 -0
- package/templates/orm-namespace/CLAUDE.md +1 -84
- package/templates/orm-namespace/package.json +1 -1
package/dist/canonical.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
// src/canonical/v2.ts
|
|
4
|
+
var objectRef = z.string().max(255).regex(/^[a-z][a-z0-9_]{0,40}\/[A-Za-z_][A-Za-z0-9_]*$/, "Expected an explicit namespace/object reference (no wildcards)");
|
|
5
|
+
var functionRef = z.string().max(255).regex(/^[a-z][a-z0-9-]*$/, "Expected a function slug");
|
|
6
|
+
var refs = (schema) => z.array(schema).max(256).refine(
|
|
7
|
+
(values) => new Set(values).size === values.length,
|
|
8
|
+
"Duplicate dependency reference"
|
|
9
|
+
).default([]);
|
|
10
|
+
var ontologyContractSchema = z.strictObject({
|
|
11
|
+
version: z.literal(1),
|
|
12
|
+
read: refs(objectRef),
|
|
13
|
+
write: refs(objectRef),
|
|
14
|
+
produce: refs(objectRef),
|
|
15
|
+
invoke: refs(functionRef)
|
|
16
|
+
}).refine((contract) => JSON.stringify(contract).length <= 4096, "Ontology contract exceeds the 4 KiB signed-context budget");
|
|
17
|
+
function readOntologyContract(manifest) {
|
|
18
|
+
if (!manifest || typeof manifest !== "object" || !("ontology" in manifest) || manifest.ontology === void 0) return void 0;
|
|
19
|
+
return ontologyContractSchema.parse(manifest.ontology);
|
|
20
|
+
}
|
|
4
21
|
var quoteIdentifier = (name) => `"${name.replaceAll('"', '""')}"`;
|
|
5
22
|
var quoteLiteral = (value) => `'${value.replaceAll("'", "''")}'`;
|
|
6
23
|
|
|
@@ -203,6 +220,7 @@ function compileCheckExpression(source, columns) {
|
|
|
203
220
|
// src/constants.ts
|
|
204
221
|
var COLUMN_IDENTIFIER_PATTERN = /^_?[a-z][a-z0-9_]*$/;
|
|
205
222
|
var MAX_IDENTIFIER_LENGTH = 63;
|
|
223
|
+
var QUALIFIED_TABLE_PATTERN = /^[a-z][a-z0-9_]{0,62}\.[a-z][a-z0-9_]{0,62}$/;
|
|
206
224
|
var CELL_PARTS = ["at", "by", "rev", "source", "conflicts"];
|
|
207
225
|
var CELL_PART_SUFFIX = {
|
|
208
226
|
at: "__at",
|
|
@@ -543,6 +561,8 @@ var canonicalLinkSchema = z.object({
|
|
|
543
561
|
kind: z.enum(["toOne", "toMany", "toPlatformUser"]),
|
|
544
562
|
/** Target table name (namespace-local). Absent for toPlatformUser. */
|
|
545
563
|
target: identifier2.optional(),
|
|
564
|
+
/** Owning namespace of an imported target; omitted for local links. */
|
|
565
|
+
namespace: identifier2.max(41).optional(),
|
|
546
566
|
/** FK column on the owning side (toOne/toPlatformUser: on this table; toMany: on the target). */
|
|
547
567
|
on: columnIdentifier,
|
|
548
568
|
/** Referenced column on the target (default: target's PK / platform user `sub`). */
|
|
@@ -801,11 +821,12 @@ var canonicalForeignKeySchema = z.object({
|
|
|
801
821
|
}).strict();
|
|
802
822
|
var canonicalTableSchema = z.object({
|
|
803
823
|
table: identifier2,
|
|
824
|
+
displayName: z.string().trim().min(1).max(120).optional(),
|
|
804
825
|
description: z.string().max(2e3).optional(),
|
|
805
826
|
/** Table-level rename hint (new in v2). */
|
|
806
827
|
renamedFrom: identifier2.optional(),
|
|
807
|
-
/** Synced/reflected read-only tables (`source:
|
|
808
|
-
source: z.string().regex(
|
|
828
|
+
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
829
|
+
source: z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
809
830
|
columns: z.array(canonicalColumnSchema).default([]),
|
|
810
831
|
primaryKey: z.array(columnIdentifier).min(1).max(8).optional(),
|
|
811
832
|
links: z.array(canonicalLinkSchema).default([]),
|
|
@@ -958,7 +979,9 @@ function validateCellMetadata(table, index, ctx) {
|
|
|
958
979
|
}
|
|
959
980
|
}
|
|
960
981
|
}
|
|
961
|
-
var
|
|
982
|
+
var exportGateSchema = z.union([z.literal(true), z.object({ capability: z.string().min(1) }).strict(), z.object({ role: z.string().min(1) }).strict()]);
|
|
983
|
+
var relationExportSchema = z.object({ read: exportGateSchema, write: exportGateSchema.optional() }).strict();
|
|
984
|
+
var localDefinitionSchema = z.object({
|
|
962
985
|
definition_format: z.literal(CANONICAL_FORMAT),
|
|
963
986
|
namespace: identifier2.max(41),
|
|
964
987
|
description: z.string().max(2e3).optional(),
|
|
@@ -966,6 +989,8 @@ var canonicalDefinitionSchema = z.object({
|
|
|
966
989
|
tables: z.array(canonicalTableSchema).min(0).max(500),
|
|
967
990
|
/** Optional to preserve byte-identical hashes for pre-view canonical v2 documents. */
|
|
968
991
|
views: z.array(canonicalViewSchema).max(500).optional(),
|
|
992
|
+
/** Target-owned cross-namespace access contract, using existing namespace grants. */
|
|
993
|
+
exports: z.record(identifier2, relationExportSchema).optional(),
|
|
969
994
|
/** Verbatim custom-roles grammar (@sequenceholdings/custom-roles-manifest). */
|
|
970
995
|
capabilities: z.object({
|
|
971
996
|
roles: z.unknown().optional(),
|
|
@@ -992,7 +1017,16 @@ var canonicalDefinitionSchema = z.object({
|
|
|
992
1017
|
}
|
|
993
1018
|
}
|
|
994
1019
|
const fkTables = new Map(definition.tables.map((table) => [table.table, table]));
|
|
1020
|
+
const relations = /* @__PURE__ */ new Set([...fkTables.keys(), ...(definition.views ?? []).map((view) => view.view)]);
|
|
1021
|
+
for (const name of Object.keys(definition.exports ?? {})) {
|
|
1022
|
+
if (!relations.has(name)) ctx.addIssue({ code: "custom", path: ["exports", name], message: `export '${name}' is not a local object` });
|
|
1023
|
+
}
|
|
995
1024
|
for (const [tableIndex, table] of definition.tables.entries()) {
|
|
1025
|
+
for (const [linkIndex, link] of table.links.entries()) {
|
|
1026
|
+
if (link.enforce && link.namespace !== void 0 && link.namespace !== definition.namespace) {
|
|
1027
|
+
ctx.addIssue({ code: "custom", path: ["tables", tableIndex, "links", linkIndex], message: "physical foreign keys require a local target; use an ORM link without enforce" });
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
996
1030
|
const names = /* @__PURE__ */ new Set([
|
|
997
1031
|
...table.primaryKey?.length ? [`${table.table}_pkey`] : [],
|
|
998
1032
|
...table.columns.filter((column) => column.unique && !(table.primaryKey?.length === 1 && table.primaryKey[0] === column.columnName)).map((column) => `${table.table}_${column.columnName}_unique`),
|
|
@@ -1162,6 +1196,10 @@ var canonicalDefinitionSchema = z.object({
|
|
|
1162
1196
|
};
|
|
1163
1197
|
for (const view of views) visit(view.view, []);
|
|
1164
1198
|
});
|
|
1199
|
+
var canonicalDefinitionSchema = localDefinitionSchema.safeExtend({
|
|
1200
|
+
/** Flattened, pinned snapshots. Imported relations never participate in this namespace's DDL. */
|
|
1201
|
+
imports: z.array(localDefinitionSchema).max(32).optional()
|
|
1202
|
+
});
|
|
1165
1203
|
function canonicalRelations(definition) {
|
|
1166
1204
|
const views = (definition.views ?? []).map((view) => ({
|
|
1167
1205
|
table: view.view,
|
|
@@ -1205,9 +1243,14 @@ function normalizeCanonical(definition) {
|
|
|
1205
1243
|
dependencies: [...view.dependencies].sort()
|
|
1206
1244
|
}));
|
|
1207
1245
|
}
|
|
1246
|
+
if (definition.imports?.length) {
|
|
1247
|
+
normalized.imports = definition.imports.map(normalizeCanonical).sort((a, b) => a.namespace.localeCompare(b.namespace));
|
|
1248
|
+
} else {
|
|
1249
|
+
delete normalized.imports;
|
|
1250
|
+
}
|
|
1208
1251
|
return normalized;
|
|
1209
1252
|
}
|
|
1210
1253
|
|
|
1211
|
-
export { CANONICAL_FORMAT, CELL_PART_TYPES, COLUMN_TYPES, COMPARATORS, IDENTIFIER_RE, RESERVED_RESOLVED_COLUMN_NAMES, RESOLVED_SOURCE_CELL_PARTS, RESOLVED_SOURCE_SYSTEM_COLUMNS, RESOLVED_VIEW_CELL_PARTS, RESOLVED_VIEW_SYSTEM_COLUMNS, VIEW_QUERY_FUNCTION_ALLOWLIST, canonicalActionSchema, canonicalCheckSchema, canonicalColumnSchema, canonicalCowMutationSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalFetchShapeSchema, canonicalForeignKeySchema, canonicalFunctionRefSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalRelations, canonicalResolveRuleSchema, canonicalResolvedSchema, canonicalResolvedSourceSchema, canonicalTableSchema, canonicalViewSchema, isSingleViewQuerySql, normalizeCanonical, parseDurationMs, policyExpressionSchema, policyVariantSchema, trackedCellColumns, validateResolvedView };
|
|
1254
|
+
export { CANONICAL_FORMAT, CELL_PART_TYPES, COLUMN_TYPES, COMPARATORS, IDENTIFIER_RE, RESERVED_RESOLVED_COLUMN_NAMES, RESOLVED_SOURCE_CELL_PARTS, RESOLVED_SOURCE_SYSTEM_COLUMNS, RESOLVED_VIEW_CELL_PARTS, RESOLVED_VIEW_SYSTEM_COLUMNS, VIEW_QUERY_FUNCTION_ALLOWLIST, canonicalActionSchema, canonicalCheckSchema, canonicalColumnSchema, canonicalCowMutationSchema, canonicalDefinitionSchema, canonicalEnumSchema, canonicalFetchShapeSchema, canonicalForeignKeySchema, canonicalFunctionRefSchema, canonicalIndexSchema, canonicalLinkSchema, canonicalPoliciesSchema, canonicalRelations, canonicalResolveRuleSchema, canonicalResolvedSchema, canonicalResolvedSourceSchema, canonicalTableSchema, canonicalViewSchema, exportGateSchema, isSingleViewQuerySql, localDefinitionSchema, normalizeCanonical, ontologyContractSchema, parseDurationMs, policyExpressionSchema, policyVariantSchema, readOntologyContract, relationExportSchema, trackedCellColumns, validateResolvedView };
|
|
1212
1255
|
//# sourceMappingURL=canonical.js.map
|
|
1213
1256
|
//# sourceMappingURL=canonical.js.map
|