@quickback-dev/cli 0.70.27 → 0.70.38
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/codex/AGENTS.md +290 -0
- package/dist/commands/build.d.ts +12 -0
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +69 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/build.test.d.ts.map +1 -0
- package/dist/commands/codex.d.ts +16 -0
- package/dist/commands/codex.d.ts.map +1 -0
- package/dist/commands/codex.js +159 -0
- package/dist/commands/codex.js.map +1 -0
- package/dist/commands/compile.d.ts +62 -0
- package/dist/commands/compile.d.ts.map +1 -0
- package/dist/commands/compile.js +830 -0
- package/dist/commands/compile.js.map +1 -0
- package/dist/commands/compile.test.d.ts.map +1 -0
- package/dist/commands/deploy.d.ts +9 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +20 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +405 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/migrate-data.d.ts +12 -0
- package/dist/commands/migrate-data.d.ts.map +1 -0
- package/dist/commands/migrate-data.js +134 -0
- package/dist/commands/migrate-data.js.map +1 -0
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +11 -0
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/migrate.test.d.ts.map +1 -0
- package/dist/commands/migrations.test.d.ts.map +1 -0
- package/dist/commands/push.test.d.ts.map +1 -0
- package/dist/commands/schema.test.d.ts.map +1 -0
- package/dist/commands/secrets.d.ts +27 -0
- package/dist/commands/secrets.d.ts.map +1 -0
- package/dist/commands/secrets.js +186 -0
- package/dist/commands/secrets.js.map +1 -0
- package/dist/docs/content.d.ts +7 -0
- package/dist/docs/content.d.ts.map +1 -0
- package/dist/docs/content.js +672 -0
- package/dist/docs/content.js.map +1 -0
- package/dist/docs/index.test.d.ts.map +1 -0
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/access-manifest-diff.d.ts +87 -0
- package/dist/lib/access-manifest-diff.d.ts.map +1 -0
- package/dist/lib/access-manifest-diff.js +331 -0
- package/dist/lib/access-manifest-diff.js.map +1 -0
- package/dist/lib/action-harvest.test.d.ts.map +1 -0
- package/dist/lib/api-client.test.d.ts.map +1 -0
- package/dist/lib/artifact-routing.d.ts.map +1 -1
- package/dist/lib/artifact-routing.js +3 -0
- package/dist/lib/artifact-routing.js.map +1 -1
- package/dist/lib/artifact-routing.test.d.ts.map +1 -0
- package/dist/lib/auth.test.d.ts.map +1 -0
- package/dist/lib/compile-next-steps.test.d.ts.map +1 -0
- package/dist/lib/compiler-floor.test.d.ts.map +1 -0
- package/dist/lib/compiler-stubs.d.ts +2 -0
- package/dist/lib/compiler-stubs.d.ts.map +1 -1
- package/dist/lib/compiler-stubs.js +2 -0
- package/dist/lib/compiler-stubs.js.map +1 -1
- package/dist/lib/config-id-splice.test.d.ts.map +1 -0
- package/dist/lib/config-sync.test.d.ts.map +1 -0
- package/dist/lib/copy-public-assets.test.d.ts.map +1 -0
- package/dist/lib/copy-source-apps.test.d.ts.map +1 -0
- package/dist/lib/drizzle-meta-routing.test.d.ts.map +1 -0
- package/dist/lib/file-loader-typescript-fallback.test.d.ts.map +1 -0
- package/dist/lib/file-loader.d.ts +6 -0
- package/dist/lib/file-loader.d.ts.map +1 -1
- package/dist/lib/file-loader.js +17 -0
- package/dist/lib/file-loader.js.map +1 -1
- package/dist/lib/file-loader.test.d.ts.map +1 -0
- package/dist/lib/file-writer.test.d.ts.map +1 -0
- package/dist/lib/helpers.d.ts +39 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/helpers.js +299 -0
- package/dist/lib/helpers.js.map +1 -0
- package/dist/lib/migrations/drizzle-prompts.test.d.ts.map +1 -0
- package/dist/lib/migrations/drizzle.test.d.ts.map +1 -0
- package/dist/lib/migrations/executor.test.d.ts.map +1 -0
- package/dist/lib/migrations/inventory.test.d.ts.map +1 -0
- package/dist/lib/migrations/lock.test.d.ts.map +1 -0
- package/dist/lib/migrations/paths.test.d.ts.map +1 -0
- package/dist/lib/migrations/plan.test.d.ts.map +1 -0
- package/dist/lib/migrations/postprocessors/index.test.d.ts.map +1 -0
- package/dist/lib/migrations/prompt-runner.test.d.ts.map +1 -0
- package/dist/lib/migrations/staging.test.d.ts.map +1 -0
- package/dist/lib/neon-canary.test.d.ts.map +1 -0
- package/dist/lib/neon-target.test.d.ts.map +1 -0
- package/dist/lib/neon.test.d.ts.map +1 -0
- package/dist/lib/ops-manifest.d.ts +76 -0
- package/dist/lib/ops-manifest.d.ts.map +1 -0
- package/dist/lib/ops-manifest.js +94 -0
- package/dist/lib/ops-manifest.js.map +1 -0
- package/dist/lib/prepare-output.test.d.ts.map +1 -0
- package/dist/lib/prepare-state-output.test.d.ts.map +1 -0
- package/dist/lib/release-and-pin.d.ts +34 -0
- package/dist/lib/release-and-pin.d.ts.map +1 -0
- package/dist/lib/release-and-pin.js +71 -0
- package/dist/lib/release-and-pin.js.map +1 -0
- package/dist/lib/schema-sync/index.test.d.ts.map +1 -0
- package/dist/lib/shell.d.ts +4 -1
- package/dist/lib/shell.d.ts.map +1 -1
- package/dist/lib/shell.js +8 -3
- package/dist/lib/shell.js.map +1 -1
- package/dist/lib/shell.test.d.ts.map +1 -0
- package/dist/lib/sweep-stale.d.ts +25 -0
- package/dist/lib/sweep-stale.d.ts.map +1 -0
- package/dist/lib/sweep-stale.js +179 -0
- package/dist/lib/sweep-stale.js.map +1 -0
- package/dist/lib/sweep-stale.test.d.ts.map +1 -0
- package/dist/lib/wrangler-resources.test.d.ts.map +1 -0
- package/dist/skill/docs/api/actions.md +2 -0
- package/dist/skill/docs/api/batch-operations.md +18 -4
- package/dist/skill/docs/api/crud.md +62 -0
- package/dist/skill/docs/api/errors.md +17 -2
- package/dist/skill/docs/configure/auth.md +49 -2
- package/dist/skill/docs/configure/bindings.md +15 -0
- package/dist/skill/docs/configure/domains.md +4 -0
- package/dist/skill/docs/configure/index.md +29 -11
- package/dist/skill/docs/configure/providers.md +1 -0
- package/dist/skill/docs/configure/tenancy.md +117 -0
- package/dist/skill/docs/define/access.md +19 -0
- package/dist/skill/docs/define/actions/access.md +76 -0
- package/dist/skill/docs/define/actions/defining.md +156 -1
- package/dist/skill/docs/define/actions/scoped-db.md +236 -9
- package/dist/skill/docs/define/areas.md +46 -0
- package/dist/skill/docs/define/authz-roles.md +10 -0
- package/dist/skill/docs/define/diagnostics.md +263 -0
- package/dist/skill/docs/define/encryption.md +34 -2
- package/dist/skill/docs/define/guards.md +13 -0
- package/dist/skill/docs/define/masking.md +77 -3
- package/dist/skill/docs/define/rate-limit.md +3 -3
- package/dist/skill/docs/define/schema.md +148 -7
- package/dist/skill/docs/define/scopes.md +79 -0
- package/dist/skill/docs/define/sealed-protocol.md +111 -9
- package/dist/skill/docs/define/transitions.md +39 -0
- package/dist/skill/docs/define/views.md +77 -3
- package/dist/skill/docs/platform/api-contract/index.md +4 -0
- package/dist/skill/docs/platform/auth/jwt-optimization.md +2 -0
- package/dist/skill/docs/platform/auth/plugins/aws-ses.md +4 -3
- package/dist/skill/docs/platform/auth/using-auth.md +6 -0
- package/dist/skill/docs/platform/database/d1.md +47 -0
- package/dist/skill/docs/platform/database/data-migrations.md +109 -0
- package/dist/skill/docs/platform/database/index.md +1 -0
- package/dist/skill/docs/platform/database/read-replication.md +257 -0
- package/dist/skill/docs/platform/database/using-d1.md +2 -1
- package/dist/skill/docs/platform/payments/one-off-checkout.md +6 -1
- package/dist/skill/docs/platform/push/index.md +2 -0
- package/dist/skill/docs/platform/realtime/partyserver-rooms.md +95 -9
- package/dist/skill/docs/platform/storage/using-r2.md +135 -19
- package/dist/skill/docs/start/deploy.md +38 -0
- package/dist/skill/docs/tooling/cli.md +120 -0
- package/dist/skill/docs/tooling/cloud-compiler/troubleshooting.md +13 -13
- package/dist/skill/docs/tooling/output.md +70 -2
- package/package.json +1 -1
- package/src/skill/docs/api/actions.md +2 -0
- package/src/skill/docs/api/batch-operations.md +18 -4
- package/src/skill/docs/api/crud.md +62 -0
- package/src/skill/docs/api/errors.md +17 -2
- package/src/skill/docs/configure/auth.md +49 -2
- package/src/skill/docs/configure/bindings.md +15 -0
- package/src/skill/docs/configure/domains.md +4 -0
- package/src/skill/docs/configure/index.md +29 -11
- package/src/skill/docs/configure/providers.md +1 -0
- package/src/skill/docs/configure/tenancy.md +117 -0
- package/src/skill/docs/define/access.md +19 -0
- package/src/skill/docs/define/actions/access.md +76 -0
- package/src/skill/docs/define/actions/defining.md +156 -1
- package/src/skill/docs/define/actions/scoped-db.md +236 -9
- package/src/skill/docs/define/areas.md +46 -0
- package/src/skill/docs/define/authz-roles.md +10 -0
- package/src/skill/docs/define/diagnostics.md +263 -0
- package/src/skill/docs/define/encryption.md +34 -2
- package/src/skill/docs/define/guards.md +13 -0
- package/src/skill/docs/define/masking.md +77 -3
- package/src/skill/docs/define/rate-limit.md +3 -3
- package/src/skill/docs/define/schema.md +148 -7
- package/src/skill/docs/define/scopes.md +79 -0
- package/src/skill/docs/define/sealed-protocol.md +111 -9
- package/src/skill/docs/define/transitions.md +39 -0
- package/src/skill/docs/define/views.md +77 -3
- package/src/skill/docs/platform/api-contract/index.md +4 -0
- package/src/skill/docs/platform/auth/jwt-optimization.md +2 -0
- package/src/skill/docs/platform/auth/plugins/aws-ses.md +4 -3
- package/src/skill/docs/platform/auth/using-auth.md +6 -0
- package/src/skill/docs/platform/database/d1.md +47 -0
- package/src/skill/docs/platform/database/data-migrations.md +109 -0
- package/src/skill/docs/platform/database/index.md +1 -0
- package/src/skill/docs/platform/database/read-replication.md +257 -0
- package/src/skill/docs/platform/database/using-d1.md +2 -1
- package/src/skill/docs/platform/payments/one-off-checkout.md +6 -1
- package/src/skill/docs/platform/push/index.md +2 -0
- package/src/skill/docs/platform/realtime/partyserver-rooms.md +95 -9
- package/src/skill/docs/platform/storage/using-r2.md +135 -19
- package/src/skill/docs/start/deploy.md +38 -0
- package/src/skill/docs/tooling/cli.md +120 -0
- package/src/skill/docs/tooling/cloud-compiler/troubleshooting.md +13 -13
- package/src/skill/docs/tooling/output.md +70 -2
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build-time halves of two plan 031 K primitives that only the CLI can do:
|
|
3
|
+
*
|
|
4
|
+
* - release.stampVars: the release identity comes from the project's own
|
|
5
|
+
* repository, which the compiler never sees. Computed here, sent in the
|
|
6
|
+
* compile request; the compiler validates and stamps it.
|
|
7
|
+
* - compiler.pin: the COMPARISON lives in the compiler (it knows exactly
|
|
8
|
+
* which build it is). The CLI forwards --accept-compiler, refuses output
|
|
9
|
+
* from a compiler that did not report a pin result, and rewrites an
|
|
10
|
+
* accepted pin in quickback.config.ts.
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'fs/promises';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { runCommandCapture } from './shell.js';
|
|
15
|
+
export async function computeReleaseStamp(options) {
|
|
16
|
+
const run = options.run ?? ((command, args, opts) => runCommandCapture(command, args, opts));
|
|
17
|
+
const head = await run('git', ['rev-parse', 'HEAD'], { cwd: options.projectRoot }).catch(() => null);
|
|
18
|
+
const sha = head?.code === 0 ? head.stdout.trim().toLowerCase() : '';
|
|
19
|
+
if (!/^[0-9a-f]{7,40}$/.test(sha)) {
|
|
20
|
+
throw new Error('release.stampVars is on, but the project is not a git checkout with a commit (`git rev-parse HEAD` failed) — ' +
|
|
21
|
+
'the release sha cannot be stamped. Commit the project, or turn release.stampVars off.');
|
|
22
|
+
}
|
|
23
|
+
const status = await run('git', ['status', '--porcelain'], { cwd: options.projectRoot });
|
|
24
|
+
const dirty = status.code === 0 && status.stdout.trim().length > 0;
|
|
25
|
+
let version = options.configVersion;
|
|
26
|
+
if (!version) {
|
|
27
|
+
const readFile = options.readFile ?? ((path) => fs.readFile(path, 'utf-8'));
|
|
28
|
+
try {
|
|
29
|
+
version = JSON.parse(await readFile(join(options.projectRoot, 'package.json'))).version;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
version = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof version !== 'string' || version.length === 0) {
|
|
36
|
+
throw new Error('release.stampVars is on, but there is no release version: set release.version in quickback.config.ts ' +
|
|
37
|
+
'or a "version" in the project package.json.');
|
|
38
|
+
}
|
|
39
|
+
return { version, sha: dirty ? `${sha}-dirty` : sha, at: (options.now ?? (() => new Date()))().toISOString() };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A project with `compiler.pin` must get a pin result back; a compiler that
|
|
43
|
+
* predates pin enforcement ignored the pin, so its output is refused.
|
|
44
|
+
*/
|
|
45
|
+
export function assertPinEnforced(pin, meta) {
|
|
46
|
+
if (pin === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
if (!meta.compilerPin || meta.compilerPin.declared !== pin) {
|
|
49
|
+
throw new Error(`compiler.pin is "${pin}", but the compiler that answered (${meta.version ?? 'unknown'}@${meta.gitSha ?? 'unknown'}) ` +
|
|
50
|
+
'did not enforce it — it predates compiler pins. Refusing the output. Point QUICKBACK_API_URL at the pinned compiler.');
|
|
51
|
+
}
|
|
52
|
+
return meta.compilerPin;
|
|
53
|
+
}
|
|
54
|
+
/** Replace the one `compiler.pin` string literal in the config source. */
|
|
55
|
+
export function rewriteCompilerPin(source, declared, served) {
|
|
56
|
+
const literals = [`'${declared}'`, `"${declared}"`, `\`${declared}\``];
|
|
57
|
+
const hits = literals.flatMap((literal) => {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (let i = source.indexOf(literal); i >= 0; i = source.indexOf(literal, i + 1))
|
|
60
|
+
out.push(i);
|
|
61
|
+
return out.map((index) => ({ index, literal }));
|
|
62
|
+
});
|
|
63
|
+
if (hits.length !== 1) {
|
|
64
|
+
throw new Error(`Could not rewrite compiler.pin: expected exactly one "${declared}" string literal in quickback.config.ts, ` +
|
|
65
|
+
`found ${hits.length}. Set compiler.pin to "${served}" by hand.`);
|
|
66
|
+
}
|
|
67
|
+
const [{ index, literal }] = hits;
|
|
68
|
+
const quote = literal[0];
|
|
69
|
+
return source.slice(0, index) + quote + served + quote + source.slice(index + literal.length);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=release-and-pin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release-and-pin.js","sourceRoot":"","sources":["../../src/lib/release-and-pin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAsB,MAAM,YAAY,CAAC;AAUnE,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAMzC;IACC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7F,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IACrG,MAAM,GAAG,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,+GAA+G;YAC7G,uFAAuF,CAC1F,CAAC;IACJ,C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KAAK,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../src/lib/schema-sync/index.test.ts"],"names":[],"mappings":""}
|
package/dist/lib/shell.d.ts
CHANGED
|
@@ -23,9 +23,12 @@ export interface CaptureResult {
|
|
|
23
23
|
* streaming. Never throws on non-zero exit — callers inspect `code`; only
|
|
24
24
|
* spawn failures (binary missing) reject.
|
|
25
25
|
*/
|
|
26
|
-
export declare function runCommandCapture(command: string, args: string[],
|
|
26
|
+
export declare function runCommandCapture(command: string, args: string[],
|
|
27
|
+
/** `input` is written to stdin and closed (e.g. a secret for `wrangler secret put`), never put on argv. */
|
|
28
|
+
options?: {
|
|
27
29
|
cwd?: string;
|
|
28
30
|
env?: NodeJS.ProcessEnv;
|
|
31
|
+
input?: string;
|
|
29
32
|
}): Promise<CaptureResult>;
|
|
30
33
|
export interface ArgvRunnerDependencies {
|
|
31
34
|
platform?: NodeJS.Platform;
|
package/dist/lib/shell.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../src/lib/shell.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;A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AAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE,iBAAsB,EAC/B,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,IAAI,CAAC,CAef"}
|
package/dist/lib/shell.js
CHANGED
|
@@ -34,16 +34,21 @@ export async function runCommand(cmd, options = {}) {
|
|
|
34
34
|
* streaming. Never throws on non-zero exit — callers inspect `code`; only
|
|
35
35
|
* spawn failures (binary missing) reject.
|
|
36
36
|
*/
|
|
37
|
-
export async function runCommandCapture(command, args,
|
|
38
|
-
|
|
37
|
+
export async function runCommandCapture(command, args,
|
|
38
|
+
/** `input` is written to stdin and closed (e.g. a secret for `wrangler secret put`), never put on argv. */
|
|
39
|
+
options = {}) {
|
|
40
|
+
const { cwd = process.cwd(), env, input } = options;
|
|
39
41
|
return new Promise((resolve, reject) => {
|
|
40
42
|
const proc = spawn(command, args, {
|
|
41
43
|
cwd,
|
|
42
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
44
|
+
stdio: [input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],
|
|
43
45
|
// Windows needs a shell to resolve npx.cmd; POSIX spawns directly.
|
|
44
46
|
shell: process.platform === 'win32',
|
|
45
47
|
env: env || process.env,
|
|
46
48
|
});
|
|
49
|
+
if (input !== undefined) {
|
|
50
|
+
proc.stdin?.end(input);
|
|
51
|
+
}
|
|
47
52
|
let stdout = '';
|
|
48
53
|
let stderr = '';
|
|
49
54
|
proc.stdout?.on('data', (chunk) => { stdout += String(chunk); });
|
package/dist/lib/shell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/lib/shell.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtC;;GAEG;AAC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AC;IACtH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.test.d.ts","sourceRoot":"","sources":["../../src/lib/shell.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface SweepOptions {
|
|
2
|
+
/**
|
|
3
|
+
* If set, copy the target dir into `<archiveDir>/<targetBasename>-<ISO>/`
|
|
4
|
+
* before deleting anything. No-op when no orphans are found.
|
|
5
|
+
*/
|
|
6
|
+
archiveDir?: string;
|
|
7
|
+
/** How many archives to retain. Defaults to 3. */
|
|
8
|
+
archiveKeep?: number;
|
|
9
|
+
/** Subtrees (relative to outputDir) to skip — e.g. SPA asset dirs that already get a hard wipe upstream. */
|
|
10
|
+
skipPrefixes?: Iterable<string>;
|
|
11
|
+
}
|
|
12
|
+
export interface SweepResult {
|
|
13
|
+
/** Files deleted because they were stale orphans. */
|
|
14
|
+
deleted: string[];
|
|
15
|
+
/** Files NOT deleted despite being missing from the manifest — they lacked the generated-header marker. */
|
|
16
|
+
preserved: string[];
|
|
17
|
+
/** Path to the archive created before deletion (undefined when nothing was deleted or archiveDir wasn't set). */
|
|
18
|
+
archivePath?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sweep stale generated files under `targetDir`. Paths in `manifest` are
|
|
22
|
+
* relative to `outputDir` (matching the wire shape the compiler returns).
|
|
23
|
+
*/
|
|
24
|
+
export declare function sweepStaleGeneratedFiles(outputDir: string, targetDir: string, manifest: Iterable<string>, options?: SweepOptions): Promise<SweepResult>;
|
|
25
|
+
//# sourceMappingURL=sweep-stale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep-stale.d.ts","sourceRoot":"","sources":["../../src/lib/sweep-stale.ts"],"names":[],"mappings":"AAyCA,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,YAAY,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,2GAA2G;IAC3G,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,iHAAiH;IACjH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC1B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,CA8CtB"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stale-file sweep for generated output trees.
|
|
3
|
+
*
|
|
4
|
+
* `src/` is hermetic — every file there is emitted by the compiler and
|
|
5
|
+
* carries the "Generated by quickback.dev" header. When a feature is
|
|
6
|
+
* removed/renamed or a generator stops emitting a file, the orphaned file
|
|
7
|
+
* lingers under merge-only writes and can mask bugs (dead routes, ghost
|
|
8
|
+
* imports, mismatched types, stale schemas the user assumes are current).
|
|
9
|
+
*
|
|
10
|
+
* This helper walks a target dir, deletes any file whose path isn't in the
|
|
11
|
+
* compiler's manifest *and* carries the generated-header marker, then
|
|
12
|
+
* collapses the empty directories left behind. Files without the marker are
|
|
13
|
+
* preserved (defence against accidentally nuking hand-authored content that
|
|
14
|
+
* snuck into a generated tree).
|
|
15
|
+
*
|
|
16
|
+
* Before any deletes, it copies the target dir into a timestamped archive
|
|
17
|
+
* under `archiveDir` (when provided). The archive is uncompressed (just a
|
|
18
|
+
* recursive copy via Node's built-in fs.cp) so it's trivially inspectable
|
|
19
|
+
* and recoverable with `cp -r`. Old archives beyond `archiveKeep` are
|
|
20
|
+
* pruned. The archive is skipped entirely on no-op compiles where no
|
|
21
|
+
* orphans were found.
|
|
22
|
+
*/
|
|
23
|
+
import { promises as fs } from 'fs';
|
|
24
|
+
import { join, relative, sep } from 'path';
|
|
25
|
+
const GENERATED_MARKER = 'Generated by quickback.dev';
|
|
26
|
+
const HEADER_PROBE_BYTES = 512;
|
|
27
|
+
const DEFAULT_ARCHIVE_KEEP = 3;
|
|
28
|
+
/**
|
|
29
|
+
* OS / editor noise that every contributor accidentally drops into checked-out
|
|
30
|
+
* trees. These files are *never* compiler output and *never* user-authored
|
|
31
|
+
* content the user cares about — silently skip them rather than warning the
|
|
32
|
+
* user every compile that ".DS_Store has no Quickback header".
|
|
33
|
+
*/
|
|
34
|
+
const SILENT_IGNORE_BASENAMES = new Set([
|
|
35
|
+
'.DS_Store',
|
|
36
|
+
'Thumbs.db',
|
|
37
|
+
'.localized',
|
|
38
|
+
]);
|
|
39
|
+
/**
|
|
40
|
+
* Sweep stale generated files under `targetDir`. Paths in `manifest` are
|
|
41
|
+
* relative to `outputDir` (matching the wire shape the compiler returns).
|
|
42
|
+
*/
|
|
43
|
+
export async function sweepStaleGeneratedFiles(outputDir, targetDir, manifest, options = {}) {
|
|
44
|
+
const result = { deleted: [], preserved: [] };
|
|
45
|
+
const fullTarget = join(outputDir, targetDir);
|
|
46
|
+
if (!(await pathExists(fullTarget)))
|
|
47
|
+
return result;
|
|
48
|
+
const manifestSet = new Set();
|
|
49
|
+
for (const p of manifest)
|
|
50
|
+
manifestSet.add(normalizePath(p));
|
|
51
|
+
const skipNormalized = [...(options.skipPrefixes ?? [])].map(normalizePath);
|
|
52
|
+
const isSkipped = (relPath) => skipNormalized.some((sp) => relPath === sp || relPath.startsWith(sp + '/'));
|
|
53
|
+
const onDisk = [];
|
|
54
|
+
await collectFiles(fullTarget, outputDir, onDisk);
|
|
55
|
+
// First pass: identify deletions without acting, so the archive captures
|
|
56
|
+
// the pre-delete state and runs only when there's something to lose.
|
|
57
|
+
const toDelete = [];
|
|
58
|
+
for (const relPath of onDisk) {
|
|
59
|
+
if (manifestSet.has(relPath))
|
|
60
|
+
continue;
|
|
61
|
+
if (isSkipped(relPath))
|
|
62
|
+
continue;
|
|
63
|
+
const base = relPath.slice(relPath.lastIndexOf('/') + 1);
|
|
64
|
+
if (SILENT_IGNORE_BASENAMES.has(base))
|
|
65
|
+
continue;
|
|
66
|
+
const fullPath = join(outputDir, relPath);
|
|
67
|
+
if (await fileHasMarker(fullPath, GENERATED_MARKER)) {
|
|
68
|
+
toDelete.push(relPath);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
result.preserved.push(relPath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (toDelete.length === 0)
|
|
75
|
+
return result;
|
|
76
|
+
if (options.archiveDir) {
|
|
77
|
+
result.archivePath = await archiveDirectory(fullTarget, options.archiveDir, basename(targetDir));
|
|
78
|
+
await pruneArchives(options.archiveDir, basename(targetDir), options.archiveKeep ?? DEFAULT_ARCHIVE_KEEP);
|
|
79
|
+
}
|
|
80
|
+
for (const relPath of toDelete) {
|
|
81
|
+
await fs.unlink(join(outputDir, relPath));
|
|
82
|
+
result.deleted.push(relPath);
|
|
83
|
+
}
|
|
84
|
+
await removeEmptyDirs(fullTarget);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
async function archiveDirectory(srcDir, archiveBase, prefix) {
|
|
88
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-').replace(/Z$/, '');
|
|
89
|
+
const dest = join(archiveBase, `${prefix}-${stamp}`);
|
|
90
|
+
await fs.mkdir(archiveBase, { recursive: true });
|
|
91
|
+
// fs.cp with recursive copies the tree, preserves dir structure, no deps.
|
|
92
|
+
await fs.cp(srcDir, dest, { recursive: true, force: true });
|
|
93
|
+
return dest;
|
|
94
|
+
}
|
|
95
|
+
async function pruneArchives(archiveBase, prefix, keep) {
|
|
96
|
+
if (!(await pathExists(archiveBase)))
|
|
97
|
+
return;
|
|
98
|
+
const entries = await fs.readdir(archiveBase);
|
|
99
|
+
const stamped = entries.filter((e) => e.startsWith(`${prefix}-`)).sort().reverse();
|
|
100
|
+
const stale = stamped.slice(keep);
|
|
101
|
+
for (const old of stale) {
|
|
102
|
+
await fs.rm(join(archiveBase, old), { recursive: true, force: true }).catch(() => { });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function pathExists(p) {
|
|
106
|
+
try {
|
|
107
|
+
await fs.access(p);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function collectFiles(dir, outputDir, into) {
|
|
115
|
+
let entries;
|
|
116
|
+
try {
|
|
117
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
const full = join(dir, entry.name);
|
|
124
|
+
if (entry.isDirectory()) {
|
|
125
|
+
await collectFiles(full, outputDir, into);
|
|
126
|
+
}
|
|
127
|
+
else if (entry.isFile()) {
|
|
128
|
+
into.push(normalizePath(relative(outputDir, full)));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function fileHasMarker(path, marker) {
|
|
133
|
+
let handle = null;
|
|
134
|
+
try {
|
|
135
|
+
handle = await fs.open(path, 'r');
|
|
136
|
+
const buf = Buffer.alloc(HEADER_PROBE_BYTES);
|
|
137
|
+
const { bytesRead } = await handle.read(buf, 0, HEADER_PROBE_BYTES, 0);
|
|
138
|
+
return buf.subarray(0, bytesRead).toString('utf8').includes(marker);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
if (handle)
|
|
145
|
+
await handle.close();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function removeEmptyDirs(dir) {
|
|
149
|
+
let entries;
|
|
150
|
+
try {
|
|
151
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
for (const entry of entries) {
|
|
157
|
+
if (entry.isDirectory()) {
|
|
158
|
+
await removeEmptyDirs(join(dir, entry.name));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const after = await fs.readdir(dir);
|
|
163
|
+
if (after.length === 0) {
|
|
164
|
+
await fs.rmdir(dir).catch(() => { });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
/* ignore */
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function normalizePath(p) {
|
|
172
|
+
return sep === '/' ? p : p.split(sep).join('/');
|
|
173
|
+
}
|
|
174
|
+
function basename(p) {
|
|
175
|
+
const norm = normalizePath(p).replace(/\/+$/, '');
|
|
176
|
+
const idx = norm.lastIndexOf('/');
|
|
177
|
+
return idx >= 0 ? norm.slice(idx + 1) : norm;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=sweep-stale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep-stale.js","sourceRoot":"","sources":["../../src/lib/sweep-stale.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAE3C,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AACtD,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC;IACtC,WAAW;IACX,WAAW;IACX,YAAY;CACb,CAAC,CAAC;AAuBH;;;G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C,CAAC;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sweep-stale.test.d.ts","sourceRoot":"","sources":["../../src/lib/sweep-stale.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrangler-resources.test.d.ts","sourceRoot":"","sources":["../../src/lib/wrangler-resources.test.ts"],"names":[],"mappings":""}
|
|
@@ -201,6 +201,8 @@ Cross-tenant unsafe actions are generated with:
|
|
|
201
201
|
|
|
202
202
|
Without unsafe mode, `unsafeDb` is `undefined`.
|
|
203
203
|
|
|
204
|
+
An operator acting on one tenant named by the input does not need `unsafe`: declare [`operator: { target }`](/define/actions/scoped-db#operator-lane-operator) on a `userRole` action. The route loads the target (404 `OPERATOR_TARGET_NOT_FOUND` when absent or soft-deleted), scopes `db` to its organization, and audits the call against that tenant.
|
|
205
|
+
|
|
204
206
|
On Postgres providers `unsafeDb` is the service-role handle for every unsafe action, so row-level security does not narrow it to the caller — the same reach as on D1. See the [provider note](/define/actions/scoped-db#unsafe-mode).
|
|
205
207
|
|
|
206
208
|
Raw SQL in action code is blocked by default at compile time. If you need it for a specific action, set `allowRawSql: true` on that action explicitly.
|
|
@@ -83,7 +83,7 @@ server-minted ids as usual.
|
|
|
83
83
|
- **201** — All records created successfully
|
|
84
84
|
- **207** — Partial success (some errors, some successes)
|
|
85
85
|
|
|
86
|
-
`POST /batch` uses
|
|
86
|
+
`POST /batch` uses one bulk `INSERT`, so `meta.transactional` is `true` on every provider — the database guarantees the insert is atomic regardless of the `failFast` flag. On D1 a wide batch is sliced to stay under the [bind limit](#database-bind-limits) and the slices run in one `db.batch()`, which D1 commits atomically.
|
|
87
87
|
|
|
88
88
|
Fields applied automatically to each record:
|
|
89
89
|
- ID generation (UUID, prefixed, etc.)
|
|
@@ -208,7 +208,7 @@ Note: Batch delete uses an `ids` array (not `records`).
|
|
|
208
208
|
}
|
|
209
209
|
```
|
|
210
210
|
|
|
211
|
-
`DELETE /batch` issues
|
|
211
|
+
`DELETE /batch` issues one bulk `UPDATE … WHERE id IN (...)` (soft delete) or `DELETE … WHERE id IN (...)` (hard delete), so `meta.transactional` is `true` on every provider regardless of `failFast`. On D1 the id list is sliced under the [bind limit](#database-bind-limits) and the slices run in one atomic `db.batch()`.
|
|
212
212
|
|
|
213
213
|
**Hard delete**: Returns objects with only the `id` field (record data is deleted).
|
|
214
214
|
|
|
@@ -318,8 +318,8 @@ transport with Neon's hyperdrive mode.
|
|
|
318
318
|
| `PATCH /batch` (update) | cloudflare-d1, neon over http (Cloudflare default) | `true` | `false` | Fail-fast loop without rollback — the driver has no `db.transaction`. Records before the failure stay committed. |
|
|
319
319
|
| `PUT /batch` (upsert) | tx-supporting (postgres, neon over websocket/hyperdrive, planetscale-postgres) | `true` | `true` | Bulk insert + per-record update share one transaction. Any failure rolls back both. |
|
|
320
320
|
| `PUT /batch` (upsert) | cloudflare-d1, neon over http (Cloudflare default) | `true` | `false` | Bulk insert commits; per-record update loop is fail-fast without rollback. |
|
|
321
|
-
| `POST /batch` (create) | (any) | (any) | `true` |
|
|
322
|
-
| `DELETE /batch` | (any) | (any) | `true` |
|
|
321
|
+
| `POST /batch` (create) | (any) | (any) | `true` | One bulk `INSERT` — atomic at the DB level. On D1, slices under the bind limit commit together via `db.batch()`. |
|
|
322
|
+
| `DELETE /batch` | (any) | (any) | `true` | One bulk `UPDATE` (soft) or `DELETE` (hard) — atomic at the DB level. On D1, slices under the bind limit commit together via `db.batch()`. |
|
|
323
323
|
| [Changeset](/define/changesets) (`application/vnd.quickback.changeset+json`) | tx-supporting (postgres, neon over websocket/hyperdrive, planetscale-postgres) | n/a | `true` | Root op + every child op share one transaction; any op failure rolls back the whole changeset. |
|
|
324
324
|
| [Changeset](/define/changesets) | cloudflare-d1, neon over http (Cloudflare default) | n/a | `false` | Deterministic parent-first fail-fast — the first op failure stops the changeset; already-applied ops stay committed (a consistent, independently-authorized prefix). |
|
|
325
325
|
|
|
@@ -370,6 +370,20 @@ The default maximum batch size is **100 records**. Requests exceeding the limit
|
|
|
370
370
|
}
|
|
371
371
|
```
|
|
372
372
|
|
|
373
|
+
### Database bind limits
|
|
374
|
+
|
|
375
|
+
Every batch route builds statements whose size grows with the request — `WHERE id IN (...)` over the submitted ids, or a multi-row `INSERT` binding every column of every row. Drivers cap the bound parameters a single statement may carry:
|
|
376
|
+
|
|
377
|
+
| Provider | Bound parameters per statement |
|
|
378
|
+
|----------|-------------------------------|
|
|
379
|
+
| `cloudflare-d1` (and local Miniflare/workerd) | 100 |
|
|
380
|
+
| `neon`, `planetscale-postgres` | 65535 |
|
|
381
|
+
| other SQLite drivers | 32766 |
|
|
382
|
+
|
|
383
|
+
The generated handlers never exceed the cap. Id lists and insert rows are sliced to fit (ids in slices of 80, leaving room for the firewall's scope binds; insert rows by `floor(80 / columns)`), and on drivers that offer `db.batch()` — D1 included — the slices run in one atomic batch, so `meta.transactional` stays honest. A full `maxBatchSize` request on D1 therefore succeeds for any table width; on Postgres a 100-record batch is always a single statement. The runtime lives in the generated `src/lib/sql-binds.ts` (`selectInChunks`, `insertInChunks`), and the budget constant `MAX_SQL_BINDS` is the provider's cap — reuse it in hand-written actions that take id lists.
|
|
384
|
+
|
|
385
|
+
The body must carry its array under the documented key. A `POST`/`PATCH`/`PUT /batch` without a `records` array, or a `DELETE /batch` without `ids`, is rejected with 400 `VALIDATION_INVALID_INPUT` naming the missing field — never a 200 that wrote nothing.
|
|
386
|
+
|
|
373
387
|
## Configuration
|
|
374
388
|
|
|
375
389
|
Batch operations inherit access control from their corresponding write operation. You can override per-batch settings:
|
|
@@ -289,6 +289,67 @@ where the id is **required** on `POST /`, `POST /batch` and a changeset
|
|
|
289
289
|
the id. `PUT /:id` and `PATCH` are unchanged — the id still comes from the
|
|
290
290
|
URL, never the body.
|
|
291
291
|
|
|
292
|
+
### Row-token idempotency
|
|
293
|
+
|
|
294
|
+
An offline or flaky client retries creates. `allowClientIds` makes a retry
|
|
295
|
+
fail loudly (`409`); a **row token** makes it succeed with the row the first
|
|
296
|
+
attempt wrote. Declare the token column on the table:
|
|
297
|
+
|
|
298
|
+
{/* doc-compile: skip — needs `allowClientIds: true` on the database config, which the docs gate's fixed harness config does not set. Compiled by tests/output-matrix/fixtures/race-safe-writes. */}
|
|
299
|
+
```typescript
|
|
300
|
+
// features/rsvps/rsvps.ts
|
|
301
|
+
import { feature, q } from "@quickback/compiler";
|
|
302
|
+
|
|
303
|
+
export default feature("rsvps", {
|
|
304
|
+
columns: {
|
|
305
|
+
id: q.id(),
|
|
306
|
+
clientMutationId: q.text({ maxLength: 64 }).optional().unique(),
|
|
307
|
+
eventId: q.text().required(),
|
|
308
|
+
guestName: q.text().required(),
|
|
309
|
+
organizationId: q.scope("organization"),
|
|
310
|
+
...q.audit(),
|
|
311
|
+
...q.softDelete(),
|
|
312
|
+
},
|
|
313
|
+
idempotency: { rowToken: "clientMutationId", clientId: { column: "id", pattern: "uuid" } },
|
|
314
|
+
read: { access: { roles: ["member"] } },
|
|
315
|
+
create: { access: { roles: ["member"] } },
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
On `POST /` and `POST /batch`:
|
|
320
|
+
|
|
321
|
+
- A create whose `clientMutationId` is already stored on a row the caller can
|
|
322
|
+
see **replays that row**: `200`, header `Idempotent-Replayed: true`, the
|
|
323
|
+
stored (masked) record as the body. Nothing runs — no insert, no trigger
|
|
324
|
+
hooks, no realtime frame, no embedding job, no after-commit effect.
|
|
325
|
+
- A create that races its own retry is arbitrated by the database: the unique
|
|
326
|
+
constraint on the token (or the primary key, when the client mints the id)
|
|
327
|
+
refuses the second INSERT, and that request replays the winner instead of
|
|
328
|
+
answering `409`.
|
|
329
|
+
- The same client id under a **different** token, or the same token with a
|
|
330
|
+
different id, is `409 IDEMPOTENCY_ROW_CONFLICT`.
|
|
331
|
+
- `POST /batch` returns replayed rows in `success` next to the created ones,
|
|
332
|
+
and inserts only the new ones; a token repeated inside one batch is a
|
|
333
|
+
per-record `400 IDEMPOTENCY_TOKEN_REPEATED`.
|
|
334
|
+
- A create with no token is an ordinary create.
|
|
335
|
+
|
|
336
|
+
Compile-time rules (fail closed): the token column must exist, be a text
|
|
337
|
+
column the client may create (in `guards.createable` when guards are
|
|
338
|
+
declared), and be covered by a non-partial unique constraint — unless
|
|
339
|
+
`clientId` is declared, in which case the primary key arbitrates and the
|
|
340
|
+
client must resend the same id on retry. `clientId.column` must be the
|
|
341
|
+
primary key, `clientId.pattern` must name the project's `generateId` strategy
|
|
342
|
+
(`uuid`, `cuid` / `cuid2`, `nanoid`, `prefixed`, `short`), and the database
|
|
343
|
+
config must accept client ids (`allowClientIds: true`).
|
|
344
|
+
|
|
345
|
+
**Row token vs `Idempotency-Key`.** The
|
|
346
|
+
[`Idempotency-Key` header](/platform/api-contract#idempotency-key) is per
|
|
347
|
+
**request**: it caches one response for 24 hours, bound to the principal that
|
|
348
|
+
sent it, on any write endpoint. A row token is per **row**: it is stored in
|
|
349
|
+
the table, never expires, and replays across sessions, devices and
|
|
350
|
+
principals that can read the row. Use the header for "don't do this request
|
|
351
|
+
twice"; use a row token for "this client-side record exists exactly once".
|
|
352
|
+
|
|
292
353
|
### Response
|
|
293
354
|
|
|
294
355
|
`201 Created`. The body is the **bare created record** — there is no `data`
|
|
@@ -314,6 +375,7 @@ wrapper:
|
|
|
314
375
|
| `400` | Invalid field or missing required field |
|
|
315
376
|
| `403` | User lacks permission to create records |
|
|
316
377
|
| `409` | Client-supplied `id` (with `allowClientIds: true`) already exists |
|
|
378
|
+
| `409` | `IDEMPOTENCY_ROW_CONFLICT` — a [row token](#row-token-idempotency) or client id already belongs to a different record |
|
|
317
379
|
|
|
318
380
|
## Update Record
|
|
319
381
|
|
|
@@ -14,9 +14,9 @@ The generated API returns structured error responses with consistent fields acro
|
|
|
14
14
|
| `403` | Forbidden | Access denied (wrong role, condition failed) or firewall blocked it |
|
|
15
15
|
| `404` | Not Found | Firewall blocked the record on a resource that set `firewallErrorMode: 'hide'` (or the route doesn't exist) |
|
|
16
16
|
| `405` | Method Not Allowed | The path is a real route, but not for this verb — the response carries an `Allow` header listing the methods it does accept |
|
|
17
|
-
| `409` | Conflict | Unique constraint hit,
|
|
17
|
+
| `409` | Conflict | Unique constraint hit, a duplicate [`Idempotency-Key`](/platform/api-contract#idempotency-key) still in flight, a [row token](/api/crud#row-token-idempotency) that belongs to a different record (`IDEMPOTENCY_ROW_CONFLICT`), or a transition that lost a race (`ACCESS_TRANSITION_LOST`, see [Transitions](/define/transitions#concurrency-the-guard-is-in-the-update)) |
|
|
18
18
|
| `412` | Precondition Failed | `If-Match` revision mismatch — [changesets](/define/changesets) and plain single-record `PATCH`/`PUT`/`DELETE` |
|
|
19
|
-
| `422` | Unprocessable | `Idempotency-Key` reused with a different request or principal, or a stored encrypted value will not decrypt (`ENCRYPTION_UNREADABLE`) |
|
|
19
|
+
| `422` | Unprocessable | `Idempotency-Key` reused with a different request or principal, or a stored encrypted value will not decrypt (`ENCRYPTION_UNREADABLE`), or a write carried a platform-managed JSON key (`JSON_KEY_RESTRICTED`) |
|
|
20
20
|
| `428` | Precondition Required | `If-Match` sent where it can't anchor: no revision column, a batch endpoint (single-resource precondition), or the POST changeset variant |
|
|
21
21
|
| `429` | Too Many Requests | Rate limit exceeded |
|
|
22
22
|
| `500` | Internal Error | Uncaught throw — generic body, full error server-side. Also `DB_WRITE_OUTCOME_UNKNOWN`: a write passed the configured [`queryTimeoutMs`](/configure/providers#database-options) and may still have committed |
|
|
@@ -198,6 +198,8 @@ Access violations return **403 Forbidden** when the user's role doesn't match th
|
|
|
198
198
|
| `ACCESS_OWNERSHIP_REQUIRED` | User must own the record |
|
|
199
199
|
| `ACCESS_NO_ORG` | No active organization set |
|
|
200
200
|
| `ACCESS_KEY_SCOPE_REQUIRED` | A [scoped API key](/platform/auth/api-keys#scopes) does not cover this route and method. `details.required` lists the scope that would admit it (empty outside the API base, which scoped keys never reach); `details.current` is the key's scopes |
|
|
201
|
+
| `ENTITLEMENT_REQUIRED` | An action's [`requires:`](/define/actions/defining#json-key-writes-and-requires) JSON key did not hold for the record. `details: { column, key }`. Checked before `execute` |
|
|
202
|
+
| `ACCESS_NO_ARM` | The action declares [`access.arms`](/define/actions/access#arms-conditioned-on-input-accessarms) and no arm's `when` matches the validated input |
|
|
201
203
|
|
|
202
204
|
### Guards (400)
|
|
203
205
|
|
|
@@ -236,6 +238,19 @@ guard failure is reported per record (207, or `BATCH_FAIL_FAST_STOPPED` under
|
|
|
236
238
|
| `GUARD_FIELD_IMMUTABLE` | Field cannot be modified after creation |
|
|
237
239
|
| `GUARD_SYSTEM_MANAGED` | System field (createdAt, modifiedAt, etc.) |
|
|
238
240
|
|
|
241
|
+
### Platform-managed JSON keys (422)
|
|
242
|
+
|
|
243
|
+
A body that sets a `platform` key of a [`q.json(schema, { keys })`](/define/schema#per-key-write-authority-keys) column answers **422 `JSON_KEY_RESTRICTED`** (`layer: "guards"`). `details.fields` names each key as `<column>.<key>`. The response is the same on POST, PATCH, PUT, the batch routes (the whole request is refused), and changeset ops. An action whose write changes a platform key without a grant gets the same code and status, with `details: { table, column, keys }`.
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"status": 422,
|
|
248
|
+
"code": "JSON_KEY_RESTRICTED",
|
|
249
|
+
"layer": "guards",
|
|
250
|
+
"details": { "fields": { "settings.beta": "is platform-managed — not writable through settings on this route" } }
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
239
254
|
### Malformed record id (400)
|
|
240
255
|
|
|
241
256
|
Record routes (`GET`/`PATCH`/`PUT`/`DELETE /:id`, the changeset `PATCH`, and
|