@supacloud/cli 0.120.0 → 0.121.3
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 +10 -9
- package/dist/index.js +633 -129
- package/dist/shared/tools/app-database-check.d.ts +2 -0
- package/dist/shared/tools/app-starter-templates.d.ts +20 -3
- package/dist/shared/tools/app-starter.d.ts +3 -2
- package/dist/shared/tools/app-tools.d.ts +1 -1
- package/dist/shared/tools/lite-cli-tools.d.ts +5 -0
- package/dist/shared/transports/http.d.ts +2 -0
- package/package.json +8 -8
- package/skills/supacloud/references/app-workflow.md +3 -0
package/dist/index.js
CHANGED
|
@@ -9537,6 +9537,7 @@ var RELEASE_MUTATION_RESPONSE_TIMEOUT = 5000;
|
|
|
9537
9537
|
var RELEASE_MUTATION_RESPONSE_MAX_BYTES = 64 * 1024;
|
|
9538
9538
|
var MAX_RETRIES = 2;
|
|
9539
9539
|
var RETRY_BASE_DELAY = 500;
|
|
9540
|
+
var MAX_RETRY_AFTER_MS = 5 * 60000;
|
|
9540
9541
|
function validatedGetResponseLimit(options) {
|
|
9541
9542
|
const maxBytes = options.maxResponseBytes;
|
|
9542
9543
|
if (maxBytes === undefined)
|
|
@@ -9579,6 +9580,21 @@ function isRetryableError(error) {
|
|
|
9579
9580
|
const networkError = error;
|
|
9580
9581
|
return networkError.name === "AbortError" || networkError.code === "ECONNREFUSED" || networkError.code === "ECONNRESET";
|
|
9581
9582
|
}
|
|
9583
|
+
function retryAfterDelayMs(value) {
|
|
9584
|
+
const normalized = value?.trim() ?? "";
|
|
9585
|
+
if (/^\d+$/.test(normalized)) {
|
|
9586
|
+
const seconds = Number(normalized);
|
|
9587
|
+
if (Number.isSafeInteger(seconds))
|
|
9588
|
+
return Math.min(MAX_RETRY_AFTER_MS, seconds * 1000);
|
|
9589
|
+
}
|
|
9590
|
+
const retryAt = Date.parse(normalized);
|
|
9591
|
+
if (!Number.isNaN(retryAt))
|
|
9592
|
+
return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, retryAt - Date.now()));
|
|
9593
|
+
return RETRY_BASE_DELAY;
|
|
9594
|
+
}
|
|
9595
|
+
function waitForRetry(delayMs) {
|
|
9596
|
+
return new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
9597
|
+
}
|
|
9582
9598
|
function transportFailure(error) {
|
|
9583
9599
|
const networkError = error instanceof Error ? error : null;
|
|
9584
9600
|
const code = networkError?.name === "AbortError" ? "TIMEOUT" : networkError?.code === "ECONNRESET" ? "CONNECTION_RESET" : "NETWORK_ERROR";
|
|
@@ -9611,21 +9627,31 @@ async function fetchWithTimeout(url, options, timeoutMs = DEFAULT_TIMEOUT, insec
|
|
|
9611
9627
|
clearTimeout(timeout);
|
|
9612
9628
|
}
|
|
9613
9629
|
}
|
|
9614
|
-
async function fetchWithRetry(url, options, timeoutMs = DEFAULT_TIMEOUT, insecureTls = false) {
|
|
9615
|
-
const
|
|
9630
|
+
async function fetchWithRetry(url, options, timeoutMs = DEFAULT_TIMEOUT, insecureTls = false, retryOptions = {}) {
|
|
9631
|
+
const retryOnRateLimit = retryOptions.retryOnRateLimit === true;
|
|
9632
|
+
const retryableMethod = isRetryableMethod(options.method);
|
|
9633
|
+
const retries = retryableMethod || retryOnRateLimit ? MAX_RETRIES : 0;
|
|
9616
9634
|
for (let attempt = 0;attempt <= retries; attempt++) {
|
|
9617
9635
|
try {
|
|
9618
9636
|
const res = await fetchWithTimeout(url, options, timeoutMs, insecureTls);
|
|
9619
|
-
if (res.status
|
|
9637
|
+
if (res.status === 429 && retryOnRateLimit && attempt < retries) {
|
|
9638
|
+
const delay = retryAfterDelayMs(res.headers.get("retry-after"));
|
|
9639
|
+
res.body?.cancel().catch(() => {
|
|
9640
|
+
return;
|
|
9641
|
+
});
|
|
9642
|
+
await waitForRetry(delay);
|
|
9643
|
+
continue;
|
|
9644
|
+
}
|
|
9645
|
+
if (retryableMethod && res.status >= 500 && res.status < 600 && attempt < retries) {
|
|
9620
9646
|
const delay = RETRY_BASE_DELAY * Math.pow(2, attempt);
|
|
9621
|
-
await
|
|
9647
|
+
await waitForRetry(delay);
|
|
9622
9648
|
continue;
|
|
9623
9649
|
}
|
|
9624
9650
|
return res;
|
|
9625
9651
|
} catch (error) {
|
|
9626
|
-
if (attempt < retries && isRetryableError(error)) {
|
|
9652
|
+
if (retryableMethod && attempt < retries && isRetryableError(error)) {
|
|
9627
9653
|
const delay = RETRY_BASE_DELAY * Math.pow(2, attempt);
|
|
9628
|
-
await
|
|
9654
|
+
await waitForRetry(delay);
|
|
9629
9655
|
continue;
|
|
9630
9656
|
}
|
|
9631
9657
|
throw error;
|
|
@@ -9776,14 +9802,14 @@ class HttpTransport {
|
|
|
9776
9802
|
...this.apiKey ? { apikey: this.apiKey } : {}
|
|
9777
9803
|
};
|
|
9778
9804
|
}
|
|
9779
|
-
async mutationWithResponseReader(method, path, serializedBody, responseReader, timeoutMs = DEFAULT_TIMEOUT) {
|
|
9805
|
+
async mutationWithResponseReader(method, path, serializedBody, responseReader, timeoutMs = DEFAULT_TIMEOUT, retryOnRateLimit = false) {
|
|
9780
9806
|
try {
|
|
9781
9807
|
const request = {
|
|
9782
9808
|
method,
|
|
9783
9809
|
headers: this.headers(),
|
|
9784
9810
|
...serializedBody === undefined ? {} : { body: serializedBody }
|
|
9785
9811
|
};
|
|
9786
|
-
const response = await fetchWithRetry(`${this.baseUrl}${path}`, request, timeoutMs, this.insecureTls);
|
|
9812
|
+
const response = await fetchWithRetry(`${this.baseUrl}${path}`, request, timeoutMs, this.insecureTls, { retryOnRateLimit });
|
|
9787
9813
|
const responseBody = await responseReader(response);
|
|
9788
9814
|
return responseBody.ok ? { ok: response.ok, status: response.status, data: responseBody.parsedJson } : responseReadFailure(response.status);
|
|
9789
9815
|
} catch (error) {
|
|
@@ -9850,7 +9876,7 @@ class HttpTransport {
|
|
|
9850
9876
|
}
|
|
9851
9877
|
async postReleaseMutation(path, body, options) {
|
|
9852
9878
|
const timeoutMs = validatedPostTimeout(options);
|
|
9853
|
-
return this.mutationWithResponseReader("POST", path, serializedRequestBody(body), releaseMutationResponseJson, timeoutMs);
|
|
9879
|
+
return this.mutationWithResponseReader("POST", path, serializedRequestBody(body), releaseMutationResponseJson, timeoutMs, options?.retryOnRateLimit === true);
|
|
9854
9880
|
}
|
|
9855
9881
|
async postBinary(path, body, options) {
|
|
9856
9882
|
if (options.contentType !== FRONTEND_ARCHIVE_CONTENT_TYPE) {
|
|
@@ -11119,10 +11145,103 @@ function summarizeDeploymentEvidence(value) {
|
|
|
11119
11145
|
liveObservationPerformed: false
|
|
11120
11146
|
};
|
|
11121
11147
|
}
|
|
11122
|
-
// node_modules/@supacloud/delivery/src/
|
|
11148
|
+
// node_modules/@supacloud/delivery/src/platform-deployment.ts
|
|
11149
|
+
var closed6 = { additionalProperties: false };
|
|
11123
11150
|
var sha2563 = String2({ pattern: "^[a-f0-9]{64}$" });
|
|
11124
|
-
var
|
|
11151
|
+
var releaseId = String2({ pattern: "^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$" });
|
|
11152
|
+
var mutationId = String2({ pattern: "^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$" });
|
|
11125
11153
|
var isoDate2 = String2({ minLength: 20, maxLength: 40 });
|
|
11154
|
+
var PLATFORM_DEPLOYMENT_STATE_SCHEMA = "supacloud.platform-deployment-state.v1";
|
|
11155
|
+
var componentName2 = Union([
|
|
11156
|
+
Literal("management-api"),
|
|
11157
|
+
Literal("web-console"),
|
|
11158
|
+
Literal("caddy"),
|
|
11159
|
+
Literal("postgres"),
|
|
11160
|
+
Literal("postgrest"),
|
|
11161
|
+
Literal("gotrue"),
|
|
11162
|
+
Literal("realtime"),
|
|
11163
|
+
Literal("storage"),
|
|
11164
|
+
Literal("victoria-logs"),
|
|
11165
|
+
Literal("edge-runtime")
|
|
11166
|
+
]);
|
|
11167
|
+
var componentStatus = Union([
|
|
11168
|
+
Literal("ready"),
|
|
11169
|
+
Literal("stopped"),
|
|
11170
|
+
Literal("starting"),
|
|
11171
|
+
Literal("unhealthy"),
|
|
11172
|
+
Literal("failed"),
|
|
11173
|
+
Literal("unknown")
|
|
11174
|
+
]);
|
|
11175
|
+
var desiredStatus = Union([Literal("running"), Literal("stopped")]);
|
|
11176
|
+
var actualStatus = Union([
|
|
11177
|
+
Literal("absent"),
|
|
11178
|
+
Literal("starting"),
|
|
11179
|
+
Literal("running"),
|
|
11180
|
+
Literal("stopped"),
|
|
11181
|
+
Literal("degraded"),
|
|
11182
|
+
Literal("failed"),
|
|
11183
|
+
Literal("unknown")
|
|
11184
|
+
]);
|
|
11185
|
+
var operationPhase = Union([
|
|
11186
|
+
Literal("idle"),
|
|
11187
|
+
Literal("preparing"),
|
|
11188
|
+
Literal("activating"),
|
|
11189
|
+
Literal("verifying"),
|
|
11190
|
+
Literal("confirmed"),
|
|
11191
|
+
Literal("failed"),
|
|
11192
|
+
Literal("unknown"),
|
|
11193
|
+
Literal("rolled-back")
|
|
11194
|
+
]);
|
|
11195
|
+
var retryAction = Union([
|
|
11196
|
+
Literal("none"),
|
|
11197
|
+
Literal("reconcile-same-mutation"),
|
|
11198
|
+
Literal("manual-recovery"),
|
|
11199
|
+
Literal("new-mutation")
|
|
11200
|
+
]);
|
|
11201
|
+
var PlatformDeploymentComponentSchema = _Object_({
|
|
11202
|
+
name: componentName2,
|
|
11203
|
+
version: Union([String2({ minLength: 1, maxLength: 128 }), Null()]),
|
|
11204
|
+
status: componentStatus,
|
|
11205
|
+
health_check: Union([String2({ minLength: 1, maxLength: 256 }), Null()]),
|
|
11206
|
+
checked_at: Union([isoDate2, Null()])
|
|
11207
|
+
}, closed6);
|
|
11208
|
+
var PlatformDeploymentStateSchema = _Object_({
|
|
11209
|
+
schema: Literal(PLATFORM_DEPLOYMENT_STATE_SCHEMA),
|
|
11210
|
+
profile: Literal("single-node"),
|
|
11211
|
+
host: _Object_({
|
|
11212
|
+
os: Literal("linux"),
|
|
11213
|
+
distribution: Literal("ubuntu"),
|
|
11214
|
+
version: Literal("24.04"),
|
|
11215
|
+
architecture: Literal("amd64"),
|
|
11216
|
+
init: Literal("systemd")
|
|
11217
|
+
}, closed6),
|
|
11218
|
+
desired: _Object_({
|
|
11219
|
+
state: desiredStatus,
|
|
11220
|
+
release_id: Union([releaseId, Null()]),
|
|
11221
|
+
manifest_sha256: Union([sha2563, Null()])
|
|
11222
|
+
}, closed6),
|
|
11223
|
+
actual: _Object_({
|
|
11224
|
+
state: actualStatus,
|
|
11225
|
+
release_id: Union([releaseId, Null()]),
|
|
11226
|
+
manifest_sha256: Union([sha2563, Null()]),
|
|
11227
|
+
checked_at: Union([isoDate2, Null()]),
|
|
11228
|
+
components: _Array_(PlatformDeploymentComponentSchema, { minItems: 1, maxItems: 16 })
|
|
11229
|
+
}, closed6),
|
|
11230
|
+
operation: _Object_({
|
|
11231
|
+
mutation_id: Union([mutationId, Null()]),
|
|
11232
|
+
phase: operationPhase,
|
|
11233
|
+
retry: retryAction,
|
|
11234
|
+
error: Union([String2({ minLength: 1, maxLength: 512 }), Null()])
|
|
11235
|
+
}, closed6),
|
|
11236
|
+
rollback: _Object_({
|
|
11237
|
+
release_id: Union([releaseId, Null()]),
|
|
11238
|
+
ready: Boolean2()
|
|
11239
|
+
}, closed6)
|
|
11240
|
+
}, closed6);
|
|
11241
|
+
// node_modules/@supacloud/delivery/src/delivery-tuple.ts
|
|
11242
|
+
var sha2564 = String2({ pattern: "^[a-f0-9]{64}$" });
|
|
11243
|
+
var commit = String2({ pattern: "^(?:[a-f0-9]{40}|[a-f0-9]{64})$" });
|
|
11244
|
+
var isoDate3 = String2({ minLength: 20, maxLength: 40 });
|
|
11126
11245
|
var DELIVERY_TUPLE_SCHEMA = "supacloud.fa-delivery-tuple.v1";
|
|
11127
11246
|
var FaDeliveryTupleSchema = _Object_({
|
|
11128
11247
|
schema: Literal(DELIVERY_TUPLE_SCHEMA),
|
|
@@ -11134,21 +11253,21 @@ var FaDeliveryTupleSchema = _Object_({
|
|
|
11134
11253
|
platform_commit: commit,
|
|
11135
11254
|
edge_runtime: _Object_({
|
|
11136
11255
|
version: String2({ minLength: 1, maxLength: 128 }),
|
|
11137
|
-
artifact_sha256:
|
|
11256
|
+
artifact_sha256: sha2564
|
|
11138
11257
|
}, { additionalProperties: false }),
|
|
11139
11258
|
compatibility_window: _Object_({
|
|
11140
11259
|
contract_schema: String2({ minLength: 1, maxLength: 128 }),
|
|
11141
|
-
starts_at:
|
|
11142
|
-
ends_at:
|
|
11260
|
+
starts_at: isoDate3,
|
|
11261
|
+
ends_at: isoDate3,
|
|
11143
11262
|
old_client_supported: Boolean2(),
|
|
11144
11263
|
partial_deployment_supported: Boolean2()
|
|
11145
11264
|
}, { additionalProperties: false })
|
|
11146
11265
|
}, { additionalProperties: false });
|
|
11147
11266
|
// node_modules/@supacloud/delivery/src/contract-matrix.ts
|
|
11148
|
-
var
|
|
11149
|
-
var
|
|
11267
|
+
var closed7 = { additionalProperties: false };
|
|
11268
|
+
var sha2565 = String2({ pattern: "^[a-f0-9]{64}$" });
|
|
11150
11269
|
var generation = Union([Literal("old"), Literal("new")]);
|
|
11151
|
-
var versions = _Object_({ old:
|
|
11270
|
+
var versions = _Object_({ old: sha2565, new: sha2565 }, closed7);
|
|
11152
11271
|
var CONTRACT_MATRIX_SCHEMA = "supacloud.consumer-contract-matrix.v1";
|
|
11153
11272
|
var FA_CONTRACT_SCENARIOS = [
|
|
11154
11273
|
"missing-display-field",
|
|
@@ -11161,9 +11280,9 @@ var FA_CONTRACT_SCENARIOS = [
|
|
|
11161
11280
|
var ConsumerContractMatrixSchema = _Object_({
|
|
11162
11281
|
schema: Literal(CONTRACT_MATRIX_SCHEMA),
|
|
11163
11282
|
customer: Literal("xigu-fa"),
|
|
11164
|
-
baseline_tuple_sha256:
|
|
11165
|
-
candidate_tuple_sha256:
|
|
11166
|
-
artifacts: _Object_({ frontend: versions, functions: versions, database: versions },
|
|
11283
|
+
baseline_tuple_sha256: sha2565,
|
|
11284
|
+
candidate_tuple_sha256: sha2565,
|
|
11285
|
+
artifacts: _Object_({ frontend: versions, functions: versions, database: versions }, closed7),
|
|
11167
11286
|
cases: _Array_(_Object_({
|
|
11168
11287
|
frontend: generation,
|
|
11169
11288
|
functions: generation,
|
|
@@ -11171,11 +11290,11 @@ var ConsumerContractMatrixSchema = _Object_({
|
|
|
11171
11290
|
scenarios: _Array_(_Object_({
|
|
11172
11291
|
name: Enum(FA_CONTRACT_SCENARIOS),
|
|
11173
11292
|
expected: Union([Literal("compatible"), Literal("blocked-safely")])
|
|
11174
|
-
},
|
|
11175
|
-
},
|
|
11176
|
-
},
|
|
11293
|
+
}, closed7), { minItems: FA_CONTRACT_SCENARIOS.length, maxItems: FA_CONTRACT_SCENARIOS.length })
|
|
11294
|
+
}, closed7), { minItems: 8, maxItems: 8 })
|
|
11295
|
+
}, closed7);
|
|
11177
11296
|
// node_modules/@supacloud/delivery/src/fa-stability.ts
|
|
11178
|
-
var
|
|
11297
|
+
var closed8 = { additionalProperties: false };
|
|
11179
11298
|
var hash3 = String2({ pattern: "^[a-f0-9]{64}$" });
|
|
11180
11299
|
var label = String2({ minLength: 1, maxLength: 256, pattern: "\\S" });
|
|
11181
11300
|
var timestamp2 = String2({ minLength: 24, maxLength: 24 });
|
|
@@ -11198,7 +11317,7 @@ var operation = Enum(FA_BUSINESS_OPERATIONS);
|
|
|
11198
11317
|
var proof = _Object_({
|
|
11199
11318
|
path: String2({ pattern: "^[A-Za-z0-9_-][A-Za-z0-9_./-]{0,255}$" }),
|
|
11200
11319
|
sha256: hash3
|
|
11201
|
-
},
|
|
11320
|
+
}, closed8);
|
|
11202
11321
|
var FaBusinessObservationSchema = _Object_({
|
|
11203
11322
|
id: String2({ pattern: "^[A-Za-z0-9_-]{1,128}$" }),
|
|
11204
11323
|
tuple_sha256: hash3,
|
|
@@ -11208,7 +11327,7 @@ var FaBusinessObservationSchema = _Object_({
|
|
|
11208
11327
|
outcome: Enum(["success", "failure", "timeout", "unknown"]),
|
|
11209
11328
|
attempts: Integer({ minimum: 1, maximum: 1000 }),
|
|
11210
11329
|
rollbacks: count
|
|
11211
|
-
},
|
|
11330
|
+
}, closed8);
|
|
11212
11331
|
var FaServiceObjectivesSchema = _Object_({
|
|
11213
11332
|
status: Literal("approved"),
|
|
11214
11333
|
owner: label,
|
|
@@ -11224,8 +11343,8 @@ var FaServiceObjectivesSchema = _Object_({
|
|
|
11224
11343
|
minimum_samples: Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }),
|
|
11225
11344
|
availability_percent: Number2({ exclusiveMinimum: 0, maximum: 100 }),
|
|
11226
11345
|
p95_ms: Number2({ exclusiveMinimum: 0, maximum: Number.MAX_SAFE_INTEGER })
|
|
11227
|
-
},
|
|
11228
|
-
},
|
|
11346
|
+
}, closed8), { minItems: FA_BUSINESS_OPERATIONS.length, maxItems: FA_BUSINESS_OPERATIONS.length })
|
|
11347
|
+
}, closed8);
|
|
11229
11348
|
var FaStabilityEvidenceSchema = _Object_({
|
|
11230
11349
|
schema: Literal("supacloud.fa-stability-evidence.v1"),
|
|
11231
11350
|
environment: environment2,
|
|
@@ -11251,7 +11370,7 @@ var FaStabilityEvidenceSchema = _Object_({
|
|
|
11251
11370
|
passed: Boolean2(),
|
|
11252
11371
|
measured_at: timestamp2,
|
|
11253
11372
|
proof
|
|
11254
|
-
},
|
|
11373
|
+
}, closed8), { minItems: 10, maxItems: 10 }),
|
|
11255
11374
|
matrix: _Array_(_Object_({
|
|
11256
11375
|
combination: label,
|
|
11257
11376
|
scenario: label,
|
|
@@ -11260,16 +11379,16 @@ var FaStabilityEvidenceSchema = _Object_({
|
|
|
11260
11379
|
passed: Boolean2(),
|
|
11261
11380
|
measured_at: timestamp2,
|
|
11262
11381
|
proof
|
|
11263
|
-
},
|
|
11382
|
+
}, closed8), { minItems: 48, maxItems: 48 }),
|
|
11264
11383
|
observation: proof,
|
|
11265
|
-
alert: _Object_({ route: label, acknowledged_by: label, delivered_at: timestamp2 },
|
|
11266
|
-
},
|
|
11384
|
+
alert: _Object_({ route: label, acknowledged_by: label, delivered_at: timestamp2 }, closed8)
|
|
11385
|
+
}, closed8);
|
|
11267
11386
|
// node_modules/@supacloud/delivery/src/application-promotion.ts
|
|
11268
|
-
var
|
|
11387
|
+
var closed9 = { additionalProperties: false };
|
|
11269
11388
|
var projectRef2 = String2({ pattern: "^[a-z0-9-]{1,20}$" });
|
|
11270
|
-
var
|
|
11389
|
+
var sha2566 = ApplicationReleaseIdSchema;
|
|
11271
11390
|
var nullableActivation2 = Union([ApplicationActivationIdSchema, Null()]);
|
|
11272
|
-
var nullableDigest = Union([
|
|
11391
|
+
var nullableDigest = Union([sha2566, Null()]);
|
|
11273
11392
|
var observation = {
|
|
11274
11393
|
activation_id: nullableActivation2,
|
|
11275
11394
|
receipt_confirmed: Boolean2(),
|
|
@@ -11295,33 +11414,33 @@ var ApplicationPromotionPlanSchema = _Object_({
|
|
|
11295
11414
|
project_ref: projectRef2,
|
|
11296
11415
|
application_id: ApplicationIdSchema,
|
|
11297
11416
|
environment_id: ApplicationIdSchema,
|
|
11298
|
-
manifest_sha256:
|
|
11299
|
-
plan_sha256:
|
|
11417
|
+
manifest_sha256: sha2566,
|
|
11418
|
+
plan_sha256: sha2566,
|
|
11300
11419
|
source: _Object_({
|
|
11301
11420
|
project_ref: projectRef2,
|
|
11302
11421
|
environment_id: ApplicationIdSchema,
|
|
11303
|
-
release_id:
|
|
11422
|
+
release_id: sha2566,
|
|
11304
11423
|
...observation
|
|
11305
|
-
},
|
|
11424
|
+
}, closed9),
|
|
11306
11425
|
target: _Object_({
|
|
11307
|
-
candidate_release_id:
|
|
11308
|
-
current_release_id: Union([
|
|
11426
|
+
candidate_release_id: sha2566,
|
|
11427
|
+
current_release_id: Union([sha2566, Null()]),
|
|
11309
11428
|
artifact_action: Union([Literal("materialize"), Literal("reuse")]),
|
|
11310
11429
|
configuration_id: Union([ApplicationConfigurationIdSchema, Null()]),
|
|
11311
11430
|
configuration: Union([ApplicationConfigurationViewSchema, Null()]),
|
|
11312
11431
|
...observation
|
|
11313
|
-
},
|
|
11432
|
+
}, closed9),
|
|
11314
11433
|
migrations: _Object_({
|
|
11315
|
-
ledger_digest:
|
|
11434
|
+
ledger_digest: sha2566,
|
|
11316
11435
|
ledger_compatible: Boolean2(),
|
|
11317
11436
|
project_migrations_applied: Boolean2(),
|
|
11318
11437
|
pending_versions: _Array_(String2({ pattern: "^\\d{1,20}$" }), { maxItems: 4096, uniqueItems: true }),
|
|
11319
11438
|
operator_provisioning_required: Boolean2()
|
|
11320
|
-
},
|
|
11439
|
+
}, closed9),
|
|
11321
11440
|
backup: _Object_({
|
|
11322
11441
|
required: Boolean2(),
|
|
11323
11442
|
confirmed: Literal(false)
|
|
11324
|
-
},
|
|
11443
|
+
}, closed9),
|
|
11325
11444
|
action: Union([Literal("promote"), Literal("no-op"), Literal("blocked")]),
|
|
11326
11445
|
blockers: _Array_(Enum([...blocker]), {
|
|
11327
11446
|
maxItems: blocker.length,
|
|
@@ -11330,7 +11449,7 @@ var ApplicationPromotionPlanSchema = _Object_({
|
|
|
11330
11449
|
steps: _Array_(String2({ minLength: 1, maxLength: 64 }), { maxItems: 8, uniqueItems: true }),
|
|
11331
11450
|
execution_performed: Literal(false),
|
|
11332
11451
|
data_recovery: Literal("separate-required")
|
|
11333
|
-
},
|
|
11452
|
+
}, closed9);
|
|
11334
11453
|
function applicationPromotionPlanDigest(value) {
|
|
11335
11454
|
return digest(canonical(value));
|
|
11336
11455
|
}
|
|
@@ -13437,7 +13556,7 @@ ${riskReport}`
|
|
|
13437
13556
|
skipped.push(file);
|
|
13438
13557
|
continue;
|
|
13439
13558
|
}
|
|
13440
|
-
const r = await managementHttp().postReleaseMutation(`/v1/projects/${ref}/database/migrations`, { name, sql, version });
|
|
13559
|
+
const r = await managementHttp().postReleaseMutation(`/v1/projects/${ref}/database/migrations`, { name, sql, version }, { retryOnRateLimit: true });
|
|
13441
13560
|
if (r.ok && r.status === 200 && confirmedMigrationReceipt(r.data, { name, version, sql })) {
|
|
13442
13561
|
applied.push(file);
|
|
13443
13562
|
} else if (isAlreadyAppliedMigrationResponse(r, { name, version, sql })) {
|
|
@@ -18092,7 +18211,7 @@ var ApplicationDeployRequestSchema2 = ApplicationDeployRequestSchema;
|
|
|
18092
18211
|
var ApplicationDeployWebReleaseSchema2 = ApplicationDeployWebReleaseSchema;
|
|
18093
18212
|
|
|
18094
18213
|
// src/shared/tools/application-workflow-schemas.ts
|
|
18095
|
-
var
|
|
18214
|
+
var closed10 = { additionalProperties: false };
|
|
18096
18215
|
var ref5 = String2({ pattern: "^[A-Za-z0-9_-]{1,20}$" });
|
|
18097
18216
|
var uuid = ApplicationActivationIdSchema2;
|
|
18098
18217
|
var nullableUuid = Union([uuid, Null()]);
|
|
@@ -18106,7 +18225,7 @@ var ApplicationPromotionResultSchema = _Object_({
|
|
|
18106
18225
|
plan_sha256: ApplicationReleaseIdSchema2,
|
|
18107
18226
|
action: Literal("promote"),
|
|
18108
18227
|
replayed: Boolean2()
|
|
18109
|
-
},
|
|
18228
|
+
}, closed10);
|
|
18110
18229
|
var ApplicationPromotionStatusSchema = _Object_({
|
|
18111
18230
|
...scope2,
|
|
18112
18231
|
mutation: Unknown(),
|
|
@@ -18125,8 +18244,8 @@ var ApplicationPromotionStatusSchema = _Object_({
|
|
|
18125
18244
|
configuration_id: Union([ApplicationConfigurationIdSchema2, Null()]),
|
|
18126
18245
|
backup_id: Union([String2({ pattern: "^logical-full_[a-z0-9-]{1,20}_[a-f0-9]{32}$" }), Null()]),
|
|
18127
18246
|
data_recovery: Literal("separate-required")
|
|
18128
|
-
},
|
|
18129
|
-
},
|
|
18247
|
+
}, closed10)
|
|
18248
|
+
}, closed10);
|
|
18130
18249
|
var phase = Union([Literal("pending"), Literal("ready"), Literal("failed"), Literal("cleaned")]);
|
|
18131
18250
|
var previewId = String2({ pattern: "^[a-f0-9-]{8,64}$" });
|
|
18132
18251
|
var name = String2({ minLength: 1, maxLength: 256 });
|
|
@@ -18145,39 +18264,39 @@ var ApplicationPreviewReceiptSchema2 = _Object_({
|
|
|
18145
18264
|
Literal("cleaned")
|
|
18146
18265
|
]),
|
|
18147
18266
|
resources: _Object_({
|
|
18148
|
-
build_artifact: _Object_({ status: phase, release_id: ApplicationReleaseIdSchema2 },
|
|
18267
|
+
build_artifact: _Object_({ status: phase, release_id: ApplicationReleaseIdSchema2 }, closed10),
|
|
18149
18268
|
database_branch: _Object_({
|
|
18150
18269
|
status: phase,
|
|
18151
18270
|
branch_ref: ref5,
|
|
18152
18271
|
data_mode: Union([Literal("schema_only"), Literal("full_clone")])
|
|
18153
|
-
},
|
|
18154
|
-
queue_namespace: _Object_({ status: phase, namespace: name },
|
|
18155
|
-
storage_namespace: _Object_({ status: phase, namespace: name },
|
|
18156
|
-
test_secret: _Object_({ status: phase, name, value_issued: Literal(false) },
|
|
18157
|
-
configuration_revision: _Object_({ status: phase, configuration_id: Union([ApplicationConfigurationIdSchema2, Null()]) },
|
|
18158
|
-
application_activation: _Object_({ status: phase, activation_id: nullableUuid },
|
|
18272
|
+
}, closed10),
|
|
18273
|
+
queue_namespace: _Object_({ status: phase, namespace: name }, closed10),
|
|
18274
|
+
storage_namespace: _Object_({ status: phase, namespace: name }, closed10),
|
|
18275
|
+
test_secret: _Object_({ status: phase, name, value_issued: Literal(false) }, closed10),
|
|
18276
|
+
configuration_revision: _Object_({ status: phase, configuration_id: Union([ApplicationConfigurationIdSchema2, Null()]) }, closed10),
|
|
18277
|
+
application_activation: _Object_({ status: phase, activation_id: nullableUuid }, closed10),
|
|
18159
18278
|
functions: Optional(_Object_({
|
|
18160
18279
|
status: phase,
|
|
18161
18280
|
slugs: _Array_(String2({ pattern: "^[A-Za-z0-9_-]{1,128}$" }), { maxItems: 64, uniqueItems: true })
|
|
18162
|
-
},
|
|
18163
|
-
smoke_test: _Object_({ status: phase, checks, passed: checks, failed: checks },
|
|
18164
|
-
},
|
|
18281
|
+
}, closed10)),
|
|
18282
|
+
smoke_test: _Object_({ status: phase, checks, passed: checks, failed: checks }, closed10)
|
|
18283
|
+
}, closed10),
|
|
18165
18284
|
cleanup: _Object_({
|
|
18166
18285
|
required: Boolean2(),
|
|
18167
18286
|
completed: Boolean2(),
|
|
18168
18287
|
error: Union([String2({ pattern: "^[A-Z][A-Z0-9_]{0,63}$" }), Null()])
|
|
18169
|
-
},
|
|
18288
|
+
}, closed10),
|
|
18170
18289
|
branch_name: Optional(String2({ minLength: 1, maxLength: 80 })),
|
|
18171
18290
|
queue_name: Optional(name),
|
|
18172
18291
|
test_secret_name: Optional(name),
|
|
18173
18292
|
source_configuration_id: Optional(Union([ApplicationConfigurationIdSchema2, Null()])),
|
|
18174
18293
|
created_at: Optional(timestamp3),
|
|
18175
18294
|
updated_at: Optional(timestamp3)
|
|
18176
|
-
},
|
|
18295
|
+
}, closed10);
|
|
18177
18296
|
var previewListSchema = _Object_({
|
|
18178
18297
|
...scope2,
|
|
18179
18298
|
previews: _Array_(ApplicationPreviewReceiptSchema2, { maxItems: 1000 })
|
|
18180
|
-
},
|
|
18299
|
+
}, closed10);
|
|
18181
18300
|
function assertScope(value, identity) {
|
|
18182
18301
|
if (value.project_ref !== identity.project_ref || value.application_id !== identity.application_id || value.environment_id !== identity.environment_id)
|
|
18183
18302
|
throw new Error("Application workflow scope mismatch");
|
|
@@ -21665,6 +21784,10 @@ function buildLiteArgs(request) {
|
|
|
21665
21784
|
optionalFlag(args, "--storage-dir", request.storage_dir);
|
|
21666
21785
|
optionalFlag(args, "--storage-backend", request.storage_backend);
|
|
21667
21786
|
optionalFlag(args, "--s3-prefix", request.s3_prefix);
|
|
21787
|
+
booleanFlag(args, "--s3-endpoint", request.s3_endpoint);
|
|
21788
|
+
optionalFlag(args, "--s3-endpoint-access-key-id", request.s3_endpoint_access_key_id);
|
|
21789
|
+
optionalFlag(args, "--s3-endpoint-region", request.s3_endpoint_region);
|
|
21790
|
+
optionalFlag(args, "--s3-endpoint-buckets", request.s3_endpoint_buckets);
|
|
21668
21791
|
optionalFlag(args, "--engine", request.engine);
|
|
21669
21792
|
optionalFlag(args, "--host", request.host);
|
|
21670
21793
|
optionalFlag(args, "--port", request.port);
|
|
@@ -21790,6 +21913,10 @@ function registerLiteCliTools(server, options = {}) {
|
|
|
21790
21913
|
storage_dir: optional(String2(), "[*] Object storage directory"),
|
|
21791
21914
|
storage_backend: optional(stringEnum2(["fs", "memory", "s3"]), "[*] Storage backend"),
|
|
21792
21915
|
s3_prefix: optional(String2(), "[*] S3 object key prefix"),
|
|
21916
|
+
s3_endpoint: optional(Boolean2(), "[start/doctor] Expose the inbound S3-compatible endpoint at /storage/v1/s3"),
|
|
21917
|
+
s3_endpoint_access_key_id: optional(String2(), "[start] Access key id for the inbound S3 endpoint"),
|
|
21918
|
+
s3_endpoint_region: optional(String2(), "[start] SigV4 region for the inbound S3 endpoint"),
|
|
21919
|
+
s3_endpoint_buckets: optional(String2(), "[start] Comma-separated bucket allowlist for the inbound S3 endpoint"),
|
|
21793
21920
|
engine: optional(stringEnum2(["pglite", "native"]), "[*] Database engine"),
|
|
21794
21921
|
host: optional(String2(), "[start] Listen host"),
|
|
21795
21922
|
port: optional(Number2(), "[start] Listen port"),
|
|
@@ -22094,6 +22221,7 @@ import {
|
|
|
22094
22221
|
createExecutionContextPack,
|
|
22095
22222
|
createDiagnosticRepairPlan,
|
|
22096
22223
|
doctorProject,
|
|
22224
|
+
formatDoctorCheck,
|
|
22097
22225
|
loadSupacloudConfig,
|
|
22098
22226
|
formatDeliveryPlan,
|
|
22099
22227
|
planDeliveryProject,
|
|
@@ -22227,7 +22355,7 @@ var starter_metadata_default = {
|
|
|
22227
22355
|
generatedBy: "supacloud/starter-metadata-v1",
|
|
22228
22356
|
packages: {
|
|
22229
22357
|
compiler: {
|
|
22230
|
-
version: "0.62.
|
|
22358
|
+
version: "0.62.2"
|
|
22231
22359
|
},
|
|
22232
22360
|
app: {
|
|
22233
22361
|
version: "0.39.1",
|
|
@@ -22236,7 +22364,7 @@ var starter_metadata_default = {
|
|
|
22236
22364
|
}
|
|
22237
22365
|
},
|
|
22238
22366
|
elysia: {
|
|
22239
|
-
version: "0.42.
|
|
22367
|
+
version: "0.42.2"
|
|
22240
22368
|
},
|
|
22241
22369
|
commands: {
|
|
22242
22370
|
version: "0.12.0"
|
|
@@ -22245,11 +22373,22 @@ var starter_metadata_default = {
|
|
|
22245
22373
|
version: "0.16.1"
|
|
22246
22374
|
},
|
|
22247
22375
|
db: {
|
|
22248
|
-
version: "0.24.
|
|
22376
|
+
version: "0.24.2",
|
|
22377
|
+
dependencies: {},
|
|
22378
|
+
devDependencies: {},
|
|
22379
|
+
peerDependencies: {
|
|
22380
|
+
"@supacloud/db-zenstack": "^0.1.0 || ^0.2.0"
|
|
22381
|
+
}
|
|
22382
|
+
},
|
|
22383
|
+
dbZenstack: {
|
|
22384
|
+
version: "0.2.1",
|
|
22249
22385
|
dependencies: {
|
|
22250
22386
|
"@zenstackhq/orm": "3.10.0",
|
|
22251
22387
|
"@zenstackhq/schema": "3.10.0",
|
|
22252
|
-
"@zenstackhq/plugin-policy": "3.10.0"
|
|
22388
|
+
"@zenstackhq/plugin-policy": "3.10.0",
|
|
22389
|
+
"@zenstackhq/language": "3.10.0",
|
|
22390
|
+
"@zenstackhq/sdk": "3.10.0",
|
|
22391
|
+
kysely: "0.29.0"
|
|
22253
22392
|
},
|
|
22254
22393
|
devDependencies: {
|
|
22255
22394
|
"@zenstackhq/cli": "3.10.0",
|
|
@@ -22502,6 +22641,27 @@ test("partial and untagged inherited remote profiles cannot mix with selected fi
|
|
|
22502
22641
|
|
|
22503
22642
|
// src/shared/tools/app-starter-templates.ts
|
|
22504
22643
|
var { compiler: compilerMetadata, app: appMetadata, elysia: elysiaMetadata } = starter_metadata_default.packages;
|
|
22644
|
+
var STARTER_TEMPLATES = ["minimal", "client", "command", "model-command"];
|
|
22645
|
+
var DEFAULT_STARTER_TEMPLATE = "minimal";
|
|
22646
|
+
var STARTER_TEMPLATE_ALIASES = {
|
|
22647
|
+
app: "minimal"
|
|
22648
|
+
};
|
|
22649
|
+
function isStarterTemplate(value) {
|
|
22650
|
+
return STARTER_TEMPLATES.includes(value);
|
|
22651
|
+
}
|
|
22652
|
+
function resolveStarterTemplate(input) {
|
|
22653
|
+
if (input === undefined)
|
|
22654
|
+
return DEFAULT_STARTER_TEMPLATE;
|
|
22655
|
+
if (isStarterTemplate(input))
|
|
22656
|
+
return input;
|
|
22657
|
+
if (Object.hasOwn(STARTER_TEMPLATE_ALIASES, input)) {
|
|
22658
|
+
return STARTER_TEMPLATE_ALIASES[input];
|
|
22659
|
+
}
|
|
22660
|
+
throw new Error(`Unknown app init template: ${input}. Use ${STARTER_TEMPLATES.join(", ")}` + " (`app` is accepted as an alias of `minimal`).");
|
|
22661
|
+
}
|
|
22662
|
+
function assertNeverTemplate(value) {
|
|
22663
|
+
throw new Error(`Unhandled starter template: ${String(value)}`);
|
|
22664
|
+
}
|
|
22505
22665
|
var json = (value) => `${JSON.stringify(value, null, 2)}
|
|
22506
22666
|
`;
|
|
22507
22667
|
var DEV_SCRIPT = `import { watchProject, compileOptionsFromConfig, loadSupacloudConfig } from "@supacloud/compiler";
|
|
@@ -22549,27 +22709,88 @@ const server = Bun.serve({
|
|
|
22549
22709
|
console.log("Local demo: " + server.url);
|
|
22550
22710
|
`;
|
|
22551
22711
|
var APPLICATION_SOURCE = (name) => `import { createApplication } from "@supacloud/elysia";
|
|
22552
|
-
import {
|
|
22712
|
+
import {
|
|
22713
|
+
createSupAuthRequestContext,
|
|
22714
|
+
type SupAuthContextOptions,
|
|
22715
|
+
type CommandGovernance,
|
|
22716
|
+
type ExecutionObserver,
|
|
22717
|
+
} from "@supacloud/elysia";
|
|
22553
22718
|
import { createCompiledModules } from "../generated/application";
|
|
22554
22719
|
|
|
22720
|
+
/** Trusted-host adapters. Keep these explicit so indexed ApplicationOptions access cannot widen to any. */
|
|
22555
22721
|
export interface AppAdapters {
|
|
22556
|
-
deps:
|
|
22557
|
-
requestContext:
|
|
22722
|
+
deps: Record<string, unknown>;
|
|
22723
|
+
requestContext: (
|
|
22724
|
+
request: Request,
|
|
22725
|
+
context: unknown,
|
|
22726
|
+
signal?: AbortSignal,
|
|
22727
|
+
) => unknown | Promise<unknown>;
|
|
22558
22728
|
commandGovernance: CommandGovernance;
|
|
22559
|
-
onExecution?:
|
|
22729
|
+
onExecution?: ExecutionObserver;
|
|
22730
|
+
}
|
|
22731
|
+
|
|
22732
|
+
export interface CreatedApplication {
|
|
22733
|
+
fetch: (request: Request) => Promise<Response>;
|
|
22734
|
+
handle: (request: Request) => Promise<Response>;
|
|
22735
|
+
initialize: () => Promise<void>;
|
|
22736
|
+
destroy: () => Promise<void>;
|
|
22737
|
+
}
|
|
22738
|
+
|
|
22739
|
+
function isRecord(value: unknown): value is { readonly [key: string]: unknown } {
|
|
22740
|
+
return typeof value === "object" && value !== null;
|
|
22741
|
+
}
|
|
22742
|
+
|
|
22743
|
+
function isApplicationHost(value: unknown): value is {
|
|
22744
|
+
fetch: (request: Request) => Response | Promise<Response>;
|
|
22745
|
+
handle: (request: Request) => Response | Promise<Response>;
|
|
22746
|
+
initialize: () => void | Promise<void>;
|
|
22747
|
+
destroy: () => void | Promise<void>;
|
|
22748
|
+
} {
|
|
22749
|
+
return isRecord(value)
|
|
22750
|
+
&& typeof value["fetch"] === "function"
|
|
22751
|
+
&& typeof value["handle"] === "function"
|
|
22752
|
+
&& typeof value["initialize"] === "function"
|
|
22753
|
+
&& typeof value["destroy"] === "function";
|
|
22754
|
+
}
|
|
22755
|
+
|
|
22756
|
+
function isRequestContextFactory(value: unknown): value is AppAdapters["requestContext"] {
|
|
22757
|
+
return typeof value === "function";
|
|
22758
|
+
}
|
|
22759
|
+
|
|
22760
|
+
export function readCreatedApplication(value: unknown): CreatedApplication {
|
|
22761
|
+
if (!isApplicationHost(value)) {
|
|
22762
|
+
throw new Error("createApplication returned an invalid application host");
|
|
22763
|
+
}
|
|
22764
|
+
return {
|
|
22765
|
+
fetch: async (request) => await value.fetch(request),
|
|
22766
|
+
handle: async (request) => await value.handle(request),
|
|
22767
|
+
initialize: async () => { await value.initialize(); },
|
|
22768
|
+
destroy: async () => { await value.destroy(); },
|
|
22769
|
+
};
|
|
22560
22770
|
}
|
|
22561
22771
|
|
|
22562
22772
|
// The host verifies external identity (SupAuth for unified login) before creating requestContext.
|
|
22563
|
-
export function createApp(adapters: AppAdapters) {
|
|
22564
|
-
|
|
22565
|
-
|
|
22773
|
+
export function createApp(adapters: AppAdapters): CreatedApplication {
|
|
22774
|
+
const application: unknown = createApplication({
|
|
22775
|
+
deps: adapters.deps,
|
|
22776
|
+
requestContext: adapters.requestContext,
|
|
22777
|
+
commandGovernance: adapters.commandGovernance,
|
|
22566
22778
|
name: ${JSON.stringify(name)},
|
|
22567
22779
|
modules: createCompiledModules(),
|
|
22780
|
+
...(adapters.onExecution === undefined ? {} : { onExecution: adapters.onExecution }),
|
|
22568
22781
|
});
|
|
22782
|
+
return readCreatedApplication(application);
|
|
22569
22783
|
}
|
|
22570
22784
|
|
|
22571
|
-
export function createSupAuthApp(
|
|
22572
|
-
|
|
22785
|
+
export function createSupAuthApp(
|
|
22786
|
+
identity: SupAuthContextOptions,
|
|
22787
|
+
adapters: Omit<AppAdapters, "requestContext">,
|
|
22788
|
+
): CreatedApplication {
|
|
22789
|
+
const resolved: unknown = createSupAuthRequestContext(identity);
|
|
22790
|
+
if (!isRequestContextFactory(resolved)) {
|
|
22791
|
+
throw new Error("createSupAuthRequestContext must return a requestContext function");
|
|
22792
|
+
}
|
|
22793
|
+
return createApp({ ...adapters, requestContext: resolved });
|
|
22573
22794
|
}
|
|
22574
22795
|
`;
|
|
22575
22796
|
var GENERATED_BOOTSTRAP = `// BOOTSTRAP ARTIFACT: bun run compile replaces this file.
|
|
@@ -22660,7 +22881,128 @@ export default defineSupacloudConfig();
|
|
|
22660
22881
|
"scripts/serve.ts": SERVE_SCRIPT
|
|
22661
22882
|
};
|
|
22662
22883
|
}
|
|
22663
|
-
|
|
22884
|
+
var DATA_CLIENT = `import { createClient, type SupabaseClient } from "@supabase/supabase-js";
|
|
22885
|
+
|
|
22886
|
+
/** Official data-plane client. Provisioned projects are reached with this client. */
|
|
22887
|
+
export function createDataClient(input: { url: string; anonKey: string }): SupabaseClient {
|
|
22888
|
+
const url = new URL(input.url);
|
|
22889
|
+
const loopback = url.hostname === "127.0.0.1" || url.hostname === "localhost";
|
|
22890
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
|
|
22891
|
+
throw new Error("Use the project HTTPS API URL, or loopback HTTP for local development");
|
|
22892
|
+
}
|
|
22893
|
+
if (input.anonKey.trim().length < 8 || input.anonKey !== input.anonKey.trim()) {
|
|
22894
|
+
throw new Error("Use the anon or publishable key");
|
|
22895
|
+
}
|
|
22896
|
+
return createClient(url.toString(), input.anonKey, {
|
|
22897
|
+
auth: { persistSession: false, autoRefreshToken: false },
|
|
22898
|
+
});
|
|
22899
|
+
}
|
|
22900
|
+
`;
|
|
22901
|
+
var DATA_CLIENT_TEST = `import { expect, test } from "bun:test";
|
|
22902
|
+
import { createDataClient } from "../src/client";
|
|
22903
|
+
|
|
22904
|
+
test("the data client is the official supabase-js client", () => {
|
|
22905
|
+
const client = createDataClient({ url: "http://127.0.0.1:54321", anonKey: "public-anon-key" });
|
|
22906
|
+
expect(typeof client.from).toBe("function");
|
|
22907
|
+
expect(typeof client.channel).toBe("function");
|
|
22908
|
+
});
|
|
22909
|
+
|
|
22910
|
+
test("non-local http URLs are rejected", () => {
|
|
22911
|
+
expect(() => createDataClient({ url: "http://example.com", anonKey: "public-anon-key" })).toThrow("HTTPS");
|
|
22912
|
+
});
|
|
22913
|
+
`;
|
|
22914
|
+
function supabaseClientTemplate(name, sdkDependencies) {
|
|
22915
|
+
return {
|
|
22916
|
+
"package.json": json({
|
|
22917
|
+
name,
|
|
22918
|
+
version: "0.0.0",
|
|
22919
|
+
private: true,
|
|
22920
|
+
type: "module",
|
|
22921
|
+
engines: { bun: ">=1.4.4" },
|
|
22922
|
+
scripts: {
|
|
22923
|
+
typecheck: "tsc --noEmit",
|
|
22924
|
+
test: "bun test",
|
|
22925
|
+
check: "bun run typecheck && bun run test"
|
|
22926
|
+
},
|
|
22927
|
+
dependencies: {
|
|
22928
|
+
"@supabase/supabase-js": sdkDependencies["@supabase/supabase-js"]
|
|
22929
|
+
},
|
|
22930
|
+
devDependencies: {
|
|
22931
|
+
"@types/bun": "^1.4.4",
|
|
22932
|
+
typescript: "7.1.0-beta"
|
|
22933
|
+
}
|
|
22934
|
+
}),
|
|
22935
|
+
"tsconfig.json": json({
|
|
22936
|
+
compilerOptions: {
|
|
22937
|
+
target: "ES2022",
|
|
22938
|
+
module: "ESNext",
|
|
22939
|
+
moduleResolution: "bundler",
|
|
22940
|
+
strict: true,
|
|
22941
|
+
skipLibCheck: true,
|
|
22942
|
+
noUncheckedIndexedAccess: true,
|
|
22943
|
+
exactOptionalPropertyTypes: true,
|
|
22944
|
+
noImplicitOverride: true,
|
|
22945
|
+
noPropertyAccessFromIndexSignature: true,
|
|
22946
|
+
noFallthroughCasesInSwitch: true,
|
|
22947
|
+
forceConsistentCasingInFileNames: true,
|
|
22948
|
+
useUnknownInCatchVariables: true,
|
|
22949
|
+
noEmit: true,
|
|
22950
|
+
types: ["bun"]
|
|
22951
|
+
},
|
|
22952
|
+
include: ["src/**/*.ts", "tests/**/*.ts"]
|
|
22953
|
+
}),
|
|
22954
|
+
"bunfig.toml": `env = false
|
|
22955
|
+
`,
|
|
22956
|
+
".gitignore": ["node_modules/", ".env", ".env.*", "!.env.example", ""].join(`
|
|
22957
|
+
`),
|
|
22958
|
+
".env.example": `SUPABASE_URL=http://127.0.0.1:54321
|
|
22959
|
+
SUPABASE_ANON_KEY=replace-with-anon-or-publishable-key
|
|
22960
|
+
`,
|
|
22961
|
+
"src/client.ts": DATA_CLIENT,
|
|
22962
|
+
"tests/client.test.ts": DATA_CLIENT_TEST,
|
|
22963
|
+
"AGENTS.md": `# ${name}
|
|
22964
|
+
|
|
22965
|
+
This project talks to a provisioned Supabase-compatible API with
|
|
22966
|
+
\`@supabase/supabase-js\`. It is the explicit \`--template client\` scaffold.
|
|
22967
|
+
|
|
22968
|
+
- Do not add \`@supacloud/app\`, \`@supacloud/compiler\`, \`@supacloud/elysia\`, or \`effect\` here.
|
|
22969
|
+
- The forced default application stack is \`supacloud app init\` (\`minimal\`).
|
|
22970
|
+
- Durable SQL and model recipes are \`--template command\` and \`--template model-command\`.
|
|
22971
|
+
- Use the anon or publishable key. Never put a service-role or Management token in this client.
|
|
22972
|
+
- Management API provision does not compile this project and does not interpret Effect.
|
|
22973
|
+
`,
|
|
22974
|
+
"README.md": `# ${name}
|
|
22975
|
+
|
|
22976
|
+
Explicit data-plane client (\`supacloud app init --template client\`) for a
|
|
22977
|
+
provisioned project. This scaffold depends on \`@supabase/supabase-js\` only. It
|
|
22978
|
+
does not install \`@supacloud/app\`, the compiler, Elysia, or Effect.
|
|
22979
|
+
|
|
22980
|
+
## Local check
|
|
22981
|
+
|
|
22982
|
+
\`\`\`sh
|
|
22983
|
+
bun install
|
|
22984
|
+
bun test tests/client.test.ts
|
|
22985
|
+
bun run check
|
|
22986
|
+
\`\`\`
|
|
22987
|
+
|
|
22988
|
+
Copy \`.env.example\` and set \`SUPABASE_URL\` to the project API URL and
|
|
22989
|
+
\`SUPABASE_ANON_KEY\` to the anon or publishable key. Do not commit the filled
|
|
22990
|
+
file, and do not put the service-role key in this client.
|
|
22991
|
+
|
|
22992
|
+
\`createDataClient\` accepts HTTPS, or HTTP only for \`127.0.0.1\` and \`localhost\`.
|
|
22993
|
+
Realtime uses the same client's \`channel()\` against the project's
|
|
22994
|
+
\`/realtime/v1/websocket\` endpoint. See the platform Realtime contract for which
|
|
22995
|
+
process owns that socket.
|
|
22996
|
+
|
|
22997
|
+
## Default application stack
|
|
22998
|
+
|
|
22999
|
+
\`supacloud app init\` (template \`minimal\`) is the forced compiler + Effect
|
|
23000
|
+
project. \`--template command\` and \`--template model-command\` are the durable
|
|
23001
|
+
reference recipes. Do not add those dependencies to this client project.
|
|
23002
|
+
`
|
|
23003
|
+
};
|
|
23004
|
+
}
|
|
23005
|
+
function appFrameworkTemplate(name, sdkDependencies) {
|
|
22664
23006
|
return {
|
|
22665
23007
|
...baseTemplateFiles(name, sdkDependencies),
|
|
22666
23008
|
"src/features/health/contracts.ts": `import { t } from "elysia";
|
|
@@ -22724,6 +23066,11 @@ export function createDemo() {
|
|
|
22724
23066
|
`,
|
|
22725
23067
|
"README.md": `# ${name}
|
|
22726
23068
|
|
|
23069
|
+
Default application stack from \`supacloud app init\` (template \`minimal\`).
|
|
23070
|
+
It installs \`@supacloud/app\`, the compiler, Elysia, and Effect. The data-plane
|
|
23071
|
+
client remains \`@supabase/supabase-js\` inside this project. Use
|
|
23072
|
+
\`--template client\` only when you need a client-only directory.
|
|
23073
|
+
|
|
22727
23074
|
## Local development
|
|
22728
23075
|
|
|
22729
23076
|
\`\`\`sh
|
|
@@ -22771,9 +23118,14 @@ regeneration, then validate types, database permissions and authenticated behavi
|
|
|
22771
23118
|
};
|
|
22772
23119
|
}
|
|
22773
23120
|
function appTemplateFiles(name, template, sdkDependencies) {
|
|
22774
|
-
|
|
22775
|
-
|
|
22776
|
-
|
|
23121
|
+
switch (template) {
|
|
23122
|
+
case "client":
|
|
23123
|
+
return supabaseClientTemplate(name, sdkDependencies);
|
|
23124
|
+
case "minimal":
|
|
23125
|
+
return appFrameworkTemplate(name, sdkDependencies);
|
|
23126
|
+
default:
|
|
23127
|
+
return assertNeverTemplate(template);
|
|
23128
|
+
}
|
|
22777
23129
|
}
|
|
22778
23130
|
|
|
22779
23131
|
// src/shared/tools/command-receipts.ts
|
|
@@ -22937,13 +23289,41 @@ var COMMANDS = `import { Command, defineOperationAspect, type Aspect } from "@su
|
|
|
22937
23289
|
import { createTypeBoxTransactionalCommand } from "@supacloud/commands/typebox";
|
|
22938
23290
|
import { plaintextCommandInput } from "@supacloud/commands";
|
|
22939
23291
|
import { CommandError, type CommandIdentity, type CommandStore } from "@supacloud/contracts";
|
|
22940
|
-
import type {
|
|
22941
|
-
import type { schema } from "../../../zenstack/generated/schema";
|
|
23292
|
+
import type { CallFunctionOptions, JsonArgument, ReadFunctionArg, ReadFunctionRow } from "@supacloud/db/model-contract";
|
|
22942
23293
|
import { Type } from "typebox";
|
|
22943
23294
|
import { CreateInput, ApproveInput, Decision, decodeApprove, decodeDecision, decodeOrder, decoder, type Principal } from "./contracts";
|
|
22944
23295
|
|
|
22945
|
-
type
|
|
22946
|
-
type
|
|
23296
|
+
type OrderRow = { readonly id: string; readonly title: string; readonly state: string; readonly version: number };
|
|
23297
|
+
type OrderDb = {
|
|
23298
|
+
readonly order: {
|
|
23299
|
+
createMany(args: { readonly data: readonly Record<string, unknown>[]; readonly skipDuplicates?: boolean }): Promise<{ readonly count: number }>;
|
|
23300
|
+
findUniqueOrThrow(args: { readonly where: { readonly tenantId_id: { readonly tenantId: string; readonly id: string } }; readonly select: Record<keyof OrderRow, true> }): Promise<OrderRow>;
|
|
23301
|
+
updateMany(args: { readonly where: Record<string, unknown>; readonly data: Record<string, unknown> }): Promise<{ readonly count: number }>;
|
|
23302
|
+
};
|
|
23303
|
+
};
|
|
23304
|
+
type Tx = {
|
|
23305
|
+
readonly db: OrderDb;
|
|
23306
|
+
readonly lock: (keys: readonly string[]) => Promise<void>;
|
|
23307
|
+
readonly readFunction: (name: string, args?: readonly ReadFunctionArg[]) => Promise<unknown>;
|
|
23308
|
+
readonly readFunctionByRow: (name: string, row: ReadFunctionRow) => Promise<unknown>;
|
|
23309
|
+
readonly callFunction: (name: string, args?: readonly JsonArgument[], options?: CallFunctionOptions) => Promise<unknown>;
|
|
23310
|
+
};
|
|
23311
|
+
type Store = CommandStore<unknown>;
|
|
23312
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
23313
|
+
return value !== null && typeof value === "object";
|
|
23314
|
+
}
|
|
23315
|
+
function isTx(value: unknown): value is Tx {
|
|
23316
|
+
const root = isRecord(value) ? value : undefined;
|
|
23317
|
+
const db = root && isRecord(root["db"]) ? root["db"] : undefined;
|
|
23318
|
+
const order = db && isRecord(db["order"]) ? db["order"] : undefined;
|
|
23319
|
+
const methods = ["lock", "readFunction", "readFunctionByRow", "callFunction"];
|
|
23320
|
+
return !!root && !!db && !!order && methods.every(name => typeof root[name] === "function")
|
|
23321
|
+
&& ["createMany", "findUniqueOrThrow", "updateMany"].every(name => typeof order[name] === "function");
|
|
23322
|
+
}
|
|
23323
|
+
function decodeTx(value: unknown): Tx {
|
|
23324
|
+
if (!isTx(value)) throw new TypeError("Invalid model command transaction");
|
|
23325
|
+
return value;
|
|
23326
|
+
}
|
|
22947
23327
|
const decodeCapabilities = decoder(Type.Object({ canApprove: Type.Boolean() }, { additionalProperties: false }));
|
|
22948
23328
|
export const approvalAspect = defineOperationAspect({
|
|
22949
23329
|
kind: "command", name: "orders.approve", input: decodeApprove, result: decodeDecision,
|
|
@@ -22967,10 +23347,11 @@ export class CreateOrder {
|
|
|
22967
23347
|
inputCodec: plaintextCommandInput,
|
|
22968
23348
|
authorize: identity => sameActor(identity, principal) && principal.canCreate ? "allow" : "deny",
|
|
22969
23349
|
audit: { event: "orders.create.decided", details: (input, result) => ({ id: input.id, outcome: result.outcome }) },
|
|
22970
|
-
execute: async (
|
|
22971
|
-
const
|
|
23350
|
+
execute: async (rawTx, input): Promise<Decision> => {
|
|
23351
|
+
const tx = decodeTx(rawTx);
|
|
23352
|
+
const created: { count: number } = await tx.db.order.createMany({ data: [{ ...input, tenantId: principal.tenantId, ownerId: principal.id, state: "draft", version: 1 }], skipDuplicates: true });
|
|
22972
23353
|
if (created.count !== 1) return { outcome: "conflict", order: null };
|
|
22973
|
-
const row = await tx.db.order.findUniqueOrThrow({ where: { tenantId_id: { tenantId: principal.tenantId, id: input.id } }, select: { id: true, title: true, state: true, version: true } });
|
|
23354
|
+
const row: { id: string; title: string; state: string; version: number } = await tx.db.order.findUniqueOrThrow({ where: { tenantId_id: { tenantId: principal.tenantId, id: input.id } }, select: { id: true, title: true, state: true, version: true } });
|
|
22974
23355
|
return { outcome: "applied", order: decodeOrder(row) };
|
|
22975
23356
|
},
|
|
22976
23357
|
});
|
|
@@ -22988,18 +23369,21 @@ export class ApproveOrder {
|
|
|
22988
23369
|
name: "orders.approve", store, schemas: { input: ApproveInput, result: Decision }, inputCodec: plaintextCommandInput,
|
|
22989
23370
|
authorize: identity => sameActor(identity, principal) && principal.canApprove ? "allow" : "deny",
|
|
22990
23371
|
audit: { event: "orders.approval.decided", details: (input, result) => ({ id: input.id, outcome: result.outcome }) },
|
|
22991
|
-
execute: async (
|
|
23372
|
+
execute: async (rawTx, input) => {
|
|
23373
|
+
const tx = decodeTx(rawTx);
|
|
23374
|
+
return decodeDecision(await pipeline({
|
|
22992
23375
|
kind: "command", name: "orders.approve", input,
|
|
22993
23376
|
services: { approval: { canApprove: principal.canApprove } },
|
|
22994
23377
|
}, async (): Promise<Decision> => {
|
|
22995
|
-
const changed = await tx.db.order.updateMany({
|
|
23378
|
+
const changed: { count: number } = await tx.db.order.updateMany({
|
|
22996
23379
|
where: { tenantId: principal.tenantId, id: input.id, state: "draft", version: input.expectedVersion },
|
|
22997
23380
|
data: { state: "approved", version: { increment: 1 } },
|
|
22998
23381
|
});
|
|
22999
23382
|
if (changed.count !== 1) return { outcome: "conflict", order: null };
|
|
23000
|
-
const row = await tx.db.order.findUniqueOrThrow({ where: { tenantId_id: { tenantId: principal.tenantId, id: input.id } }, select: { id: true, title: true, state: true, version: true } });
|
|
23383
|
+
const row: { id: string; title: string; state: string; version: number } = await tx.db.order.findUniqueOrThrow({ where: { tenantId_id: { tenantId: principal.tenantId, id: input.id } }, select: { id: true, title: true, state: true, version: true } });
|
|
23001
23384
|
return { outcome: "applied", order: decodeOrder(row) };
|
|
23002
|
-
}))
|
|
23385
|
+
}));
|
|
23386
|
+
},
|
|
23003
23387
|
});
|
|
23004
23388
|
}
|
|
23005
23389
|
execute(identity: CommandIdentity, key: string, input: ApproveInput, signal?: AbortSignal) {
|
|
@@ -23044,7 +23428,7 @@ export class OrdersModule {}
|
|
|
23044
23428
|
var HOST = `import type { SQL } from "bun";
|
|
23045
23429
|
import { createApplication, ApplicationError, type CompiledModule } from "@supacloud/elysia";
|
|
23046
23430
|
import { createZenStackDatabase } from "@supacloud/db/zenstack";
|
|
23047
|
-
import { CommandError } from "@supacloud/contracts";
|
|
23431
|
+
import { CommandError, type CommandStore } from "@supacloud/contracts";
|
|
23048
23432
|
import { schema } from "../../zenstack/generated/schema";
|
|
23049
23433
|
import { createCompiledModules } from "../../generated/application";
|
|
23050
23434
|
import { CreateOrder, ApproveOrder } from "../features/orders/commands";
|
|
@@ -23060,6 +23444,34 @@ export interface IdentityAuthority {
|
|
|
23060
23444
|
resolve(actor: ActorBinding): Promise<Principal | null>;
|
|
23061
23445
|
}
|
|
23062
23446
|
|
|
23447
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
23448
|
+
return value !== null && typeof value === "object";
|
|
23449
|
+
}
|
|
23450
|
+
function isCommandStore(value: unknown): value is CommandStore<unknown> {
|
|
23451
|
+
return isRecord(value) && typeof value["transaction"] === "function";
|
|
23452
|
+
}
|
|
23453
|
+
function requireCommandStore(value: unknown): CommandStore<unknown> {
|
|
23454
|
+
if (!isCommandStore(value)) throw new CommandError("COMMAND_UNAVAILABLE");
|
|
23455
|
+
return value;
|
|
23456
|
+
}
|
|
23457
|
+
interface ScopedDatabase {
|
|
23458
|
+
readonly commandStore: unknown;
|
|
23459
|
+
readonly models: { readonly order: { findUnique(args: unknown): Promise<unknown> } };
|
|
23460
|
+
}
|
|
23461
|
+
interface DatabaseFacade {
|
|
23462
|
+
forIdentity(identity: Principal): ScopedDatabase;
|
|
23463
|
+
dispose(): Promise<void>;
|
|
23464
|
+
}
|
|
23465
|
+
function isDatabaseFacade(value: unknown): value is DatabaseFacade {
|
|
23466
|
+
if (!isRecord(value) || typeof value["forIdentity"] !== "function" || typeof value["dispose"] !== "function") return false;
|
|
23467
|
+
const scoped = value["forIdentity"];
|
|
23468
|
+
return typeof scoped === "function";
|
|
23469
|
+
}
|
|
23470
|
+
function requireDatabase(value: unknown): DatabaseFacade {
|
|
23471
|
+
if (!isDatabaseFacade(value)) throw new CommandError("COMMAND_UNAVAILABLE");
|
|
23472
|
+
return value;
|
|
23473
|
+
}
|
|
23474
|
+
|
|
23063
23475
|
export async function createModelOrderHost(pool: SQL, authority: IdentityAuthority) {
|
|
23064
23476
|
const roles = await pool<unknown[]>\`SELECT rolsuper, rolbypassrls, pg_has_role(current_user, 'model_orders_app', 'USAGE') AS allowed,
|
|
23065
23477
|
EXISTS (SELECT FROM pg_class WHERE oid IN ('public.model_orders'::regclass, 'supacloud_commands.execution_receipts'::regclass, 'supacloud_commands.execution_audit'::regclass)
|
|
@@ -23071,7 +23483,7 @@ export async function createModelOrderHost(pool: SQL, authority: IdentityAuthori
|
|
|
23071
23483
|
|| !("owns_data" in role) || role.owns_data !== false) {
|
|
23072
23484
|
throw new Error("Use a non-owner application login with model_orders_app membership");
|
|
23073
23485
|
}
|
|
23074
|
-
const database = createZenStackDatabase(schema, pool, {});
|
|
23486
|
+
const database = requireDatabase(createZenStackDatabase(schema, pool, {}));
|
|
23075
23487
|
const modules: CompiledModule[] = createCompiledModules();
|
|
23076
23488
|
const ordersModule = modules.find(module => module.name === "orders");
|
|
23077
23489
|
const approval = ordersModule?.commands?.find(command => command.name === "orders.approve")?.aspectPipeline;
|
|
@@ -23097,11 +23509,11 @@ export async function createModelOrderHost(pool: SQL, authority: IdentityAuthori
|
|
|
23097
23509
|
const port: OrderPort = {
|
|
23098
23510
|
create: async (context, key, input) => {
|
|
23099
23511
|
const bound = await bind(context);
|
|
23100
|
-
return decodeReceipt(await new CreateOrder(bound.scoped.commandStore, bound.principal).execute(bound.identity, key, decodeCreate(input), bound.signal));
|
|
23512
|
+
return decodeReceipt(await new CreateOrder(requireCommandStore(bound.scoped.commandStore), bound.principal).execute(bound.identity, key, decodeCreate(input), bound.signal));
|
|
23101
23513
|
},
|
|
23102
23514
|
approve: async (context, key, input) => {
|
|
23103
23515
|
const bound = await bind(context);
|
|
23104
|
-
return decodeReceipt(await new ApproveOrder(bound.scoped.commandStore, bound.principal, approval).execute(bound.identity, key, decodeApprove(input), bound.signal));
|
|
23516
|
+
return decodeReceipt(await new ApproveOrder(requireCommandStore(bound.scoped.commandStore), bound.principal, approval).execute(bound.identity, key, decodeApprove(input), bound.signal));
|
|
23105
23517
|
},
|
|
23106
23518
|
read: async (context, id) => {
|
|
23107
23519
|
const bound = await bind(context);
|
|
@@ -23147,7 +23559,7 @@ GRANT SELECT, INSERT, UPDATE ON supacloud_commands.execution_receipts TO model_o
|
|
|
23147
23559
|
GRANT SELECT, INSERT ON supacloud_commands.execution_audit TO model_orders_app;
|
|
23148
23560
|
`;
|
|
23149
23561
|
function modelCommandTemplateFiles(name, sdk) {
|
|
23150
|
-
const { app, compiler, elysia, commands, contracts, db } = starter_metadata_default.packages;
|
|
23562
|
+
const { app, compiler, elysia, commands, contracts, db, dbZenstack } = starter_metadata_default.packages;
|
|
23151
23563
|
const files = baseTemplateFiles(name, sdk);
|
|
23152
23564
|
delete files["scripts/dev.ts"];
|
|
23153
23565
|
delete files["scripts/serve.ts"];
|
|
@@ -23186,13 +23598,15 @@ function modelCommandTemplateFiles(name, sdk) {
|
|
|
23186
23598
|
"@supacloud/commands": "^" + commands.version,
|
|
23187
23599
|
"@supacloud/contracts": "^" + contracts.version,
|
|
23188
23600
|
"@supacloud/db": "^" + db.version,
|
|
23601
|
+
"@supacloud/db-zenstack": "^" + dbZenstack.version,
|
|
23189
23602
|
...db.dependencies,
|
|
23603
|
+
...dbZenstack.dependencies,
|
|
23190
23604
|
typebox: "1.4.3",
|
|
23191
23605
|
effect: "4.0.5",
|
|
23192
23606
|
elysia: "2.0.0-rc.1",
|
|
23193
23607
|
...sdk
|
|
23194
23608
|
},
|
|
23195
|
-
devDependencies: { "@supacloud/compiler": "^" + compiler.version, ...db.devDependencies, "@types/bun": "^1.4.4", typescript: "7.1.0-beta" }
|
|
23609
|
+
devDependencies: { "@supacloud/compiler": "^" + compiler.version, ...db.devDependencies, ...dbZenstack.devDependencies, "@types/bun": "^1.4.4", typescript: "7.1.0-beta" }
|
|
23196
23610
|
}),
|
|
23197
23611
|
"supacloud.config.ts": `import { defineSupacloudConfig } from "@supacloud/compiler";
|
|
23198
23612
|
export default defineSupacloudConfig({
|
|
@@ -25902,7 +26316,7 @@ export async function createReviewTaskAdapters(options: ReviewTaskOptions): Prom
|
|
|
25902
26316
|
`;
|
|
25903
26317
|
|
|
25904
26318
|
// src/shared/tools/app-starter.ts
|
|
25905
|
-
var { compiler: compilerMetadata2, app: appMetadata2, elysia: elysiaMetadata2, commands: commandsMetadata, contracts: contractsMetadata, db: dbMetadata, sdk: sdkMetadata } = starter_metadata_default.packages;
|
|
26319
|
+
var { compiler: compilerMetadata2, app: appMetadata2, elysia: elysiaMetadata2, commands: commandsMetadata, contracts: contractsMetadata, db: dbMetadata, dbZenstack: dbZenstackMetadata, sdk: sdkMetadata } = starter_metadata_default.packages;
|
|
25906
26320
|
var json3 = (value) => `${JSON.stringify(value, null, 2)}
|
|
25907
26321
|
`;
|
|
25908
26322
|
function appStarterFiles(name) {
|
|
@@ -25944,7 +26358,9 @@ function appStarterFiles(name) {
|
|
|
25944
26358
|
"@supacloud/commands": `^${commandsMetadata.version}`,
|
|
25945
26359
|
"@supacloud/contracts": `^${contractsMetadata.version}`,
|
|
25946
26360
|
"@supacloud/db": `^${dbMetadata.version}`,
|
|
26361
|
+
"@supacloud/db-zenstack": `^${dbZenstackMetadata.version}`,
|
|
25947
26362
|
...dbMetadata.dependencies,
|
|
26363
|
+
...dbZenstackMetadata.dependencies,
|
|
25948
26364
|
"@supacloud/js": `^${sdkMetadata.version}`,
|
|
25949
26365
|
"@supabase/supabase-js": sdkMetadata.peerDependencies["@supabase/supabase-js"],
|
|
25950
26366
|
effect: "4.0.5",
|
|
@@ -25954,6 +26370,7 @@ function appStarterFiles(name) {
|
|
|
25954
26370
|
devDependencies: {
|
|
25955
26371
|
"@supacloud/compiler": `^${compilerMetadata2.version}`,
|
|
25956
26372
|
...dbMetadata.devDependencies,
|
|
26373
|
+
...dbZenstackMetadata.devDependencies,
|
|
25957
26374
|
"@types/bun": "^1.4.4",
|
|
25958
26375
|
typescript: "7.1.0-beta"
|
|
25959
26376
|
}
|
|
@@ -26151,27 +26568,88 @@ export function createDemo() {
|
|
|
26151
26568
|
}
|
|
26152
26569
|
`,
|
|
26153
26570
|
"src/application.ts": `import { createApplication } from "@supacloud/elysia";
|
|
26154
|
-
import {
|
|
26571
|
+
import {
|
|
26572
|
+
createSupAuthRequestContext,
|
|
26573
|
+
type SupAuthContextOptions,
|
|
26574
|
+
type CommandGovernance,
|
|
26575
|
+
type ExecutionObserver,
|
|
26576
|
+
} from "@supacloud/elysia";
|
|
26155
26577
|
import { createCompiledModules } from "../generated/application";
|
|
26156
26578
|
|
|
26579
|
+
/** Trusted-host adapters. Keep these explicit so indexed ApplicationOptions access cannot widen to any. */
|
|
26157
26580
|
export interface AppAdapters {
|
|
26158
|
-
deps:
|
|
26159
|
-
requestContext:
|
|
26581
|
+
deps: Record<string, unknown>;
|
|
26582
|
+
requestContext: (
|
|
26583
|
+
request: Request,
|
|
26584
|
+
context: unknown,
|
|
26585
|
+
signal?: AbortSignal,
|
|
26586
|
+
) => unknown | Promise<unknown>;
|
|
26160
26587
|
commandGovernance: CommandGovernance;
|
|
26161
|
-
onExecution?:
|
|
26588
|
+
onExecution?: ExecutionObserver;
|
|
26589
|
+
}
|
|
26590
|
+
|
|
26591
|
+
export interface CreatedApplication {
|
|
26592
|
+
fetch: (request: Request) => Promise<Response>;
|
|
26593
|
+
handle: (request: Request) => Promise<Response>;
|
|
26594
|
+
initialize: () => Promise<void>;
|
|
26595
|
+
destroy: () => Promise<void>;
|
|
26596
|
+
}
|
|
26597
|
+
|
|
26598
|
+
function isRecord(value: unknown): value is { readonly [key: string]: unknown } {
|
|
26599
|
+
return typeof value === "object" && value !== null;
|
|
26600
|
+
}
|
|
26601
|
+
|
|
26602
|
+
function isApplicationHost(value: unknown): value is {
|
|
26603
|
+
fetch: (request: Request) => Response | Promise<Response>;
|
|
26604
|
+
handle: (request: Request) => Response | Promise<Response>;
|
|
26605
|
+
initialize: () => void | Promise<void>;
|
|
26606
|
+
destroy: () => void | Promise<void>;
|
|
26607
|
+
} {
|
|
26608
|
+
return isRecord(value)
|
|
26609
|
+
&& typeof value["fetch"] === "function"
|
|
26610
|
+
&& typeof value["handle"] === "function"
|
|
26611
|
+
&& typeof value["initialize"] === "function"
|
|
26612
|
+
&& typeof value["destroy"] === "function";
|
|
26613
|
+
}
|
|
26614
|
+
|
|
26615
|
+
function isRequestContextFactory(value: unknown): value is AppAdapters["requestContext"] {
|
|
26616
|
+
return typeof value === "function";
|
|
26617
|
+
}
|
|
26618
|
+
|
|
26619
|
+
export function readCreatedApplication(value: unknown): CreatedApplication {
|
|
26620
|
+
if (!isApplicationHost(value)) {
|
|
26621
|
+
throw new Error("createApplication returned an invalid application host");
|
|
26622
|
+
}
|
|
26623
|
+
return {
|
|
26624
|
+
fetch: async (request) => await value.fetch(request),
|
|
26625
|
+
handle: async (request) => await value.handle(request),
|
|
26626
|
+
initialize: async () => { await value.initialize(); },
|
|
26627
|
+
destroy: async () => { await value.destroy(); },
|
|
26628
|
+
};
|
|
26162
26629
|
}
|
|
26163
26630
|
|
|
26164
26631
|
// The host verifies external identity (SupAuth for unified login) before creating requestContext.
|
|
26165
|
-
export function createApp(adapters: AppAdapters) {
|
|
26166
|
-
|
|
26167
|
-
|
|
26632
|
+
export function createApp(adapters: AppAdapters): CreatedApplication {
|
|
26633
|
+
const application: unknown = createApplication({
|
|
26634
|
+
deps: adapters.deps,
|
|
26635
|
+
requestContext: adapters.requestContext,
|
|
26636
|
+
commandGovernance: adapters.commandGovernance,
|
|
26168
26637
|
name: ${JSON.stringify(name)},
|
|
26169
26638
|
modules: createCompiledModules(),
|
|
26639
|
+
...(adapters.onExecution === undefined ? {} : { onExecution: adapters.onExecution }),
|
|
26170
26640
|
});
|
|
26641
|
+
return readCreatedApplication(application);
|
|
26171
26642
|
}
|
|
26172
26643
|
|
|
26173
|
-
export function createSupAuthApp(
|
|
26174
|
-
|
|
26644
|
+
export function createSupAuthApp(
|
|
26645
|
+
identity: SupAuthContextOptions,
|
|
26646
|
+
adapters: Omit<AppAdapters, "requestContext">,
|
|
26647
|
+
): CreatedApplication {
|
|
26648
|
+
const resolved: unknown = createSupAuthRequestContext(identity);
|
|
26649
|
+
if (!isRequestContextFactory(resolved)) {
|
|
26650
|
+
throw new Error("createSupAuthRequestContext must return a requestContext function");
|
|
26651
|
+
}
|
|
26652
|
+
return createApp({ ...adapters, requestContext: resolved });
|
|
26175
26653
|
}
|
|
26176
26654
|
`,
|
|
26177
26655
|
"generated/application.ts": `// BOOTSTRAP ARTIFACT: bun run compile replaces this file.
|
|
@@ -26517,7 +26995,10 @@ Management API tokens and service-role keys remain on trusted servers.
|
|
|
26517
26995
|
Ordinary reads use PostgREST through the existing user-scoped
|
|
26518
26996
|
@supabase/supabase-js client: client.from("starter_reviews").select("id,state,version").
|
|
26519
26997
|
Use the caller's session, RLS and grants; never introduce a second session store.
|
|
26520
|
-
|
|
26998
|
+
Command is the write boundary of this compiler application lane only.
|
|
26999
|
+
Cross-table change, idempotency, and audit stay on the governed Command/RPC
|
|
27000
|
+
boundary. Ordinary reads and low-risk CRUD stay on PostgREST and
|
|
27001
|
+
@supabase/supabase-js.
|
|
26521
27002
|
|
|
26522
27003
|
Use listReviews from src/review/list-reviews.ts for the paginated review list.
|
|
26523
27004
|
Type the existing client with ReviewReadDatabase (a read-only projection derived
|
|
@@ -26851,18 +27332,32 @@ async function initializeAppProject(options) {
|
|
|
26851
27332
|
if ((await readdir3(root)).some((entry) => entry !== ".git")) {
|
|
26852
27333
|
throw new Error("app init requires an empty directory (an existing .git directory is allowed)");
|
|
26853
27334
|
}
|
|
26854
|
-
const template = options.template
|
|
27335
|
+
const template = resolveStarterTemplate(options.template);
|
|
26855
27336
|
const sdk = {
|
|
26856
27337
|
"@supacloud/js": `^${sdkMetadata.version}`,
|
|
26857
27338
|
"@supabase/supabase-js": sdkMetadata.peerDependencies["@supabase/supabase-js"]
|
|
26858
27339
|
};
|
|
26859
|
-
const files =
|
|
27340
|
+
const files = (() => {
|
|
27341
|
+
switch (template) {
|
|
27342
|
+
case "command":
|
|
27343
|
+
return appStarterFiles(name);
|
|
27344
|
+
case "model-command":
|
|
27345
|
+
return modelCommandTemplateFiles(name, sdk);
|
|
27346
|
+
case "minimal":
|
|
27347
|
+
case "client":
|
|
27348
|
+
return appTemplateFiles(name, template, sdk);
|
|
27349
|
+
default: {
|
|
27350
|
+
const exhausted = template;
|
|
27351
|
+
throw new Error(`Unknown app init template: ${String(exhausted)}`);
|
|
27352
|
+
}
|
|
27353
|
+
}
|
|
27354
|
+
})();
|
|
26860
27355
|
for (const [relativePath, content] of Object.entries(files)) {
|
|
26861
27356
|
const path = join9(root, relativePath);
|
|
26862
27357
|
await mkdir3(dirname6(path), { recursive: true });
|
|
26863
27358
|
await writeFile3(path, content, { encoding: "utf8", flag: "wx" });
|
|
26864
27359
|
}
|
|
26865
|
-
return { root, name, files: Object.keys(files) };
|
|
27360
|
+
return { root, name, files: Object.keys(files), template };
|
|
26866
27361
|
}
|
|
26867
27362
|
|
|
26868
27363
|
// src/shared/tools/app-database-check.ts
|
|
@@ -26904,12 +27399,18 @@ function checkAppDatabaseSources(projectRoot) {
|
|
|
26904
27399
|
}
|
|
26905
27400
|
return {
|
|
26906
27401
|
name,
|
|
27402
|
+
layer: "source",
|
|
26907
27403
|
ok: (result.exitCode === 0 || result.success) && report.ok && !messages.length,
|
|
26908
27404
|
detail: messages.join(`
|
|
26909
27405
|
`) || ((result.exitCode === 0 || result.success) && report.ok ? "Offline database contracts and boundaries are current" : "Database source check failed")
|
|
26910
27406
|
};
|
|
26911
27407
|
} catch {
|
|
26912
|
-
return {
|
|
27408
|
+
return {
|
|
27409
|
+
name,
|
|
27410
|
+
layer: "runtime",
|
|
27411
|
+
ok: false,
|
|
27412
|
+
detail: "Cannot run the project database checker. Install the project runtime and @supacloud/db with source-contracts support, then run `supacloud-db check --root .` for diagnostics."
|
|
27413
|
+
};
|
|
26913
27414
|
}
|
|
26914
27415
|
}
|
|
26915
27416
|
|
|
@@ -28564,17 +29065,20 @@ for (const [name, schema] of Object.entries(REMOTE_APP_SCHEMA)) {
|
|
|
28564
29065
|
async function initProject(args) {
|
|
28565
29066
|
if (args.force)
|
|
28566
29067
|
throw new Error("app init never overwrites files; choose an empty directory");
|
|
28567
|
-
const template =
|
|
28568
|
-
|
|
28569
|
-
|
|
29068
|
+
const { root, name, files, template } = await initializeAppProject({
|
|
29069
|
+
root: args.root,
|
|
29070
|
+
name: args.name,
|
|
29071
|
+
template: args.template
|
|
29072
|
+
});
|
|
29073
|
+
const next = template === "client" ? ["bun install", "bun run check"] : [
|
|
28570
29074
|
"bun install",
|
|
28571
|
-
...template
|
|
29075
|
+
...template === "command" || template === "model-command" ? ["bun run db:generate"] : [],
|
|
28572
29076
|
...template === "model-command" ? ["bun run compile"] : [],
|
|
28573
29077
|
"bun run check",
|
|
28574
29078
|
...template === "model-command" ? ["# Follow README.md: apply reviewed local migrations, provision the application role and configure IdentityAuthority before dev."] : [],
|
|
28575
29079
|
"bun run dev"
|
|
28576
29080
|
];
|
|
28577
|
-
const note = template === "model-command" ? "Requires an explicitly selected database, reviewed migrations and trusted HTTP/worker identity authority; see README.md." : "Local demo only. Production requires persistent governance and identity adapters; see README.md.";
|
|
29081
|
+
const note = template === "client" ? "Data-plane client only (@supabase/supabase-js). The forced default is app init (minimal compiler/Effect stack)." : template === "model-command" ? "Requires an explicitly selected database, reviewed migrations and trusted HTTP/worker identity authority; see README.md." : "Local demo only. Production requires persistent governance and identity adapters; see README.md.";
|
|
28578
29082
|
if (args.format === "json")
|
|
28579
29083
|
return textResult(JSON.stringify({
|
|
28580
29084
|
version: 1,
|
|
@@ -29108,7 +29612,7 @@ async function runDoctor(args) {
|
|
|
29108
29612
|
...doctor
|
|
29109
29613
|
}, null, 2), doctor.errors > 0);
|
|
29110
29614
|
}
|
|
29111
|
-
const lines = doctor.checks.map((check) =>
|
|
29615
|
+
const lines = doctor.checks.map((check) => formatDoctorCheck(check));
|
|
29112
29616
|
if (scope)
|
|
29113
29617
|
lines.unshift(`TARGET ${scope.target}; omitted project diagnostics=${scope.omittedProjectDiagnostics}; generated drift remains project-wide`);
|
|
29114
29618
|
for (const diagnostic of doctor.diagnostics ?? []) {
|
|
@@ -29416,7 +29920,7 @@ async function runCheck(args) {
|
|
|
29416
29920
|
return textResult([
|
|
29417
29921
|
formatDiagnostics(result.diagnostics),
|
|
29418
29922
|
...result.mismatches.map((path) => `generated artifact mismatch: ${path}`),
|
|
29419
|
-
...database ? [
|
|
29923
|
+
...database ? [formatDoctorCheck(database)] : [],
|
|
29420
29924
|
"",
|
|
29421
29925
|
summary
|
|
29422
29926
|
].join(`
|
|
@@ -30262,7 +30766,7 @@ function registerAppTools(server, options = {}) {
|
|
|
30262
30766
|
"promote-reconcile"
|
|
30263
30767
|
]), "App action; promote obtains and verifies its plan before one mutation request"),
|
|
30264
30768
|
kind: optional(stringEnum2(["module", "command", "query", "controller", "job", "contract", "resource", "feature"]), "[generate] Scaffold kind"),
|
|
30265
|
-
template: optional(stringEnum2(["minimal", "command", "model-command"]), "[init]
|
|
30769
|
+
template: optional(stringEnum2(["minimal", "client", "command", "model-command", "app"]), "[init] minimal (default) is the compiler/Effect stack; client is @supabase/supabase-js only; command is the native-SQL reference; model-command adds ZenStack HTTP/worker commands; app is an alias of minimal"),
|
|
30266
30770
|
name: optional(String2(), "[init/generate] Project or object name"),
|
|
30267
30771
|
module: optional(String2(), "[generate] Target feature module (required for command/query/controller)"),
|
|
30268
30772
|
permission: optional(String2(), "[generate feature] Explicit approval permission; not inferred from name"),
|
|
@@ -34343,7 +34847,7 @@ async function runProjectDeployment(http, args) {
|
|
|
34343
34847
|
// package.json
|
|
34344
34848
|
var package_default = {
|
|
34345
34849
|
name: "@supacloud/cli",
|
|
34346
|
-
version: "0.
|
|
34850
|
+
version: "0.121.3",
|
|
34347
34851
|
description: "Project-scoped CLI for SupaCloud users",
|
|
34348
34852
|
type: "module",
|
|
34349
34853
|
main: "./dist/index.js",
|
|
@@ -34395,23 +34899,23 @@ var package_default = {
|
|
|
34395
34899
|
directory: "packages/cli"
|
|
34396
34900
|
},
|
|
34397
34901
|
dependencies: {
|
|
34398
|
-
"@supacloud/compiler": "^0.62.
|
|
34399
|
-
"@supacloud/delivery": "0.
|
|
34400
|
-
"@supacloud/db": "0.24.
|
|
34902
|
+
"@supacloud/compiler": "^0.62.2",
|
|
34903
|
+
"@supacloud/delivery": "0.27.0",
|
|
34904
|
+
"@supacloud/db": "0.24.2",
|
|
34401
34905
|
typebox: "1.4.3"
|
|
34402
34906
|
},
|
|
34403
34907
|
overrides: {
|
|
34404
34908
|
"@supacloud/contracts": "0.16.1",
|
|
34405
|
-
"@supacloud/delivery": "0.
|
|
34909
|
+
"@supacloud/delivery": "0.27.0",
|
|
34406
34910
|
"@graphql-tools/utils": "^12.0.4",
|
|
34407
|
-
"@supacloud/compiler": "^0.62.
|
|
34408
|
-
"@supacloud/db": "0.24.
|
|
34911
|
+
"@supacloud/compiler": "^0.62.2",
|
|
34912
|
+
"@supacloud/db": "0.24.2",
|
|
34409
34913
|
"deepmerge-ts": "8.0.2",
|
|
34410
34914
|
prisma: "6.19.3"
|
|
34411
34915
|
},
|
|
34412
34916
|
devDependencies: {
|
|
34413
34917
|
"@supabase/supabase-js": "2.118.0",
|
|
34414
|
-
"@supacloud/elysia": "0.42.
|
|
34918
|
+
"@supacloud/elysia": "0.42.2",
|
|
34415
34919
|
"@types/bun": "^1.4.4",
|
|
34416
34920
|
effect: "4.0.5",
|
|
34417
34921
|
elysia: "2.0.0-rc.1",
|