@sequenceholdings/orm 2.8.3 → 2.8.4
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/authoring.cjs +31 -8
- package/dist/authoring.cjs.map +1 -1
- package/dist/authoring.d.cts +8 -2
- package/dist/authoring.d.ts +8 -2
- package/dist/authoring.js +31 -8
- package/dist/authoring.js.map +1 -1
- package/dist/canonical.cjs +1 -1
- 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 +1 -1
- package/dist/canonical.js.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/compiler.cjs +1 -1
- package/dist/compiler.cjs.map +1 -1
- package/dist/compiler.d.cts +4 -4
- package/dist/compiler.d.ts +4 -4
- package/dist/compiler.js +1 -1
- package/dist/compiler.js.map +1 -1
- package/dist/index.cjs +31 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -9
- package/dist/index.d.ts +7 -9
- package/dist/index.js +31 -8
- package/dist/index.js.map +1 -1
- package/dist/ir.cjs +1 -1
- package/dist/ir.cjs.map +1 -1
- package/dist/ir.d.cts +2 -2
- package/dist/ir.d.ts +2 -2
- package/dist/ir.js +1 -1
- package/dist/ir.js.map +1 -1
- package/dist/{naming-CU9ThP_E.d.cts → naming-BMZKFO0W.d.cts} +1 -2
- package/dist/{naming-CPfx7EfF.d.ts → naming-DUk7AcXs.d.ts} +1 -2
- package/dist/predicate-v2.cjs +1 -1
- package/dist/predicate-v2.cjs.map +1 -1
- package/dist/predicate-v2.d.cts +3 -3
- package/dist/predicate-v2.d.ts +3 -3
- package/dist/predicate-v2.js +1 -1
- package/dist/predicate-v2.js.map +1 -1
- package/dist/sdl.cjs +1 -1
- package/dist/sdl.cjs.map +1 -1
- package/dist/sdl.d.cts +2 -2
- package/dist/sdl.d.ts +2 -2
- package/dist/sdl.js +1 -1
- package/dist/sdl.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen-gql/apollo-hooks.cjs +1 -1
- package/src/codegen-gql/server-fns.cjs +1 -1
- package/templates/orm-namespace/graphql/example/queries.ts +1 -1
package/dist/authoring.cjs
CHANGED
|
@@ -1698,7 +1698,7 @@ var canonicalTableSchema = zod.z.object({
|
|
|
1698
1698
|
table: identifier2,
|
|
1699
1699
|
displayName: zod.z.string().trim().min(1).max(120).optional(),
|
|
1700
1700
|
description: zod.z.string().max(2e3).optional(),
|
|
1701
|
-
/** Table-level rename hint
|
|
1701
|
+
/** Table-level rename hint. */
|
|
1702
1702
|
renamedFrom: identifier2.optional(),
|
|
1703
1703
|
/** Synced/reflected read-only tables (`source: schema.table`) — v1 semantics. */
|
|
1704
1704
|
source: zod.z.string().regex(QUALIFIED_TABLE_PATTERN).optional(),
|
|
@@ -2362,6 +2362,12 @@ function builtinCell({ comparator, candidates }) {
|
|
|
2362
2362
|
}
|
|
2363
2363
|
};
|
|
2364
2364
|
}
|
|
2365
|
+
function existsInCell(candidate) {
|
|
2366
|
+
return {
|
|
2367
|
+
value: candidate.value,
|
|
2368
|
+
parts: { source: literal(candidate.source), at: candidate.at, by: candidate.by, conflicts: "CAST(NULL AS jsonb)" }
|
|
2369
|
+
};
|
|
2370
|
+
}
|
|
2365
2371
|
function customCell({ candidates, orderBy, index }) {
|
|
2366
2372
|
const w = ident(`w_${index}`);
|
|
2367
2373
|
const rows = candidates.map((c, ord) => `(${literal(c.source)}, ${c.has}, ${c.value}, ${c.at}, ${c.by}, ${ord})`);
|
|
@@ -2385,26 +2391,29 @@ function buildResolvedQuery({ context, plan }) {
|
|
|
2385
2391
|
const tombstoned2 = RESOLVED_SOURCE_SYSTEM_COLUMNS.tombstoned.columnName;
|
|
2386
2392
|
const sourceByName = new Map(plan.plans.map((source) => [source.name, source]));
|
|
2387
2393
|
const schema = pgCore.getTableConfig(relation(plan.plans[0].table)).schema;
|
|
2394
|
+
const keySource = plan.existsIn === void 0 ? void 0 : sourceByName.get(plan.existsIn);
|
|
2395
|
+
const keyRef = keySource ? `${alias(keySource.name)}.${ident(physical({ source: keySource, property: plan.pk }))}` : `"k".${ident(pkColumn)}`;
|
|
2388
2396
|
const keyBranches = plan.plans.map((source) => {
|
|
2389
2397
|
const where = source.kind === "prefetch" ? drizzleOrm.sql.raw(` WHERE NOT ${ident(tombstoned2)}`) : drizzleOrm.sql.raw("");
|
|
2390
2398
|
const sourcePk = ident(physical({ source, property: plan.pk }));
|
|
2391
2399
|
const selectedPk = sourcePk === ident(pkColumn) ? sourcePk : `${sourcePk} AS ${ident(pkColumn)}`;
|
|
2392
2400
|
return drizzleOrm.sql`SELECT ${drizzleOrm.sql.raw(selectedPk)} FROM ${relation(source.table)}${where}`;
|
|
2393
2401
|
});
|
|
2394
|
-
const
|
|
2395
|
-
|
|
2402
|
+
const base2 = keySource ? drizzleOrm.sql`${relation(keySource.table)} AS ${drizzleOrm.sql.raw(alias(keySource.name))}` : drizzleOrm.sql`(${drizzleOrm.sql.join(keyBranches, drizzleOrm.sql.raw(" UNION "))}) AS "k"`;
|
|
2403
|
+
const joins = plan.plans.filter((source) => source !== keySource).map(
|
|
2404
|
+
(source) => drizzleOrm.sql` LEFT JOIN ${relation(source.table)} AS ${drizzleOrm.sql.raw(alias(source.name))} ON ${drizzleOrm.sql.raw(`${alias(source.name)}.${ident(physical({ source, property: plan.pk }))} = ${keyRef}`)}`
|
|
2396
2405
|
);
|
|
2397
2406
|
const cells = /* @__PURE__ */ new Map();
|
|
2398
2407
|
plan.rules.forEach((rule, index) => {
|
|
2399
2408
|
const canonical = plan.columns[rule.column].toCanonicalColumn(rule.column);
|
|
2400
2409
|
const pgType = typeof canonical.type === "string" ? PG_TYPE[canonical.type] : `${schema === void 0 ? "" : `${ident(schema)}.`}${ident(canonical.type.enum)}`;
|
|
2401
2410
|
const candidates = rule.candidates.map((name2) => candidateSql({ source: sourceByName.get(name2), column: rule.column, pk: plan.pk, pgType }));
|
|
2402
|
-
cells.set(rule.column, rule.comparator === "custom" ? customCell({ candidates, orderBy: rule.orderBy, index }) : builtinCell({ comparator: rule.comparator, candidates }));
|
|
2411
|
+
cells.set(rule.column, keySource && rule.candidates.length === 1 && rule.candidates[0] === keySource.name ? existsInCell(candidates[0]) : rule.comparator === "custom" ? customCell({ candidates, orderBy: rule.orderBy, index }) : builtinCell({ comparator: rule.comparator, candidates }));
|
|
2403
2412
|
});
|
|
2404
2413
|
const laterals = [...cells.values()].flatMap((cell) => cell.lateral ? [drizzleOrm.sql.raw(cell.lateral)] : []);
|
|
2405
|
-
const from = drizzleOrm.sql.join([
|
|
2414
|
+
const from = drizzleOrm.sql.join([base2, ...joins, ...laterals], drizzleOrm.sql.raw(""));
|
|
2406
2415
|
const selected = {
|
|
2407
|
-
[plan.pk]: drizzleOrm.sql.raw(
|
|
2416
|
+
[plan.pk]: drizzleOrm.sql.raw(keyRef).as(pkColumn)
|
|
2408
2417
|
};
|
|
2409
2418
|
for (const [property, builder] of Object.entries(plan.columns)) {
|
|
2410
2419
|
if (property === plan.pk) continue;
|
|
@@ -2476,10 +2485,12 @@ function defineResolvedTable(name2, columns, config) {
|
|
|
2476
2485
|
for (const source of deletedBy) {
|
|
2477
2486
|
if (plans.find((plan) => plan.name === source)?.kind !== "manual") fail(`rows.deletedBy "${source}" must be the manual source`);
|
|
2478
2487
|
}
|
|
2488
|
+
const existsIn = planExistsIn({ config, plans, fail });
|
|
2489
|
+
const notNullColumns = existsIn ? inheritedNotNullColumns({ existsIn, rules }) : /* @__PURE__ */ new Set();
|
|
2479
2490
|
const partType = { source: t.text, at: t.timestamptz, by: t.text, conflicts: t.jsonb };
|
|
2480
2491
|
const viewColumns = {};
|
|
2481
2492
|
for (const [property, builder] of Object.entries(columns)) {
|
|
2482
|
-
viewColumns[property] = cloneColumn({ builder, property, notNull: property === pk, primaryKey: property === pk });
|
|
2493
|
+
viewColumns[property] = cloneColumn({ builder, property, notNull: property === pk || notNullColumns.has(property), primaryKey: property === pk });
|
|
2483
2494
|
if (property === pk) continue;
|
|
2484
2495
|
const columnName = builder.columnNameFor(property);
|
|
2485
2496
|
for (const part of RESOLVED_VIEW_CELL_PARTS) {
|
|
@@ -2495,7 +2506,7 @@ function defineResolvedTable(name2, columns, config) {
|
|
|
2495
2506
|
deletedBy,
|
|
2496
2507
|
policies: writePolicies
|
|
2497
2508
|
};
|
|
2498
|
-
const queryPlan = { columns, pk, plans, rules, deletedBy };
|
|
2509
|
+
const queryPlan = { columns, pk, plans, rules, deletedBy, ...existsIn ? { existsIn: existsIn.name } : {} };
|
|
2499
2510
|
const typedColumns = viewColumns;
|
|
2500
2511
|
const surface = {
|
|
2501
2512
|
...config.description !== void 0 ? { description: config.description } : {},
|
|
@@ -2537,6 +2548,18 @@ function defineResolvedTable(name2, columns, config) {
|
|
|
2537
2548
|
}
|
|
2538
2549
|
});
|
|
2539
2550
|
}
|
|
2551
|
+
function planExistsIn({ config, plans, fail }) {
|
|
2552
|
+
const names = config.rows?.existsIn;
|
|
2553
|
+
if (names === void 0) return void 0;
|
|
2554
|
+
if (names.length !== 1) fail("rows.existsIn names exactly one etl source");
|
|
2555
|
+
const source = plans.find((plan) => plan.name === names[0]);
|
|
2556
|
+
if (source?.kind !== "etl") fail(`rows.existsIn "${names[0]}" must be an etl source`);
|
|
2557
|
+
if (config.policies.insert !== void 0 || config.policies.write !== void 0) fail("rows.existsIn allows only an update policy: rows come from the etl source");
|
|
2558
|
+
return source;
|
|
2559
|
+
}
|
|
2560
|
+
function inheritedNotNullColumns({ existsIn, rules }) {
|
|
2561
|
+
return new Set(rules.filter((rule) => rule.candidates.length === 1 && rule.candidates[0] === existsIn.name).map((rule) => rule.column).filter((column) => existsIn.table.columns[column]?.toCanonicalColumn(column).nullable === false));
|
|
2562
|
+
}
|
|
2540
2563
|
function planRules({ config, plans, dataColumns, fail }) {
|
|
2541
2564
|
const kindOrder = { manual: 0, prefetch: 1, etl: 2 };
|
|
2542
2565
|
const fallback = config.default ?? priority([...plans].sort((a, b) => kindOrder[a.kind] - kindOrder[b.kind]).map((plan) => plan.name));
|