gencow 0.1.299 → 0.2.1

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.
Files changed (151) hide show
  1. package/bin/gencow.mjs +0 -6
  2. package/core/package.json +1 -1
  3. package/docs/packaging.md +14 -4
  4. package/lib/cli-artifact-guard.mjs +53 -3
  5. package/lib/cli-dev-runtime.mjs +1 -0
  6. package/lib/cli-project-runtime.mjs +26 -14
  7. package/lib/codegen-command.mjs +16 -0
  8. package/lib/coding-guardrails.mjs +2 -0
  9. package/lib/dashboard-artifact.mjs +65 -0
  10. package/lib/dashboard-assets.mjs +20 -0
  11. package/lib/db-command.mjs +121 -80
  12. package/lib/db-migration-command-steps.mjs +19 -16
  13. package/lib/db-push-command.mjs +1 -1
  14. package/lib/deploy-codegen-preflight.mjs +1 -0
  15. package/lib/dev-cloud-command.mjs +1 -1
  16. package/lib/dev-local-command.mjs +19 -56
  17. package/lib/document-local-converter.mjs +11 -0
  18. package/lib/local-dashboard-plan.mjs +60 -0
  19. package/lib/local-database-commands.mjs +127 -0
  20. package/lib/local-development-migrations.mjs +157 -0
  21. package/lib/local-drizzle-database.config.mjs +10 -0
  22. package/lib/local-runtime-features.mjs +12 -0
  23. package/lib/rag-selection.mjs +7 -0
  24. package/lib/runtime-local-worker.mjs +116 -0
  25. package/lib/runtime-mode.mjs +3 -0
  26. package/lib/standalone-codegen-adapter.mjs +91 -0
  27. package/lib/ts-codegen-import-extension.mjs +228 -19
  28. package/package.json +15 -8
  29. package/runtime/config.mjs +218 -2
  30. package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
  31. package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
  32. package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
  33. package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
  34. package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
  35. package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
  36. package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
  37. package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
  38. package/runtime/engine/chunk-5575APCJ.mjs +215 -0
  39. package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
  40. package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
  41. package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
  42. package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
  43. package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
  44. package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
  45. package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
  46. package/runtime/engine/chunk-6W653LXI.mjs +13 -0
  47. package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
  48. package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
  49. package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
  50. package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
  51. package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
  52. package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
  53. package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
  54. package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
  55. package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
  56. package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
  57. package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
  58. package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
  59. package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
  60. package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
  61. package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
  62. package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
  63. package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
  64. package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
  65. package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
  66. package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
  67. package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
  68. package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
  69. package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
  70. package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
  71. package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
  72. package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
  73. package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
  74. package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
  75. package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
  76. package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
  77. package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
  78. package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
  79. package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
  80. package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
  81. package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
  82. package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
  83. package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
  84. package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
  85. package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
  86. package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
  87. package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
  88. package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
  89. package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
  90. package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
  91. package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
  92. package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
  93. package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
  94. package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
  95. package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
  96. package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
  97. package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
  98. package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
  99. package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
  100. package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
  101. package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
  102. package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
  103. package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
  104. package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
  105. package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
  106. package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
  107. package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
  108. package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
  109. package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
  110. package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
  111. package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
  112. package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
  113. package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
  114. package/runtime/engine/chunk-YRHM272W.mjs +528 -0
  115. package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
  116. package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
  117. package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
  118. package/runtime/engine/composition.mjs +325 -0
  119. package/runtime/engine/document-local.mjs +504 -0
  120. package/runtime/engine/graph.json +4134 -0
  121. package/runtime/engine/index.mjs +265 -0
  122. package/runtime/engine/local-postgres-support.mjs +69 -0
  123. package/runtime/engine/local.mjs +3275 -0
  124. package/runtime/engine/pglite-directory-lock.mjs +8 -0
  125. package/runtime/engine/rag.mjs +11 -0
  126. package/runtime/engine/search.mjs +18 -0
  127. package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
  128. package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
  129. package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
  130. package/runtime/framework-migrations/manifest.json +56 -0
  131. package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
  132. package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
  133. package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
  134. package/runtime/runtime-metadata.json +27 -0
  135. package/runtime/tooling.mjs +10399 -8951
  136. package/scripts/bundle-runtime-config.mjs +23 -0
  137. package/scripts/bundle-runtime.mjs +100 -0
  138. package/scripts/bundle-runtime.test.mjs +33 -0
  139. package/scripts/bundle-shared.mjs +3 -0
  140. package/scripts/copy-dashboard.mjs +16 -0
  141. package/scripts/pre-publish-check.mjs +23 -11
  142. package/templateFeature/ai/ai-facade.ts +38 -15
  143. package/templateFeature/ai/manifest.json +1 -0
  144. package/templateFeature/sso/sso-auth-callback.tsx +37 -5
  145. package/templateFeature/tools/manifest.json +5 -2
  146. package/templateFeature/tools/tools.ts +3 -3
  147. package/runtime/server.mjs +0 -14389
  148. package/scripts/bundle-server.mjs +0 -223
  149. package/server/config.js +0 -1
  150. package/server/index.js +0 -1
  151. package/server/package.json +0 -6
