@specdest/devkit 0.4.9 → 0.4.11
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/npm/client-only-boundary.d.ts +1 -0
- package/dist/npm/client-only-boundary.js +29 -0
- package/dist/npm/predefined-packages/supabase.js +61 -41
- package/dist/npm/project-check.js +14 -0
- package/dist/npm/project-context.js +5 -0
- package/dist/npm/state.js +16 -2
- package/dist/npm/supabase-local.js +9 -9
- package/package.json +1 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clientOnlyBoundaryViolations(projectRoot: string): Promise<string[]>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const forbiddenCommands = /\b(?:supabase\s+(?:db\s+(?:push|reset|diff|schema|migration)|migration\s+|functions\s+deploy)|nps\s+db\.(?:migrate|push|release|schema))\b/u;
|
|
4
|
+
export async function clientOnlyBoundaryViolations(projectRoot) {
|
|
5
|
+
const findings = [];
|
|
6
|
+
try {
|
|
7
|
+
const entries = await readdir(join(projectRoot, 'supabase'));
|
|
8
|
+
if (entries.length)
|
|
9
|
+
findings.push('supabase/: client-only projects cannot own a Supabase backend directory');
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
for (const file of ['package-scripts.yml', 'package.json']) {
|
|
16
|
+
let content;
|
|
17
|
+
try {
|
|
18
|
+
content = await readFile(join(projectRoot, file), 'utf8');
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
22
|
+
continue;
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
if (forbiddenCommands.test(content))
|
|
26
|
+
findings.push(`${file}: backend database or deployment command is forbidden in a client-only project`);
|
|
27
|
+
}
|
|
28
|
+
return findings;
|
|
29
|
+
}
|
|
@@ -208,6 +208,56 @@ module.exports = {
|
|
|
208
208
|
run,
|
|
209
209
|
};
|
|
210
210
|
`;
|
|
211
|
+
const productionOperations = `#!/usr/bin/env bash
|
|
212
|
+
set -euo pipefail
|
|
213
|
+
cd "$(dirname "\${BASH_SOURCE[0]}")/../.."
|
|
214
|
+
|
|
215
|
+
operation="\${1:-}"
|
|
216
|
+
case "$operation" in
|
|
217
|
+
reconcile|migrationGen|migrate|push|squash|generate|release) ;;
|
|
218
|
+
*) echo 'Unsupported production database operation' >&2; exit 2 ;;
|
|
219
|
+
esac
|
|
220
|
+
|
|
221
|
+
# No production configuration is accessed before the human-only check.
|
|
222
|
+
node scripts/safety/require-human-remote-operation.cjs --operation "prod.db.$operation"
|
|
223
|
+
source ./supabase/.env.production
|
|
224
|
+
: "\${SUPABASE_DB_URL:?SUPABASE_DB_URL must be configured}"
|
|
225
|
+
export SUPABASE_DB_URL
|
|
226
|
+
|
|
227
|
+
case "$operation" in
|
|
228
|
+
reconcile)
|
|
229
|
+
node scripts/db/generate-production-reconcile.cjs
|
|
230
|
+
;;
|
|
231
|
+
migrationGen)
|
|
232
|
+
pnpm exec supabase db schema declarative sync --experimental --no-apply --name schema_change
|
|
233
|
+
;;
|
|
234
|
+
migrate)
|
|
235
|
+
bash "$0" reconcile
|
|
236
|
+
bash "$0" migrationGen
|
|
237
|
+
pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --include-all
|
|
238
|
+
;;
|
|
239
|
+
push)
|
|
240
|
+
pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --yes
|
|
241
|
+
;;
|
|
242
|
+
squash)
|
|
243
|
+
pnpm exec supabase migration squash --db-url "$SUPABASE_DB_URL" --yes
|
|
244
|
+
;;
|
|
245
|
+
generate)
|
|
246
|
+
types_tmp="$(mktemp ./src/__generated__/.db-types-XXXXXX)"
|
|
247
|
+
trap 'rm -f "$types_tmp"' EXIT
|
|
248
|
+
pnpm exec supabase gen types typescript --db-url "$SUPABASE_DB_URL" > "$types_tmp"
|
|
249
|
+
mv "$types_tmp" src/__generated__/database.ts
|
|
250
|
+
trap - EXIT
|
|
251
|
+
;;
|
|
252
|
+
release)
|
|
253
|
+
bash "$0" reconcile
|
|
254
|
+
bash "$0" migrationGen
|
|
255
|
+
bash "$0" push
|
|
256
|
+
bash "$0" squash
|
|
257
|
+
bash "$0" generate
|
|
258
|
+
;;
|
|
259
|
+
esac
|
|
260
|
+
`;
|
|
211
261
|
async function installSupabase(projectRoot, context) {
|
|
212
262
|
const pkg = await updatePackageJson(projectRoot, (currentPackage) => ({
|
|
213
263
|
...currentPackage,
|
|
@@ -247,54 +297,24 @@ declarative_schema_path = "./schemas"
|
|
|
247
297
|
await writeProjectFileIfMissing(projectRoot, 'src/__generated__/schema.ts', bootstrapSchema);
|
|
248
298
|
await writeProjectFileIfMissing(projectRoot, 'scripts/safety/require-human-remote-operation.cjs', humanRemoteGuard);
|
|
249
299
|
await writeProjectFileIfMissing(projectRoot, 'scripts/db/generate-production-reconcile.cjs', productionReconcile);
|
|
300
|
+
await writeProjectFileIfMissing(projectRoot, 'scripts/db/run-production-operation.sh', productionOperations);
|
|
250
301
|
const supabaseScripts = `scripts:
|
|
251
302
|
local:
|
|
252
303
|
db:
|
|
253
|
-
start: nps db.local.start
|
|
254
|
-
stop: nps db.local.stop
|
|
255
|
-
status: nps db.local.status
|
|
256
|
-
migrate: nps db.local.migrate
|
|
257
|
-
generate: nps db.local.generate
|
|
258
|
-
reset: nps db.local.reset
|
|
259
|
-
prod:
|
|
260
|
-
db:
|
|
261
|
-
migrate: nps db.prod.migrate
|
|
262
|
-
db:
|
|
263
|
-
local:
|
|
264
304
|
start: pnpm exec supabase start
|
|
265
305
|
stop: pnpm exec supabase stop
|
|
266
306
|
status: pnpm exec supabase status
|
|
267
|
-
|
|
307
|
+
migrationGen: pnpm exec supabase db schema declarative sync --experimental --no-apply --name schema_change
|
|
268
308
|
generate: pnpm exec supabase gen types typescript --local > src/__generated__/database.ts
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
SUPABASE_DB_URL="$SUPABASE_DB_URL" node scripts/db/generate-production-reconcile.cjs
|
|
279
|
-
prod: |-
|
|
280
|
-
node scripts/safety/require-human-remote-operation.cjs --operation db.migrate.prod
|
|
281
|
-
nps db.migrate.reconcileRemote
|
|
282
|
-
nps db.schema.sync
|
|
283
|
-
pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --include-all
|
|
284
|
-
squashYes: |-
|
|
285
|
-
node scripts/safety/require-human-remote-operation.cjs --operation db.migrate.squashYes
|
|
286
|
-
set -e
|
|
287
|
-
pnpm exec supabase migration squash --db-url "$SUPABASE_DB_URL" --yes
|
|
288
|
-
push:
|
|
289
|
-
remoteYes: |-
|
|
290
|
-
node scripts/safety/require-human-remote-operation.cjs --operation db.push.remoteYes
|
|
291
|
-
pnpm exec supabase db push --db-url "$SUPABASE_DB_URL" --yes
|
|
292
|
-
release:
|
|
293
|
-
remote: >-
|
|
294
|
-
node scripts/safety/require-human-remote-operation.cjs --operation db.release.remote && nps db.migrate.reconcileRemote && nps db.migrationGen && nps db.push.remoteYes && nps db.migrate.squashYes && nps db.generate.remote
|
|
295
|
-
generate:
|
|
296
|
-
remote: |-
|
|
297
|
-
pnpm exec supabase gen types typescript --db-url "$SUPABASE_DB_URL" > src/__generated__/database.ts
|
|
309
|
+
prod:
|
|
310
|
+
db:
|
|
311
|
+
reconcile: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.reconcile && bash scripts/db/run-production-operation.sh reconcile
|
|
312
|
+
migrationGen: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.migrationGen && bash scripts/db/run-production-operation.sh migrationGen
|
|
313
|
+
migrate: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.migrate && bash scripts/db/run-production-operation.sh migrate
|
|
314
|
+
push: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.push && bash scripts/db/run-production-operation.sh push
|
|
315
|
+
squash: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.squash && bash scripts/db/run-production-operation.sh squash
|
|
316
|
+
generate: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.generate && bash scripts/db/run-production-operation.sh generate
|
|
317
|
+
release: node scripts/safety/require-human-remote-operation.cjs --operation prod.db.release && bash scripts/db/run-production-operation.sh release
|
|
298
318
|
`;
|
|
299
319
|
const scriptPath = join(projectRoot, 'package-scripts.yml');
|
|
300
320
|
let existingScripts;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { clientOnlyBoundaryViolations } from "./client-only-boundary.js";
|
|
3
|
+
import { readRuleProfile } from "./project-context.js";
|
|
2
4
|
import { loadCanonicalProjectContext, prepareCanonicalManifest } from "./project-runtime.js";
|
|
3
5
|
import { assertPredefinedPackageState } from "./predefined-packages/health.js";
|
|
4
6
|
import { readInstalledState, writeChecksState } from "./state.js";
|
|
@@ -49,6 +51,18 @@ export async function canonicalCheck(projectRoot, source, options = {}) {
|
|
|
49
51
|
}
|
|
50
52
|
const normalizedTargetFiles = (targetFiles ?? []).map((file) => String(file).replaceAll('\\', '/'));
|
|
51
53
|
let exitCode = 0;
|
|
54
|
+
const profile = await readRuleProfile(projectRoot);
|
|
55
|
+
if (profile.capabilities.includes('client-only')) {
|
|
56
|
+
const findings = await clientOnlyBoundaryViolations(projectRoot);
|
|
57
|
+
results['client-only-boundary'] = {
|
|
58
|
+
status: findings.length ? 'fail' : 'pass',
|
|
59
|
+
exitCode: findings.length ? 1 : 0,
|
|
60
|
+
stderr: findings.join('\n'),
|
|
61
|
+
diagnostics: findings.map((message) => ({ message })),
|
|
62
|
+
};
|
|
63
|
+
if (findings.length)
|
|
64
|
+
exitCode = 1;
|
|
65
|
+
}
|
|
52
66
|
for (const [id, installed] of Object.entries(current.installed).sort(([a], [b]) => a.localeCompare(b))) {
|
|
53
67
|
const entry = byId.get(id);
|
|
54
68
|
if (!entry || installed.kind !== 'rule')
|
|
@@ -80,7 +80,10 @@ export const STACK_PACKAGES = {
|
|
|
80
80
|
function effectivePackages(stack, packageIds = []) {
|
|
81
81
|
return new Set([...(stack ? (STACK_PACKAGES[stack] ?? []) : []), ...packageIds]);
|
|
82
82
|
}
|
|
83
|
+
const backendOnlyRuleIds = new Set(['db-schema-static-validation']);
|
|
83
84
|
export function ruleApplies(entry, stack, profile = EMPTY_RULE_PROFILE, packageIds = []) {
|
|
85
|
+
if (profile.capabilities?.includes('client-only') && backendOnlyRuleIds.has(entry.id))
|
|
86
|
+
return false;
|
|
84
87
|
const included = new Set(profile.include ?? []);
|
|
85
88
|
const excluded = new Set((profile.exclude ?? []).map((item) => item.id));
|
|
86
89
|
if (excluded.has(entry.id))
|
|
@@ -108,6 +111,8 @@ function capabilitySatisfied(entry, profile) {
|
|
|
108
111
|
return !entry.requiredCapabilities?.some((capability) => !capabilities.has(capability));
|
|
109
112
|
}
|
|
110
113
|
export function projectRuleApplies(entry, stack, profile = EMPTY_RULE_PROFILE, entries = [], packageIds = []) {
|
|
114
|
+
if (profile.capabilities?.includes('client-only') && backendOnlyRuleIds.has(entry.id))
|
|
115
|
+
return false;
|
|
111
116
|
const included = new Set(profile.include ?? []);
|
|
112
117
|
const excluded = new Set((profile.exclude ?? []).map((item) => item.id));
|
|
113
118
|
if (excluded.has(entry.id))
|
package/dist/npm/state.js
CHANGED
|
@@ -223,9 +223,23 @@ export async function writeChecksState(projectRoot, state) {
|
|
|
223
223
|
schemaVersion: CHECKS_SCHEMA_VERSION,
|
|
224
224
|
results: {},
|
|
225
225
|
}));
|
|
226
|
-
|
|
226
|
+
const next = migrateChecksStateRuleIds({
|
|
227
227
|
...current,
|
|
228
228
|
...state,
|
|
229
229
|
schemaVersion: CHECKS_SCHEMA_VERSION,
|
|
230
|
-
})
|
|
230
|
+
});
|
|
231
|
+
let fileExists = true;
|
|
232
|
+
try {
|
|
233
|
+
await access(join(projectRoot, STATE_RELATIVE_PATH));
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (error.code !== 'ENOENT')
|
|
237
|
+
throw error;
|
|
238
|
+
fileExists = false;
|
|
239
|
+
}
|
|
240
|
+
const { checkedAt: _previousCheckedAt, ...previousMeaningful } = current;
|
|
241
|
+
const { checkedAt: _nextCheckedAt, ...nextMeaningful } = next;
|
|
242
|
+
if (fileExists && JSON.stringify(previousMeaningful) === JSON.stringify(nextMeaningful))
|
|
243
|
+
return;
|
|
244
|
+
await writeJsonAtomic(join(projectRoot, STATE_RELATIVE_PATH), next);
|
|
231
245
|
}
|
|
@@ -3,17 +3,17 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
const OPERATIONS = new Set(['status', 'start', 'stop']);
|
|
5
5
|
const ID = /^[a-f0-9]{32}$/;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// Use the Supabase project's declared identity rather than a checkout-path heuristic.
|
|
7
|
+
const PROJECT_IDS = {
|
|
8
|
+
mykone: 'mycone-app',
|
|
9
|
+
one_and_only: 'one_and_only',
|
|
8
10
|
};
|
|
9
11
|
export function projectFromCwd(cwd) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return undefined;
|
|
12
|
+
const config = resolve(cwd, 'supabase/config.toml');
|
|
13
|
+
if (!existsSync(config))
|
|
14
|
+
return undefined;
|
|
15
|
+
const match = /^project_id\s*=\s*"([^"]+)"\s*$/mu.exec(readFileSync(config, 'utf8'));
|
|
16
|
+
return match ? PROJECT_IDS[match[1]] : undefined;
|
|
17
17
|
}
|
|
18
18
|
export function runSupabaseLocal(args, cwd = process.cwd()) {
|
|
19
19
|
if (args[0] === 'result' && args.length === 2 && ID.test(args[1])) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specdest/devkit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"specdest": "dist/npm/cli.js"
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "node --test test/*.test.js",
|
|
24
|
-
"temp.migrate.commands": "node scripts/temp.migrate.commands.mjs",
|
|
25
24
|
"db:validate": "node scripts/validate-db-command-aliases.mjs",
|
|
26
25
|
"test:acceptance": "node scripts/fresh-project-acceptance.mjs",
|
|
27
26
|
"lint": "oxlint src",
|