@prisma/composer-prisma-cloud 0.1.0 → 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/dist/control.d.mts +52 -38
- package/dist/control.mjs +1050 -326
- package/dist/control.mjs.map +1 -1
- package/dist/cron/index.d.mts +9 -6
- package/dist/cron/index.mjs +114 -5
- package/dist/cron/index.mjs.map +1 -1
- package/dist/cron/scheduler-entrypoint.mjs +281 -111
- package/dist/cron/scheduler-entrypoint.mjs.map +1 -1
- package/dist/cron/scheduler-service.mjs +114 -5
- package/dist/cron/scheduler-service.mjs.map +1 -1
- package/dist/index.d.mts +118 -23
- package/dist/index.mjs +44 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{prisma-next-COrwlg3N.mjs → prisma-next-DlU01kXJ-2sP5mQb6.mjs} +3 -3
- package/dist/prisma-next-DlU01kXJ-2sP5mQb6.mjs.map +1 -0
- package/dist/prisma-next.d.mts +1 -2
- package/dist/prisma-next.mjs +1 -1
- package/dist/provisioned-edges-DIQAR4q4-Bn9op-JG.mjs +151 -0
- package/dist/provisioned-edges-DIQAR4q4-Bn9op-JG.mjs.map +1 -0
- package/dist/{serializer-C2CsA7xm-29Eg2Tjl.mjs → serializer-CX4VYdf_-KKGoAxfx.mjs} +61 -7
- package/dist/serializer-CX4VYdf_-KKGoAxfx.mjs.map +1 -0
- package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts +36 -0
- package/dist/storage/index.d.mts +5 -16
- package/dist/storage/index.mjs +114 -3
- package/dist/storage/index.mjs.map +1 -1
- package/dist/storage/storage-entrypoint.mjs +7242 -12
- package/dist/storage/storage-entrypoint.mjs.map +1 -1
- package/dist/storage/storage-service.mjs +114 -3
- package/dist/storage/storage-service.mjs.map +1 -1
- package/dist/storage/testing.d.mts +7 -4
- package/dist/storage/testing.mjs.map +1 -1
- package/dist/streams/index.d.mts +250 -0
- package/dist/streams/index.mjs +4058 -0
- package/dist/streams/index.mjs.map +1 -0
- package/dist/streams/streams-entrypoint.mjs +48095 -0
- package/dist/streams/streams-entrypoint.mjs.map +1 -0
- package/dist/streams/streams-service.mjs +811 -0
- package/dist/streams/streams-service.mjs.map +1 -0
- package/dist/streams/testing.d.mts +33 -0
- package/dist/streams/testing.mjs +31335 -0
- package/dist/streams/testing.mjs.map +1 -0
- package/dist/testing.d.mts +1 -2
- package/dist/testing.mjs +1 -1
- package/dist/testing.mjs.map +1 -1
- package/package.json +27 -22
- package/dist/prisma-next-COrwlg3N.mjs.map +0 -1
- package/dist/serializer-C2CsA7xm-29Eg2Tjl.mjs.map +0 -1
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { dependency, hydrateSecrets, hydrateSync, number, provisionNeed, resource, service, string } from "@prisma/composer";
|
|
2
|
+
import { blindCast } from "@prisma/composer/casts";
|
|
3
|
+
import { RPC_PEER_KEY } from "@prisma/composer/service-rpc";
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
import node from "@prisma/composer/node";
|
|
6
|
+
blindCast(Symbol.for("prisma:prisma-cloud-secret-source"));
|
|
7
|
+
/**
|
|
8
|
+
* Walks a node's own params, then each dependency input's connection params —
|
|
9
|
+
* the same enumeration order `configOf` uses, but carrying the raw
|
|
10
|
+
* `ConfigParam` (with its `serialize`/`deserialize`) instead of a pure-data
|
|
11
|
+
* projection.
|
|
12
|
+
*/
|
|
13
|
+
function paramEntries(node) {
|
|
14
|
+
const entries = [];
|
|
15
|
+
for (const [input, value] of Object.entries(node.inputs)) {
|
|
16
|
+
if (typeof value !== "object" || value === null) continue;
|
|
17
|
+
const params = blindCast(value).connection.params;
|
|
18
|
+
for (const [name, param] of Object.entries(params)) entries.push({
|
|
19
|
+
owner: { input },
|
|
20
|
+
name,
|
|
21
|
+
param
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
for (const [name, param] of Object.entries(node.params)) entries.push({
|
|
25
|
+
owner: "service",
|
|
26
|
+
name,
|
|
27
|
+
param
|
|
28
|
+
});
|
|
29
|
+
return entries;
|
|
30
|
+
}
|
|
31
|
+
const configKey = (address, d) => {
|
|
32
|
+
const segments = address.split(".").filter((s) => s.length > 0);
|
|
33
|
+
const owner = d.owner === "service" ? [] : [d.owner.input];
|
|
34
|
+
return [
|
|
35
|
+
"COMPOSER",
|
|
36
|
+
...segments,
|
|
37
|
+
...owner,
|
|
38
|
+
d.name
|
|
39
|
+
].join("_").toUpperCase();
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Typed value → its stored string. Service-own literals are JSON-encoded; a
|
|
43
|
+
* dependency-input value is a provisioning ref at deploy (and a resolved
|
|
44
|
+
* string at boot) and passes through untouched — LANDMINE: JSON-encoding it
|
|
45
|
+
* would break the ordering edge Alchemy resolves through it.
|
|
46
|
+
*/
|
|
47
|
+
function encode(owner, value) {
|
|
48
|
+
return owner === "service" ? JSON.stringify(value) : blindCast(value);
|
|
49
|
+
}
|
|
50
|
+
/** Reverses `encode`: JSON-parse a service-own value, take a dependency-input value raw. */
|
|
51
|
+
function decode(owner, raw) {
|
|
52
|
+
return owner === "service" ? JSON.parse(raw) : raw;
|
|
53
|
+
}
|
|
54
|
+
const PARAM_POINTER_PREFIX = "@composer-param-pointer:";
|
|
55
|
+
/** True iff `raw` is a param pointer row (as opposed to a JSON-encoded literal). */
|
|
56
|
+
const isParamPointerRow = (raw) => raw.startsWith(PARAM_POINTER_PREFIX);
|
|
57
|
+
/** Reverses `encodeParamPointer`: the platform var NAME a pointer row points to. */
|
|
58
|
+
const decodeParamPointer = (raw) => raw.slice(24);
|
|
59
|
+
function coerce(raw, d, key) {
|
|
60
|
+
if (!(raw !== void 0 && raw !== "")) {
|
|
61
|
+
if (d.param.default !== void 0) return d.param.default;
|
|
62
|
+
if (d.param.optional === true) return void 0;
|
|
63
|
+
throw new Error(`missing required config param "${d.name}" (env ${key})`);
|
|
64
|
+
}
|
|
65
|
+
if (d.owner === "service" && isParamPointerRow(raw)) return coerceEnvSourcedParam(raw, d, key);
|
|
66
|
+
try {
|
|
67
|
+
return standardValidateSync(d.param.schema, decode(d.owner, raw));
|
|
68
|
+
} catch (cause) {
|
|
69
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
70
|
+
throw new Error(`invalid value for config param "${d.name}" (env ${key}): ${message}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Boot resolution for an env-sourced param: double-lookup (pointer → platform
|
|
75
|
+
* var), then the param's own schema on the raw string — no JSON decode, and
|
|
76
|
+
* no redaction (it's config, not a secret). An UNSET platform var is a loud
|
|
77
|
+
* boot failure naming both the param and the platform var; an EMPTY string is
|
|
78
|
+
* not special-cased here — it reaches the schema like any other value, so it
|
|
79
|
+
* passes iff the schema accepts it (deliberately unlike a literal param's own
|
|
80
|
+
* ""-means-absent rule, and unlike a secret's non-empty requirement).
|
|
81
|
+
*/
|
|
82
|
+
function coerceEnvSourcedParam(raw, d, key) {
|
|
83
|
+
const platformVar = decodeParamPointer(raw);
|
|
84
|
+
const value = process.env[platformVar];
|
|
85
|
+
if (value === void 0) throw new Error(`env-sourced config param "${d.name}" (env ${key} → ${platformVar}) is unset: the platform variable "${platformVar}" was not injected — the deploy did not provision it.`);
|
|
86
|
+
try {
|
|
87
|
+
return standardValidateSync(d.param.schema, value);
|
|
88
|
+
} catch (cause) {
|
|
89
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
90
|
+
throw new Error(`invalid value for env-sourced config param "${d.name}" (env ${key} → ${platformVar}): ${message}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Boot: read each declared param from env by its key, reverse the param's own
|
|
95
|
+
* serialization (missing/invalid fails loudly), assemble the typed Config.
|
|
96
|
+
* Secrets ride a separate channel (deserializeSecrets), not this one.
|
|
97
|
+
*/
|
|
98
|
+
const deserialize = (node, address) => {
|
|
99
|
+
const service = {};
|
|
100
|
+
const inputs = {};
|
|
101
|
+
for (const d of paramEntries(node)) {
|
|
102
|
+
const key = configKey(address, d);
|
|
103
|
+
const value = coerce(process.env[key], d, key);
|
|
104
|
+
if (d.owner === "service") service[d.name] = value;
|
|
105
|
+
else {
|
|
106
|
+
let bucket = inputs[d.owner.input];
|
|
107
|
+
if (bucket === void 0) {
|
|
108
|
+
bucket = {};
|
|
109
|
+
inputs[d.owner.input] = bucket;
|
|
110
|
+
}
|
|
111
|
+
bucket[d.name] = value;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
service,
|
|
116
|
+
inputs
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* run()'s setup step: write the resolved config to the environment under
|
|
121
|
+
* address-free keys (configKey("", d) + each serialize suffix), which load()
|
|
122
|
+
* reads back with no address. Uses env, not a module variable, because a
|
|
123
|
+
* framework may fork worker processes that inherit env but not memory.
|
|
124
|
+
* Writes only these keys; nothing else is touched.
|
|
125
|
+
*/
|
|
126
|
+
const stash = (node, config) => {
|
|
127
|
+
for (const d of paramEntries(node)) {
|
|
128
|
+
const value = d.owner === "service" ? config.service[d.name] : config.inputs[d.owner.input]?.[d.name];
|
|
129
|
+
if (value === void 0) continue;
|
|
130
|
+
process.env[configKey("", d)] = encode(d.owner, value);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/** The pointer-row key for a secret slot: COMPOSER_<addr>_<slot> (secrets are service-level). */
|
|
134
|
+
const secretKey = (address, slot) => configKey(address, {
|
|
135
|
+
owner: "service",
|
|
136
|
+
name: slot
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* Boot: resolve every secret slot to its value by double-lookup — read the
|
|
140
|
+
* pointer key (the platform NAME), then read that platform var. A missing
|
|
141
|
+
* pointer or a missing/empty platform value is a loud failure naming both keys.
|
|
142
|
+
* Returns a plain Record for core's `hydrateSecrets` to box.
|
|
143
|
+
*/
|
|
144
|
+
const deserializeSecrets = (node, address) => {
|
|
145
|
+
const values = {};
|
|
146
|
+
for (const slot of Object.keys(node.secretSlots)) {
|
|
147
|
+
const key = secretKey(address, slot);
|
|
148
|
+
const name = process.env[key];
|
|
149
|
+
if (name === void 0 || name === "") throw new Error(`missing secret pointer for slot "${slot}" (env ${key}) — the deploy did not write it.`);
|
|
150
|
+
const value = process.env[name];
|
|
151
|
+
if (value === void 0 || value === "") throw new Error(`secret "${slot}" is not provisioned (env ${key} → ${name}): the platform var "${name}" is unset or empty.`);
|
|
152
|
+
values[slot] = value;
|
|
153
|
+
}
|
|
154
|
+
return values;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* run()'s setup step for secrets: re-emit each slot's pointer NAME under its
|
|
158
|
+
* address-free key, so the address-free `deserializeSecrets` double-looks-up
|
|
159
|
+
* identically. Never the value — the value stays only in the platform var.
|
|
160
|
+
*/
|
|
161
|
+
const stashSecrets = (node, address) => {
|
|
162
|
+
for (const slot of Object.keys(node.secretSlots)) {
|
|
163
|
+
const name = process.env[secretKey(address, slot)];
|
|
164
|
+
if (name === void 0) continue;
|
|
165
|
+
process.env[secretKey("", slot)] = name;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Boot: for each reserved provider param, read its address-scoped row through
|
|
170
|
+
* the same `coerce` a declared param uses (JSON-decode, schema-validate), and
|
|
171
|
+
* re-emit it address-free — `stash`'s counterpart for this separate
|
|
172
|
+
* declaration space. A param is declared optional here unconditionally: an
|
|
173
|
+
* absent row means "never provisioned" (local dev, tests, a provider with no
|
|
174
|
+
* registered value for this deploy), never a boot failure, so nothing is
|
|
175
|
+
* stashed and the runtime reader that owns this slot falls back to its own
|
|
176
|
+
* pass-through behavior.
|
|
177
|
+
*/
|
|
178
|
+
function stashProviderParams(entries, address) {
|
|
179
|
+
for (const entry of entries) {
|
|
180
|
+
const d = {
|
|
181
|
+
owner: "service",
|
|
182
|
+
name: entry.name,
|
|
183
|
+
param: {
|
|
184
|
+
schema: entry.schema,
|
|
185
|
+
optional: true
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const key = configKey(address, d);
|
|
189
|
+
const value = coerce(process.env[key], d, key);
|
|
190
|
+
if (value === void 0) continue;
|
|
191
|
+
process.env[configKey("", d)] = encode("service", value);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** Synchronous Standard Schema validation — see the matching note in core's `config.ts`. */
|
|
195
|
+
function standardValidateSync(schema, value) {
|
|
196
|
+
const result = schema["~standard"].validate(value);
|
|
197
|
+
if (result instanceof Promise) throw new Error("config param schema validation must be synchronous — async Standard Schema validators are not supported for config params");
|
|
198
|
+
if (result.issues !== void 0) throw new Error(`config param validation failed: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
199
|
+
return result.value;
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region ../../1-prisma-cloud/1-extensions/target/dist/provisioned-edges-DIQAR4q4.mjs
|
|
203
|
+
/**
|
|
204
|
+
* RPC's reserved provider param (ADR-0030/ADR-0031): the declaration —
|
|
205
|
+
* name + schema + brand — for the accepted-keys set a provider stores, shared
|
|
206
|
+
* by `control.ts` (which registers the deploy-side `value(refs)` that mints
|
|
207
|
+
* and aggregates it — see its `rpcAcceptedKeysValue`) and `compute.ts` (which
|
|
208
|
+
* validates and stashes it at boot), so writer and reader cannot drift.
|
|
209
|
+
* Finding the edges themselves is `provisioned-edges.ts`'s generic,
|
|
210
|
+
* brand-blind scan — RPC is not special-cased anywhere in this target.
|
|
211
|
+
*
|
|
212
|
+
* This module is reachable from the RUNTIME/authoring side — it must never
|
|
213
|
+
* import `@internal/lowering` or `effect`, or those tokens leak into a user
|
|
214
|
+
* service's bundle (the deploy-side `value(refs)` lives in control.ts, the
|
|
215
|
+
* control-plane-only entry).
|
|
216
|
+
*/
|
|
217
|
+
/**
|
|
218
|
+
* The reserved provider param for RPC's accepted-keys set: the var name is
|
|
219
|
+
* `RPC_ACCEPTED_KEYS`, derived through `configKey` at both ends
|
|
220
|
+
* (`configKey(address, …)` at deploy, `configKey('', …)` at boot — the
|
|
221
|
+
* address-free form is `@internal/service-rpc`'s `RPC_ACCEPTED_KEYS_ENV`). `brand` is
|
|
222
|
+
* `RPC_PEER_KEY`, the same brand `perBindingToken()`'s need carries — control.ts
|
|
223
|
+
* looks its `value(refs)` up by this field.
|
|
224
|
+
*/
|
|
225
|
+
const RPC_ACCEPTED_KEYS_PARAM = {
|
|
226
|
+
name: "RPC_ACCEPTED_KEYS",
|
|
227
|
+
schema: type("string[]"),
|
|
228
|
+
brand: RPC_PEER_KEY
|
|
229
|
+
};
|
|
230
|
+
/** ADR-0031's need brand for the streams module's bearer key — control.ts registers the provisioner under this. */
|
|
231
|
+
const STREAMS_API_KEY = Symbol.for("prisma:streams/api-key");
|
|
232
|
+
/**
|
|
233
|
+
* The provisioning need `durableStreams()`'s `apiKey` param declares: an
|
|
234
|
+
* unguessable value the target mints ONCE PER PROVIDER (not per edge) —
|
|
235
|
+
* `@prisma/streams-server` authenticates a single `API_KEY`, so every
|
|
236
|
+
* consumer of one streams module must present the same value. Per-provider
|
|
237
|
+
* cardinality is provisioner policy (ADR-0031), invisible to core.
|
|
238
|
+
*/
|
|
239
|
+
const streamsApiKeyNeed = () => provisionNeed(STREAMS_API_KEY);
|
|
240
|
+
/**
|
|
241
|
+
* The reserved provider param for the streams bearer key: the var name is
|
|
242
|
+
* `STREAMS_API_KEY`. `brand` is `STREAMS_API_KEY` itself (the same symbol
|
|
243
|
+
* `streamsApiKeyNeed()`'s need carries) — control.ts looks its `value(refs)`
|
|
244
|
+
* up by this field.
|
|
245
|
+
*/
|
|
246
|
+
const STREAMS_API_KEY_PARAM = {
|
|
247
|
+
name: "STREAMS_API_KEY",
|
|
248
|
+
schema: type("string"),
|
|
249
|
+
brand: STREAMS_API_KEY
|
|
250
|
+
};
|
|
251
|
+
configKey("", {
|
|
252
|
+
owner: "service",
|
|
253
|
+
name: STREAMS_API_KEY_PARAM.name
|
|
254
|
+
});
|
|
255
|
+
const RESERVED_PROVIDER_PARAMS = [RPC_ACCEPTED_KEYS_PARAM, STREAMS_API_KEY_PARAM];
|
|
256
|
+
blindCast(Symbol.for("prisma:prisma-cloud-param-source"));
|
|
257
|
+
Object.freeze({
|
|
258
|
+
kind: "s3",
|
|
259
|
+
__cmp: {
|
|
260
|
+
url: "",
|
|
261
|
+
bucket: "",
|
|
262
|
+
accessKeyId: "",
|
|
263
|
+
secretAccessKey: ""
|
|
264
|
+
},
|
|
265
|
+
satisfies: (required) => required.kind === "s3"
|
|
266
|
+
});
|
|
267
|
+
const reservedParams = { port: number({ default: 3e3 }) };
|
|
268
|
+
/**
|
|
269
|
+
* A Prisma Compute service — declarations only (deps + params + build + the
|
|
270
|
+
* ports it exposes), no descriptor. `params` merges with the reserved
|
|
271
|
+
* `ReservedParams` (`port`); a user param whose name collides with a reserved
|
|
272
|
+
* one fails at authoring, the same way a colliding dependency name does.
|
|
273
|
+
* Returns the extension's runnable/loadable node:
|
|
274
|
+
* · run(address, boot) — the process controller: deserialize the platform
|
|
275
|
+
* environment (keyed off `address`, the extension's ONE env read) into a
|
|
276
|
+
* typed Config, re-emit it under address-free process-local stash keys,
|
|
277
|
+
* then call boot() to start the app's entry.
|
|
278
|
+
* · load() / config() — called from inside the app's entry: read the stash;
|
|
279
|
+
* load() hydrates + memoizes the deps, config() returns the typed params.
|
|
280
|
+
* Separate accessors so a dep and a param never share a namespace (ADR-0021).
|
|
281
|
+
*
|
|
282
|
+
* `service()`'s underlying node carries `extension: '@prisma/composer-prisma-cloud'` —
|
|
283
|
+
* the control-plane registry key `prisma-composer deploy` resolves through the
|
|
284
|
+
* app's `prisma-composer.config.ts` (ADR-0017). This module loads nothing at
|
|
285
|
+
* deploy time; nodes are pure data.
|
|
286
|
+
*/
|
|
287
|
+
const compute = (def) => {
|
|
288
|
+
const userParams = def.params ?? blindCast({});
|
|
289
|
+
for (const reserved of Object.keys(reservedParams)) {
|
|
290
|
+
if (reserved in def.deps) throw new Error(`compute(): dependency "${reserved}" collides with the reserved service param of the same name — rename the dependency.`);
|
|
291
|
+
if (reserved in userParams) throw new Error(`compute(): param "${reserved}" collides with the reserved service param of the same name — rename the param.`);
|
|
292
|
+
}
|
|
293
|
+
const params = blindCast({
|
|
294
|
+
...userParams,
|
|
295
|
+
...reservedParams
|
|
296
|
+
});
|
|
297
|
+
const node = service({
|
|
298
|
+
name: def.name,
|
|
299
|
+
extension: "@prisma/composer-prisma-cloud",
|
|
300
|
+
type: "compute",
|
|
301
|
+
inputs: def.deps,
|
|
302
|
+
params,
|
|
303
|
+
...def.secrets !== void 0 ? { secrets: def.secrets } : {},
|
|
304
|
+
build: def.build,
|
|
305
|
+
...def.expose !== void 0 ? { expose: def.expose } : {}
|
|
306
|
+
});
|
|
307
|
+
let resolved;
|
|
308
|
+
let loadedDeps;
|
|
309
|
+
let loadedParams;
|
|
310
|
+
let loadedSecrets;
|
|
311
|
+
function processConfig() {
|
|
312
|
+
if (resolved === void 0) resolved = deserialize(node, "");
|
|
313
|
+
return resolved;
|
|
314
|
+
}
|
|
315
|
+
const runnable = {
|
|
316
|
+
...node,
|
|
317
|
+
async run(address, boot) {
|
|
318
|
+
const config = deserialize(node, address);
|
|
319
|
+
stash(node, config);
|
|
320
|
+
stashProviderParams(RESERVED_PROVIDER_PARAMS, address);
|
|
321
|
+
stashSecrets(node, address);
|
|
322
|
+
const port = config.service["port"];
|
|
323
|
+
if (typeof port === "number") process.env["PORT"] = String(port);
|
|
324
|
+
return boot();
|
|
325
|
+
},
|
|
326
|
+
load() {
|
|
327
|
+
if (loadedDeps === void 0) loadedDeps = blindCast(hydrateSync(node, processConfig()));
|
|
328
|
+
return loadedDeps;
|
|
329
|
+
},
|
|
330
|
+
config() {
|
|
331
|
+
if (loadedParams === void 0) loadedParams = blindCast(processConfig().service);
|
|
332
|
+
return loadedParams;
|
|
333
|
+
},
|
|
334
|
+
secrets() {
|
|
335
|
+
if (loadedSecrets === void 0) loadedSecrets = blindCast(hydrateSecrets(node, deserializeSecrets(node, "")));
|
|
336
|
+
return loadedSecrets;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
return Object.freeze(blindCast(runnable));
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* The contract a Postgres provides — and the contract its consumers require.
|
|
343
|
+
* `satisfies` compares KIND, not identity: an extension module can be duplicated
|
|
344
|
+
* across a workspace (same rationale as the Symbol.for node brand), and every
|
|
345
|
+
* duplicate's contract must still satisfy. `__cmp` is the connection config a
|
|
346
|
+
* postgres offers; core never inspects it.
|
|
347
|
+
*/
|
|
348
|
+
const postgresContract = Object.freeze({
|
|
349
|
+
kind: "postgres",
|
|
350
|
+
__cmp: { url: "" },
|
|
351
|
+
satisfies: (required) => required.kind === "postgres"
|
|
352
|
+
});
|
|
353
|
+
function postgres(opts) {
|
|
354
|
+
if (opts?.name !== void 0) return resource({
|
|
355
|
+
name: opts.name,
|
|
356
|
+
extension: "@prisma/composer-prisma-cloud",
|
|
357
|
+
provides: postgresContract
|
|
358
|
+
});
|
|
359
|
+
return dependency({
|
|
360
|
+
type: "postgres",
|
|
361
|
+
connection: {
|
|
362
|
+
params: { url: string() },
|
|
363
|
+
hydrate: (v) => v
|
|
364
|
+
},
|
|
365
|
+
required: postgresContract
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The contract the `s3-credentials` resource provides — a minted SigV4 key
|
|
370
|
+
* pair. `satisfies` compares KIND only (mirrors `postgresContract`); `__cmp` is
|
|
371
|
+
* the config the resource offers, which core never inspects.
|
|
372
|
+
*/
|
|
373
|
+
const credentialsContract = Object.freeze({
|
|
374
|
+
kind: "credentials",
|
|
375
|
+
__cmp: {
|
|
376
|
+
accessKeyId: "",
|
|
377
|
+
secretAccessKey: ""
|
|
378
|
+
},
|
|
379
|
+
satisfies: (required) => required.kind === "credentials"
|
|
380
|
+
});
|
|
381
|
+
function s3Credentials(opts) {
|
|
382
|
+
if (opts?.name !== void 0) return resource({
|
|
383
|
+
name: opts.name,
|
|
384
|
+
extension: "@prisma/composer-prisma-cloud",
|
|
385
|
+
provides: credentialsContract
|
|
386
|
+
});
|
|
387
|
+
return dependency({
|
|
388
|
+
type: "credentials",
|
|
389
|
+
connection: {
|
|
390
|
+
params: {
|
|
391
|
+
accessKeyId: string(),
|
|
392
|
+
secretAccessKey: string()
|
|
393
|
+
},
|
|
394
|
+
hydrate: (v) => v
|
|
395
|
+
},
|
|
396
|
+
required: credentialsContract
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* The storage service authoring factory — a `compute` service routed to the
|
|
401
|
+
* `s3-store` lowering instead of `compute`'s. It is exactly `compute`'s
|
|
402
|
+
* runnable (run/load/config, deps, params, build, expose) with the routing
|
|
403
|
+
* `type` overridden to `'s3-store'`: nothing at runtime keys off `type` (the
|
|
404
|
+
* serializer keys off the deployment address and each param's owner/name, and
|
|
405
|
+
* `load`/`config` off deps/params), so only the deploy-time descriptor lookup
|
|
406
|
+
* sees the override and routes to the extended-output lowering (§ 5). The
|
|
407
|
+
* return type is compute's exactly (including the reserved `port` param). The
|
|
408
|
+
* storage module (D4b) calls this with its `db`/`credentials` deps, a `bucket`
|
|
409
|
+
* param, and `expose: { store: s3Contract }`.
|
|
410
|
+
*/
|
|
411
|
+
function s3StoreService(def) {
|
|
412
|
+
const node = compute(def);
|
|
413
|
+
return Object.freeze(blindCast({
|
|
414
|
+
...node,
|
|
415
|
+
type: "s3-store"
|
|
416
|
+
}));
|
|
417
|
+
}
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region ../../1-prisma-cloud/2-shared-modules/storage/dist/storage-service-DSaZsAC4.mjs
|
|
420
|
+
const s3Contract = Object.freeze({
|
|
421
|
+
kind: "s3",
|
|
422
|
+
__cmp: {
|
|
423
|
+
url: "",
|
|
424
|
+
bucket: "",
|
|
425
|
+
accessKeyId: "",
|
|
426
|
+
secretAccessKey: ""
|
|
427
|
+
},
|
|
428
|
+
satisfies: (required) => required.kind === "s3"
|
|
429
|
+
});
|
|
430
|
+
/**
|
|
431
|
+
* A consumer's dependency on an S3-compatible store. No `region` in the
|
|
432
|
+
* binding — the server accepts whatever region string the client signed.
|
|
433
|
+
*/
|
|
434
|
+
function s3() {
|
|
435
|
+
return dependency({
|
|
436
|
+
type: "s3",
|
|
437
|
+
connection: {
|
|
438
|
+
params: {
|
|
439
|
+
url: string(),
|
|
440
|
+
bucket: string(),
|
|
441
|
+
accessKeyId: string(),
|
|
442
|
+
secretAccessKey: string()
|
|
443
|
+
},
|
|
444
|
+
hydrate: (v) => v
|
|
445
|
+
},
|
|
446
|
+
required: s3Contract
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The storage service node (like cron's `scheduler.ts` + `scheduler-service.ts`
|
|
451
|
+
* combined): `storageService` builds the `s3-store` service — a Postgres `db`
|
|
452
|
+
* dependency, a minted `credentials` dependency, a `bucket` param, and the
|
|
453
|
+
* `store` port exposing `s3Contract`. The deploy bootstrap runs the
|
|
454
|
+
* default-exported bare node (`main.run(address, boot)`); the real bucket comes
|
|
455
|
+
* from serialized config at runtime, so the default's `bucket` is only a
|
|
456
|
+
* placeholder — exactly like `scheduler-service.ts` default-exports
|
|
457
|
+
* `cronScheduler({ jobs: [] })`.
|
|
458
|
+
*/
|
|
459
|
+
function storageService(opts) {
|
|
460
|
+
return s3StoreService({
|
|
461
|
+
name: "storage",
|
|
462
|
+
deps: {
|
|
463
|
+
db: postgres(),
|
|
464
|
+
credentials: s3Credentials()
|
|
465
|
+
},
|
|
466
|
+
params: { bucket: string({ default: opts.bucket }) },
|
|
467
|
+
build: node({
|
|
468
|
+
module: new URL("./storage-service.mjs", import.meta.url).href,
|
|
469
|
+
entry: "./storage-entrypoint.mjs"
|
|
470
|
+
}),
|
|
471
|
+
expose: { store: s3Contract }
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
storageService({ bucket: "storage" });
|
|
475
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
476
|
+
var require_reusify = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
477
|
+
function reusify(Constructor) {
|
|
478
|
+
var head = new Constructor();
|
|
479
|
+
var tail = head;
|
|
480
|
+
function get() {
|
|
481
|
+
var current = head;
|
|
482
|
+
if (current.next) head = current.next;
|
|
483
|
+
else {
|
|
484
|
+
head = new Constructor();
|
|
485
|
+
tail = head;
|
|
486
|
+
}
|
|
487
|
+
current.next = null;
|
|
488
|
+
return current;
|
|
489
|
+
}
|
|
490
|
+
function release(obj) {
|
|
491
|
+
tail.next = obj;
|
|
492
|
+
tail = obj;
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
get,
|
|
496
|
+
release
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
module.exports = reusify;
|
|
500
|
+
}));
|
|
501
|
+
(/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
502
|
+
var reusify = require_reusify();
|
|
503
|
+
function fastqueue(context, worker, _concurrency) {
|
|
504
|
+
if (typeof context === "function") {
|
|
505
|
+
_concurrency = worker;
|
|
506
|
+
worker = context;
|
|
507
|
+
context = null;
|
|
508
|
+
}
|
|
509
|
+
if (!(_concurrency >= 1)) throw new Error("fastqueue concurrency must be equal to or greater than 1");
|
|
510
|
+
var cache = reusify(Task);
|
|
511
|
+
var queueHead = null;
|
|
512
|
+
var queueTail = null;
|
|
513
|
+
var _running = 0;
|
|
514
|
+
var errorHandler = null;
|
|
515
|
+
var self = {
|
|
516
|
+
push,
|
|
517
|
+
drain: noop,
|
|
518
|
+
saturated: noop,
|
|
519
|
+
pause,
|
|
520
|
+
paused: false,
|
|
521
|
+
get concurrency() {
|
|
522
|
+
return _concurrency;
|
|
523
|
+
},
|
|
524
|
+
set concurrency(value) {
|
|
525
|
+
if (!(value >= 1)) throw new Error("fastqueue concurrency must be equal to or greater than 1");
|
|
526
|
+
_concurrency = value;
|
|
527
|
+
if (self.paused) return;
|
|
528
|
+
for (; queueHead && _running < _concurrency;) {
|
|
529
|
+
_running++;
|
|
530
|
+
release();
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
running,
|
|
534
|
+
resume,
|
|
535
|
+
idle,
|
|
536
|
+
length,
|
|
537
|
+
getQueue,
|
|
538
|
+
unshift,
|
|
539
|
+
empty: noop,
|
|
540
|
+
kill,
|
|
541
|
+
killAndDrain,
|
|
542
|
+
error,
|
|
543
|
+
abort
|
|
544
|
+
};
|
|
545
|
+
return self;
|
|
546
|
+
function running() {
|
|
547
|
+
return _running;
|
|
548
|
+
}
|
|
549
|
+
function pause() {
|
|
550
|
+
self.paused = true;
|
|
551
|
+
}
|
|
552
|
+
function length() {
|
|
553
|
+
var current = queueHead;
|
|
554
|
+
var counter = 0;
|
|
555
|
+
while (current) {
|
|
556
|
+
current = current.next;
|
|
557
|
+
counter++;
|
|
558
|
+
}
|
|
559
|
+
return counter;
|
|
560
|
+
}
|
|
561
|
+
function getQueue() {
|
|
562
|
+
var current = queueHead;
|
|
563
|
+
var tasks = [];
|
|
564
|
+
while (current) {
|
|
565
|
+
tasks.push(current.value);
|
|
566
|
+
current = current.next;
|
|
567
|
+
}
|
|
568
|
+
return tasks;
|
|
569
|
+
}
|
|
570
|
+
function resume() {
|
|
571
|
+
if (!self.paused) return;
|
|
572
|
+
self.paused = false;
|
|
573
|
+
if (queueHead === null) {
|
|
574
|
+
_running++;
|
|
575
|
+
release();
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
for (; queueHead && _running < _concurrency;) {
|
|
579
|
+
_running++;
|
|
580
|
+
release();
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function idle() {
|
|
584
|
+
return _running === 0 && self.length() === 0;
|
|
585
|
+
}
|
|
586
|
+
function push(value, done) {
|
|
587
|
+
var current = cache.get();
|
|
588
|
+
current.context = context;
|
|
589
|
+
current.release = release;
|
|
590
|
+
current.value = value;
|
|
591
|
+
current.callback = done || noop;
|
|
592
|
+
current.errorHandler = errorHandler;
|
|
593
|
+
if (_running >= _concurrency || self.paused) if (queueTail) {
|
|
594
|
+
queueTail.next = current;
|
|
595
|
+
queueTail = current;
|
|
596
|
+
} else {
|
|
597
|
+
queueHead = current;
|
|
598
|
+
queueTail = current;
|
|
599
|
+
self.saturated();
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
_running++;
|
|
603
|
+
worker.call(context, current.value, current.worked);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function unshift(value, done) {
|
|
607
|
+
var current = cache.get();
|
|
608
|
+
current.context = context;
|
|
609
|
+
current.release = release;
|
|
610
|
+
current.value = value;
|
|
611
|
+
current.callback = done || noop;
|
|
612
|
+
current.errorHandler = errorHandler;
|
|
613
|
+
if (_running >= _concurrency || self.paused) if (queueHead) {
|
|
614
|
+
current.next = queueHead;
|
|
615
|
+
queueHead = current;
|
|
616
|
+
} else {
|
|
617
|
+
queueHead = current;
|
|
618
|
+
queueTail = current;
|
|
619
|
+
self.saturated();
|
|
620
|
+
}
|
|
621
|
+
else {
|
|
622
|
+
_running++;
|
|
623
|
+
worker.call(context, current.value, current.worked);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function release(holder) {
|
|
627
|
+
if (holder) cache.release(holder);
|
|
628
|
+
var next = queueHead;
|
|
629
|
+
if (next && _running <= _concurrency) if (!self.paused) {
|
|
630
|
+
if (queueTail === queueHead) queueTail = null;
|
|
631
|
+
queueHead = next.next;
|
|
632
|
+
next.next = null;
|
|
633
|
+
worker.call(context, next.value, next.worked);
|
|
634
|
+
if (queueTail === null) self.empty();
|
|
635
|
+
} else _running--;
|
|
636
|
+
else if (--_running === 0) self.drain();
|
|
637
|
+
}
|
|
638
|
+
function kill() {
|
|
639
|
+
queueHead = null;
|
|
640
|
+
queueTail = null;
|
|
641
|
+
self.drain = noop;
|
|
642
|
+
}
|
|
643
|
+
function killAndDrain() {
|
|
644
|
+
queueHead = null;
|
|
645
|
+
queueTail = null;
|
|
646
|
+
self.drain();
|
|
647
|
+
self.drain = noop;
|
|
648
|
+
}
|
|
649
|
+
function abort() {
|
|
650
|
+
var current = queueHead;
|
|
651
|
+
queueHead = null;
|
|
652
|
+
queueTail = null;
|
|
653
|
+
while (current) {
|
|
654
|
+
var next = current.next;
|
|
655
|
+
var callback = current.callback;
|
|
656
|
+
var errorHandler = current.errorHandler;
|
|
657
|
+
var val = current.value;
|
|
658
|
+
var context = current.context;
|
|
659
|
+
current.value = null;
|
|
660
|
+
current.callback = noop;
|
|
661
|
+
current.errorHandler = null;
|
|
662
|
+
if (errorHandler) errorHandler(/* @__PURE__ */ new Error("abort"), val);
|
|
663
|
+
callback.call(context, /* @__PURE__ */ new Error("abort"));
|
|
664
|
+
current.release(current);
|
|
665
|
+
current = next;
|
|
666
|
+
}
|
|
667
|
+
self.drain = noop;
|
|
668
|
+
}
|
|
669
|
+
function error(handler) {
|
|
670
|
+
errorHandler = handler;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
function noop() {}
|
|
674
|
+
function Task() {
|
|
675
|
+
this.value = null;
|
|
676
|
+
this.callback = noop;
|
|
677
|
+
this.next = null;
|
|
678
|
+
this.release = noop;
|
|
679
|
+
this.context = null;
|
|
680
|
+
this.errorHandler = null;
|
|
681
|
+
var self = this;
|
|
682
|
+
this.worked = function worked(err, result) {
|
|
683
|
+
var callback = self.callback;
|
|
684
|
+
var errorHandler = self.errorHandler;
|
|
685
|
+
var val = self.value;
|
|
686
|
+
self.value = null;
|
|
687
|
+
self.callback = noop;
|
|
688
|
+
if (self.errorHandler) errorHandler(err, val);
|
|
689
|
+
callback.call(self.context, err, result);
|
|
690
|
+
self.release(self);
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function queueAsPromised(context, worker, _concurrency) {
|
|
694
|
+
if (typeof context === "function") {
|
|
695
|
+
_concurrency = worker;
|
|
696
|
+
worker = context;
|
|
697
|
+
context = null;
|
|
698
|
+
}
|
|
699
|
+
function asyncWrapper(arg, cb) {
|
|
700
|
+
worker.call(this, arg).then(function(res) {
|
|
701
|
+
cb(null, res);
|
|
702
|
+
}, cb);
|
|
703
|
+
}
|
|
704
|
+
var queue = fastqueue(context, asyncWrapper, _concurrency);
|
|
705
|
+
var pushCb = queue.push;
|
|
706
|
+
var unshiftCb = queue.unshift;
|
|
707
|
+
queue.push = push;
|
|
708
|
+
queue.unshift = unshift;
|
|
709
|
+
queue.drained = drained;
|
|
710
|
+
return queue;
|
|
711
|
+
function push(value) {
|
|
712
|
+
var p = new Promise(function(resolve, reject) {
|
|
713
|
+
pushCb(value, function(err, result) {
|
|
714
|
+
if (err) {
|
|
715
|
+
reject(err);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
resolve(result);
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
p.catch(noop);
|
|
722
|
+
return p;
|
|
723
|
+
}
|
|
724
|
+
function unshift(value) {
|
|
725
|
+
var p = new Promise(function(resolve, reject) {
|
|
726
|
+
unshiftCb(value, function(err, result) {
|
|
727
|
+
if (err) {
|
|
728
|
+
reject(err);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
resolve(result);
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
p.catch(noop);
|
|
735
|
+
return p;
|
|
736
|
+
}
|
|
737
|
+
function drained() {
|
|
738
|
+
return new Promise(function(resolve) {
|
|
739
|
+
process.nextTick(function() {
|
|
740
|
+
if (queue.idle()) resolve();
|
|
741
|
+
else {
|
|
742
|
+
var previousDrain = queue.drain;
|
|
743
|
+
queue.drain = function() {
|
|
744
|
+
if (typeof previousDrain === "function") previousDrain();
|
|
745
|
+
resolve();
|
|
746
|
+
queue.drain = previousDrain;
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
module.exports = fastqueue;
|
|
754
|
+
module.exports.promise = queueAsPromised;
|
|
755
|
+
})))();
|
|
756
|
+
/**
|
|
757
|
+
* Default backoff options.
|
|
758
|
+
*/
|
|
759
|
+
const BackoffDefaults = {
|
|
760
|
+
initialDelay: 100,
|
|
761
|
+
maxDelay: 6e4,
|
|
762
|
+
multiplier: 1.3,
|
|
763
|
+
maxRetries: Infinity
|
|
764
|
+
};
|
|
765
|
+
({ ...BackoffDefaults });
|
|
766
|
+
({ ...BackoffDefaults });
|
|
767
|
+
/**
|
|
768
|
+
* The `streams()` module's own exposed port: a general streams provider,
|
|
769
|
+
* satisfied by kind alone — the `postgresContract` pattern. The module
|
|
770
|
+
* cannot know its eventual consumers' stream names (different consumers of
|
|
771
|
+
* one module each name their own), and the server genuinely serves any
|
|
772
|
+
* stream, so what a consumer requires of its provider is only "is a streams
|
|
773
|
+
* provider". That is exactly what this wide type says, and the empty def
|
|
774
|
+
* map is a legitimate `StreamDefs` value — a placeholder nobody reads, like
|
|
775
|
+
* postgres's `{ url: '' }`. Consumers keep their literal handle typing from
|
|
776
|
+
* `durableStreams(contract)`'s generic parameter, which is independent of
|
|
777
|
+
* the wiring-compatibility type here.
|
|
778
|
+
*/
|
|
779
|
+
const streamsProviderContract = Object.freeze({
|
|
780
|
+
kind: "streams",
|
|
781
|
+
__cmp: {},
|
|
782
|
+
satisfies: (required) => required.kind === "streams"
|
|
783
|
+
});
|
|
784
|
+
string(), string({ provision: streamsApiKeyNeed() });
|
|
785
|
+
/**
|
|
786
|
+
* The streams service node: a plain `compute` service — the contract binding's
|
|
787
|
+
* `url` is a producer output compute's deploy already carries, and its
|
|
788
|
+
* `apiKey` is minted by the target's registered provisioner (ADR-0031), so
|
|
789
|
+
* nothing is left for a bespoke lowering to extend. It declares the `store`
|
|
790
|
+
* dependency (`s3()`, the storage module's port) and the `streams` expose; the
|
|
791
|
+
* bearer key reaches this service through the target's reserved provider
|
|
792
|
+
* param, not through a dependency. The deploy bootstrap runs the
|
|
793
|
+
* default-exported bare node; the real wiring arrives through serialized
|
|
794
|
+
* config at runtime — exactly like `storage-service.ts`.
|
|
795
|
+
*/
|
|
796
|
+
function streamsService() {
|
|
797
|
+
return compute({
|
|
798
|
+
name: "streams",
|
|
799
|
+
deps: { store: s3() },
|
|
800
|
+
build: node({
|
|
801
|
+
module: new URL("./streams-service.mjs", import.meta.url).href,
|
|
802
|
+
entry: "./streams-entrypoint.mjs"
|
|
803
|
+
}),
|
|
804
|
+
expose: { streams: streamsProviderContract }
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
var streams_service_default = streamsService();
|
|
808
|
+
//#endregion
|
|
809
|
+
export { streams_service_default as default, streamsService };
|
|
810
|
+
|
|
811
|
+
//# sourceMappingURL=streams-service.mjs.map
|