@@ -0,0 +1,428 @@
1
+ import {
2
+ snapshotSearchOptions
3
+ } from "./chunk-QL2TQX2N.mjs";
4
+ import {
5
+ RuntimeSearchError
6
+ } from "./chunk-LEW5ZMLR.mjs";
7
+ import {
8
+ RuntimeDiagnosticError,
9
+ runtimeDiagnostic
10
+ } from "./chunk-AEBW7XZJ.mjs";
11
+
12
+ // ../runtime/dist/adapters/database/borrowed-drizzle.js
13
+ var ownerProperties = /* @__PURE__ */ new Set([
14
+ "$client",
15
+ "client",
16
+ "session",
17
+ // Protected builder configuration can retain unwrapped union/CTE builders
18
+ // and their sessions. Actual methods use the original RLS-aware instance.
19
+ "config",
20
+ "close",
21
+ "end",
22
+ "dispose",
23
+ Symbol.asyncDispose,
24
+ Symbol.dispose
25
+ ]);
26
+ function isExecutionObject(value) {
27
+ if (!value || typeof value !== "object" || value instanceof Promise)
28
+ return false;
29
+ return "session" in value || "client" in value || ["select", "execute", "from", "prepare", "findMany", "findFirst"].some((key) => typeof Reflect.get(value, key) === "function");
30
+ }
31
+ function borrowRuntimeDrizzle(database, assertActive = () => {
32
+ }, withExecutionScope, transactionBoundary) {
33
+ const views = /* @__PURE__ */ new WeakMap();
34
+ const sources = /* @__PURE__ */ new WeakMap();
35
+ function result(value) {
36
+ return isExecutionObject(value) ? view(value) : value;
37
+ }
38
+ function metadata(source) {
39
+ return Object.freeze(Object.fromEntries(Reflect.ownKeys(source).filter((key) => !ownerProperties.has(key)).map((key) => [key, result(Reflect.get(source, key))])));
40
+ }
41
+ function view(source) {
42
+ const previous = views.get(source);
43
+ if (previous)
44
+ return previous;
45
+ const methods = /* @__PURE__ */ new Map();
46
+ const get = (key) => {
47
+ if (ownerProperties.has(key))
48
+ return void 0;
49
+ assertActive();
50
+ const value = Reflect.get(source, key, source);
51
+ if (key === "_" && value && typeof value === "object")
52
+ return metadata(value);
53
+ if (key === "query" && value && typeof value === "object")
54
+ return metadata(value);
55
+ if (typeof value !== "function")
56
+ return result(value);
57
+ if (key === "constructor")
58
+ return value;
59
+ let method = methods.get(key);
60
+ if (!method) {
61
+ method = (...args) => {
62
+ assertActive();
63
+ const forwarded = args.map((argument) => argument && typeof argument === "object" ? sources.get(argument) ?? argument : argument);
64
+ const callbackIndex = key === "transactionWithCharacteristics" ? 1 : 0;
65
+ if ((key === "transaction" || key === "transactionWithCharacteristics") && typeof forwarded[callbackIndex] === "function") {
66
+ const callback = forwarded[callbackIndex];
67
+ forwarded[callbackIndex] = (transaction) => {
68
+ const invokeCallback = () => callback(view(transaction));
69
+ return transactionBoundary ? transactionBoundary.withTransaction(transaction, invokeCallback) : invokeCallback();
70
+ };
71
+ }
72
+ const invoke = () => result(Reflect.apply(value, source, forwarded));
73
+ const isTransaction = key === "transaction" || key === "transactionWithCharacteristics";
74
+ const run = () => isTransaction && transactionBoundary ? transactionBoundary.run(invoke) : invoke();
75
+ return withExecutionScope ? withExecutionScope(assertActive, run) : run();
76
+ };
77
+ methods.set(key, method);
78
+ }
79
+ return method;
80
+ };
81
+ const borrowed = new Proxy({}, {
82
+ get: (_target, key) => get(key),
83
+ has: (_target, key) => !ownerProperties.has(key) && Reflect.has(source, key),
84
+ ownKeys: () => Reflect.ownKeys(source).filter((key) => !ownerProperties.has(key)),
85
+ getOwnPropertyDescriptor: (_target, key) => !ownerProperties.has(key) && Reflect.has(source, key) ? { value: get(key), enumerable: true, configurable: true, writable: false } : void 0,
86
+ getPrototypeOf: () => Reflect.getPrototypeOf(source),
87
+ set: () => false,
88
+ defineProperty: () => false,
89
+ deleteProperty: () => false,
90
+ preventExtensions: () => false
91
+ });
92
+ views.set(source, borrowed);
93
+ sources.set(borrowed, source);
94
+ return borrowed;
95
+ }
96
+ return view(database);
97
+ }
98
+
99
+ // ../runtime/dist/admin/data-catalog.js
100
+ import { sql } from "drizzle-orm";
101
+
102
+ // ../runtime/dist/admin/data-diagnostics.js
103
+ function administrationInputInvalid(dataImpact = "none") {
104
+ return new RuntimeDiagnosticError({
105
+ code: "RUNTIME_LOCAL_ADMIN_INPUT_INVALID",
106
+ stage: "request",
107
+ capability: "database",
108
+ servingStarted: "unchanged",
109
+ dataImpact,
110
+ retryable: false,
111
+ retryPrecondition: "Correct the selected table, row, page or input and inspect current data before a deliberate write.",
112
+ nextAction: "Refresh the current app's Data schema and inspect the selected row. Use valid bounded inputs; protected and unsupported targets cannot be administered through Data."
113
+ });
114
+ }
115
+ function administrationDatabaseFailure(error) {
116
+ if (runtimeDiagnostic(error))
117
+ return error;
118
+ let cause = error;
119
+ try {
120
+ for (let depth = 0; depth < 4 && cause && typeof cause === "object"; depth++) {
121
+ if ("code" in cause && typeof cause.code === "string" && ["22P02", "22003", "23502", "23503", "23505", "23514"].includes(cause.code))
122
+ return administrationInputInvalid("unknown");
123
+ cause = cause instanceof Error ? cause.cause : void 0;
124
+ }
125
+ } catch {
126
+ }
127
+ return new RuntimeDiagnosticError({
128
+ code: "RUNTIME_LOCAL_ADMIN_DATABASE_UNAVAILABLE",
129
+ stage: "request",
130
+ capability: "database",
131
+ servingStarted: "unchanged",
132
+ dataImpact: "unknown",
133
+ retryable: false,
134
+ retryPrecondition: "Restore the selected database's existing maintenance capability and schema readiness; inspect any prior effects before a deliberate write.",
135
+ nextAction: "Inspect the selected app's database configuration and current rows using the correlation ID. Preserve applied migrations and existing role policy; do not blindly retry writes."
136
+ });
137
+ }
138
+
139
+ // ../runtime/dist/admin/data-catalog.js
140
+ function relationIdentity(relation) {
141
+ return `${relation.schema}\0${relation.name}`;
142
+ }
143
+ function label(schema, name) {
144
+ if (schema === "public" && !name.includes("."))
145
+ return name;
146
+ if (!schema.includes(".") && !name.includes("."))
147
+ return `${schema}.${name}`;
148
+ return `"${schema.replaceAll('"', '""')}"."${name.replaceAll('"', '""')}"`;
149
+ }
150
+ function dataRows(value) {
151
+ const rows = Array.isArray(value) ? value : value && typeof value === "object" && "rows" in value ? value.rows : void 0;
152
+ if (!Array.isArray(rows) || rows.some((row) => !row || typeof row !== "object" || Array.isArray(row)))
153
+ throw administrationDatabaseFailure(void 0);
154
+ return rows;
155
+ }
156
+ function text(value) {
157
+ if (typeof value !== "string")
158
+ throw administrationDatabaseFailure(void 0);
159
+ return value;
160
+ }
161
+ async function loadDataCatalog(database, protectedRelations, includeProtected = false) {
162
+ let rows;
163
+ try {
164
+ rows = dataRows(await database.execute(sql`
165
+ select n.nspname as schema_name, c.relname as table_name, a.attname as column_name,
166
+ format_type(a.atttypid,a.atttypmod) as column_type, not a.attnotnull as nullable,
167
+ pg_get_expr(d.adbin,d.adrelid) as column_default,
168
+ a.attgenerated <> '' or a.attidentity='a' as generated,
169
+ a.atthasdef or a.attidentity<>'' as has_default,
170
+ exists(select 1 from pg_constraint p where p.conrelid=c.oid and p.contype='p' and a.attnum=any(p.conkey)) as primary_key,
171
+ rn.nspname as reference_schema, rc.relname as reference_table, ra.attname as reference_column
172
+ from pg_class c join pg_namespace n on n.oid=c.relnamespace
173
+ join pg_attribute a on a.attrelid=c.oid and a.attnum>0 and not a.attisdropped
174
+ left join pg_attrdef d on d.adrelid=c.oid and d.adnum=a.attnum
175
+ left join pg_constraint fk on fk.conrelid=c.oid and fk.contype='f'
176
+ and array_length(fk.conkey,1)=1 and fk.conkey[1]=a.attnum
177
+ and (select count(*) from pg_constraint alternatives
178
+ where alternatives.conrelid=c.oid and alternatives.contype='f'
179
+ and array_length(alternatives.conkey,1)=1 and alternatives.conkey[1]=a.attnum)=1
180
+ left join pg_class rc on rc.oid=fk.confrelid
181
+ left join pg_namespace rn on rn.oid=rc.relnamespace
182
+ left join pg_attribute ra on ra.attrelid=rc.oid and ra.attnum=fk.confkey[1]
183
+ where c.relkind in ('r','p') and not c.relispartition
184
+ and n.nspname !~ '^pg_' and n.nspname <> 'information_schema'
185
+ order by n.nspname,c.relname,a.attnum
186
+ limit 10001
187
+ `));
188
+ } catch (error) {
189
+ throw administrationDatabaseFailure(error);
190
+ }
191
+ if (rows.length > 1e4)
192
+ throw administrationInputInvalid();
193
+ const excluded = new Set(protectedRelations.map(relationIdentity));
194
+ const migrationTable = (schema, name) => schema === "drizzle" || ["__drizzle_migrations", "drizzle_migrations", "drizzle_migration"].includes(name);
195
+ const protectedTable = (schema, name) => excluded.has(relationIdentity({ schema, name })) || /^_(?:system|gencow)_/u.test(name);
196
+ const allowed = (schema, name) => !migrationTable(schema, name) && (includeProtected || !protectedTable(schema, name));
197
+ const visible = new Set(rows.filter((row) => allowed(text(row.schema_name), text(row.table_name))).map((row) => relationIdentity({ schema: text(row.schema_name), name: text(row.table_name) })));
198
+ const catalog = /* @__PURE__ */ new Map();
199
+ const columns = /* @__PURE__ */ new Map();
200
+ for (const row of rows) {
201
+ const schema = text(row.schema_name), name = text(row.table_name);
202
+ if (!allowed(schema, name))
203
+ continue;
204
+ const key = label(schema, name);
205
+ if (!columns.has(key)) {
206
+ columns.set(key, []);
207
+ catalog.set(key, {
208
+ schema,
209
+ name,
210
+ key,
211
+ readOnly: protectedTable(schema, name),
212
+ columns: columns.get(key)
213
+ });
214
+ }
215
+ const relation = catalog.get(key);
216
+ if (relation.schema !== schema || relation.name !== name)
217
+ throw administrationInputInvalid();
218
+ const reference = typeof row.reference_schema === "string" && typeof row.reference_table === "string" && visible.has(relationIdentity({ schema: row.reference_schema, name: row.reference_table })) ? { table: label(row.reference_schema, row.reference_table), column: text(row.reference_column) } : void 0;
219
+ columns.get(key).push(Object.freeze({
220
+ ...relation.readOnly ? { readOnly: true } : {},
221
+ column: text(row.column_name),
222
+ type: text(row.column_type),
223
+ nullable: row.nullable === true,
224
+ default: row.column_default === null ? null : text(row.column_default),
225
+ primaryKey: row.primary_key === true,
226
+ generated: row.generated === true,
227
+ hasDefault: row.has_default === true,
228
+ ...reference ? { references: Object.freeze(reference) } : {}
229
+ }));
230
+ }
231
+ for (const [key, relation] of catalog)
232
+ catalog.set(key, Object.freeze({ ...relation, columns: Object.freeze([...relation.columns]) }));
233
+ return catalog;
234
+ }
235
+ function selectDataRelation(catalog, target) {
236
+ const relation = catalog.get(target) ?? (target.startsWith("public.") ? catalog.get(target.slice(7)) : void 0);
237
+ if (!relation || target.startsWith("public.") && relation.schema !== "public")
238
+ throw administrationInputInvalid();
239
+ return relation;
240
+ }
241
+ function dataRelationSql(relation) {
242
+ return sql`${sql.identifier(relation.schema)}.${sql.identifier(relation.name)}`;
243
+ }
244
+ function publicDataCatalog(catalog) {
245
+ return Object.fromEntries([...catalog].map(([key, relation]) => [
246
+ key,
247
+ // Consumers need truthful insert/editability, especially identity columns
248
+ // whose SQL default is null. These booleans expose no internal authority.
249
+ relation.columns
250
+ ]));
251
+ }
252
+
253
+ // ../runtime/dist/adapters/search/postgres/input.js
254
+ var SEARCH_QUERY_MIN_CODEPOINTS = 2;
255
+ var SEARCH_QUERY_MAX_CODEPOINTS = 512;
256
+ function normalizeSearchQuery(query) {
257
+ return query.normalize("NFC").trim().replace(/\s+/g, " ");
258
+ }
259
+ function boundGeneratedSearchQuery(query, fallback) {
260
+ const normalized = normalizeSearchQuery(query);
261
+ const bounded = Array.from(normalized).slice(0, SEARCH_QUERY_MAX_CODEPOINTS).join("").trim();
262
+ const length = Array.from(bounded).length;
263
+ if (length >= SEARCH_QUERY_MIN_CODEPOINTS)
264
+ return bounded;
265
+ const safeFallback = normalizeSearchQuery(fallback);
266
+ const boundedFallback = Array.from(safeFallback).slice(0, SEARCH_QUERY_MAX_CODEPOINTS).join("").trim();
267
+ return Array.from(boundedFallback).length >= SEARCH_QUERY_MIN_CODEPOINTS ? boundedFallback : void 0;
268
+ }
269
+ function prepareSearchInput(owner, table, query, raw, mode) {
270
+ const fail = (code) => {
271
+ throw new RuntimeSearchError(code, owner.correlationId, owner.stage);
272
+ };
273
+ const safe = (name) => {
274
+ if (typeof name !== "string" || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name))
275
+ return fail("SEARCH_INVALID_IDENTIFIER");
276
+ return name;
277
+ };
278
+ const finite = (value, code, fallback) => {
279
+ if (value === void 0)
280
+ return fallback;
281
+ if (typeof value !== "number" || !Number.isFinite(value))
282
+ return fail(code);
283
+ return value;
284
+ };
285
+ const integer = (value, fallback, minimum, code) => {
286
+ if (value === void 0)
287
+ return fallback;
288
+ if (typeof value !== "number" || !Number.isInteger(value) || value < minimum)
289
+ return fail(code);
290
+ return value;
291
+ };
292
+ const positive = (value, code) => {
293
+ const result = finite(value, code, 1);
294
+ if (result <= 0)
295
+ return fail(code);
296
+ return result;
297
+ };
298
+ const captured = snapshotSearchOptions(raw, mode, owner);
299
+ const options = captured;
300
+ safe(table);
301
+ const scope = options.scope;
302
+ if (typeof scope.corpus !== "string" || !scope.corpus.trim())
303
+ fail("SEARCH_SCOPE_REQUIRED");
304
+ if (!["private", "shared", "public"].includes(scope.visibility))
305
+ fail("SEARCH_INVALID_SCOPE");
306
+ if (scope.ownerUserId !== void 0 && typeof scope.ownerUserId !== "string")
307
+ fail("SEARCH_INVALID_OPTIONS");
308
+ const id = owner.identity?.id;
309
+ if (scope.visibility === "private" && !id) {
310
+ throw new RuntimeSearchError("RUNTIME_AUTHENTICATION_REQUIRED", owner.correlationId, owner.stage);
311
+ }
312
+ const effectiveOwner = scope.ownerUserId ?? (scope.visibility === "private" ? id : void 0);
313
+ if (scope.visibility === "private" && effectiveOwner !== id)
314
+ fail("SEARCH_SCOPE_OWNER_MISMATCH");
315
+ const limit = Math.min(100, integer(options.limit, 20, 1, "SEARCH_INVALID_LIMIT"));
316
+ const offset = integer(options.offset, 0, 0, "SEARCH_INVALID_OFFSET");
317
+ if (offset > 1e4)
318
+ fail("SEARCH_OFFSET_TOO_LARGE");
319
+ let normalized = "", fields = [];
320
+ if (mode !== "vector") {
321
+ if (typeof query !== "string")
322
+ fail("SEARCH_INVALID_OPTIONS");
323
+ normalized = normalizeSearchQuery(query);
324
+ const length = Array.from(normalized).length;
325
+ if (!length)
326
+ fail("SEARCH_QUERY_REQUIRED");
327
+ if (length > SEARCH_QUERY_MAX_CODEPOINTS)
328
+ fail("SEARCH_QUERY_TOO_LONG");
329
+ if (length < SEARCH_QUERY_MIN_CODEPOINTS)
330
+ fail("SEARCH_QUERY_TOO_SHORT");
331
+ if (!options.fields.length)
332
+ fail("SEARCH_INVALID_OPTIONS");
333
+ fields = Object.freeze(options.fields.map(safe));
334
+ }
335
+ let vector, vectorLength = 0;
336
+ const vectorField = mode === "lexical" ? "embedding" : safe(options.vectorField ?? "embedding");
337
+ if (mode !== "lexical") {
338
+ if (!options.vector.length)
339
+ fail("SEARCH_VECTOR_REQUIRED");
340
+ if (options.vector.some((value) => typeof value !== "number" || !Number.isFinite(value)))
341
+ fail("SEARCH_INVALID_VECTOR");
342
+ vector = `[${options.vector.join(",")}]`;
343
+ vectorLength = options.vector.length;
344
+ }
345
+ const filters = [];
346
+ const scalar = (value) => {
347
+ if (typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))
348
+ return value;
349
+ return fail("SEARCH_INVALID_FILTER");
350
+ };
351
+ for (const [field, value] of Object.entries(options.filters?.eq ?? {}))
352
+ filters.push({ field: safe(field), operator: "eq", values: [scalar(value)] });
353
+ for (const [field, values] of Object.entries(options.filters?.in ?? {})) {
354
+ if (!values.length)
355
+ fail("SEARCH_INVALID_FILTER");
356
+ filters.push({ field: safe(field), operator: "in", values: Object.freeze(values.map(scalar)) });
357
+ }
358
+ for (const [field, range] of Object.entries(options.filters?.range ?? {})) {
359
+ safe(field);
360
+ for (const operator of ["gte", "lte"])
361
+ if (range[operator] !== void 0) {
362
+ const value = scalar(range[operator]);
363
+ if (typeof value === "boolean")
364
+ fail("SEARCH_INVALID_FILTER");
365
+ filters.push({ field, operator, values: [value] });
366
+ }
367
+ }
368
+ const tuning = options.tuning;
369
+ const pool = (value) => {
370
+ const result = integer(value, limit * 2, 1, "SEARCH_INVALID_CANDIDATE_LIMIT");
371
+ if (result > 500)
372
+ fail("SEARCH_CANDIDATE_LIMIT_TOO_LARGE");
373
+ return Math.max(limit, result);
374
+ };
375
+ if (mode === "hybrid" && (tuning?.fusion?.mode ?? "rrf") !== "rrf")
376
+ fail("SEARCH_INVALID_FUSION");
377
+ return Object.freeze({
378
+ table,
379
+ mode,
380
+ query: normalized,
381
+ fields,
382
+ limit,
383
+ offset,
384
+ scope: Object.freeze({ ...scope, corpus: scope.corpus.trim() }),
385
+ owner: effectiveOwner || null,
386
+ filters: Object.freeze(filters.map((item) => Object.freeze({ ...item, values: Object.freeze([...item.values]) }))),
387
+ vectorField,
388
+ vector,
389
+ vectorLength,
390
+ minScore: mode === "vector" ? finite(captured.tuning?.minScore, "SEARCH_INVALID_MIN_SCORE") : mode === "hybrid" ? finite(tuning?.minFusedScore, "SEARCH_INVALID_MIN_FUSED_SCORE") : void 0,
391
+ rrfK: mode === "hybrid" ? integer(tuning?.fusion?.rrfK, 60, 1, "SEARCH_INVALID_RRF_K") : 60,
392
+ keywordWeight: mode === "hybrid" ? positive(tuning?.fusion?.keywordWeight, "SEARCH_INVALID_FUSION_WEIGHT") : 1,
393
+ vectorWeight: mode === "hybrid" ? positive(tuning?.fusion?.vectorWeight, "SEARCH_INVALID_FUSION_WEIGHT") : 1,
394
+ keywordCandidates: mode === "hybrid" ? pool(tuning?.keywordCandidateLimit) : limit,
395
+ vectorCandidates: mode === "hybrid" ? pool(tuning?.vectorCandidateLimit) : limit
396
+ });
397
+ }
398
+
399
+ // ../runtime/dist/adapters/search/postgres/config.js
400
+ function captureSearchCapabilityConfig(value) {
401
+ let extensions = { vector: true, pgTrgm: true };
402
+ if (value)
403
+ try {
404
+ const parsed = JSON.parse(value);
405
+ extensions = { vector: parsed.extensions?.vector === true, pgTrgm: parsed.extensions?.pgTrgm === true };
406
+ } catch {
407
+ }
408
+ return Object.freeze({
409
+ lexicalStrategies: Object.freeze(["fts", "trigram"]),
410
+ hybridSearch: extensions.vector,
411
+ locale: "multilingual",
412
+ extensions: Object.freeze(extensions)
413
+ });
414
+ }
415
+
416
+ export {
417
+ administrationInputInvalid,
418
+ administrationDatabaseFailure,
419
+ dataRows,
420
+ loadDataCatalog,
421
+ selectDataRelation,
422
+ dataRelationSql,
423
+ publicDataCatalog,
424
+ borrowRuntimeDrizzle,
425
+ boundGeneratedSearchQuery,
426
+ prepareSearchInput,
427
+ captureSearchCapabilityConfig
428
+ };