gencow 0.1.299 → 0.2.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/bin/gencow.mjs +0 -6
- package/core/package.json +1 -1
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-dev-runtime.mjs +1 -0
- package/lib/cli-project-runtime.mjs +26 -14
- package/lib/codegen-command.mjs +16 -0
- package/lib/coding-guardrails.mjs +2 -0
- package/lib/dashboard-artifact.mjs +65 -0
- package/lib/dashboard-assets.mjs +20 -0
- package/lib/db-command.mjs +121 -80
- package/lib/db-migration-command-steps.mjs +19 -16
- package/lib/db-push-command.mjs +1 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- package/lib/local-dashboard-plan.mjs +60 -0
- package/lib/local-database-commands.mjs +127 -0
- package/lib/local-development-migrations.mjs +157 -0
- package/lib/local-drizzle-database.config.mjs +10 -0
- package/lib/local-runtime-features.mjs +12 -0
- package/lib/rag-selection.mjs +7 -0
- package/lib/runtime-local-worker.mjs +116 -0
- package/lib/runtime-mode.mjs +3 -0
- package/lib/standalone-codegen-adapter.mjs +91 -0
- package/lib/ts-codegen-import-extension.mjs +228 -19
- package/package.json +16 -9
- package/runtime/config.mjs +218 -2
- package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
- package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
- package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
- package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
- package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
- package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
- package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
- package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
- package/runtime/engine/chunk-5575APCJ.mjs +215 -0
- package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
- package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
- package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
- package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
- package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
- package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
- package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
- package/runtime/engine/chunk-6W653LXI.mjs +13 -0
- package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
- package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
- package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
- package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
- package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
- package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
- package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
- package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
- package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
- package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
- package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
- package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
- package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
- package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
- package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
- package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
- package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
- package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
- package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
- package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
- package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
- package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
- package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
- package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
- package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
- package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
- package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
- package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
- package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
- package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
- package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
- package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
- package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
- package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
- package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
- package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
- package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
- package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
- package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
- package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
- package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
- package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
- package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
- package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
- package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
- package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
- package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
- package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
- package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
- package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
- package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
- package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
- package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
- package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
- package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
- package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
- package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
- package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
- package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
- package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
- package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
- package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
- package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
- package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
- package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
- package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
- package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
- package/runtime/engine/chunk-YRHM272W.mjs +528 -0
- package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
- package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
- package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
- package/runtime/engine/composition.mjs +325 -0
- package/runtime/engine/document-local.mjs +504 -0
- package/runtime/engine/graph.json +4134 -0
- package/runtime/engine/index.mjs +265 -0
- package/runtime/engine/local-postgres-support.mjs +69 -0
- package/runtime/engine/local.mjs +3275 -0
- package/runtime/engine/pglite-directory-lock.mjs +8 -0
- package/runtime/engine/rag.mjs +11 -0
- package/runtime/engine/search.mjs +18 -0
- package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
- package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
- package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
- package/runtime/framework-migrations/manifest.json +56 -0
- package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
- package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
- package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
- package/runtime/runtime-metadata.json +27 -0
- package/runtime/tooling.mjs +10399 -8951
- package/scripts/bundle-runtime-config.mjs +23 -0
- package/scripts/bundle-runtime.mjs +100 -0
- package/scripts/bundle-runtime.test.mjs +33 -0
- package/scripts/bundle-shared.mjs +3 -0
- package/scripts/copy-dashboard.mjs +16 -0
- package/scripts/pre-publish-check.mjs +23 -11
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +2 -1
- package/templateFeature/tools/tools.ts +3 -3
- package/runtime/server.mjs +0 -14389
- package/scripts/bundle-server.mjs +0 -223
- package/server/config.js +0 -1
- package/server/index.js +0 -1
- package/server/package.json +0 -6
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runtimeDatabaseSetupError
|
|
3
|
+
} from "./chunk-SVJCOUI3.mjs";
|
|
4
|
+
|
|
5
|
+
// ../runtime/dist/framework-schema/migration-artifacts.js
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
8
|
+
import { dirname, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { readMigrationFiles } from "drizzle-orm/migrator";
|
|
11
|
+
function artifactRoot() {
|
|
12
|
+
const moduleDirectory = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const candidates = [
|
|
14
|
+
resolve(moduleDirectory, "../framework-migrations"),
|
|
15
|
+
resolve(moduleDirectory, "../../framework-migrations")
|
|
16
|
+
];
|
|
17
|
+
const found = candidates.find((candidate) => existsSync(resolve(candidate, "manifest.json")));
|
|
18
|
+
if (!found)
|
|
19
|
+
throw new Error("Runtime framework migration artifacts are unavailable.");
|
|
20
|
+
return found;
|
|
21
|
+
}
|
|
22
|
+
function fail() {
|
|
23
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID");
|
|
24
|
+
}
|
|
25
|
+
function sha256(bytes) {
|
|
26
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
27
|
+
}
|
|
28
|
+
function manifest(root, requireFoundationBootstraps = false, selectedFoundationBootstrap) {
|
|
29
|
+
let value;
|
|
30
|
+
try {
|
|
31
|
+
value = JSON.parse(readFileSync(resolve(root, "manifest.json"), "utf8"));
|
|
32
|
+
} catch {
|
|
33
|
+
return fail();
|
|
34
|
+
}
|
|
35
|
+
if (!value || typeof value !== "object")
|
|
36
|
+
return fail();
|
|
37
|
+
const record = value;
|
|
38
|
+
const bootstrap = record.journalBootstrap;
|
|
39
|
+
const foundationBootstraps = record.foundationBootstraps;
|
|
40
|
+
if (record.formatVersion !== 2 || !Array.isArray(record.components) || !bootstrap || typeof bootstrap.artifactId !== "string" || typeof bootstrap.hash !== "string" || !/^[0-9a-f]{64}$/u.test(bootstrap.hash) || requireFoundationBootstraps && (!Array.isArray(foundationBootstraps) || foundationBootstraps.length !== 2) || foundationBootstraps !== void 0 && !Array.isArray(foundationBootstraps))
|
|
41
|
+
return fail();
|
|
42
|
+
const foundationIds = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const candidate of foundationBootstraps ?? []) {
|
|
44
|
+
if (!candidate || typeof candidate !== "object")
|
|
45
|
+
return fail();
|
|
46
|
+
const foundation = candidate;
|
|
47
|
+
if (foundation.componentId !== "workflow" && foundation.componentId !== "rag" || foundationIds.has(foundation.componentId) || foundation.artifactId !== `framework-foundation-${foundation.componentId}-v1` || typeof foundation.hash !== "string" || !/^[0-9a-f]{64}$/u.test(foundation.hash) || foundation.executionEligibility !== "startup-compatible")
|
|
48
|
+
return fail();
|
|
49
|
+
foundationIds.add(foundation.componentId);
|
|
50
|
+
}
|
|
51
|
+
if (requireFoundationBootstraps && (!foundationIds.has("workflow") || !foundationIds.has("rag")))
|
|
52
|
+
return fail();
|
|
53
|
+
let foundationBootstrapBytes;
|
|
54
|
+
if (selectedFoundationBootstrap !== void 0) {
|
|
55
|
+
if (selectedFoundationBootstrap !== "workflow" && selectedFoundationBootstrap !== "rag")
|
|
56
|
+
return fail();
|
|
57
|
+
const selected = foundationBootstraps?.find((entry) => entry.componentId === selectedFoundationBootstrap);
|
|
58
|
+
if (!selected)
|
|
59
|
+
return fail();
|
|
60
|
+
try {
|
|
61
|
+
foundationBootstrapBytes = readFileSync(resolve(root, "foundation-bootstrap", `${selectedFoundationBootstrap}.sql`));
|
|
62
|
+
} catch {
|
|
63
|
+
return fail();
|
|
64
|
+
}
|
|
65
|
+
if (sha256(foundationBootstrapBytes) !== selected.hash)
|
|
66
|
+
return fail();
|
|
67
|
+
}
|
|
68
|
+
const seen = /* @__PURE__ */ new Set();
|
|
69
|
+
for (const candidate of record.components) {
|
|
70
|
+
if (!candidate || typeof candidate !== "object")
|
|
71
|
+
return fail();
|
|
72
|
+
const component = candidate;
|
|
73
|
+
if (typeof component.componentId !== "string" || !/^[a-z][a-z0-9-]{0,62}$/u.test(component.componentId) || seen.has(component.componentId) || typeof component.targetHead !== "string" || !Array.isArray(component.migrations) || component.migrations.length === 0)
|
|
74
|
+
return fail();
|
|
75
|
+
seen.add(component.componentId);
|
|
76
|
+
for (const [index, value2] of component.migrations.entries()) {
|
|
77
|
+
if (!value2 || typeof value2 !== "object")
|
|
78
|
+
return fail();
|
|
79
|
+
const migration = value2;
|
|
80
|
+
if (typeof migration.migrationId !== "string" || !/^[0-9]{14}_[a-z0-9_]{1,48}$/u.test(migration.migrationId) || migration.migrationOrder !== index + 1 || typeof migration.createdAt !== "number" || !Number.isSafeInteger(migration.createdAt) || migration.createdAt <= 0 || typeof migration.hash !== "string" || !/^[0-9a-f]{64}$/u.test(migration.hash) || migration.executionEligibility !== "startup-compatible" && migration.executionEligibility !== "owner-maintenance")
|
|
81
|
+
return fail();
|
|
82
|
+
}
|
|
83
|
+
if (component.migrations.at(-1).migrationId !== component.targetHead)
|
|
84
|
+
return fail();
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...value,
|
|
88
|
+
foundationBootstraps: foundationBootstraps ?? [],
|
|
89
|
+
...foundationBootstrapBytes ? { foundationBootstrapBytes } : {}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function readComponent(root, componentId, release) {
|
|
93
|
+
const selected = release.components.find((entry) => entry.componentId === componentId);
|
|
94
|
+
if (!selected || !Array.isArray(selected.migrations) || !selected.migrations.length)
|
|
95
|
+
return fail();
|
|
96
|
+
const directory = resolve(root, componentId);
|
|
97
|
+
let parsed;
|
|
98
|
+
try {
|
|
99
|
+
parsed = readMigrationFiles({ migrationsFolder: directory });
|
|
100
|
+
} catch {
|
|
101
|
+
return fail();
|
|
102
|
+
}
|
|
103
|
+
const folders = readdirSync(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "meta").map((entry) => entry.name).sort((a, b) => a.localeCompare(b));
|
|
104
|
+
if (folders.length !== selected.migrations.length || parsed.length !== selected.migrations.length)
|
|
105
|
+
return fail();
|
|
106
|
+
const migrations = parsed.map((migration, index) => {
|
|
107
|
+
const expected = selected.migrations[index];
|
|
108
|
+
const bytes = readFileSync(resolve(directory, migration.name, "migration.sql"));
|
|
109
|
+
if (!expected || migration.name !== expected.migrationId || migration.folderMillis !== expected.createdAt || migration.hash !== expected.hash || sha256(bytes) !== expected.hash || expected.migrationOrder !== index + 1 || !migration.sql.length || migration.sql.some((statement) => !statement.trim()))
|
|
110
|
+
return fail();
|
|
111
|
+
return Object.freeze({
|
|
112
|
+
migrationId: expected.migrationId,
|
|
113
|
+
migrationOrder: expected.migrationOrder,
|
|
114
|
+
createdAt: expected.createdAt,
|
|
115
|
+
hash: expected.hash,
|
|
116
|
+
executionEligibility: expected.executionEligibility,
|
|
117
|
+
statements: Object.freeze([...migration.sql])
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
if (selected.targetHead !== migrations.at(-1)?.migrationId)
|
|
121
|
+
return fail();
|
|
122
|
+
return Object.freeze({
|
|
123
|
+
componentId,
|
|
124
|
+
targetHead: selected.targetHead,
|
|
125
|
+
migrations: Object.freeze(migrations)
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function loadRuntimeFrameworkMigrationBundle(componentId) {
|
|
129
|
+
return readRuntimeFrameworkMigrationBundleAtRoot(artifactRoot(), componentId);
|
|
130
|
+
}
|
|
131
|
+
function readRuntimeFrameworkMigrationBundleAtRoot(root, componentId) {
|
|
132
|
+
if (typeof root !== "string" || !root.trim())
|
|
133
|
+
return fail();
|
|
134
|
+
if (!/^[a-z][a-z0-9-]{0,62}$/u.test(componentId))
|
|
135
|
+
return fail();
|
|
136
|
+
const checkedRoot = resolve(root);
|
|
137
|
+
return readComponent(checkedRoot, componentId, manifest(checkedRoot, componentId === "workflow" || componentId === "rag"));
|
|
138
|
+
}
|
|
139
|
+
function readRuntimeFrameworkFoundationBootstrapAtRoot(root, componentId) {
|
|
140
|
+
if (typeof root !== "string" || !root.trim())
|
|
141
|
+
return fail();
|
|
142
|
+
if (componentId !== "workflow" && componentId !== "rag")
|
|
143
|
+
return fail();
|
|
144
|
+
const checkedRoot = resolve(root);
|
|
145
|
+
const release = manifest(checkedRoot, true, componentId);
|
|
146
|
+
const definition = release.foundationBootstraps?.find((entry) => entry.componentId === componentId);
|
|
147
|
+
const bytes = release.foundationBootstrapBytes;
|
|
148
|
+
if (!definition || !bytes || sha256(bytes) !== definition.hash)
|
|
149
|
+
return fail();
|
|
150
|
+
const text = bytes.toString("utf8");
|
|
151
|
+
if (Buffer.from(text, "utf8").compare(bytes) !== 0 || !text.trim())
|
|
152
|
+
return fail();
|
|
153
|
+
return Object.freeze({
|
|
154
|
+
componentId,
|
|
155
|
+
artifactId: definition.artifactId,
|
|
156
|
+
hash: definition.hash,
|
|
157
|
+
executionEligibility: "startup-compatible",
|
|
158
|
+
sql: text
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function loadRuntimeFrameworkJournalBootstrap() {
|
|
162
|
+
const root = artifactRoot();
|
|
163
|
+
const definition = manifest(root, true).journalBootstrap;
|
|
164
|
+
const bytes = readFileSync(resolve(root, "journal-bootstrap/migration.sql"));
|
|
165
|
+
if (sha256(bytes) !== definition.hash)
|
|
166
|
+
return fail();
|
|
167
|
+
const text = bytes.toString("utf8");
|
|
168
|
+
if (Buffer.from(text, "utf8").compare(bytes) !== 0 || !text.trim())
|
|
169
|
+
return fail();
|
|
170
|
+
return Object.freeze({ artifactId: definition.artifactId, hash: definition.hash, sql: text });
|
|
171
|
+
}
|
|
172
|
+
function loadRuntimeFrameworkFoundationBootstrap(componentId) {
|
|
173
|
+
return readRuntimeFrameworkFoundationBootstrapAtRoot(artifactRoot(), componentId);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
loadRuntimeFrameworkMigrationBundle,
|
|
178
|
+
loadRuntimeFrameworkJournalBootstrap,
|
|
179
|
+
loadRuntimeFrameworkFoundationBootstrap
|
|
180
|
+
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RuntimeSearchError
|
|
3
|
+
} from "./chunk-LEW5ZMLR.mjs";
|
|
4
|
+
|
|
5
|
+
// ../runtime/dist/search/snapshot.js
|
|
6
|
+
function snapshotSearchOptions(input, mode, owner) {
|
|
7
|
+
const invalid = () => new RuntimeSearchError("SEARCH_INVALID_OPTIONS", owner.correlationId, owner.stage);
|
|
8
|
+
function record(value) {
|
|
9
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
10
|
+
throw invalid();
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function scalar(value) {
|
|
14
|
+
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number")
|
|
15
|
+
return value;
|
|
16
|
+
throw invalid();
|
|
17
|
+
}
|
|
18
|
+
function optional(value) {
|
|
19
|
+
return value === void 0 ? void 0 : scalar(value);
|
|
20
|
+
}
|
|
21
|
+
function array(value) {
|
|
22
|
+
if (!Array.isArray(value) || Object.keys(value).length !== value.length)
|
|
23
|
+
throw invalid();
|
|
24
|
+
return Array.from(value);
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const raw = record(input), scope = record(raw.scope);
|
|
28
|
+
const copy = {
|
|
29
|
+
scope: Object.freeze({
|
|
30
|
+
corpus: scalar(scope.corpus),
|
|
31
|
+
visibility: scalar(scope.visibility),
|
|
32
|
+
...scope.ownerUserId !== void 0 ? { ownerUserId: scalar(scope.ownerUserId) } : {}
|
|
33
|
+
}),
|
|
34
|
+
...raw.limit !== void 0 ? { limit: optional(raw.limit) } : {},
|
|
35
|
+
...raw.offset !== void 0 ? { offset: optional(raw.offset) } : {}
|
|
36
|
+
};
|
|
37
|
+
if (mode !== "vector")
|
|
38
|
+
copy.fields = Object.freeze(array(raw.fields).map((field) => {
|
|
39
|
+
if (typeof field !== "string")
|
|
40
|
+
throw invalid();
|
|
41
|
+
return field;
|
|
42
|
+
}));
|
|
43
|
+
if (mode !== "lexical") {
|
|
44
|
+
copy.vector = Object.freeze(array(raw.vector).map((value) => scalar(value)));
|
|
45
|
+
if (raw.vectorField !== void 0)
|
|
46
|
+
copy.vectorField = scalar(raw.vectorField);
|
|
47
|
+
}
|
|
48
|
+
if (raw.filters !== void 0) {
|
|
49
|
+
const filters = record(raw.filters), captured = {};
|
|
50
|
+
for (const [kind, values] of Object.entries(filters)) {
|
|
51
|
+
if (!["eq", "in", "range"].includes(kind))
|
|
52
|
+
throw invalid();
|
|
53
|
+
const entries = Object.entries(record(values)).map(([field, value]) => [
|
|
54
|
+
field,
|
|
55
|
+
kind === "eq" ? scalar(value) : kind === "in" ? Object.freeze(array(value).map(scalar)) : Object.freeze(Object.fromEntries(Object.entries(record(value)).map(([operator, boundary]) => {
|
|
56
|
+
if (!["gte", "lte"].includes(operator))
|
|
57
|
+
throw invalid();
|
|
58
|
+
return [operator, scalar(boundary)];
|
|
59
|
+
})))
|
|
60
|
+
]);
|
|
61
|
+
captured[kind] = Object.freeze(Object.fromEntries(entries));
|
|
62
|
+
}
|
|
63
|
+
copy.filters = Object.freeze(captured);
|
|
64
|
+
}
|
|
65
|
+
const tuning = raw.tuning === void 0 ? void 0 : record(raw.tuning);
|
|
66
|
+
if (mode === "vector" && tuning)
|
|
67
|
+
copy.tuning = Object.freeze({ minScore: optional(tuning.minScore) });
|
|
68
|
+
if (mode === "hybrid") {
|
|
69
|
+
const fusion = tuning?.fusion === void 0 ? void 0 : record(tuning.fusion);
|
|
70
|
+
copy.tuning = Object.freeze({
|
|
71
|
+
keywordCandidateLimit: optional(tuning?.keywordCandidateLimit ?? raw.keywordCandidateLimit),
|
|
72
|
+
vectorCandidateLimit: optional(tuning?.vectorCandidateLimit ?? raw.vectorCandidateLimit),
|
|
73
|
+
minFusedScore: optional(tuning?.minFusedScore),
|
|
74
|
+
fusion: Object.freeze({
|
|
75
|
+
mode: optional(fusion?.mode ?? raw.fusion),
|
|
76
|
+
rrfK: optional(fusion?.rrfK),
|
|
77
|
+
keywordWeight: optional(fusion?.keywordWeight),
|
|
78
|
+
vectorWeight: optional(fusion?.vectorWeight)
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return Object.freeze(copy);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof RuntimeSearchError)
|
|
85
|
+
throw error;
|
|
86
|
+
throw invalid();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ../runtime/dist/search/scope.js
|
|
91
|
+
function assertSearchScope(owner, scope) {
|
|
92
|
+
const fail = (code) => {
|
|
93
|
+
throw new RuntimeSearchError(code, owner.correlationId, owner.stage);
|
|
94
|
+
};
|
|
95
|
+
if (typeof scope.corpus !== "string" || !scope.corpus.trim())
|
|
96
|
+
fail("SEARCH_SCOPE_REQUIRED");
|
|
97
|
+
if (!["private", "shared", "public"].includes(scope.visibility))
|
|
98
|
+
fail("SEARCH_INVALID_SCOPE");
|
|
99
|
+
if (scope.ownerUserId !== void 0 && typeof scope.ownerUserId !== "string")
|
|
100
|
+
fail("SEARCH_INVALID_OPTIONS");
|
|
101
|
+
if (scope.corpus.includes("\0") || scope.ownerUserId?.includes("\0"))
|
|
102
|
+
fail("SEARCH_INVALID_OPTIONS");
|
|
103
|
+
if (scope.visibility === "private") {
|
|
104
|
+
if (!owner.identity?.id)
|
|
105
|
+
fail("RUNTIME_AUTHENTICATION_REQUIRED");
|
|
106
|
+
if ((scope.ownerUserId ?? owner.identity.id) !== owner.identity.id)
|
|
107
|
+
fail("SEARCH_SCOPE_OWNER_MISMATCH");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export {
|
|
112
|
+
snapshotSearchOptions,
|
|
113
|
+
assertSearchScope
|
|
114
|
+
};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import {
|
|
2
|
+
workflowTerminalGuardSchema
|
|
3
|
+
} from "./chunk-ZXMM7QFP.mjs";
|
|
4
|
+
import {
|
|
5
|
+
loadRuntimeFrameworkFoundationBootstrap
|
|
6
|
+
} from "./chunk-PZFMKFHO.mjs";
|
|
7
|
+
import {
|
|
8
|
+
workflowSchemaDefaultMatches,
|
|
9
|
+
workflowSchemaIndexes,
|
|
10
|
+
workflowSchemaTables
|
|
11
|
+
} from "./chunk-GOLP7OSG.mjs";
|
|
12
|
+
import {
|
|
13
|
+
runtimeDatabaseSetupError
|
|
14
|
+
} from "./chunk-SVJCOUI3.mjs";
|
|
15
|
+
|
|
16
|
+
// ../runtime/dist/workflow/schema-created-identities.js
|
|
17
|
+
function workflowCreatedRelationName(table, column, label) {
|
|
18
|
+
let tableBytes = Buffer.byteLength(table);
|
|
19
|
+
let columnBytes = Buffer.byteLength(column ?? "");
|
|
20
|
+
const available = 63 - Buffer.byteLength(label) - 1 - (column === void 0 ? 0 : 1);
|
|
21
|
+
while (tableBytes + columnBytes > available) {
|
|
22
|
+
if (tableBytes > columnBytes)
|
|
23
|
+
tableBytes--;
|
|
24
|
+
else
|
|
25
|
+
columnBytes--;
|
|
26
|
+
}
|
|
27
|
+
const clip = (value, bytes) => {
|
|
28
|
+
let result = "";
|
|
29
|
+
for (const character of value) {
|
|
30
|
+
if (Buffer.byteLength(result) + Buffer.byteLength(character) > bytes)
|
|
31
|
+
break;
|
|
32
|
+
result += character;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
return `${clip(table, tableBytes)}${column === void 0 ? "" : `_${clip(column, columnBytes)}`}_${label}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ../runtime/dist/workflow/schema-component-inspection.js
|
|
40
|
+
function equal(left, right) {
|
|
41
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
42
|
+
}
|
|
43
|
+
function predicate(value) {
|
|
44
|
+
return value?.replaceAll(/status\s+in\s*\('pending'\s*,\s*'sending'\)/giu, "status = any (array['pending', 'sending'])")?.split(/('(?:''|[^'])*')/gu).map((part, index) => index % 2 ? part : part.toLowerCase().replaceAll(/[()]/gu, "").replaceAll(/::text/gu, "").replaceAll(/\s+/gu, " ")).join("").trim() ?? null;
|
|
45
|
+
}
|
|
46
|
+
function inspectWorkflowSchemaComponent(snapshot) {
|
|
47
|
+
const selected = /* @__PURE__ */ new Set();
|
|
48
|
+
const incompatible = () => ({ state: "incompatible", reason: "shape-incompatible" });
|
|
49
|
+
for (const table of workflowSchemaTables) {
|
|
50
|
+
const id = table.name.replaceAll("_", "-").replace(/^-+/u, "");
|
|
51
|
+
const relation = snapshot.relations.find((relation2) => relation2.schema === "public" && relation2.name === table.name);
|
|
52
|
+
if (!relation) {
|
|
53
|
+
const creationNames = [
|
|
54
|
+
workflowCreatedRelationName(table.name, void 0, "pkey"),
|
|
55
|
+
...table.unique.map((columns2) => workflowCreatedRelationName(table.name, columns2.join("_"), "key")),
|
|
56
|
+
...table.columns.filter((column) => column[3] === "sequence").map(([column]) => workflowCreatedRelationName(table.name, column, "seq"))
|
|
57
|
+
];
|
|
58
|
+
if (snapshot.relations.some((candidate) => candidate.schema === "public" && creationNames.includes(candidate.name)))
|
|
59
|
+
return incompatible();
|
|
60
|
+
selected.add(`create-${id}`);
|
|
61
|
+
selected.add(`access-${id}`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (relation.kind !== "r")
|
|
65
|
+
return incompatible();
|
|
66
|
+
const columns = snapshot.columns.filter((column) => column.schema === "public" && column.table === table.name);
|
|
67
|
+
const known = new Set(table.columns.map(([name]) => name));
|
|
68
|
+
if (columns.some((column) => !known.has(column.name) && !column.nullable && column.defaultValue === null && !column.identity && !column.generated))
|
|
69
|
+
return incompatible();
|
|
70
|
+
for (const [name, type, nullable, defaultValue, additive] of table.columns) {
|
|
71
|
+
const actual = columns.find((column) => column.name === name);
|
|
72
|
+
if (!actual && additive) {
|
|
73
|
+
selected.add(`add-${id}-${name.replaceAll("_", "-")}`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (!actual || actual.type !== type || actual.nullable !== nullable || actual.identity || actual.generated)
|
|
77
|
+
return incompatible();
|
|
78
|
+
if (defaultValue === "sequence") {
|
|
79
|
+
const sequences = snapshot.sequences.filter((sequence) => sequence.schema === "public" && sequence.table === table.name && sequence.column === name && sequence.defaultLinked);
|
|
80
|
+
if (!actual.defaultValue?.startsWith("nextval(") || sequences.length !== 1)
|
|
81
|
+
return incompatible();
|
|
82
|
+
} else if (!workflowSchemaDefaultMatches(table.name, name, defaultValue, actual.defaultValue))
|
|
83
|
+
return incompatible();
|
|
84
|
+
}
|
|
85
|
+
const expected = [
|
|
86
|
+
{ kind: "primary", columns: table.primary },
|
|
87
|
+
...table.unique.map((columns2) => ({ kind: "unique", columns: columns2 })),
|
|
88
|
+
...table.foreign.map(([column, target]) => ({
|
|
89
|
+
kind: "foreign",
|
|
90
|
+
columns: [column],
|
|
91
|
+
target: { schema: "public", table: target, columns: ["id"], deleteAction: "c" }
|
|
92
|
+
}))
|
|
93
|
+
];
|
|
94
|
+
const constraints = snapshot.constraints.filter((constraint) => constraint.schema === "public" && constraint.table === table.name);
|
|
95
|
+
const matches = (actual, contract) => actual.kind === contract.kind && actual.validated && !actual.deferrable && !actual.nullsNotDistinct && equal(actual.columns, contract.columns) && (!contract.target || actual.target?.schema === contract.target.schema && actual.target?.table === contract.target.table && equal(actual.target?.columns ?? [], contract.target.columns) && actual.target?.deleteAction === contract.target.deleteAction);
|
|
96
|
+
if (expected.some((contract) => !constraints.some((constraint) => matches(constraint, contract))))
|
|
97
|
+
return incompatible();
|
|
98
|
+
if (constraints.some((constraint) => !expected.some((contract) => matches(constraint, contract)) && !(constraint.kind === "unique" && constraint.validated && !constraint.deferrable && table.primary.every((name) => constraint.columns.includes(name)))))
|
|
99
|
+
return incompatible();
|
|
100
|
+
if (snapshot.indexes.some((index) => index.schema === "public" && index.table === table.name && index.unique && !index.constraintOwned && !workflowSchemaIndexes.some((expected2) => expected2.name === index.name) && !table.primary.every((name) => index.keys.includes(name))))
|
|
101
|
+
return incompatible();
|
|
102
|
+
const accessObjects = [
|
|
103
|
+
{
|
|
104
|
+
name: table.name,
|
|
105
|
+
kind: "table",
|
|
106
|
+
privileges: ["SELECT", "INSERT", "UPDATE", "DELETE"]
|
|
107
|
+
},
|
|
108
|
+
...snapshot.sequences.filter((sequence) => sequence.schema === "public" && sequence.table === table.name && sequence.defaultLinked).map((sequence) => ({
|
|
109
|
+
name: sequence.name,
|
|
110
|
+
kind: "sequence",
|
|
111
|
+
privileges: ["USAGE", "SELECT"]
|
|
112
|
+
}))
|
|
113
|
+
];
|
|
114
|
+
if (!snapshot.access.some((access) => access.path === "maintenance" && access.schema === "public" && access.kind === "schema" && access.privileges.includes("USAGE")) || accessObjects.some((object) => !snapshot.access.some((access) => access.path === "maintenance" && access.schema === "public" && access.kind === object.kind && access.name === object.name && object.privileges.every((privilege) => access.privileges.includes(privilege)))))
|
|
115
|
+
selected.add(`access-${id}`);
|
|
116
|
+
}
|
|
117
|
+
for (const expected of workflowSchemaIndexes) {
|
|
118
|
+
const actual = snapshot.indexes.find((index) => index.schema === "public" && index.name === expected.name);
|
|
119
|
+
if (!actual) {
|
|
120
|
+
if (snapshot.relations.some((relation) => relation.schema === "public" && relation.name === expected.name))
|
|
121
|
+
return incompatible();
|
|
122
|
+
selected.add(`index-${expected.name.replaceAll("_", "-").replace(/-+/gu, "-")}`);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (actual.table !== expected.table || actual.method !== "btree" || !actual.valid || !actual.ready || actual.unique !== (expected.unique ?? false) || actual.constraintOwned || actual.includes.length || !equal(actual.keys, expected.keys) || actual.options.length !== expected.keys.length || actual.options.some((option, index) => option !== (expected.descending?.includes(expected.keys[index]) ? 3 : 0)) || predicate(actual.predicate) !== predicate(expected.predicate ?? null))
|
|
126
|
+
return incompatible();
|
|
127
|
+
}
|
|
128
|
+
return selected.size ? { state: "compatible-change", stepIds: [...selected] } : { state: "ready" };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ../runtime/dist/workflow/schema-component.js
|
|
132
|
+
function workflowBaseline() {
|
|
133
|
+
const baseline = loadRuntimeFrameworkFoundationBootstrap("workflow");
|
|
134
|
+
if (!baseline || baseline.executionEligibility !== "startup-compatible")
|
|
135
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID");
|
|
136
|
+
return {
|
|
137
|
+
statements: baseline.sql.split("--> statement-breakpoint").map((statement) => statement.trim()).filter(Boolean)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function reviewedIndex(name, unique) {
|
|
141
|
+
const prefix = `CREATE ${unique ? "UNIQUE " : ""}INDEX "${name}" `;
|
|
142
|
+
const statement = workflowBaseline().statements.find((candidate) => candidate.trimStart().startsWith(prefix));
|
|
143
|
+
if (!statement)
|
|
144
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID");
|
|
145
|
+
return statement;
|
|
146
|
+
}
|
|
147
|
+
var objects = [];
|
|
148
|
+
var steps = [];
|
|
149
|
+
for (const table of workflowSchemaTables) {
|
|
150
|
+
const constraints = [
|
|
151
|
+
{
|
|
152
|
+
kind: "primary",
|
|
153
|
+
columns: table.primary,
|
|
154
|
+
creationIndexName: workflowCreatedRelationName(table.name, void 0, "pkey")
|
|
155
|
+
},
|
|
156
|
+
...table.unique.map((columns) => ({
|
|
157
|
+
kind: "unique",
|
|
158
|
+
columns,
|
|
159
|
+
creationIndexName: workflowCreatedRelationName(table.name, columns.join("_"), "key")
|
|
160
|
+
})),
|
|
161
|
+
...table.foreign.map(([column, target]) => ({
|
|
162
|
+
kind: "foreign",
|
|
163
|
+
columns: [column],
|
|
164
|
+
target: { schema: "public", table: target, columns: ["id"], deleteAction: "c" }
|
|
165
|
+
}))
|
|
166
|
+
];
|
|
167
|
+
const object = {
|
|
168
|
+
kind: "table",
|
|
169
|
+
schema: "public",
|
|
170
|
+
name: table.name,
|
|
171
|
+
columns: table.columns.map(([name, type, nullable, defaultValue]) => ({
|
|
172
|
+
name,
|
|
173
|
+
type,
|
|
174
|
+
nullable,
|
|
175
|
+
defaultValue
|
|
176
|
+
})),
|
|
177
|
+
constraints,
|
|
178
|
+
paths: ["maintenance"],
|
|
179
|
+
privileges: ["SELECT", "INSERT", "UPDATE", "DELETE"]
|
|
180
|
+
};
|
|
181
|
+
const ownedSequences = table.columns.flatMap(([column, _type, _nullable, value]) => value === "sequence" ? [
|
|
182
|
+
{
|
|
183
|
+
kind: "sequence",
|
|
184
|
+
schema: "public",
|
|
185
|
+
table: table.name,
|
|
186
|
+
column,
|
|
187
|
+
creationName: workflowCreatedRelationName(table.name, column, "seq"),
|
|
188
|
+
paths: ["maintenance"],
|
|
189
|
+
privileges: ["USAGE", "SELECT"]
|
|
190
|
+
}
|
|
191
|
+
] : []);
|
|
192
|
+
objects.push(object, ...ownedSequences);
|
|
193
|
+
const id = table.name.replaceAll("_", "-").replace(/^-+/u, "");
|
|
194
|
+
steps.push({
|
|
195
|
+
id: `access-${id}`,
|
|
196
|
+
statements: [],
|
|
197
|
+
affectedObjects: [object, ...ownedSequences],
|
|
198
|
+
grants: [object, ...ownedSequences].map((object2) => ({
|
|
199
|
+
object: object2,
|
|
200
|
+
paths: ["maintenance"],
|
|
201
|
+
privileges: "privileges" in object2 ? object2.privileges : []
|
|
202
|
+
}))
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
for (const index of workflowSchemaIndexes) {
|
|
206
|
+
const object = {
|
|
207
|
+
kind: "index",
|
|
208
|
+
schema: "public",
|
|
209
|
+
name: index.name,
|
|
210
|
+
table: index.table,
|
|
211
|
+
keys: index.keys,
|
|
212
|
+
descending: index.descending ?? [],
|
|
213
|
+
predicate: index.predicate ?? null
|
|
214
|
+
};
|
|
215
|
+
objects.push(object);
|
|
216
|
+
steps.push({
|
|
217
|
+
id: `index-${index.name.replaceAll("_", "-").replace(/-+/gu, "-")}`,
|
|
218
|
+
get statements() {
|
|
219
|
+
return [reviewedIndex(index.name, Boolean(index.unique))];
|
|
220
|
+
},
|
|
221
|
+
affectedObjects: [object],
|
|
222
|
+
grants: []
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
var foundationStep = {
|
|
226
|
+
id: "create-workflow-foundation",
|
|
227
|
+
get statements() {
|
|
228
|
+
return workflowBaseline().statements;
|
|
229
|
+
},
|
|
230
|
+
affectedObjects: objects,
|
|
231
|
+
grants: []
|
|
232
|
+
};
|
|
233
|
+
var runtimeWorkflowSchemaComponent = {
|
|
234
|
+
id: "workflow",
|
|
235
|
+
contractVersion: 2,
|
|
236
|
+
dependsOn: [],
|
|
237
|
+
objects: [...objects, ...workflowTerminalGuardSchema.objects],
|
|
238
|
+
steps: [foundationStep, ...steps, ...workflowTerminalGuardSchema.steps],
|
|
239
|
+
inspect(snapshot) {
|
|
240
|
+
const base = inspectWorkflowSchemaComponent(snapshot);
|
|
241
|
+
const terminal = workflowTerminalGuardSchema.inspect(snapshot);
|
|
242
|
+
if (base.state === "incompatible")
|
|
243
|
+
return base;
|
|
244
|
+
if (terminal.state === "incompatible")
|
|
245
|
+
return terminal;
|
|
246
|
+
const baseSteps = base.state === "compatible-change" ? base.stepIds : [];
|
|
247
|
+
const present = workflowSchemaTables.filter((table) => snapshot.relations.some((row) => row.schema === "public" && row.name === table.name)).length;
|
|
248
|
+
if (present !== 0 && present !== workflowSchemaTables.length || baseSteps.some((id) => id.startsWith("add-")))
|
|
249
|
+
return { state: "incompatible", reason: "shape-incompatible" };
|
|
250
|
+
const selected = present === 0 ? ["create-workflow-foundation", ...baseSteps.filter((id) => id.startsWith("access-"))] : baseSteps;
|
|
251
|
+
const stepIds = [...selected, ...terminal.state === "compatible-change" ? terminal.stepIds : []];
|
|
252
|
+
return stepIds.length ? { state: "compatible-change", stepIds } : { state: "ready" };
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
runtimeWorkflowSchemaComponent
|
|
258
|
+
};
|