okmodel 0.0.0 → 0.1.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/README.md +44 -1
- package/dist/adapters/capabilities.d.ts +62 -0
- package/dist/adapters/error.d.ts +91 -0
- package/dist/adapters/failure.d.ts +39 -0
- package/dist/adapters/pg/batch.d.ts +36 -0
- package/dist/adapters/pg/call.d.ts +59 -0
- package/dist/adapters/pg/pglite.d.ts +21 -0
- package/dist/adapters/pg/postgres-extra.d.ts +43 -0
- package/dist/adapters/pg/postgresjs.d.ts +95 -0
- package/dist/adapters/pg/result.d.ts +30 -0
- package/dist/contracts/catalog/build.d.ts +18 -0
- package/dist/contracts/catalog/document.d.ts +79 -0
- package/dist/contracts/catalog/enum.d.ts +35 -0
- package/dist/contracts/catalog/identifier.d.ts +71 -0
- package/dist/contracts/catalog/identity.d.ts +98 -0
- package/dist/contracts/catalog/index.d.ts +11 -0
- package/dist/contracts/catalog/json.d.ts +17 -0
- package/dist/contracts/catalog/object.d.ts +142 -0
- package/dist/contracts/catalog/order.d.ts +43 -0
- package/dist/contracts/catalog/rewrite.d.ts +18 -0
- package/dist/contracts/catalog/types.d.ts +292 -0
- package/dist/contracts/catalog/words.d.ts +13 -0
- package/dist/contracts/connection.d.ts +33 -0
- package/dist/contracts/driver.d.ts +163 -0
- package/dist/contracts/error.d.ts +298 -0
- package/dist/contracts/index.d.ts +11 -0
- package/dist/contracts/index.js +16 -0
- package/dist/contracts/internal.d.ts +15 -0
- package/dist/contracts/internal.js +68 -0
- package/dist/contracts/nearest.d.ts +15 -0
- package/dist/contracts/rows.d.ts +84 -0
- package/dist/contracts/sha256.d.ts +14 -0
- package/dist/contracts/utf8.d.ts +33 -0
- package/dist/dialects/pg/array-literal.d.ts +25 -0
- package/dist/dialects/pg/bool.d.ts +46 -0
- package/dist/dialects/pg/column.d.ts +386 -0
- package/dist/dialects/pg/compile.d.ts +81 -0
- package/dist/dialects/pg/custom.d.ts +21 -0
- package/dist/dialects/pg/ddl.d.ts +70 -0
- package/dist/dialects/pg/decimal.d.ts +62 -0
- package/dist/dialects/pg/declarations.d.ts +34 -0
- package/dist/dialects/pg/emit.d.ts +18 -0
- package/dist/dialects/pg/enum.d.ts +30 -0
- package/dist/dialects/pg/errors.d.ts +30 -0
- package/dist/dialects/pg/finite.d.ts +15 -0
- package/dist/dialects/pg/geometry.d.ts +55 -0
- package/dist/dialects/pg/index.d.ts +45 -0
- package/dist/dialects/pg/index.js +1821 -0
- package/dist/dialects/pg/integer.d.ts +96 -0
- package/dist/dialects/pg/introspect.d.ts +43 -0
- package/dist/dialects/pg/json.d.ts +43 -0
- package/dist/dialects/pg/keys.d.ts +32 -0
- package/dist/dialects/pg/misuse.d.ts +31 -0
- package/dist/dialects/pg/model.d.ts +71 -0
- package/dist/dialects/pg/namespace.d.ts +63 -0
- package/dist/dialects/pg/network.d.ts +28 -0
- package/dist/dialects/pg/operators.d.ts +71 -0
- package/dist/dialects/pg/ops/between.d.ts +10 -0
- package/dist/dialects/pg/ops/contains.d.ts +8 -0
- package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
- package/dist/dialects/pg/ops/eq.d.ts +9 -0
- package/dist/dialects/pg/ops/every.d.ts +9 -0
- package/dist/dialects/pg/ops/gt.d.ts +9 -0
- package/dist/dialects/pg/ops/gte.d.ts +9 -0
- package/dist/dialects/pg/ops/has.d.ts +9 -0
- package/dist/dialects/pg/ops/ilike.d.ts +8 -0
- package/dist/dialects/pg/ops/inList.d.ts +9 -0
- package/dist/dialects/pg/ops/inc.d.ts +13 -0
- package/dist/dialects/pg/ops/like.d.ts +8 -0
- package/dist/dialects/pg/ops/lt.d.ts +9 -0
- package/dist/dialects/pg/ops/lte.d.ts +9 -0
- package/dist/dialects/pg/ops/none.d.ts +9 -0
- package/dist/dialects/pg/ops/not.d.ts +9 -0
- package/dist/dialects/pg/ops/notIn.d.ts +9 -0
- package/dist/dialects/pg/ops/or.d.ts +9 -0
- package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
- package/dist/dialects/pg/quote.d.ts +24 -0
- package/dist/dialects/pg/range.d.ts +50 -0
- package/dist/dialects/pg/relations.d.ts +45 -0
- package/dist/dialects/pg/schema.d.ts +77 -0
- package/dist/dialects/pg/search.d.ts +23 -0
- package/dist/dialects/pg/table.d.ts +201 -0
- package/dist/dialects/pg/temporal.d.ts +211 -0
- package/dist/dialects/pg/text.d.ts +44 -0
- package/dist/dialects/pg/time.d.ts +46 -0
- package/dist/okm.js +2 -0
- package/dist/okmodel.js +2 -0
- package/dist/runtime/client.d.ts +47 -0
- package/dist/runtime/conflict.d.ts +38 -0
- package/dist/runtime/drift-detail.d.ts +32 -0
- package/dist/runtime/drift.d.ts +29 -0
- package/dist/runtime/include.d.ts +15 -0
- package/dist/runtime/pg/pglite.d.ts +25 -0
- package/dist/runtime/pg/pglite.js +48 -0
- package/dist/runtime/pg/postgresjs.d.ts +29 -0
- package/dist/runtime/pg/postgresjs.js +62 -0
- package/dist/runtime/plan.d.ts +167 -0
- package/dist/runtime/tx.d.ts +29 -0
- package/dist/runtime/types.d.ts +369 -0
- package/dist/runtime/write.d.ts +48 -0
- package/dist/shared/4j72449d.js +37 -0
- package/dist/shared/79ggp945.js +148 -0
- package/dist/shared/7ck0dtry.js +259 -0
- package/dist/shared/8b04d28c.js +14 -0
- package/dist/shared/ax16zpvm.js +171 -0
- package/dist/shared/ckb1p0a4.js +566 -0
- package/dist/shared/cn0n68ft.js +16 -0
- package/dist/shared/dynq16vb.js +81 -0
- package/dist/shared/f5thc1s0.js +1050 -0
- package/dist/shared/fgqgsb5z.js +281 -0
- package/dist/shared/g2v6gnc8.js +347 -0
- package/dist/shared/g5fhqmwe.js +188 -0
- package/dist/shared/gk7cs7sp.js +566 -0
- package/dist/shared/hd293j9g.js +98 -0
- package/dist/shared/j5cn2963.js +701 -0
- package/dist/shared/kynx7vbm.js +1490 -0
- package/dist/shared/mkjmqjv4.js +456 -0
- package/dist/shared/mtkwv8wx.js +18 -0
- package/dist/shared/ngk8gj61.js +40 -0
- package/dist/shared/p0cbr3g2.js +79 -0
- package/dist/shared/px90pf9p.js +396 -0
- package/dist/shared/qk3hxfja.js +83 -0
- package/dist/shared/tb4ze1tr.js +119 -0
- package/dist/shared/vkm3q4x1.js +30 -0
- package/dist/shared/w8samvk1.js +18 -0
- package/dist/shared/xy79j5hq.js +177 -0
- package/dist/shared/y9m15dfv.js +888 -0
- package/dist/shared/ycwz42az.js +412 -0
- package/dist/shared/zhc5vmgf.js +257 -0
- package/dist/tooling/cli.d.ts +1 -0
- package/dist/tooling/cli.js +193 -0
- package/dist/tooling/errors/registry.d.ts +33 -0
- package/dist/tooling/migrate/apply.d.ts +86 -0
- package/dist/tooling/migrate/commands.d.ts +21 -0
- package/dist/tooling/migrate/config.d.ts +48 -0
- package/dist/tooling/migrate/dev.d.ts +16 -0
- package/dist/tooling/migrate/equal.d.ts +15 -0
- package/dist/tooling/migrate/files.d.ts +19 -0
- package/dist/tooling/migrate/index.d.ts +7 -0
- package/dist/tooling/migrate/index.js +7 -0
- package/dist/tooling/migrate/plan.d.ts +76 -0
- package/dist/tooling/migrate/policy.d.ts +78 -0
- package/dist/tooling/migrate/project.d.ts +69 -0
- package/dist/tooling/migrate/status.d.ts +74 -0
- package/dist/tooling/migrate/values.d.ts +29 -0
- package/package.json +94 -7
- package/dist/index.js +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CATALOG_VERSION2,
|
|
3
|
+
assertNamespace2,
|
|
4
|
+
identityKey2,
|
|
5
|
+
identityLabel2,
|
|
6
|
+
normaliseEdges,
|
|
7
|
+
compareText,
|
|
8
|
+
assertProvenance
|
|
9
|
+
} from "./j5cn2963.js";
|
|
10
|
+
import {
|
|
11
|
+
assertIdentifier2,
|
|
12
|
+
assertStoredText
|
|
13
|
+
} from "./mkjmqjv4.js";
|
|
14
|
+
import {
|
|
15
|
+
catalogError2
|
|
16
|
+
} from "./ycwz42az.js";
|
|
17
|
+
|
|
18
|
+
// src/contracts/catalog/order.ts
|
|
19
|
+
function indexObjects(objects) {
|
|
20
|
+
const seen = new Set;
|
|
21
|
+
const indexed = [];
|
|
22
|
+
for (const object of objects) {
|
|
23
|
+
const key = identityKey2(object.identity);
|
|
24
|
+
if (seen.has(key)) {
|
|
25
|
+
catalogError2("OKM1023", `Duplicate identity for ${identityLabel2(object.identity)}.`);
|
|
26
|
+
}
|
|
27
|
+
seen.add(key);
|
|
28
|
+
indexed.push({ key, object });
|
|
29
|
+
}
|
|
30
|
+
return indexed;
|
|
31
|
+
}
|
|
32
|
+
function dependencyOrder(objects) {
|
|
33
|
+
return orderIndexed(indexObjects(objects));
|
|
34
|
+
}
|
|
35
|
+
function orderIndexed(indexed) {
|
|
36
|
+
const byKey = new Map;
|
|
37
|
+
for (const item of indexed) {
|
|
38
|
+
byKey.set(item.key, item.object);
|
|
39
|
+
}
|
|
40
|
+
const dependents = new Map;
|
|
41
|
+
const remaining = new Map;
|
|
42
|
+
for (const item of indexed) {
|
|
43
|
+
dependents.set(item.key, []);
|
|
44
|
+
remaining.set(item.key, 0);
|
|
45
|
+
}
|
|
46
|
+
for (const item of indexed) {
|
|
47
|
+
const seen = new Set;
|
|
48
|
+
for (const edge of item.object.dependencies) {
|
|
49
|
+
const dependency = identityKey2(edge.target);
|
|
50
|
+
if (dependency === item.key) {
|
|
51
|
+
catalogError2("OKM1020", `${identityLabel2(item.object.identity)} depends on itself.`);
|
|
52
|
+
}
|
|
53
|
+
if (!byKey.has(dependency)) {
|
|
54
|
+
catalogError2("OKM1020", `${identityLabel2(item.object.identity)} depends on ${identityLabel2(edge.target)}, which is not in the catalog.`);
|
|
55
|
+
}
|
|
56
|
+
if (seen.has(dependency)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
seen.add(dependency);
|
|
60
|
+
remaining.set(item.key, (remaining.get(item.key) ?? 0) + 1);
|
|
61
|
+
dependents.get(dependency)?.push(item.key);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const ready = indexed.filter((item) => remaining.get(item.key) === 0).map((item) => item.key);
|
|
65
|
+
ready.sort(compareText);
|
|
66
|
+
const ordered = [];
|
|
67
|
+
let cursor = 0;
|
|
68
|
+
while (cursor < ready.length) {
|
|
69
|
+
const key = ready[cursor];
|
|
70
|
+
if (key === undefined) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
cursor += 1;
|
|
74
|
+
const object = byKey.get(key);
|
|
75
|
+
if (object === undefined) {
|
|
76
|
+
catalogError2("OKM1020", "Dependency order lost an object while sorting.");
|
|
77
|
+
}
|
|
78
|
+
ordered.push(object);
|
|
79
|
+
for (const dependent of dependents.get(key) ?? []) {
|
|
80
|
+
const left = (remaining.get(dependent) ?? 0) - 1;
|
|
81
|
+
remaining.set(dependent, left);
|
|
82
|
+
if (left === 0) {
|
|
83
|
+
insertSorted(ready, cursor, dependent);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (ordered.length !== byKey.size) {
|
|
88
|
+
catalogError2("OKM1026", "Catalog has a dependency cycle.");
|
|
89
|
+
}
|
|
90
|
+
return ordered;
|
|
91
|
+
}
|
|
92
|
+
function insertSorted(ready, from, key) {
|
|
93
|
+
let index = from;
|
|
94
|
+
while (index < ready.length && compareText(ready[index] ?? "", key) < 0) {
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
ready.splice(index, 0, key);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/contracts/catalog/build.ts
|
|
101
|
+
function catalog(objects) {
|
|
102
|
+
for (const object of objects) {
|
|
103
|
+
if (object.kind !== object.identity.kind) {
|
|
104
|
+
catalogError2("OKM1020", `${identityLabel2(object.identity)} has kind ${object.kind}.`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const indexed = indexObjects(objects);
|
|
108
|
+
const keys = new Set;
|
|
109
|
+
for (const item of indexed) {
|
|
110
|
+
keys.add(item.key);
|
|
111
|
+
}
|
|
112
|
+
assertForeignKeys(objects, keys);
|
|
113
|
+
orderIndexed(indexed);
|
|
114
|
+
const sorted = [...indexed].sort((left, right) => compareText(left.key, right.key));
|
|
115
|
+
return { version: CATALOG_VERSION2, objects: sorted.map((item) => item.object) };
|
|
116
|
+
}
|
|
117
|
+
function assertForeignKeys(objects, keys) {
|
|
118
|
+
for (const object of objects) {
|
|
119
|
+
if (object.kind !== "constraint" || object.definition.constraintKind !== "foreignKey") {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const references = object.definition.references;
|
|
123
|
+
if (references === undefined) {
|
|
124
|
+
catalogError2("OKM1021", `Foreign key ${object.identity.name} is missing its target.`);
|
|
125
|
+
}
|
|
126
|
+
const tableKey = identityKey2({
|
|
127
|
+
kind: "table",
|
|
128
|
+
namespace: references.parent.namespace,
|
|
129
|
+
name: references.parent.name
|
|
130
|
+
});
|
|
131
|
+
if (!keys.has(tableKey)) {
|
|
132
|
+
catalogError2("OKM1021", `Foreign key ${object.identity.name} references missing table ${references.parent.name}.`);
|
|
133
|
+
}
|
|
134
|
+
for (const name of references.columns) {
|
|
135
|
+
const columnKey = identityKey2({ kind: "column", parent: references.parent, name });
|
|
136
|
+
if (!keys.has(columnKey)) {
|
|
137
|
+
catalogError2("OKM1021", `Foreign key ${object.identity.name} references missing column ${name}.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// src/contracts/catalog/enum.ts
|
|
144
|
+
function enumType(input) {
|
|
145
|
+
assertNamespace2(input.namespace);
|
|
146
|
+
assertIdentifier2(input.name, "type");
|
|
147
|
+
assertProvenance(input.provenance);
|
|
148
|
+
if (input.labels.length === 0) {
|
|
149
|
+
catalogError2("OKM1020", `Enum ${input.name} must list at least one label.`);
|
|
150
|
+
}
|
|
151
|
+
const labels = [];
|
|
152
|
+
const seen = new Set;
|
|
153
|
+
for (const label of input.labels) {
|
|
154
|
+
assertStoredText(label, "enum label");
|
|
155
|
+
if (label.length === 0) {
|
|
156
|
+
catalogError2("OKM1020", `Enum ${input.name} has an empty label.`);
|
|
157
|
+
}
|
|
158
|
+
if (seen.has(label)) {
|
|
159
|
+
catalogError2("OKM1020", `Enum ${input.name} repeats label ${label}.`);
|
|
160
|
+
}
|
|
161
|
+
seen.add(label);
|
|
162
|
+
labels.push(label);
|
|
163
|
+
}
|
|
164
|
+
const identity = {
|
|
165
|
+
kind: "type",
|
|
166
|
+
namespace: input.namespace,
|
|
167
|
+
name: input.name
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
kind: "type",
|
|
171
|
+
identity,
|
|
172
|
+
owner: input.owner ?? "managed",
|
|
173
|
+
definition: { labels },
|
|
174
|
+
dependencies: normaliseEdges(input.dependencies ?? []),
|
|
175
|
+
provenance: input.provenance
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function sameEnumLabels(left, right) {
|
|
179
|
+
if (left.length !== right.length)
|
|
180
|
+
return false;
|
|
181
|
+
for (let index = 0;index < left.length; index += 1) {
|
|
182
|
+
if (left[index] !== right[index])
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { dependencyOrder, catalog, enumType, sameEnumLabels };
|