@palbase/backend 35.0.1 → 36.0.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.
- package/dist/bin/palbase-backend.cjs +556 -487
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +6 -6
- package/dist/{chunk-L4R7WXLH.js → chunk-7WAGQ3VR.js} +4 -171
- package/dist/chunk-7WAGQ3VR.js.map +1 -0
- package/dist/{chunk-UMESJJRS.js → chunk-CS6NQ6PO.js} +2 -1
- package/dist/chunk-CS6NQ6PO.js.map +1 -0
- package/dist/{chunk-BOD3DT6D.js → chunk-EHKEMHB4.js} +560 -430
- package/dist/chunk-EHKEMHB4.js.map +1 -0
- package/dist/{chunk-PRH45NZU.js → chunk-FFO36MQQ.js} +2 -45
- package/dist/chunk-FFO36MQQ.js.map +1 -0
- package/dist/{chunk-P7MGSAFT.js → chunk-LFUNRWUE.js} +1 -40
- package/dist/chunk-LFUNRWUE.js.map +1 -0
- package/dist/{chunk-RZLY4BOY.js → chunk-PDD55QWN.js} +2 -2
- package/dist/{chunk-YO5GYM73.js → chunk-X7UR3VXA.js} +5 -6
- package/dist/chunk-X7UR3VXA.js.map +1 -0
- package/dist/{chunk-6FEHCEB7.js → chunk-YANGWAIM.js} +3 -3
- package/dist/db/index.cjs +1 -232
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +3 -46
- package/dist/db/index.d.ts +3 -46
- package/dist/db/index.js +4 -12
- package/dist/engine/index.cjs +556 -487
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.cts +4 -4
- package/dist/engine/index.d.ts +4 -4
- package/dist/engine/index.js +6 -6
- package/dist/{index-DllNjpTl.d.cts → index-CI7S0Wqv.d.cts} +61 -8
- package/dist/{endpoint-BI0yGuEL.d.ts → index-CUy50OLU.d.ts} +6 -82
- package/dist/{endpoint-DaGnjt42.d.cts → index-DRx880KY.d.cts} +6 -82
- package/dist/{index-E8Sd6NFy.d.ts → index-Ogi30dbt.d.ts} +61 -8
- package/dist/index.cjs +5 -237
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +7 -15
- package/dist/index.js.map +1 -1
- package/dist/openapi/index.cjs +1 -0
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +3 -3
- package/dist/openapi/index.d.ts +3 -3
- package/dist/openapi/index.js +2 -2
- package/dist/{registry-BnKvIyve.d.cts → registry-C7UCkQf0.d.cts} +1 -1
- package/dist/{registry-zDCj0eOU.d.ts → registry-DJcvbomD.d.ts} +1 -1
- package/dist/test/index.cjs +3 -11
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +2 -2
- package/dist/test/index.d.ts +2 -2
- package/dist/test/index.js +2 -9
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +1 -1
- package/docs/database.md +2 -60
- package/docs/examples/database-dx.ts +12 -17
- package/docs/llms-full.txt +3 -61
- package/package.json +1 -1
- package/stager/inferred_returns.js +153 -0
- package/stager/return_types.js +9 -4
- package/stager/stage.js +3 -1
- package/template/AGENTS.md +5 -5
- package/template/package.json +2 -2
- package/dist/chunk-BOD3DT6D.js.map +0 -1
- package/dist/chunk-L4R7WXLH.js.map +0 -1
- package/dist/chunk-P7MGSAFT.js.map +0 -1
- package/dist/chunk-PRH45NZU.js.map +0 -1
- package/dist/chunk-UMESJJRS.js.map +0 -1
- package/dist/chunk-YO5GYM73.js.map +0 -1
- package/docs/examples/check-query-contracts.ts +0 -5
- package/docs/examples/database-dx.contract.json +0 -65
- /package/dist/{chunk-RZLY4BOY.js.map → chunk-PDD55QWN.js.map} +0 -0
- /package/dist/{chunk-6FEHCEB7.js.map → chunk-YANGWAIM.js.map} +0 -0
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
BootRefused,
|
|
4
4
|
createApp,
|
|
5
5
|
loadConfig
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-EHKEMHB4.js";
|
|
7
|
+
import "../chunk-YANGWAIM.js";
|
|
8
8
|
import "../chunk-GHNC2UHS.js";
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-X7UR3VXA.js";
|
|
10
|
+
import "../chunk-FFO36MQQ.js";
|
|
11
|
+
import "../chunk-LFUNRWUE.js";
|
|
12
12
|
import {
|
|
13
13
|
getRegisteredControllers
|
|
14
14
|
} from "../chunk-JJW3L62T.js";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-CS6NQ6PO.js";
|
|
16
16
|
import {
|
|
17
17
|
__name
|
|
18
18
|
} from "../chunk-VXPNPVAG.js";
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
queryColumnContract,
|
|
3
|
-
stableContract
|
|
4
|
-
} from "./chunk-PRH45NZU.js";
|
|
5
1
|
import {
|
|
6
2
|
TxPlanBuilder,
|
|
7
3
|
brandRef,
|
|
8
4
|
qualifiedTableKey,
|
|
9
5
|
retryBudget,
|
|
10
6
|
runTxPlan
|
|
11
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-LFUNRWUE.js";
|
|
12
8
|
import {
|
|
13
9
|
isRetryable
|
|
14
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-CS6NQ6PO.js";
|
|
15
11
|
import {
|
|
16
12
|
__name
|
|
17
13
|
} from "./chunk-VXPNPVAG.js";
|
|
@@ -187,13 +183,6 @@ function defineTable(name, input) {
|
|
|
187
183
|
}
|
|
188
184
|
__name(defineTable, "defineTable");
|
|
189
185
|
var declaringSchemaOf = /* @__PURE__ */ new WeakMap();
|
|
190
|
-
function declaredTableKey(table) {
|
|
191
|
-
const metadata = table[TABLE_META];
|
|
192
|
-
const schema = declaringSchemaOf.get(metadata);
|
|
193
|
-
if (schema === void 0) throw new Error(`defineQuery: table ${metadata.name} must belong to defineSchema before defining its query`);
|
|
194
|
-
return qualifiedTableKey(schema, metadata.name);
|
|
195
|
-
}
|
|
196
|
-
__name(declaredTableKey, "declaredTableKey");
|
|
197
186
|
function resolveReferences(tables, schemaName) {
|
|
198
187
|
for (const table of Object.values(tables)) {
|
|
199
188
|
for (const [colName, builder] of Object.entries(table.columns)) {
|
|
@@ -669,9 +658,6 @@ function makeTypedDB(schema, raw2) {
|
|
|
669
658
|
const result = {
|
|
670
659
|
tables,
|
|
671
660
|
diagnostics: /* @__PURE__ */ __name(() => raw2.diagnostics(), "diagnostics"),
|
|
672
|
-
readQuery: /* @__PURE__ */ __name((query) => raw2.readQuery(query), "readQuery"),
|
|
673
|
-
compileQuery: /* @__PURE__ */ __name((query) => raw2.compileQuery(query), "compileQuery"),
|
|
674
|
-
explainQuery: /* @__PURE__ */ __name((query) => raw2.explainQuery(query), "explainQuery"),
|
|
675
661
|
command(fn, options) {
|
|
676
662
|
const builder = new TxPlanBuilder();
|
|
677
663
|
const planTables = Object.fromEntries(Object.entries(schema.tables).map(([key, table]) => [
|
|
@@ -730,156 +716,6 @@ function sqlFragment(strings, ...values) {
|
|
|
730
716
|
}
|
|
731
717
|
__name(sqlFragment, "sqlFragment");
|
|
732
718
|
|
|
733
|
-
// src/db/query.ts
|
|
734
|
-
import { z as z2 } from "zod";
|
|
735
|
-
import { OpenAPIRegistry, OpenApiGeneratorV31, extendZodWithOpenApi } from "@asteasolutions/zod-to-openapi";
|
|
736
|
-
extendZodWithOpenApi(z2);
|
|
737
|
-
function responseColumn(column, validator) {
|
|
738
|
-
const contract = queryColumnContract(column);
|
|
739
|
-
let schema;
|
|
740
|
-
if (validator) return validator;
|
|
741
|
-
if (contract.codec === "number") schema = z2.number().finite();
|
|
742
|
-
else if (contract.codec === "decimal") schema = z2.string();
|
|
743
|
-
else switch (contract.type) {
|
|
744
|
-
case "integer":
|
|
745
|
-
schema = z2.number().int().min(-2147483648).max(2147483647);
|
|
746
|
-
break;
|
|
747
|
-
case "boolean":
|
|
748
|
-
schema = z2.boolean();
|
|
749
|
-
break;
|
|
750
|
-
case "vector":
|
|
751
|
-
schema = z2.array(z2.number().finite());
|
|
752
|
-
break;
|
|
753
|
-
case "enum": {
|
|
754
|
-
const values = contract.enumValues;
|
|
755
|
-
if (!values?.length) throw new Error("Query response requires declared enum values");
|
|
756
|
-
schema = z2.enum(values);
|
|
757
|
-
break;
|
|
758
|
-
}
|
|
759
|
-
case "uuid":
|
|
760
|
-
case "text":
|
|
761
|
-
case "timestamp":
|
|
762
|
-
case "numeric":
|
|
763
|
-
case "bigint":
|
|
764
|
-
schema = z2.string();
|
|
765
|
-
break;
|
|
766
|
-
case "jsonb":
|
|
767
|
-
throw new Error("Query response requires a fields validator for a selected jsonb column: its TypeScript payload is erased at runtime");
|
|
768
|
-
default:
|
|
769
|
-
throw new Error(`Query response does not support column type ${contract.type}`);
|
|
770
|
-
}
|
|
771
|
-
return contract.nullable ? schema.nullable() : schema;
|
|
772
|
-
}
|
|
773
|
-
__name(responseColumn, "responseColumn");
|
|
774
|
-
function defineQuery(name, options) {
|
|
775
|
-
if (typeof name !== "string" || !/^[A-Za-z][A-Za-z0-9_]{0,127}$/.test(name)) throw new Error("defineQuery requires a stable name of 1\u2013128 letters, digits or underscores");
|
|
776
|
-
const table = declaredTableKey(options.table);
|
|
777
|
-
const select = [
|
|
778
|
-
...options.select
|
|
779
|
-
];
|
|
780
|
-
if (!select.length || new Set(select).size !== select.length) throw new Error(`Query ${name}: select must be explicit, nonempty and distinct`);
|
|
781
|
-
const shape = {}, columns = {};
|
|
782
|
-
for (const key of select) {
|
|
783
|
-
if (!Object.hasOwn(options.table[TABLE_META].columns, key)) throw new Error(`Query ${name}: unknown column ${key}`);
|
|
784
|
-
columns[key] = queryColumnContract(options.table[key]);
|
|
785
|
-
shape[key] = responseColumn(options.table[key], options.fields?.[key]);
|
|
786
|
-
}
|
|
787
|
-
const response = z2.array(z2.object(shape).strict());
|
|
788
|
-
const queryInput = options.input, where = options.where, limit = options.limit;
|
|
789
|
-
const orderBy = options.orderBy === void 0 ? void 0 : JSON.parse(JSON.stringify(options.orderBy));
|
|
790
|
-
const prepare = /* @__PURE__ */ __name((input) => {
|
|
791
|
-
const parsed = queryInput.parse(input);
|
|
792
|
-
const filter = where === void 0 ? {} : where(parsed);
|
|
793
|
-
if (!filter || typeof filter !== "object" || Array.isArray(filter) || typeof filter.then === "function") {
|
|
794
|
-
throw new Error(`Query ${name}: where must return a synchronous filter object`);
|
|
795
|
-
}
|
|
796
|
-
const size = typeof limit === "function" ? limit(parsed) : limit;
|
|
797
|
-
if (limit !== void 0 && (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0)) throw new Error(`Query ${name}: limit must produce a nonnegative safe integer`);
|
|
798
|
-
return {
|
|
799
|
-
name,
|
|
800
|
-
table,
|
|
801
|
-
columns: JSON.parse(JSON.stringify(columns)),
|
|
802
|
-
where: filter,
|
|
803
|
-
options: {
|
|
804
|
-
select: [
|
|
805
|
-
...select
|
|
806
|
-
],
|
|
807
|
-
...orderBy === void 0 ? {} : {
|
|
808
|
-
orderBy: structuredClone(orderBy)
|
|
809
|
-
},
|
|
810
|
-
...limit === void 0 ? {} : {
|
|
811
|
-
limit: size
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
}, "prepare");
|
|
816
|
-
const attach = /* @__PURE__ */ __name((schema) => {
|
|
817
|
-
const api = {
|
|
818
|
-
queryName: name,
|
|
819
|
-
input: queryInput,
|
|
820
|
-
prepare,
|
|
821
|
-
async run(database, input) {
|
|
822
|
-
const request = prepare(input);
|
|
823
|
-
const rows = await ("$readQuery" in database ? database.$readQuery(request) : database.readQuery(request));
|
|
824
|
-
return schema.parse(rows);
|
|
825
|
-
},
|
|
826
|
-
sql(database, input) {
|
|
827
|
-
const request = prepare(input);
|
|
828
|
-
return "$compileQuery" in database ? database.$compileQuery(request) : database.compileQuery(request);
|
|
829
|
-
},
|
|
830
|
-
explain(database, input) {
|
|
831
|
-
const request = prepare(input);
|
|
832
|
-
return "$explainQuery" in database ? database.$explainQuery(request) : database.explainQuery(request);
|
|
833
|
-
},
|
|
834
|
-
contract() {
|
|
835
|
-
const registry = new OpenAPIRegistry();
|
|
836
|
-
registry.register(`${name}Input`, queryInput);
|
|
837
|
-
registry.register(`${name}Response`, schema);
|
|
838
|
-
return JSON.parse(JSON.stringify({
|
|
839
|
-
name,
|
|
840
|
-
table,
|
|
841
|
-
select,
|
|
842
|
-
columns,
|
|
843
|
-
components: new OpenApiGeneratorV31(registry.definitions).generateComponents().components
|
|
844
|
-
}));
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
for (const key of [
|
|
848
|
-
"min",
|
|
849
|
-
"max",
|
|
850
|
-
"length",
|
|
851
|
-
"describe",
|
|
852
|
-
"openapi"
|
|
853
|
-
]) {
|
|
854
|
-
const modify = schema[key].bind(schema);
|
|
855
|
-
Object.defineProperty(schema, key, {
|
|
856
|
-
value: /* @__PURE__ */ __name((...args) => attach(modify(...args)), "value"),
|
|
857
|
-
configurable: true
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
return Object.assign(schema, api);
|
|
861
|
-
}, "attach");
|
|
862
|
-
return attach(response);
|
|
863
|
-
}
|
|
864
|
-
__name(defineQuery, "defineQuery");
|
|
865
|
-
function queryManifest(queries) {
|
|
866
|
-
const sorted = [
|
|
867
|
-
...queries
|
|
868
|
-
].sort((a, b) => a.queryName.localeCompare(b.queryName));
|
|
869
|
-
if (new Set(sorted.map((query) => query.queryName)).size !== sorted.length) throw new Error("Query manifest contains duplicate names");
|
|
870
|
-
return JSON.parse(stableContract({
|
|
871
|
-
version: 1,
|
|
872
|
-
queries: sorted.map((query) => query.contract())
|
|
873
|
-
}));
|
|
874
|
-
}
|
|
875
|
-
__name(queryManifest, "queryManifest");
|
|
876
|
-
function assertQueryManifest(queries, baseline) {
|
|
877
|
-
if (stableContract(queryManifest(queries)) !== stableContract(baseline)) {
|
|
878
|
-
throw new Error("Query contract drift: compare queryManifest() with the committed manifest and review the API/client changes before updating it");
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
__name(assertQueryManifest, "assertQueryManifest");
|
|
882
|
-
|
|
883
719
|
export {
|
|
884
720
|
PolicyExprRef,
|
|
885
721
|
exprCtx,
|
|
@@ -899,9 +735,6 @@ export {
|
|
|
899
735
|
makeTypedDB,
|
|
900
736
|
col,
|
|
901
737
|
withRetry,
|
|
902
|
-
sqlFragment
|
|
903
|
-
defineQuery,
|
|
904
|
-
queryManifest,
|
|
905
|
-
assertQueryManifest
|
|
738
|
+
sqlFragment
|
|
906
739
|
};
|
|
907
|
-
//# sourceMappingURL=chunk-
|
|
740
|
+
//# sourceMappingURL=chunk-7WAGQ3VR.js.map
|