@substrat-run/contracts 0.127.0 → 0.129.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/dist/control-plane.d.ts +153 -0
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/control-plane.js +93 -0
- package/dist/control-plane.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/introspection.d.ts +3 -3
- package/dist/introspection.d.ts.map +1 -1
- package/dist/introspection.js +37 -3
- package/dist/introspection.js.map +1 -1
- package/dist/invocation-record.d.ts +63 -0
- package/dist/invocation-record.d.ts.map +1 -0
- package/dist/invocation-record.js +88 -0
- package/dist/invocation-record.js.map +1 -0
- package/dist/lifecycle-flow.d.ts +158 -0
- package/dist/lifecycle-flow.d.ts.map +1 -0
- package/dist/lifecycle-flow.js +154 -0
- package/dist/lifecycle-flow.js.map +1 -0
- package/dist/sql-tokens.d.ts +37 -0
- package/dist/sql-tokens.d.ts.map +1 -0
- package/dist/sql-tokens.js +150 -0
- package/dist/sql-tokens.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One SQL scanner, for every place that has to read a table name out of SQL text it did not
|
|
3
|
+
* write: the spine write guard (`assertNoSpineWrite`, #954), a dump's replay check
|
|
4
|
+
* (`assertReplayableDump`, #1898), and the CLI's foreign-key ordering of a dump. The CLI's
|
|
5
|
+
* was a regex wanting whitespace after `REFERENCES`, so a comment there, which SQLite reads as
|
|
6
|
+
* whitespace, hid the table from it.
|
|
7
|
+
*
|
|
8
|
+
* The scan tokenises OUTSIDE comments and string literals but KEEPS quoted identifiers as
|
|
9
|
+
* tokens — `INSERT INTO "_substrat_tuples"` is the first thing anyone tries, and a scanner
|
|
10
|
+
* that skips quotes hands it through. Dotted names (`main._substrat_tuples`) merge into one
|
|
11
|
+
* token.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The platform spine's table prefix — the same one `isSystemTable` groups on, the one the
|
|
15
|
+
* spine guard protects, and the one a restore builds from the kernel's DDL (`isSpineTable`,
|
|
16
|
+
* #1883). Compared lowercased: SQLite matches table names without regard to case, so
|
|
17
|
+
* `_SUBSTRAT_TUPLES` is the tuples table.
|
|
18
|
+
*/
|
|
19
|
+
export const SPINE_PREFIX = '_substrat';
|
|
20
|
+
/** The statement text as identifier and keyword tokens, comments and whitespace dropped. */
|
|
21
|
+
export function tokenizeSql(sql) {
|
|
22
|
+
const tokens = [];
|
|
23
|
+
const n = sql.length;
|
|
24
|
+
let i = 0;
|
|
25
|
+
// Set when the previous token ended on a `.`, so `main . tbl` folds into one name.
|
|
26
|
+
let continues = false;
|
|
27
|
+
const push = (text, quoted) => {
|
|
28
|
+
const prev = tokens[tokens.length - 1];
|
|
29
|
+
if (continues && prev) {
|
|
30
|
+
tokens[tokens.length - 1] = { text: `${prev.text}.${text}`, quoted: prev.quoted || quoted };
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
tokens.push({ text, quoted });
|
|
34
|
+
}
|
|
35
|
+
// Look ahead for the dot that joins this name to the next part. SQLite treats a
|
|
36
|
+
// COMMENT as whitespace, so `main /* … */ . _substrat_tuples` is one qualified
|
|
37
|
+
// name — skipping only spaces here would record `main` as the target and miss it.
|
|
38
|
+
let j = i;
|
|
39
|
+
for (;;) {
|
|
40
|
+
if (j < n && /\s/.test(sql[j])) {
|
|
41
|
+
j += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (sql[j] === '-' && sql[j + 1] === '-') {
|
|
45
|
+
while (j < n && sql[j] !== '\n')
|
|
46
|
+
j += 1;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (sql[j] === '/' && sql[j + 1] === '*') {
|
|
50
|
+
j += 2;
|
|
51
|
+
while (j < n && !(sql[j] === '*' && sql[j + 1] === '/'))
|
|
52
|
+
j += 1;
|
|
53
|
+
j += 2;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (sql[j] === '.') {
|
|
59
|
+
continues = true;
|
|
60
|
+
i = j + 1;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
continues = false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
while (i < n) {
|
|
67
|
+
const c = sql[i];
|
|
68
|
+
const c2 = sql[i + 1];
|
|
69
|
+
if (c === '-' && c2 === '-') {
|
|
70
|
+
while (i < n && sql[i] !== '\n')
|
|
71
|
+
i += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (c === '/' && c2 === '*') {
|
|
75
|
+
i += 2;
|
|
76
|
+
while (i < n && !(sql[i] === '*' && sql[i + 1] === '/'))
|
|
77
|
+
i += 1;
|
|
78
|
+
i += 2;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (c === "'" || c === '"' || c === '`') {
|
|
82
|
+
// A quoted identifier, or a string literal SQLite would still accept as one
|
|
83
|
+
// in a table position. The closing quote doubles to escape itself.
|
|
84
|
+
i += 1;
|
|
85
|
+
let text = '';
|
|
86
|
+
while (i < n) {
|
|
87
|
+
if (sql[i] === c) {
|
|
88
|
+
if (sql[i + 1] === c) {
|
|
89
|
+
text += c;
|
|
90
|
+
i += 2;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
i += 1;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
text += sql[i];
|
|
97
|
+
i += 1;
|
|
98
|
+
}
|
|
99
|
+
push(text, true);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (c === '[') {
|
|
103
|
+
i += 1;
|
|
104
|
+
let text = '';
|
|
105
|
+
while (i < n && sql[i] !== ']') {
|
|
106
|
+
text += sql[i];
|
|
107
|
+
i += 1;
|
|
108
|
+
}
|
|
109
|
+
i += 1;
|
|
110
|
+
push(text, true);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (/[A-Za-z_]/.test(c)) {
|
|
114
|
+
let j = i;
|
|
115
|
+
while (j < n && /[A-Za-z0-9_$]/.test(sql[j]))
|
|
116
|
+
j += 1;
|
|
117
|
+
const text = sql.slice(i, j);
|
|
118
|
+
i = j;
|
|
119
|
+
push(text, false);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
// Whitespace does not break a dotted name (`main . tbl` is one); anything else does.
|
|
123
|
+
if (!/\s/.test(c))
|
|
124
|
+
continues = false;
|
|
125
|
+
i += 1;
|
|
126
|
+
}
|
|
127
|
+
return tokens;
|
|
128
|
+
}
|
|
129
|
+
/** True when any part of a (possibly dotted, possibly quoted) name is a spine table. */
|
|
130
|
+
export function namesSpineTable(name) {
|
|
131
|
+
return name.split('.').some((part) => part.toLowerCase().startsWith(SPINE_PREFIX));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The tables a statement's `REFERENCES` clauses name, in order, unquoted and as spelled.
|
|
135
|
+
* A `REFERENCES` that is itself quoted (a column called "references") is not a keyword.
|
|
136
|
+
*/
|
|
137
|
+
export function referencedTables(sql) {
|
|
138
|
+
return referencedTablesIn(tokenizeSql(sql));
|
|
139
|
+
}
|
|
140
|
+
/** `referencedTables` over a statement already tokenized, for a caller that scans it anyway. */
|
|
141
|
+
export function referencedTablesIn(tokens) {
|
|
142
|
+
const out = [];
|
|
143
|
+
for (let i = 0; i < tokens.length - 1; i += 1) {
|
|
144
|
+
const token = tokens[i];
|
|
145
|
+
if (!token.quoted && token.text.toLowerCase() === 'references')
|
|
146
|
+
out.push(tokens[i + 1].text);
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=sql-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-tokens.js","sourceRoot":"","sources":["../src/sql-tokens.ts"],"names":[],"mapp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G,CAAC,CAAE,CAAC,IAAI,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@substrat-run/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.129.0",
|
|
4
4
|
"description": "Substrat kernel contract schemas — Zod is the source of truth (master plan D-22); OAS/JSON Schema are emitted artifacts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
".": {
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./invocation-record": {
|
|
21
|
+
"types": "./dist/invocation-record.d.ts",
|
|
22
|
+
"default": "./dist/invocation-record.js"
|
|
19
23
|
}
|
|
20
24
|
},
|
|
21
25
|
"files": [
|