gencow 0.1.298 → 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/index.js +261 -1447
- package/core/package.json +1 -1
- package/dashboard/assets/{index-BnBn8uo4.js → index-DYqUzCmS.js} +3 -3
- package/dashboard/assets/index-OH2xW1ZG.css +2 -0
- package/dashboard/index.html +2 -2
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-command-runner.d.mts +11 -0
- 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/component-readme.mjs +4 -4
- 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/deploy-cron-manifest-diagnostic.mjs +93 -0
- package/lib/deploy-failure-diagnostic.mjs +4 -43
- package/lib/deploy-route-target-rejection-diagnostic.mjs +43 -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/jobs-command.mjs +33 -1
- 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/readme-codegen.mjs +2 -2
- 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/dependency-lock.mjs +5 -1
- 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 +10549 -10543
- 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/ai/ai-embedding-result.ts +82 -0
- package/templateFeature/ai/ai-facade.ts +24 -7
- package/templateFeature/ai/ai-provider.ts +17 -1
- package/templateFeature/ai/ai.ts +1 -0
- package/templateFeature/ai/manifest.json +4 -3
- package/templateFeature/reranker/manifest.json +1 -1
- package/templateFeature/reranker/reranker.ts +4 -3
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +2 -1
- package/templateFeature/tools/tools.ts +3 -3
- package/dashboard/assets/index-C6-BpKKR.css +0 -2
- package/runtime/server.mjs +0 -14320
- 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,317 @@
|
|
|
1
|
+
import {
|
|
2
|
+
markRuntimeStartupStage,
|
|
3
|
+
observeRuntimeStartupStage,
|
|
4
|
+
recordRuntimeStartupStage
|
|
5
|
+
} from "./chunk-KVLTJFCH.mjs";
|
|
6
|
+
import {
|
|
7
|
+
runtimeDatabaseSetupError
|
|
8
|
+
} from "./chunk-SVJCOUI3.mjs";
|
|
9
|
+
|
|
10
|
+
// ../runtime/dist/adapters/database/schema-catalog.js
|
|
11
|
+
import { sql as sql3 } from "drizzle-orm";
|
|
12
|
+
|
|
13
|
+
// ../runtime/dist/adapters/database/schema-catalog-programs.js
|
|
14
|
+
import { sql as sql2 } from "drizzle-orm";
|
|
15
|
+
|
|
16
|
+
// ../runtime/dist/adapters/database/schema-catalog-shape.js
|
|
17
|
+
import { sql } from "drizzle-orm";
|
|
18
|
+
function schemaCatalogRows(result) {
|
|
19
|
+
const rows = Array.isArray(result) ? result : result && typeof result === "object" && "rows" in result && Array.isArray(result.rows) ? result.rows : void 0;
|
|
20
|
+
if (!rows)
|
|
21
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_FAILED");
|
|
22
|
+
return rows.map((row) => {
|
|
23
|
+
if (!row || typeof row !== "object")
|
|
24
|
+
return row;
|
|
25
|
+
const normalized = {};
|
|
26
|
+
for (const [key, value] of Object.entries(row)) {
|
|
27
|
+
normalized[key] = ArrayBuffer.isView(value) ? value instanceof DataView ? Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) : Array.from(value) : value;
|
|
28
|
+
}
|
|
29
|
+
return normalized;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function match(schema, name, identities) {
|
|
33
|
+
return identities.length ? sql`(${sql.join(identities.map((identity) => sql`(${schema}=${identity.schema} AND ${name}=${identity.name})`), sql` OR `)})` : sql`false`;
|
|
34
|
+
}
|
|
35
|
+
function copyIndexOptions(value) {
|
|
36
|
+
const options = Array.isArray(value) ? Array.from(value) : value instanceof Int32Array ? Array.from(value) : void 0;
|
|
37
|
+
if (!options || options.some((option) => typeof option !== "number" || !Number.isSafeInteger(option) || option < 0))
|
|
38
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_FAILED");
|
|
39
|
+
return options;
|
|
40
|
+
}
|
|
41
|
+
async function readSchemaCatalogShape(database, plan) {
|
|
42
|
+
const tables = plan.objects.flatMap((object) => object.kind === "table" ? [{ schema: object.schema, name: object.name }] : "table" in object ? [{ schema: object.schema, name: object.table }] : []);
|
|
43
|
+
const relations = plan.objects.flatMap((object) => "name" in object && object.name && !["constraint", "function", "trigger"].includes(object.kind) ? [{ schema: object.schema, name: object.name }] : []);
|
|
44
|
+
for (const object of plan.objects) {
|
|
45
|
+
if (object.kind === "sequence" && object.creationName)
|
|
46
|
+
relations.push({ schema: object.schema, name: object.creationName });
|
|
47
|
+
if (object.kind === "table") {
|
|
48
|
+
for (const constraint of object.constraints)
|
|
49
|
+
if (constraint.creationIndexName)
|
|
50
|
+
relations.push({ schema: object.schema, name: constraint.creationIndexName });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const indices = plan.objects.flatMap((object) => object.kind === "index" ? [{ schema: object.schema, name: object.name }] : []);
|
|
54
|
+
const selectedTables = match(sql`namespace.nspname`, sql`relation.relname`, tables);
|
|
55
|
+
const read = async (query) => schemaCatalogRows(await database.execute(query));
|
|
56
|
+
const relationRows = await observeRuntimeStartupStage("databaseCatalogRelations", () => read(sql`
|
|
57
|
+
SELECT namespace.nspname AS schema, relation.relname AS name, relation.relkind AS kind,
|
|
58
|
+
relation.relrowsecurity AS "rowSecurity",relation.relforcerowsecurity AS "forceRowSecurity"
|
|
59
|
+
FROM pg_catalog.pg_class relation JOIN pg_catalog.pg_namespace namespace ON namespace.oid=relation.relnamespace
|
|
60
|
+
WHERE ${match(sql`namespace.nspname`, sql`relation.relname`, [...relations, ...tables])}
|
|
61
|
+
`));
|
|
62
|
+
const columns = await observeRuntimeStartupStage("databaseCatalogColumns", () => read(sql`
|
|
63
|
+
SELECT namespace.nspname AS schema, relation.relname AS table, attribute.attname AS name,
|
|
64
|
+
type.typname AS type, NOT attribute.attnotnull AS nullable,
|
|
65
|
+
pg_catalog.pg_get_expr(defaults.adbin,defaults.adrelid) AS "defaultValue",
|
|
66
|
+
type_namespace.nspname AS "typeSchema", attribute.atttypmod AS "typeModifier",
|
|
67
|
+
pg_catalog.format_type(attribute.atttypid,attribute.atttypmod) AS "formattedType",
|
|
68
|
+
attribute.attidentity AS identity, attribute.attgenerated AS generated
|
|
69
|
+
FROM pg_catalog.pg_class relation JOIN pg_catalog.pg_namespace namespace ON namespace.oid=relation.relnamespace
|
|
70
|
+
JOIN pg_catalog.pg_attribute attribute ON attribute.attrelid=relation.oid AND attribute.attnum>0 AND NOT attribute.attisdropped
|
|
71
|
+
JOIN pg_catalog.pg_type type ON type.oid=attribute.atttypid
|
|
72
|
+
JOIN pg_catalog.pg_namespace type_namespace ON type_namespace.oid=type.typnamespace
|
|
73
|
+
LEFT JOIN pg_catalog.pg_attrdef defaults ON defaults.adrelid=relation.oid AND defaults.adnum=attribute.attnum
|
|
74
|
+
WHERE ${selectedTables}
|
|
75
|
+
`));
|
|
76
|
+
const constraints = await observeRuntimeStartupStage("databaseCatalogConstraints", () => read(sql`
|
|
77
|
+
SELECT namespace.nspname AS schema, relation.relname AS table, constraint_row.conname AS name,
|
|
78
|
+
CASE constraint_row.contype WHEN 'p' THEN 'primary' WHEN 'u' THEN 'unique' WHEN 'f' THEN 'foreign'
|
|
79
|
+
WHEN 'c' THEN 'check' WHEN 'x' THEN 'exclusion' WHEN 't' THEN 'trigger' END AS kind,
|
|
80
|
+
ARRAY(SELECT attribute.attname::text FROM pg_catalog.unnest(constraint_row.conkey) WITH ORDINALITY key(number,position)
|
|
81
|
+
JOIN pg_catalog.pg_attribute attribute ON attribute.attrelid=relation.oid AND attribute.attnum=key.number ORDER BY key.position) AS columns,
|
|
82
|
+
target_namespace.nspname AS "targetSchema", target.relname AS "targetTable",
|
|
83
|
+
ARRAY(SELECT attribute.attname::text FROM pg_catalog.unnest(constraint_row.confkey) WITH ORDINALITY key(number,position)
|
|
84
|
+
JOIN pg_catalog.pg_attribute attribute ON attribute.attrelid=target.oid AND attribute.attnum=key.number ORDER BY key.position) AS "targetColumns",
|
|
85
|
+
constraint_row.confdeltype AS "deleteAction", constraint_row.confupdtype AS "updateAction",
|
|
86
|
+
constraint_row.condeferrable AS deferrable,
|
|
87
|
+
constraint_row.convalidated AS validated, pg_catalog.pg_get_expr(constraint_row.conbin,constraint_row.conrelid) AS expression,
|
|
88
|
+
coalesce(index_row.indnullsnotdistinct,false) AS "nullsNotDistinct"
|
|
89
|
+
FROM pg_catalog.pg_constraint constraint_row JOIN pg_catalog.pg_class relation ON relation.oid=constraint_row.conrelid
|
|
90
|
+
JOIN pg_catalog.pg_namespace namespace ON namespace.oid=relation.relnamespace
|
|
91
|
+
LEFT JOIN pg_catalog.pg_class target ON target.oid=constraint_row.confrelid
|
|
92
|
+
LEFT JOIN pg_catalog.pg_namespace target_namespace ON target_namespace.oid=target.relnamespace
|
|
93
|
+
LEFT JOIN pg_catalog.pg_index index_row ON index_row.indexrelid=constraint_row.conindid
|
|
94
|
+
WHERE ${selectedTables}
|
|
95
|
+
-- PostgreSQL 18 also represents column NOT NULL in pg_constraint.
|
|
96
|
+
-- Nullability is already checked via pg_attribute above: omit only a
|
|
97
|
+
-- validated, single-column entry that agrees with that catalog fact.
|
|
98
|
+
-- Unknown or malformed constraint kinds must remain visible and fail closed.
|
|
99
|
+
AND (constraint_row.contype = 'n' AND constraint_row.convalidated
|
|
100
|
+
AND pg_catalog.cardinality(constraint_row.conkey) = 1
|
|
101
|
+
AND EXISTS (SELECT 1 FROM pg_catalog.pg_attribute not_null_column
|
|
102
|
+
WHERE not_null_column.attrelid = relation.oid
|
|
103
|
+
AND not_null_column.attnum = constraint_row.conkey[1]
|
|
104
|
+
AND not_null_column.attnotnull AND NOT not_null_column.attisdropped)) IS NOT TRUE
|
|
105
|
+
`));
|
|
106
|
+
const indexes = await observeRuntimeStartupStage("databaseCatalogIndexes", () => read(sql`
|
|
107
|
+
SELECT namespace.nspname AS schema, index_relation.relname AS name, table_relation.relname AS table,
|
|
108
|
+
method.amname AS method, index_row.indisvalid AS valid, index_row.indisready AS ready,
|
|
109
|
+
index_row.indisunique AS unique, pg_catalog.pg_get_expr(index_row.indpred,index_row.indrelid,true) AS predicate,
|
|
110
|
+
EXISTS (SELECT 1 FROM pg_catalog.pg_constraint constraint_row WHERE constraint_row.conindid=index_relation.oid) AS "constraintOwned",
|
|
111
|
+
ARRAY(SELECT coalesce(attribute.attname::text,pg_catalog.pg_get_indexdef(index_row.indexrelid,key.position,true))
|
|
112
|
+
FROM pg_catalog.generate_series(1,index_row.indnkeyatts) key(position)
|
|
113
|
+
LEFT JOIN pg_catalog.pg_attribute attribute ON attribute.attrelid=table_relation.oid AND attribute.attnum=index_row.indkey[key.position-1]
|
|
114
|
+
ORDER BY key.position) AS keys,
|
|
115
|
+
ARRAY(SELECT index_row.indoption[key.position-1]::int FROM pg_catalog.generate_series(1,index_row.indnkeyatts) key(position) ORDER BY key.position) AS options,
|
|
116
|
+
ARRAY(SELECT jsonb_build_object('schema',operator_namespace.nspname,'name',operator_class.opcname,'isDefault',operator_class.opcdefault)
|
|
117
|
+
FROM pg_catalog.generate_series(1,index_row.indnkeyatts) key(position)
|
|
118
|
+
JOIN pg_catalog.pg_opclass operator_class ON operator_class.oid=index_row.indclass[key.position-1]
|
|
119
|
+
JOIN pg_catalog.pg_namespace operator_namespace ON operator_namespace.oid=operator_class.opcnamespace
|
|
120
|
+
ORDER BY key.position) AS "operatorClasses",
|
|
121
|
+
ARRAY(SELECT attribute.attname::text FROM pg_catalog.generate_series(index_row.indnkeyatts+1,index_row.indnatts) key(position)
|
|
122
|
+
JOIN pg_catalog.pg_attribute attribute ON attribute.attrelid=table_relation.oid AND attribute.attnum=index_row.indkey[key.position-1] ORDER BY key.position) AS includes
|
|
123
|
+
FROM pg_catalog.pg_class index_relation JOIN pg_catalog.pg_namespace namespace ON namespace.oid=index_relation.relnamespace
|
|
124
|
+
JOIN pg_catalog.pg_index index_row ON index_row.indexrelid=index_relation.oid
|
|
125
|
+
JOIN pg_catalog.pg_class table_relation ON table_relation.oid=index_row.indrelid
|
|
126
|
+
JOIN pg_catalog.pg_am method ON method.oid=index_relation.relam
|
|
127
|
+
WHERE ${match(sql`namespace.nspname`, sql`index_relation.relname`, indices)}
|
|
128
|
+
OR ${match(sql`namespace.nspname`, sql`table_relation.relname`, tables)}
|
|
129
|
+
`));
|
|
130
|
+
const sequences = await observeRuntimeStartupStage("databaseCatalogSequences", () => read(sql`
|
|
131
|
+
SELECT sequence_namespace.nspname AS schema, sequence_relation.relname AS name,
|
|
132
|
+
relation.relname AS table, attribute.attname AS column,
|
|
133
|
+
EXISTS (SELECT 1 FROM pg_catalog.pg_depend dependency JOIN pg_catalog.pg_attrdef defaults ON defaults.oid=dependency.objid
|
|
134
|
+
WHERE dependency.classid='pg_catalog.pg_attrdef'::regclass AND dependency.refclassid='pg_catalog.pg_class'::regclass
|
|
135
|
+
AND dependency.refobjid=sequence_relation.oid AND defaults.adrelid=relation.oid
|
|
136
|
+
AND defaults.adnum=attribute.attnum) AS "defaultLinked"
|
|
137
|
+
FROM pg_catalog.pg_class sequence_relation JOIN pg_catalog.pg_namespace sequence_namespace ON sequence_namespace.oid=sequence_relation.relnamespace
|
|
138
|
+
JOIN pg_catalog.pg_depend ownership ON ownership.classid='pg_catalog.pg_class'::regclass AND ownership.objid=sequence_relation.oid
|
|
139
|
+
AND ownership.refclassid='pg_catalog.pg_class'::regclass AND ownership.deptype IN ('a','i')
|
|
140
|
+
JOIN pg_catalog.pg_class relation ON relation.oid=ownership.refobjid
|
|
141
|
+
JOIN pg_catalog.pg_namespace namespace ON namespace.oid=relation.relnamespace
|
|
142
|
+
JOIN pg_catalog.pg_attribute attribute ON attribute.attrelid=relation.oid AND attribute.attnum=ownership.refobjsubid
|
|
143
|
+
WHERE sequence_relation.relkind='S' AND ${selectedTables}
|
|
144
|
+
`));
|
|
145
|
+
const relationBehavior = await observeRuntimeStartupStage("databaseCatalogRelationBehavior", () => read(sql`
|
|
146
|
+
SELECT namespace.nspname AS schema, relation.relname AS name,
|
|
147
|
+
EXISTS (SELECT 1 FROM pg_catalog.pg_inherits inheritance
|
|
148
|
+
WHERE inheritance.inhrelid=relation.oid OR inheritance.inhparent=relation.oid) AS inherited,
|
|
149
|
+
ARRAY(SELECT rule.rulename::text FROM pg_catalog.pg_rewrite rule
|
|
150
|
+
WHERE rule.ev_class=relation.oid AND rule.rulename <> '_RETURN' ORDER BY rule.rulename) AS rules,
|
|
151
|
+
ARRAY(SELECT policy.polname::text FROM pg_catalog.pg_policy policy
|
|
152
|
+
WHERE policy.polrelid=relation.oid ORDER BY policy.polname) AS policies,
|
|
153
|
+
ARRAY(SELECT trigger.tgname::text FROM pg_catalog.pg_trigger trigger
|
|
154
|
+
WHERE trigger.tgrelid=relation.oid AND NOT trigger.tgisinternal ORDER BY trigger.tgname) AS "nonInternalTriggers"
|
|
155
|
+
FROM pg_catalog.pg_class relation JOIN pg_catalog.pg_namespace namespace ON namespace.oid=relation.relnamespace
|
|
156
|
+
WHERE ${selectedTables}
|
|
157
|
+
`));
|
|
158
|
+
const extensions = await observeRuntimeStartupStage("databaseCatalogExtensions", () => read(sql`
|
|
159
|
+
SELECT extension.extname AS name, namespace.nspname AS schema
|
|
160
|
+
FROM pg_catalog.pg_extension extension
|
|
161
|
+
JOIN pg_catalog.pg_namespace namespace ON namespace.oid=extension.extnamespace
|
|
162
|
+
WHERE extension.extname IN ('vector','pg_trgm')
|
|
163
|
+
`));
|
|
164
|
+
return {
|
|
165
|
+
relations: relationRows,
|
|
166
|
+
columns,
|
|
167
|
+
sequences,
|
|
168
|
+
constraints: constraints.map(({ targetSchema, targetTable, targetColumns, deleteAction, updateAction, ...constraint }) => ({
|
|
169
|
+
...constraint,
|
|
170
|
+
...constraint.kind === "foreign" && targetSchema && targetTable ? {
|
|
171
|
+
target: {
|
|
172
|
+
schema: targetSchema,
|
|
173
|
+
table: targetTable,
|
|
174
|
+
columns: targetColumns,
|
|
175
|
+
deleteAction,
|
|
176
|
+
updateAction
|
|
177
|
+
}
|
|
178
|
+
} : {}
|
|
179
|
+
})),
|
|
180
|
+
indexes: indexes.map((index) => {
|
|
181
|
+
const options = copyIndexOptions(index.options);
|
|
182
|
+
if (options.length !== index.keys.length)
|
|
183
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_FAILED");
|
|
184
|
+
return {
|
|
185
|
+
...index,
|
|
186
|
+
options,
|
|
187
|
+
descending: index.keys.filter((_key, position) => (options[position] & 1) !== 0)
|
|
188
|
+
};
|
|
189
|
+
}),
|
|
190
|
+
relationBehavior,
|
|
191
|
+
extensions
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ../runtime/dist/adapters/database/schema-catalog-programs.js
|
|
196
|
+
async function readSchemaCatalogPrograms(database, plan) {
|
|
197
|
+
const routines = [];
|
|
198
|
+
const triggers = [];
|
|
199
|
+
const functions = plan.objects.filter((object) => object.kind === "function");
|
|
200
|
+
if (functions.length) {
|
|
201
|
+
const selected = sql2.join(functions.map((object) => sql2`(namespace.nspname=${object.schema} AND routine.proname=${object.name})`), sql2` OR `);
|
|
202
|
+
routines.push(...schemaCatalogRows(await database.execute(sql2`
|
|
203
|
+
SELECT namespace.nspname AS schema,routine.proname AS name,routine.prosrc AS body,
|
|
204
|
+
language.lanname AS language,return_type.typname AS "returnType",routine.prosecdef AS "securityDefiner",
|
|
205
|
+
coalesce(routine.proconfig,ARRAY[]::text[]) AS configuration,routine.pronargs::int AS "argumentCount",
|
|
206
|
+
routine.provolatile::text AS volatility,
|
|
207
|
+
routine.prokind::text AS kind FROM pg_catalog.pg_proc routine
|
|
208
|
+
JOIN pg_catalog.pg_namespace namespace ON namespace.oid=routine.pronamespace
|
|
209
|
+
JOIN pg_catalog.pg_language language ON language.oid=routine.prolang
|
|
210
|
+
JOIN pg_catalog.pg_type return_type ON return_type.oid=routine.prorettype WHERE ${selected}
|
|
211
|
+
`)));
|
|
212
|
+
}
|
|
213
|
+
const declarations = plan.objects.filter((object) => object.kind === "trigger");
|
|
214
|
+
if (declarations.length) {
|
|
215
|
+
const selected = sql2.join(declarations.map((object) => sql2`(namespace.nspname=${object.schema} AND relation.relname=${object.table})`), sql2` OR `);
|
|
216
|
+
triggers.push(...schemaCatalogRows(await database.execute(sql2`
|
|
217
|
+
SELECT namespace.nspname AS schema,relation.relname AS table,trigger.tgname AS name,
|
|
218
|
+
function_namespace.nspname AS "functionSchema",routine.proname AS "functionName",
|
|
219
|
+
trigger.tgtype::int AS type,trigger.tgdeferrable AS deferrable,
|
|
220
|
+
trigger.tginitdeferred AS "initiallyDeferred",trigger.tgenabled::text AS enabled,
|
|
221
|
+
trigger.tgnargs::int AS "argumentCount",pg_catalog.pg_get_expr(trigger.tgqual,trigger.tgrelid) AS predicate,
|
|
222
|
+
trigger.tgisinternal AS internal FROM pg_catalog.pg_trigger trigger
|
|
223
|
+
JOIN pg_catalog.pg_class relation ON relation.oid=trigger.tgrelid
|
|
224
|
+
JOIN pg_catalog.pg_namespace namespace ON namespace.oid=relation.relnamespace
|
|
225
|
+
JOIN pg_catalog.pg_proc routine ON routine.oid=trigger.tgfoid
|
|
226
|
+
JOIN pg_catalog.pg_namespace function_namespace ON function_namespace.oid=routine.pronamespace WHERE ${selected}
|
|
227
|
+
`)));
|
|
228
|
+
}
|
|
229
|
+
return { routines, triggers };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// ../runtime/dist/adapters/database/schema-catalog.js
|
|
233
|
+
async function readRuntimeDatabaseSchemaCatalog(database, plan, roles) {
|
|
234
|
+
if (plan.objects.length === 0)
|
|
235
|
+
return { relations: [], columns: [], constraints: [], indexes: [], sequences: [], access: [] };
|
|
236
|
+
const shapeStarted = markRuntimeStartupStage("databaseCatalogShape");
|
|
237
|
+
let shape;
|
|
238
|
+
try {
|
|
239
|
+
shape = await readSchemaCatalogShape(database, plan);
|
|
240
|
+
} finally {
|
|
241
|
+
recordRuntimeStartupStage("databaseCatalogShape", shapeStarted);
|
|
242
|
+
}
|
|
243
|
+
const access = [];
|
|
244
|
+
const accessStarted = markRuntimeStartupStage("databaseCatalogAccess");
|
|
245
|
+
try {
|
|
246
|
+
for (const path of ["application", "maintenance"]) {
|
|
247
|
+
const schemas = /* @__PURE__ */ new Set();
|
|
248
|
+
const requests = [];
|
|
249
|
+
for (const object of plan.objects) {
|
|
250
|
+
if (!("paths" in object) || !object.paths.includes(path))
|
|
251
|
+
continue;
|
|
252
|
+
schemas.add(object.schema);
|
|
253
|
+
const names = object.kind === "table" ? [object.name] : shape.sequences.filter((sequence) => sequence.schema === object.schema && sequence.table === object.table && sequence.column === object.column && sequence.defaultLinked && (object.name === void 0 || sequence.name === object.name)).map((sequence) => sequence.name);
|
|
254
|
+
for (const name of names) {
|
|
255
|
+
const accessIndex = access.length;
|
|
256
|
+
access.push({ path, schema: object.schema, name, kind: object.kind, privileges: [] });
|
|
257
|
+
for (const privilege of object.privileges)
|
|
258
|
+
requests.push({ accessIndex, schema: object.schema, name, kind: object.kind, privilege });
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
for (let start = 0; start < requests.length; start += 1e3) {
|
|
262
|
+
const batch = requests.slice(start, start + 1e3);
|
|
263
|
+
const requested = sql3.join(batch.map((request, offset) => sql3`(
|
|
264
|
+
${start + offset}::integer,${request.schema}::text,${request.name}::text,
|
|
265
|
+
${request.kind}::text,${request.privilege}::text
|
|
266
|
+
)`), sql3`, `);
|
|
267
|
+
const rows = schemaCatalogRows(await database.execute(sql3`
|
|
268
|
+
SELECT requested.ordinal AS ordinal,
|
|
269
|
+
CASE
|
|
270
|
+
WHEN requested.kind='sequence' AND relation.relkind='S'
|
|
271
|
+
THEN pg_catalog.has_sequence_privilege(${roles[path]},relation.oid,requested.privilege)
|
|
272
|
+
WHEN requested.kind='table' AND relation.relkind IN ('r','p')
|
|
273
|
+
THEN pg_catalog.has_table_privilege(${roles[path]},relation.oid,requested.privilege)
|
|
274
|
+
ELSE false
|
|
275
|
+
END AS allowed
|
|
276
|
+
FROM (VALUES ${requested}) AS requested(ordinal,schema_name,relation_name,kind,privilege)
|
|
277
|
+
LEFT JOIN pg_catalog.pg_namespace namespace ON namespace.nspname=requested.schema_name
|
|
278
|
+
LEFT JOIN pg_catalog.pg_class relation ON relation.relnamespace=namespace.oid
|
|
279
|
+
AND relation.relname=requested.relation_name
|
|
280
|
+
ORDER BY requested.ordinal
|
|
281
|
+
`));
|
|
282
|
+
for (const row of rows) {
|
|
283
|
+
const request = requests[row.ordinal];
|
|
284
|
+
if (!request || row.allowed !== true)
|
|
285
|
+
continue;
|
|
286
|
+
const entry = access[request.accessIndex];
|
|
287
|
+
access[request.accessIndex] = { ...entry, privileges: [...entry.privileges, request.privilege] };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
for (const schema of schemas) {
|
|
291
|
+
const [row] = schemaCatalogRows(await database.execute(sql3`SELECT pg_catalog.has_schema_privilege(${roles[path]},namespace.oid,'USAGE') AS allowed FROM pg_catalog.pg_namespace namespace WHERE namespace.nspname=${schema}`));
|
|
292
|
+
access.push({
|
|
293
|
+
path,
|
|
294
|
+
schema,
|
|
295
|
+
name: schema,
|
|
296
|
+
kind: "schema",
|
|
297
|
+
privileges: row?.allowed === true ? ["USAGE"] : []
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
} finally {
|
|
302
|
+
recordRuntimeStartupStage("databaseCatalogAccess", accessStarted);
|
|
303
|
+
}
|
|
304
|
+
const programsStarted = markRuntimeStartupStage("databaseCatalogPrograms");
|
|
305
|
+
let programs;
|
|
306
|
+
try {
|
|
307
|
+
programs = await readSchemaCatalogPrograms(database, plan);
|
|
308
|
+
} finally {
|
|
309
|
+
recordRuntimeStartupStage("databaseCatalogPrograms", programsStarted);
|
|
310
|
+
}
|
|
311
|
+
return { ...shape, access, ...programs };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export {
|
|
315
|
+
schemaCatalogRows,
|
|
316
|
+
readRuntimeDatabaseSchemaCatalog
|
|
317
|
+
};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLocalSchedulerResource,
|
|
3
|
+
snapshotLocalSchedulerPolicy
|
|
4
|
+
} from "./chunk-2SR2M7SR.mjs";
|
|
5
|
+
import {
|
|
6
|
+
schedulerIdentifier,
|
|
7
|
+
schedulerInstant,
|
|
8
|
+
schedulerOptionsSnapshot,
|
|
9
|
+
snapshotSchedulerAdmissionArgs,
|
|
10
|
+
snapshotSchedulerArgs
|
|
11
|
+
} from "./chunk-WDTKPPMU.mjs";
|
|
12
|
+
import {
|
|
13
|
+
schedulerFailure
|
|
14
|
+
} from "./chunk-NAG2OXS5.mjs";
|
|
15
|
+
import "./chunk-IFMOTJNU.mjs";
|
|
16
|
+
import {
|
|
17
|
+
RuntimeDiagnosticError,
|
|
18
|
+
issuedRuntimeDiagnostic
|
|
19
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
20
|
+
|
|
21
|
+
// ../runtime/dist/scheduler/local-effects.js
|
|
22
|
+
import { randomUUID } from "node:crypto";
|
|
23
|
+
function createLocalSchedulerEffects(input) {
|
|
24
|
+
const { delivery, catalog, signal, correlationId, parentDeliveryId, logger } = input;
|
|
25
|
+
const origin = Object.freeze({
|
|
26
|
+
appId: input.binding.appId,
|
|
27
|
+
generationId: input.binding.generationId,
|
|
28
|
+
deploymentId: input.binding.generationId,
|
|
29
|
+
artifactId: input.binding.generationId
|
|
30
|
+
});
|
|
31
|
+
const now = input.now ?? Date.now;
|
|
32
|
+
const operationIds = [];
|
|
33
|
+
let sealed = false;
|
|
34
|
+
let settlement;
|
|
35
|
+
function alive() {
|
|
36
|
+
if (signal.aborted)
|
|
37
|
+
throw schedulerFailure("RUNTIME_GENERATION_CLOSING", "Use an active handler in a ready local generation; an ended scope cannot admit new work.", "request", correlationId);
|
|
38
|
+
if (sealed)
|
|
39
|
+
throw new RuntimeDiagnosticError({
|
|
40
|
+
code: "RUNTIME_REQUEST_EFFECTS_SEALED",
|
|
41
|
+
stage: "request",
|
|
42
|
+
capability: "scheduler",
|
|
43
|
+
servingStarted: "unchanged",
|
|
44
|
+
dataImpact: "unknown",
|
|
45
|
+
retryable: false,
|
|
46
|
+
retryPrecondition: "Admit scheduler work before returning the route response; inspect earlier accepted operations before any deliberate retry.",
|
|
47
|
+
nextAction: "Move scheduler admissions into the request handler before returning a streaming response; do not retry merely because the stream ended.",
|
|
48
|
+
correlationId
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function slot() {
|
|
52
|
+
alive();
|
|
53
|
+
if (operationIds.length >= 64)
|
|
54
|
+
throw schedulerFailure("RUNTIME_SCHEDULER_CAPACITY_EXCEEDED", "Use at most 64 scheduler operations in one handler; inspect accepted operations before deliberate new work.", "request", correlationId);
|
|
55
|
+
}
|
|
56
|
+
function schedule(runAtMs, action, args, options) {
|
|
57
|
+
slot();
|
|
58
|
+
const captured = schedulerOptionsSnapshot(options);
|
|
59
|
+
const target = catalog.resolveLocal(action);
|
|
60
|
+
const onErrorTarget = captured.onError === void 0 ? void 0 : catalog.resolveLocal(captured.onError);
|
|
61
|
+
const snapshot = snapshotSchedulerAdmissionArgs(args, delivery.policy?.maxArgsBytes, onErrorTarget === void 0 ? void 0 : target.name, correlationId);
|
|
62
|
+
const logicalJobId = captured.id ?? randomUUID();
|
|
63
|
+
const operationId = randomUUID();
|
|
64
|
+
const receipt = delivery.reserve(Object.freeze({
|
|
65
|
+
operationId,
|
|
66
|
+
logicalJobId,
|
|
67
|
+
origin,
|
|
68
|
+
target,
|
|
69
|
+
...snapshot,
|
|
70
|
+
runAtMs,
|
|
71
|
+
correlationId,
|
|
72
|
+
...onErrorTarget ? { onErrorTarget } : {},
|
|
73
|
+
...captured.dedupeKey === void 0 ? {} : { dedupeKey: captured.dedupeKey },
|
|
74
|
+
...parentDeliveryId ? { parentDeliveryId } : {},
|
|
75
|
+
...delivery.revisionFor(logicalJobId) === void 0 ? {} : { expectedRevision: delivery.revisionFor(logicalJobId) }
|
|
76
|
+
}));
|
|
77
|
+
operationIds.push(operationId);
|
|
78
|
+
return captured.id ?? receipt.canonicalJobId;
|
|
79
|
+
}
|
|
80
|
+
async function executeActionStrict(name, args) {
|
|
81
|
+
alive();
|
|
82
|
+
let target;
|
|
83
|
+
try {
|
|
84
|
+
target = catalog.resolveLocal(name);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
const diagnostic = issuedRuntimeDiagnostic(error);
|
|
87
|
+
if (diagnostic?.code === "RUNTIME_SCHEDULER_ACTION_NOT_FOUND")
|
|
88
|
+
throw new RuntimeDiagnosticError({ ...diagnostic, schedulerLookup: "direct", correlationId });
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
const outcome = await delivery.executeDirect(target, snapshotSchedulerArgs(args, delivery.policy?.maxArgsBytes).args, correlationId);
|
|
92
|
+
if (outcome.execution !== "succeeded" || outcome.effects !== "settled")
|
|
93
|
+
throw new RuntimeDiagnosticError(outcome.diagnostic ?? outcome.settlementDiagnostic ?? schedulerFailure("RUNTIME_SCHEDULER_EXECUTION_FAILED", "Inspect prior local effects before deliberately invoking new work.", "request", correlationId).diagnostic);
|
|
94
|
+
}
|
|
95
|
+
function inRequest(operation) {
|
|
96
|
+
try {
|
|
97
|
+
return operation();
|
|
98
|
+
} catch (error) {
|
|
99
|
+
const diagnostic = issuedRuntimeDiagnostic(error);
|
|
100
|
+
if (diagnostic?.capability === "scheduler" && diagnostic.stage === "request")
|
|
101
|
+
throw new RuntimeDiagnosticError({ ...diagnostic, correlationId });
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const scheduler = Object.freeze({
|
|
106
|
+
runAfter(ms, action, args, options) {
|
|
107
|
+
return inRequest(() => {
|
|
108
|
+
alive();
|
|
109
|
+
if (typeof ms !== "number" || !Number.isFinite(ms) || ms < 0)
|
|
110
|
+
throw schedulerFailure("RUNTIME_SCHEDULER_INPUT_INVALID", "Provide a finite, non-negative delay.");
|
|
111
|
+
return schedule(schedulerInstant(now() + ms), action, args, options);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
runAt(timestamp, action, args, options) {
|
|
115
|
+
return inRequest(() => {
|
|
116
|
+
alive();
|
|
117
|
+
return schedule(schedulerInstant(timestamp), action, args, options);
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
cancel(jobId) {
|
|
121
|
+
return inRequest(() => {
|
|
122
|
+
slot();
|
|
123
|
+
schedulerIdentifier(jobId);
|
|
124
|
+
const operationId = randomUUID();
|
|
125
|
+
const result = delivery.cancelNow({
|
|
126
|
+
operationId,
|
|
127
|
+
logicalJobId: jobId,
|
|
128
|
+
correlationId,
|
|
129
|
+
...parentDeliveryId ? { parentDeliveryId } : {}
|
|
130
|
+
});
|
|
131
|
+
operationIds.push(operationId);
|
|
132
|
+
return result.outcome === "cancelled";
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
cron(name, pattern, handler) {
|
|
136
|
+
alive();
|
|
137
|
+
delivery.cron(name, pattern, handler);
|
|
138
|
+
},
|
|
139
|
+
registerAction(name, handler) {
|
|
140
|
+
alive();
|
|
141
|
+
delivery.registerAction(name, handler);
|
|
142
|
+
},
|
|
143
|
+
executeActionStrict,
|
|
144
|
+
async executeAction(name, args) {
|
|
145
|
+
try {
|
|
146
|
+
await executeActionStrict(name, args);
|
|
147
|
+
} catch {
|
|
148
|
+
try {
|
|
149
|
+
logger?.error("runtime.scheduler.compatibility.failed", {
|
|
150
|
+
"runtime.public_code": "RUNTIME_SCHEDULER_EXECUTION_FAILED",
|
|
151
|
+
"request.id": correlationId
|
|
152
|
+
});
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return Object.freeze({
|
|
159
|
+
scheduler,
|
|
160
|
+
sealAdmissions() {
|
|
161
|
+
sealed = true;
|
|
162
|
+
},
|
|
163
|
+
settleAdmissions() {
|
|
164
|
+
sealed = true;
|
|
165
|
+
settlement ??= Promise.resolve(Object.freeze({ state: "accepted", operationIds: Object.freeze([...operationIds]) }));
|
|
166
|
+
return settlement;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ../runtime/dist/adapters/scheduler/local/transport.js
|
|
172
|
+
var localSystemClock = Object.freeze({
|
|
173
|
+
now: Date.now,
|
|
174
|
+
setTimer(callback, delayMs) {
|
|
175
|
+
const timer = setTimeout(callback, delayMs);
|
|
176
|
+
return { cancel: () => clearTimeout(timer) };
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// ../runtime/dist/adapters/scheduler/local/library-transport.js
|
|
181
|
+
import { createTask, validate } from "node-cron";
|
|
182
|
+
function localCronTransport(timezone) {
|
|
183
|
+
return {
|
|
184
|
+
validate,
|
|
185
|
+
create(pattern, onDue, onMissed) {
|
|
186
|
+
const task = createTask(pattern, (context) => onDue(context.date.getTime()), {
|
|
187
|
+
timezone,
|
|
188
|
+
noOverlap: true,
|
|
189
|
+
suppressMissedWarning: true,
|
|
190
|
+
logger: { info() {
|
|
191
|
+
}, warn() {
|
|
192
|
+
}, error() {
|
|
193
|
+
}, debug() {
|
|
194
|
+
} }
|
|
195
|
+
});
|
|
196
|
+
task.on("execution:missed", (context) => onMissed(context.date.getTime()));
|
|
197
|
+
task.on("execution:overlap", (context) => onMissed(context.date.getTime()));
|
|
198
|
+
return {
|
|
199
|
+
start() {
|
|
200
|
+
void task.start();
|
|
201
|
+
},
|
|
202
|
+
stop() {
|
|
203
|
+
void task.stop();
|
|
204
|
+
},
|
|
205
|
+
destroy() {
|
|
206
|
+
void task.destroy();
|
|
207
|
+
},
|
|
208
|
+
nextRun: () => task.getNextRun()?.getTime() ?? null
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ../runtime/dist/adapters/scheduler/local.js
|
|
215
|
+
function createLocalSchedulerModule(options) {
|
|
216
|
+
const policy = snapshotLocalSchedulerPolicy(options.policy);
|
|
217
|
+
const timezone = options.timezone;
|
|
218
|
+
const activation = options.activation;
|
|
219
|
+
try {
|
|
220
|
+
if (!activation || typeof activation.isActive !== "function" || typeof activation.subscribe !== "function" || typeof timezone !== "string" || !timezone)
|
|
221
|
+
throw new Error();
|
|
222
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone });
|
|
223
|
+
} catch {
|
|
224
|
+
throw schedulerFailure("RUNTIME_CRON_DECLARATION_INVALID", "Supply an explicit activation gate and valid captured local timezone before allocating providers.", "startup");
|
|
225
|
+
}
|
|
226
|
+
return (c) => c.registerAsyncFactory("schedulerDelivery", async (binding, catalog, admission, logger) => createLocalSchedulerResource({
|
|
227
|
+
binding,
|
|
228
|
+
catalog,
|
|
229
|
+
admission,
|
|
230
|
+
logger,
|
|
231
|
+
activation,
|
|
232
|
+
timezone,
|
|
233
|
+
policy,
|
|
234
|
+
clock: localSystemClock,
|
|
235
|
+
cron: localCronTransport(timezone)
|
|
236
|
+
}), ["runtimeBinding", "schedulerCatalog", "jobAdmission", "logger"], "singleton").registerAsyncFactory("schedulerEffects", async (delivery, catalog, verified, assert, logger) => {
|
|
237
|
+
assert(verified);
|
|
238
|
+
return createLocalSchedulerEffects({
|
|
239
|
+
delivery,
|
|
240
|
+
catalog,
|
|
241
|
+
binding: verified.binding,
|
|
242
|
+
signal: verified.signal,
|
|
243
|
+
correlationId: verified.correlationId,
|
|
244
|
+
parentDeliveryId: verified.parentDeliveryId,
|
|
245
|
+
logger
|
|
246
|
+
});
|
|
247
|
+
}, ["schedulerDelivery", "schedulerCatalog", "verifiedRequest", "assertVerifiedRequest", "logger"], "scoped");
|
|
248
|
+
}
|
|
249
|
+
export {
|
|
250
|
+
createLocalSchedulerModule
|
|
251
|
+
};
|