@supatype/cli 0.3.2 → 0.3.4
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +153 -150
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +77 -0
- package/dist/augmentation-generator.d.ts.map +1 -1
- package/dist/augmentation-generator.js +70 -15
- package/dist/augmentation-generator.js.map +1 -1
- package/dist/cli-version-embedded.js +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +3 -3
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +29 -19
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/seed.d.ts +27 -1
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +206 -33
- package/dist/commands/seed.js.map +1 -1
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +12 -10
- package/dist/dev-compose.js.map +1 -1
- package/dist/engine-client.d.ts +1 -0
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +47 -2
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-floor.d.ts +27 -4
- package/dist/engine-floor.d.ts.map +1 -1
- package/dist/engine-floor.js +90 -9
- package/dist/engine-floor.js.map +1 -1
- package/dist/gitignore.d.ts.map +1 -1
- package/dist/gitignore.js +7 -0
- package/dist/gitignore.js.map +1 -1
- package/dist/hooks-generator.d.ts.map +1 -1
- package/dist/hooks-generator.js +18 -3
- package/dist/hooks-generator.js.map +1 -1
- package/dist/seed-connection.d.ts +60 -0
- package/dist/seed-connection.d.ts.map +1 -0
- package/dist/seed-connection.js +90 -0
- package/dist/seed-connection.js.map +1 -0
- package/dist/seed-ir.d.ts +66 -0
- package/dist/seed-ir.d.ts.map +1 -0
- package/dist/seed-ir.js +265 -0
- package/dist/seed-ir.js.map +1 -0
- package/dist/seed-runner.d.ts +44 -0
- package/dist/seed-runner.d.ts.map +1 -0
- package/dist/seed-runner.js +83 -0
- package/dist/seed-runner.js.map +1 -0
- package/dist/seed.d.ts +345 -0
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +138 -0
- package/dist/seed.js.map +1 -1
- package/dist/self-host-compose.d.ts +15 -0
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +31 -8
- package/dist/self-host-compose.js.map +1 -1
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +73 -0
- package/dist/type-extractor.js.map +1 -1
- package/dist/type-generation.d.ts +29 -0
- package/dist/type-generation.d.ts.map +1 -1
- package/dist/type-generation.js +52 -0
- package/dist/type-generation.js.map +1 -1
- package/package.json +2 -2
- package/src/augmentation-generator.ts +73 -14
- package/src/cli-version-embedded.ts +1 -1
- package/src/commands/generate.ts +7 -3
- package/src/commands/init.ts +31 -21
- package/src/commands/seed.ts +294 -44
- package/src/dev-compose.ts +12 -11
- package/src/engine-client.ts +52 -3
- package/src/engine-floor.ts +100 -9
- package/src/gitignore.ts +7 -0
- package/src/hooks-generator.ts +21 -6
- package/src/seed-connection.ts +146 -0
- package/src/seed-ir.ts +311 -0
- package/src/seed-runner.ts +109 -0
- package/src/seed.ts +408 -0
- package/src/self-host-compose.ts +32 -8
- package/src/type-extractor.ts +101 -0
- package/src/type-generation.ts +64 -0
- package/tests/access-composition.test.ts +123 -0
- package/tests/augmentation-generator.test.ts +149 -9
- package/tests/db-published-and-addressable.test.ts +69 -0
- package/tests/engine-floor.test.ts +93 -0
- package/tests/fixtures/seed_golden_ir.json +186 -0
- package/tests/runtime-contract.test.ts +31 -6
- package/tests/seed-connection.test.ts +158 -0
- package/tests/seed-ir.test.ts +436 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/seed.d.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a project's seed file imports.
|
|
3
|
+
*
|
|
4
|
+
* Two contracts live here. `sql()` is the old one: the author opens a connection, writes
|
|
5
|
+
* statements and closes it. It is unchanged and still supported, because every existing
|
|
6
|
+
* project uses it.
|
|
7
|
+
*
|
|
8
|
+
* The rest is the new one. A seed exports a function, the runner hands it a `db` typed from
|
|
9
|
+
* the project's schema, and the calls it makes are **collected, not executed**: they become
|
|
10
|
+
* a seed IR document that the engine validates, orders, batches and runs in one
|
|
11
|
+
* transaction.
|
|
12
|
+
*
|
|
13
|
+
* **Nothing here connects to a database, and nothing here builds SQL.** That is the point of
|
|
14
|
+
* the split: the hard parts, ordering a foreign-key graph, batching, mapping a Postgres
|
|
15
|
+
* error back to the schema, are written once in the engine rather than once per language.
|
|
16
|
+
* This file is the part that has to exist per language, and it is deliberately small enough
|
|
17
|
+
* to be worth writing seven times.
|
|
18
|
+
*/
|
|
1
19
|
import pg from "pg";
|
|
2
20
|
export interface SeedSql {
|
|
3
21
|
(strings: TemplateStringsArray, ...values: unknown[]): Promise<pg.QueryResult>;
|
|
@@ -5,4 +23,331 @@ export interface SeedSql {
|
|
|
5
23
|
}
|
|
6
24
|
/** Lightweight tagged-template SQL helper for project `seed.ts` scripts. */
|
|
7
25
|
export declare function sql(connectionString: string): SeedSql;
|
|
26
|
+
/**
|
|
27
|
+
* A value the database computes, rather than one the seed hardcodes.
|
|
28
|
+
*
|
|
29
|
+
* The same operand set the schema's access rules use, serialised the same way. Not a second
|
|
30
|
+
* vocabulary: forking one for seeds would need a second validator and a second SQL
|
|
31
|
+
* renderer, and would re-litigate decisions the engine has already made and documented.
|
|
32
|
+
*/
|
|
33
|
+
export type Operand<C extends string = string> = {
|
|
34
|
+
kind: "literal";
|
|
35
|
+
value: LiteralValue;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "column";
|
|
38
|
+
name: C;
|
|
39
|
+
} | {
|
|
40
|
+
kind: "now";
|
|
41
|
+
} | {
|
|
42
|
+
kind: "startOf";
|
|
43
|
+
unit: TruncUnit;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "ago";
|
|
46
|
+
amount: number;
|
|
47
|
+
unit: TimeUnit;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "fromNow";
|
|
50
|
+
amount: number;
|
|
51
|
+
unit: TimeUnit;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "after";
|
|
54
|
+
base: Operand<C>;
|
|
55
|
+
interval: IntervalSpec;
|
|
56
|
+
} | {
|
|
57
|
+
kind: "before";
|
|
58
|
+
base: Operand<C>;
|
|
59
|
+
interval: IntervalSpec;
|
|
60
|
+
};
|
|
61
|
+
export type LiteralValue = string | number | boolean;
|
|
62
|
+
export type TruncUnit = "day" | "week" | "month" | "year";
|
|
63
|
+
export type TimeUnit = "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years";
|
|
64
|
+
/**
|
|
65
|
+
* A span of time, in any combination of units.
|
|
66
|
+
*
|
|
67
|
+
* Multi-unit because a fixture calendar wants "thirty days from now at 09:00", which a
|
|
68
|
+
* single `{ amount, unit }` cannot say. Components are non-negative: the direction lives in
|
|
69
|
+
* the operand's name, so that `ago` reads as itself rather than as a double negative.
|
|
70
|
+
*/
|
|
71
|
+
export interface IntervalSpec {
|
|
72
|
+
years?: number;
|
|
73
|
+
months?: number;
|
|
74
|
+
weeks?: number;
|
|
75
|
+
days?: number;
|
|
76
|
+
hours?: number;
|
|
77
|
+
minutes?: number;
|
|
78
|
+
seconds?: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A time the database evaluates.
|
|
82
|
+
*
|
|
83
|
+
* Its own type so a generated builder can accept it on date-like columns and nowhere else:
|
|
84
|
+
* `expr.now()` assigned to a title does not compile.
|
|
85
|
+
*/
|
|
86
|
+
export type TimeExpr = Extract<Operand, {
|
|
87
|
+
kind: "now" | "startOf" | "ago" | "fromNow" | "after" | "before";
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* The column's own default.
|
|
91
|
+
*
|
|
92
|
+
* Distinct from leaving the field out. Omission means "do not write this column", which on
|
|
93
|
+
* the update half of an upsert keeps the existing value; this means "put it back to the
|
|
94
|
+
* default". Both are wanted and only one can be spelled by absence.
|
|
95
|
+
*/
|
|
96
|
+
export interface DefaultExpr {
|
|
97
|
+
readonly $default: true;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Values the database computes.
|
|
101
|
+
*
|
|
102
|
+
* Deliberately database-side rather than computed here. A client-computed `daysFromNow(30)`
|
|
103
|
+
* produces a different instant on every run, so a builder emitting it could never reproduce
|
|
104
|
+
* a checked-in fixture; and one IR applied to several environments at different times would
|
|
105
|
+
* give every one of them the same hardcoded instant, which for a fixture calendar is never
|
|
106
|
+
* what people mean.
|
|
107
|
+
*/
|
|
108
|
+
export declare const expr: {
|
|
109
|
+
/** `now()`, optionally shifted forward. */
|
|
110
|
+
readonly now: (after?: IntervalSpec) => TimeExpr;
|
|
111
|
+
/** `now()` shifted back. */
|
|
112
|
+
readonly ago: (before: IntervalSpec) => TimeExpr;
|
|
113
|
+
/** The start of the current day, week, month or year, optionally shifted forward. */
|
|
114
|
+
readonly startOf: (unit: TruncUnit, after?: IntervalSpec) => TimeExpr;
|
|
115
|
+
/** The start of a period, shifted back. */
|
|
116
|
+
readonly startOfBefore: (unit: TruncUnit, amount: IntervalSpec) => TimeExpr;
|
|
117
|
+
/** The column's own default. */
|
|
118
|
+
readonly default: () => DefaultExpr;
|
|
119
|
+
};
|
|
120
|
+
export type CompareOp = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "like";
|
|
121
|
+
/**
|
|
122
|
+
* A condition on rows, in the schema's own rule language.
|
|
123
|
+
*
|
|
124
|
+
* The engine already parses, validates and compiles this tree for every RLS policy it
|
|
125
|
+
* writes, so a seed condition is that tree scoped to a model rather than anything new. A
|
|
126
|
+
* person who has written `Eq<"status", Literal<"published">>` in their schema already knows
|
|
127
|
+
* this language.
|
|
128
|
+
*/
|
|
129
|
+
export type Predicate<C extends string = string> = {
|
|
130
|
+
type: "compare";
|
|
131
|
+
left: Operand<C>;
|
|
132
|
+
op: CompareOp;
|
|
133
|
+
right: Operand<C>;
|
|
134
|
+
} | {
|
|
135
|
+
type: "any";
|
|
136
|
+
rules: Predicate<C>[];
|
|
137
|
+
} | {
|
|
138
|
+
type: "all";
|
|
139
|
+
rules: Predicate<C>[];
|
|
140
|
+
} | {
|
|
141
|
+
type: "not";
|
|
142
|
+
rule: Predicate<C>;
|
|
143
|
+
} | {
|
|
144
|
+
type: "nullCheck";
|
|
145
|
+
operand: Operand<C>;
|
|
146
|
+
isNull: boolean;
|
|
147
|
+
} | {
|
|
148
|
+
type: "in";
|
|
149
|
+
column: C;
|
|
150
|
+
source: {
|
|
151
|
+
kind: "literal";
|
|
152
|
+
values: LiteralValue[];
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
export declare const eq: <C extends string>(column: C, value: LiteralValue) => Predicate<C>;
|
|
156
|
+
export declare const neq: <C extends string>(column: C, value: LiteralValue) => Predicate<C>;
|
|
157
|
+
export declare const gt: <C extends string>(column: C, value: LiteralValue) => Predicate<C>;
|
|
158
|
+
export declare const gte: <C extends string>(column: C, value: LiteralValue) => Predicate<C>;
|
|
159
|
+
export declare const lt: <C extends string>(column: C, value: LiteralValue) => Predicate<C>;
|
|
160
|
+
export declare const lte: <C extends string>(column: C, value: LiteralValue) => Predicate<C>;
|
|
161
|
+
export declare const like: <C extends string>(column: C, pattern: string) => Predicate<C>;
|
|
162
|
+
export declare const isNull: <C extends string>(column: C) => Predicate<C>;
|
|
163
|
+
export declare const notNull: <C extends string>(column: C) => Predicate<C>;
|
|
164
|
+
/** Every rule must hold. */
|
|
165
|
+
export declare const and: <C extends string>(...rules: Predicate<C>[]) => Predicate<C>;
|
|
166
|
+
/** Any one rule holding is enough. */
|
|
167
|
+
export declare const or: <C extends string>(...rules: Predicate<C>[]) => Predicate<C>;
|
|
168
|
+
export declare const not: <C extends string>(rule: Predicate<C>) => Predicate<C>;
|
|
169
|
+
/**
|
|
170
|
+
* The column's value is one of these.
|
|
171
|
+
*
|
|
172
|
+
* `oneOf` rather than `in`, which is a reserved word and cannot be an identifier.
|
|
173
|
+
*/
|
|
174
|
+
export declare const oneOf: <C extends string>(column: C, values: readonly LiteralValue[]) => Predicate<C>;
|
|
175
|
+
/** A value produced by an earlier operation in the same document. */
|
|
176
|
+
export interface RefValue {
|
|
177
|
+
readonly $ref: string;
|
|
178
|
+
}
|
|
179
|
+
/** An exact decimal, kept as text because JSON has no decimal type. */
|
|
180
|
+
export interface NumericValue {
|
|
181
|
+
readonly $numeric: string;
|
|
182
|
+
}
|
|
183
|
+
export type SeedValue = string | number | boolean | null | readonly SeedValue[] | RefValue | NumericValue | DefaultExpr | Operand | {
|
|
184
|
+
readonly [key: string]: SeedValue | undefined;
|
|
185
|
+
};
|
|
186
|
+
export type SeedData = Record<string, SeedValue>;
|
|
187
|
+
export type SeedOperation = {
|
|
188
|
+
op: "create";
|
|
189
|
+
model: string;
|
|
190
|
+
id?: string;
|
|
191
|
+
data: SeedData;
|
|
192
|
+
} | {
|
|
193
|
+
op: "createMany";
|
|
194
|
+
model: string;
|
|
195
|
+
rows: SeedData[];
|
|
196
|
+
} | {
|
|
197
|
+
op: "upsert";
|
|
198
|
+
model: string;
|
|
199
|
+
id?: string;
|
|
200
|
+
where: SeedData;
|
|
201
|
+
data: SeedData;
|
|
202
|
+
} | {
|
|
203
|
+
op: "sql";
|
|
204
|
+
text: string;
|
|
205
|
+
params?: SeedValue[];
|
|
206
|
+
} | {
|
|
207
|
+
op: "group";
|
|
208
|
+
if?: SeedCondition;
|
|
209
|
+
operations: SeedOperation[];
|
|
210
|
+
};
|
|
211
|
+
export type SeedCondition = {
|
|
212
|
+
kind: "exists";
|
|
213
|
+
model: string;
|
|
214
|
+
where?: Predicate;
|
|
215
|
+
} | {
|
|
216
|
+
kind: "notExists";
|
|
217
|
+
model: string;
|
|
218
|
+
where?: Predicate;
|
|
219
|
+
} | {
|
|
220
|
+
kind: "environment";
|
|
221
|
+
name: string;
|
|
222
|
+
};
|
|
223
|
+
/** One seed document, as the engine reads it. */
|
|
224
|
+
export interface SeedIr {
|
|
225
|
+
irVersion: 1;
|
|
226
|
+
schemaFingerprint: string;
|
|
227
|
+
operations: SeedOperation[];
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* What the runtime needs to know about a model and cannot tell from a value.
|
|
231
|
+
*
|
|
232
|
+
* Written by the generator, read by the collector. Three facts, each of which changes how a
|
|
233
|
+
* value is encoded and none of which is visible at runtime: which columns are exact
|
|
234
|
+
* decimals, which hold a time, and which fields are relations to what.
|
|
235
|
+
*/
|
|
236
|
+
export interface ModelManifest {
|
|
237
|
+
model: string;
|
|
238
|
+
table: string;
|
|
239
|
+
/** Columns where a number would lose precision, so the value travels as an exact decimal. */
|
|
240
|
+
numeric: readonly string[];
|
|
241
|
+
/** Columns that hold an instant, so a `Date` is rendered as one. */
|
|
242
|
+
temporal: readonly string[];
|
|
243
|
+
relations: Readonly<Record<string, {
|
|
244
|
+
kind: RelationKind;
|
|
245
|
+
target: string;
|
|
246
|
+
}>>;
|
|
247
|
+
}
|
|
248
|
+
export type RelationKind = "belongsTo" | "hasOne" | "hasMany" | "manyToMany";
|
|
249
|
+
/** What a model exposes on `db`. */
|
|
250
|
+
export interface ModelApi<TCreate, TWhere, TRef> {
|
|
251
|
+
/** Insert one row, and hand back something later operations can point at. */
|
|
252
|
+
create(data: TCreate, options?: {
|
|
253
|
+
id?: string;
|
|
254
|
+
}): TRef;
|
|
255
|
+
/**
|
|
256
|
+
* Insert many rows of one model in one statement.
|
|
257
|
+
*
|
|
258
|
+
* Not sugar for repeated `create`: a per-row API is how a seed of a few thousand rows
|
|
259
|
+
* becomes a few thousand round trips.
|
|
260
|
+
*/
|
|
261
|
+
createMany(rows: readonly TCreate[]): void;
|
|
262
|
+
/**
|
|
263
|
+
* Insert, or update the row the `where` columns already identify.
|
|
264
|
+
*
|
|
265
|
+
* The primary operation for a seed, because seeds get re-run and idempotency is the thing
|
|
266
|
+
* every hand-written one gets wrong.
|
|
267
|
+
*/
|
|
268
|
+
upsert(args: {
|
|
269
|
+
where: TWhere;
|
|
270
|
+
data: TCreate;
|
|
271
|
+
id?: string;
|
|
272
|
+
}): TRef;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Filled in by the generated builder, through declaration merging.
|
|
276
|
+
*
|
|
277
|
+
* Empty here so the runtime compiles on its own, and so a project that has not run
|
|
278
|
+
* `supatype generate` yet gets a loosely typed `db` rather than a module that does not
|
|
279
|
+
* resolve.
|
|
280
|
+
*/
|
|
281
|
+
export interface SupatypeSeedRegistry {
|
|
282
|
+
/** Never set. Present so the interface is not empty, which some lint rules refuse. */
|
|
283
|
+
readonly __generated?: never;
|
|
284
|
+
}
|
|
285
|
+
type FallbackModel = ModelApi<SeedData, SeedData, Record<string, RefValue>>;
|
|
286
|
+
type RegisteredModels = SupatypeSeedRegistry extends {
|
|
287
|
+
models: infer M;
|
|
288
|
+
} ? M : Record<string, FallbackModel>;
|
|
289
|
+
type RegisteredCondition = SupatypeSeedRegistry extends {
|
|
290
|
+
condition: infer C;
|
|
291
|
+
} ? C : SeedConditionInput;
|
|
292
|
+
/** The condition surface, before a generated builder narrows it to this schema's models. */
|
|
293
|
+
export type SeedConditionInput = {
|
|
294
|
+
exists: {
|
|
295
|
+
model: string;
|
|
296
|
+
where?: Predicate;
|
|
297
|
+
};
|
|
298
|
+
} | {
|
|
299
|
+
notExists: {
|
|
300
|
+
model: string;
|
|
301
|
+
where?: Predicate;
|
|
302
|
+
};
|
|
303
|
+
} | {
|
|
304
|
+
environment: string;
|
|
305
|
+
};
|
|
306
|
+
export type SeedDb = RegisteredModels & {
|
|
307
|
+
/**
|
|
308
|
+
* Run a block only when the database says so.
|
|
309
|
+
*
|
|
310
|
+
* Plain `if` already works for anything decided from the program's own inputs, and should
|
|
311
|
+
* be preferred. This is for the one thing plain `if` cannot do: branch on database state,
|
|
312
|
+
* which the builder cannot read because it never connects. The condition travels in the
|
|
313
|
+
* IR and the engine evaluates it at this position, inside the transaction.
|
|
314
|
+
*/
|
|
315
|
+
$if(condition: RegisteredCondition, body: () => void): void;
|
|
316
|
+
/**
|
|
317
|
+
* A raw statement, in the same transaction and the same order as everything else.
|
|
318
|
+
*
|
|
319
|
+
* Inside the IR rather than offered as a side channel, so a seed that mixes typed
|
|
320
|
+
* operations and raw SQL still runs as one thing instead of the author opening a second
|
|
321
|
+
* connection the engine knows nothing about.
|
|
322
|
+
*/
|
|
323
|
+
$sql(text: string, params?: readonly SeedValue[]): void;
|
|
324
|
+
};
|
|
325
|
+
/** What the runner hands a seed's default export. */
|
|
326
|
+
export interface SeedContext {
|
|
327
|
+
db: SeedDb;
|
|
328
|
+
expr: typeof expr;
|
|
329
|
+
/** Print a line, through the runner's own output rather than straight to stdout. */
|
|
330
|
+
log: (message: string) => void;
|
|
331
|
+
/** The environment this run targets, when the runner was told one. */
|
|
332
|
+
environment?: string | undefined;
|
|
333
|
+
}
|
|
334
|
+
/** What a seed file may ask of the runner. */
|
|
335
|
+
export interface SeedConfig {
|
|
336
|
+
/** Run this document in a transaction. Default true, and rarely worth changing. */
|
|
337
|
+
transaction?: boolean;
|
|
338
|
+
/**
|
|
339
|
+
* Apply this document at most once per environment.
|
|
340
|
+
*
|
|
341
|
+
* For a genuine one-time backfill rather than a fixture. Off by default, because seeds
|
|
342
|
+
* are idempotent upserts by design and skipping one because it ran before would turn
|
|
343
|
+
* every seed file into a one-shot migration.
|
|
344
|
+
*/
|
|
345
|
+
runOnce?: boolean;
|
|
346
|
+
}
|
|
347
|
+
/** The shape a seed module exports. */
|
|
348
|
+
export interface SeedModule {
|
|
349
|
+
default?: (context: SeedContext) => void | Promise<void>;
|
|
350
|
+
config?: SeedConfig;
|
|
351
|
+
}
|
|
352
|
+
export {};
|
|
8
353
|
//# sourceMappingURL=seed.d.ts.map
|
package/dist/seed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"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,GAAG;IACtC;;;;;;;OAOG;IACH,GAAG,CAAC,SAAS,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IAC3D;;;;;;OAMG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAAA;CACxD,CAAA;AAED,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,OAAO,IAAI,CAAA;IACjB,oFAAoF;IACpF,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,mFAAmF;IACnF,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,uCAAuC;AACvC,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB"}
|
package/dist/seed.js
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a project's seed file imports.
|
|
3
|
+
*
|
|
4
|
+
* Two contracts live here. `sql()` is the old one: the author opens a connection, writes
|
|
5
|
+
* statements and closes it. It is unchanged and still supported, because every existing
|
|
6
|
+
* project uses it.
|
|
7
|
+
*
|
|
8
|
+
* The rest is the new one. A seed exports a function, the runner hands it a `db` typed from
|
|
9
|
+
* the project's schema, and the calls it makes are **collected, not executed**: they become
|
|
10
|
+
* a seed IR document that the engine validates, orders, batches and runs in one
|
|
11
|
+
* transaction.
|
|
12
|
+
*
|
|
13
|
+
* **Nothing here connects to a database, and nothing here builds SQL.** That is the point of
|
|
14
|
+
* the split: the hard parts, ordering a foreign-key graph, batching, mapping a Postgres
|
|
15
|
+
* error back to the schema, are written once in the engine rather than once per language.
|
|
16
|
+
* This file is the part that has to exist per language, and it is deliberately small enough
|
|
17
|
+
* to be worth writing seven times.
|
|
18
|
+
*/
|
|
1
19
|
import pg from "pg";
|
|
2
20
|
/** Lightweight tagged-template SQL helper for project `seed.ts` scripts. */
|
|
3
21
|
export function sql(connectionString) {
|
|
@@ -29,4 +47,124 @@ export function sql(connectionString) {
|
|
|
29
47
|
},
|
|
30
48
|
});
|
|
31
49
|
}
|
|
50
|
+
const DEFAULT_EXPR = { $default: true };
|
|
51
|
+
const INTERVAL_UNITS = [
|
|
52
|
+
"years",
|
|
53
|
+
"months",
|
|
54
|
+
"weeks",
|
|
55
|
+
"days",
|
|
56
|
+
"hours",
|
|
57
|
+
"minutes",
|
|
58
|
+
"seconds",
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* Drop the units nobody asked for, so two equal intervals serialise the same way.
|
|
62
|
+
*
|
|
63
|
+
* A negative or fractional component is refused rather than carried. The engine's interval
|
|
64
|
+
* components are whole and unsigned, so one that is not fails to read as an operand, falls
|
|
65
|
+
* through to being a plain value, and reaches the database as JSON text in a date column.
|
|
66
|
+
* That surfaced as `invalid input syntax for type timestamp with time zone`, naming neither
|
|
67
|
+
* the field nor the real mistake. Here it names both, at the call that made it.
|
|
68
|
+
*/
|
|
69
|
+
function interval(spec) {
|
|
70
|
+
const out = {};
|
|
71
|
+
for (const unit of INTERVAL_UNITS) {
|
|
72
|
+
const value = spec[unit];
|
|
73
|
+
if (value === undefined || value === 0)
|
|
74
|
+
continue;
|
|
75
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
76
|
+
throw new TypeError(`An interval's \`${unit}\` must be a whole number and not negative, and this is ${value}. ` +
|
|
77
|
+
"The direction is in the name: use `ago` or `before` to go backwards.");
|
|
78
|
+
}
|
|
79
|
+
out[unit] = value;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function shifted(base, spec, ahead) {
|
|
84
|
+
if (spec === undefined)
|
|
85
|
+
return base;
|
|
86
|
+
const amount = interval(spec);
|
|
87
|
+
if (Object.keys(amount).length === 0)
|
|
88
|
+
return base;
|
|
89
|
+
return ahead
|
|
90
|
+
? { kind: "after", base, interval: amount }
|
|
91
|
+
: { kind: "before", base, interval: amount };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Values the database computes.
|
|
95
|
+
*
|
|
96
|
+
* Deliberately database-side rather than computed here. A client-computed `daysFromNow(30)`
|
|
97
|
+
* produces a different instant on every run, so a builder emitting it could never reproduce
|
|
98
|
+
* a checked-in fixture; and one IR applied to several environments at different times would
|
|
99
|
+
* give every one of them the same hardcoded instant, which for a fixture calendar is never
|
|
100
|
+
* what people mean.
|
|
101
|
+
*/
|
|
102
|
+
export const expr = {
|
|
103
|
+
/** `now()`, optionally shifted forward. */
|
|
104
|
+
now(after) {
|
|
105
|
+
return shifted({ kind: "now" }, after, true);
|
|
106
|
+
},
|
|
107
|
+
/** `now()` shifted back. */
|
|
108
|
+
ago(before) {
|
|
109
|
+
return shifted({ kind: "now" }, before, false);
|
|
110
|
+
},
|
|
111
|
+
/** The start of the current day, week, month or year, optionally shifted forward. */
|
|
112
|
+
startOf(unit, after) {
|
|
113
|
+
return shifted({ kind: "startOf", unit }, after, true);
|
|
114
|
+
},
|
|
115
|
+
/** The start of a period, shifted back. */
|
|
116
|
+
startOfBefore(unit, amount) {
|
|
117
|
+
return shifted({ kind: "startOf", unit }, amount, false);
|
|
118
|
+
},
|
|
119
|
+
/** The column's own default. */
|
|
120
|
+
default() {
|
|
121
|
+
return DEFAULT_EXPR;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
function compare(column, op, value) {
|
|
125
|
+
return {
|
|
126
|
+
type: "compare",
|
|
127
|
+
left: { kind: "column", name: column },
|
|
128
|
+
op,
|
|
129
|
+
right: { kind: "literal", value },
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export const eq = (column, value) => compare(column, "eq", value);
|
|
133
|
+
export const neq = (column, value) => compare(column, "neq", value);
|
|
134
|
+
export const gt = (column, value) => compare(column, "gt", value);
|
|
135
|
+
export const gte = (column, value) => compare(column, "gte", value);
|
|
136
|
+
export const lt = (column, value) => compare(column, "lt", value);
|
|
137
|
+
export const lte = (column, value) => compare(column, "lte", value);
|
|
138
|
+
export const like = (column, pattern) => compare(column, "like", pattern);
|
|
139
|
+
export const isNull = (column) => ({
|
|
140
|
+
type: "nullCheck",
|
|
141
|
+
operand: { kind: "column", name: column },
|
|
142
|
+
isNull: true,
|
|
143
|
+
});
|
|
144
|
+
export const notNull = (column) => ({
|
|
145
|
+
type: "nullCheck",
|
|
146
|
+
operand: { kind: "column", name: column },
|
|
147
|
+
isNull: false,
|
|
148
|
+
});
|
|
149
|
+
/** Every rule must hold. */
|
|
150
|
+
export const and = (...rules) => ({
|
|
151
|
+
type: "all",
|
|
152
|
+
rules,
|
|
153
|
+
});
|
|
154
|
+
/** Any one rule holding is enough. */
|
|
155
|
+
export const or = (...rules) => ({
|
|
156
|
+
type: "any",
|
|
157
|
+
rules,
|
|
158
|
+
});
|
|
159
|
+
export const not = (rule) => ({ type: "not", rule });
|
|
160
|
+
/**
|
|
161
|
+
* The column's value is one of these.
|
|
162
|
+
*
|
|
163
|
+
* `oneOf` rather than `in`, which is a reserved word and cannot be an identifier.
|
|
164
|
+
*/
|
|
165
|
+
export const oneOf = (column, values) => ({
|
|
166
|
+
type: "in",
|
|
167
|
+
column,
|
|
168
|
+
source: { kind: "literal", values: [...values] },
|
|
169
|
+
});
|
|
32
170
|
//# sourceMappingURL=seed.js.map
|
package/dist/seed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.js","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IA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AqB,EAAgB,EAAE,CAAC,CAAC;IAC/E,IAAI,EAAE,KAAK;IACX,KAAK;CACN,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAmB,IAAkB,EAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAElG;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,MAAS,EACT,MAA+B,EACjB,EAAE,CAAC,CAAC;IAClB,IAAI,EAAE,IAAI;IACV,MAAM;IACN,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,EAAE;CACjD,CAAC,CAAA"}
|
|
@@ -26,6 +26,21 @@ export declare function composePullNeedsIgnoreFailures(config: SupatypeProjectCo
|
|
|
26
26
|
* Uses config pin when set; otherwise CDN engine semver (Docker Hub `:latest` can lag).
|
|
27
27
|
* Does not touch `.env`, server/postgres still use compose `:latest` defaults.
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* Whether this project's database is published to the host, and so needs a `DATABASE_URL` that
|
|
31
|
+
* points at it.
|
|
32
|
+
*
|
|
33
|
+
* One function because the two halves came apart once. Publishing was made unconditional for a
|
|
34
|
+
* local stack, because seeding is a host process and a database nothing on the host can reach is
|
|
35
|
+
* a database no seed can use. The code that writes `DATABASE_URL` to match kept an older
|
|
36
|
+
* condition, `overrides.engine`, so a project without a local engine build got a database
|
|
37
|
+
* published on 54329 and a `DATABASE_URL` still pointing at 5432. `supatype seed` then timed out
|
|
38
|
+
* and advised checking that the stack was running, which it was.
|
|
39
|
+
*
|
|
40
|
+
* The exception is an external database. There is no `db` container to publish, and that URL
|
|
41
|
+
* belongs to the operator: writing it once clobbered a real external Postgres.
|
|
42
|
+
*/
|
|
43
|
+
export declare function publishesDbToHost(config: SupatypeProjectConfig): boolean;
|
|
29
44
|
export declare function schemaEngineImageForPush(config: SupatypeProjectConfig): Promise<string | undefined>;
|
|
30
45
|
/**
|
|
31
46
|
* SeaweedFS reads its identities from a file, so the stack's credentials are a generated artifact
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"self-host-compose.d.ts","sourceRoot":"","sources":["../src/self-host-compose.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAElF,OAAO,EASL,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAA;AAM5B,OAAO,EAA+B,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAG5F,yEAAyE;AACzE,eAAO,MAAM,6BAA6B,wFAIhC,CAAA;AAEV,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,iQAQzB,CAAA;AAwBV,KAAK,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAA;AAE1D,gEAAgE;AAChE,wBAAgB,cAAc,CAC5B,SAAS,EAAE,kBAAkB,EAC7B,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,qBAAqB,GAC7B,MAAM,CAeR;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAe3F;AAED,8FAA8F;AAC9F,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAQ/D;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAS1E;AAcD;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,qBAAqB,EAC7B,GAAG,GAAE,MAAsB,GAC1B,OAAO,CAGT;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAM7B;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAahD;AAED,M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fatalError } from "./ui/fatal.js";
|
|
6
6
|
import { apiSchemaList, externalDatabaseUrl, hooksPathFromProject, preferredFunctionsPathFromProject, realtimeEnabled, serviceRoleRoutes, selfHostTlsEnabled, usesExternalDatabase, } from "./project-config.js";
|
|
7
|
-
import {
|
|
7
|
+
import { hasStudioOverride, pinnedVersion, fetchLatestVersion, VERSION_PIN_LOCAL } from "./binary-cache.js";
|
|
8
8
|
import { buildKongDeclarative } from "./kong-config.js";
|
|
9
9
|
import { keyspaceInPostgres } from "./cache-provider.js";
|
|
10
10
|
import { STUDIO_DEV_PORT } from "./studio-dev-server.js";
|
|
11
|
-
import {
|
|
11
|
+
import { readEnvFile } from "./env-file.js";
|
|
12
12
|
import { fieldMaskingTierFromProject } from "./field-masking-tier.js";
|
|
13
13
|
import { projectHasVersionedModels } from "./model-versioning.js";
|
|
14
14
|
/** Env keys written when `versions` pins exist in supatype.config.ts. */
|
|
@@ -133,6 +133,23 @@ export function composePullNeedsIgnoreFailures(config, cwd = process.cwd()) {
|
|
|
133
133
|
* Uses config pin when set; otherwise CDN engine semver (Docker Hub `:latest` can lag).
|
|
134
134
|
* Does not touch `.env`, server/postgres still use compose `:latest` defaults.
|
|
135
135
|
*/
|
|
136
|
+
/**
|
|
137
|
+
* Whether this project's database is published to the host, and so needs a `DATABASE_URL` that
|
|
138
|
+
* points at it.
|
|
139
|
+
*
|
|
140
|
+
* One function because the two halves came apart once. Publishing was made unconditional for a
|
|
141
|
+
* local stack, because seeding is a host process and a database nothing on the host can reach is
|
|
142
|
+
* a database no seed can use. The code that writes `DATABASE_URL` to match kept an older
|
|
143
|
+
* condition, `overrides.engine`, so a project without a local engine build got a database
|
|
144
|
+
* published on 54329 and a `DATABASE_URL` still pointing at 5432. `supatype seed` then timed out
|
|
145
|
+
* and advised checking that the stack was running, which it was.
|
|
146
|
+
*
|
|
147
|
+
* The exception is an external database. There is no `db` container to publish, and that URL
|
|
148
|
+
* belongs to the operator: writing it once clobbered a real external Postgres.
|
|
149
|
+
*/
|
|
150
|
+
export function publishesDbToHost(config) {
|
|
151
|
+
return !usesExternalDatabase(config);
|
|
152
|
+
}
|
|
136
153
|
export async function schemaEngineImageForPush(config) {
|
|
137
154
|
const pinned = pinnedVersion("engine", config);
|
|
138
155
|
if (pinned === VERSION_PIN_LOCAL)
|
|
@@ -331,12 +348,18 @@ ${studioService}
|
|
|
331
348
|
: ` - server
|
|
332
349
|
- studio
|
|
333
350
|
- control-plane`;
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
|
|
351
|
+
// The database is always reachable from the host.
|
|
352
|
+
//
|
|
353
|
+
// It used to be published in dev only when something was known to need it, which was a host
|
|
354
|
+
// engine build or a project that had named `SUPATYPE_DEV_DB_PORT`. Seeding is now a host
|
|
355
|
+
// process: the CLI resolves a connection string and the engine connects over TCP. Under the old
|
|
356
|
+
// rule a fresh `supatype init` produced a stack whose database nothing on the host could reach,
|
|
357
|
+
// so the first `supatype seed` got ECONNREFUSED and the remedy was an environment variable
|
|
358
|
+
// nobody had reason to know about.
|
|
359
|
+
//
|
|
360
|
+
// This exposes nothing new: the dev port below is bound to `127.0.0.1`, so it is reachable from
|
|
361
|
+
// this machine and from nowhere else.
|
|
362
|
+
const publishDbToHost = publishesDbToHost(config);
|
|
340
363
|
const dbPorts = publishDbToHost
|
|
341
364
|
? devLocal
|
|
342
365
|
? ` ports:
|