@coreframe/scripts 0.1.0 → 0.1.2

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.
Files changed (96) hide show
  1. package/dist/config.d.ts +18 -4
  2. package/dist/config.js +1 -3
  3. package/dist/coreframe.d.ts +243 -241
  4. package/dist/coreframe.js +1 -239
  5. package/dist/db/client.d.ts +26 -18
  6. package/dist/db/client.js +1 -29
  7. package/dist/db/config.d.ts +22 -19
  8. package/dist/db/config.js +1 -32
  9. package/dist/db/drizzle-kit.d.ts +6 -5
  10. package/dist/db/drizzle-kit.js +1 -21
  11. package/dist/db/ensure.d.ts +20 -2
  12. package/dist/db/ensure.js +1 -39
  13. package/dist/db/migrate-held.d.ts +16 -10
  14. package/dist/db/migrate-held.js +3 -112
  15. package/dist/db/migrate.d.ts +4 -2
  16. package/dist/db/migrate.js +1 -24
  17. package/dist/db/project.d.ts +19 -7
  18. package/dist/db/project.js +1 -9
  19. package/dist/db/reset.d.ts +4 -2
  20. package/dist/db/reset.js +1 -18
  21. package/dist/db/schema-push.d.ts +22 -0
  22. package/dist/db/schema-push.js +1 -0
  23. package/dist/db/seed.d.ts +6 -3
  24. package/dist/db/seed.js +1 -22
  25. package/dist/db/setup.d.ts +6 -3
  26. package/dist/db/setup.js +1 -14
  27. package/dist/deploy/check-migrations.d.ts +4 -2
  28. package/dist/deploy/check-migrations.js +1 -17
  29. package/dist/deploy/checks.d.ts +6 -2
  30. package/dist/deploy/checks.js +1 -27
  31. package/dist/deploy/config.d.ts +47 -44
  32. package/dist/deploy/config.js +1 -9
  33. package/dist/deploy/migrations.d.ts +21 -18
  34. package/dist/deploy/migrations.js +4 -203
  35. package/dist/deploy/pending-migrations.d.ts +9 -5
  36. package/dist/deploy/pending-migrations.js +1 -30
  37. package/dist/deploy/tauri-release.d.ts +93 -73
  38. package/dist/deploy/tauri-release.js +1 -512
  39. package/dist/deploy/version.d.ts +15 -13
  40. package/dist/deploy/version.js +1 -41
  41. package/dist/deploy.d.ts +16 -15
  42. package/dist/deploy.js +1 -246
  43. package/dist/dev.d.ts +23 -12
  44. package/dist/dev.js +1 -95
  45. package/dist/image-generator.d.ts +18 -2
  46. package/dist/image-generator.js +1 -59
  47. package/dist/project.d.ts +4 -1
  48. package/dist/project.js +1 -13
  49. package/dist/typecheck.d.ts +4 -2
  50. package/dist/typecheck.js +1 -44
  51. package/dist/upgrade/check-skill-current.d.ts +10 -5
  52. package/dist/upgrade/check-skill-current.js +1 -87
  53. package/dist/upgrade/ensure-template-remote.d.ts +10 -5
  54. package/dist/upgrade/ensure-template-remote.js +1 -56
  55. package/dist/upgrade/fast-forward-template-files.d.ts +8 -6
  56. package/dist/upgrade/fast-forward-template-files.js +1 -279
  57. package/package.json +7 -2
  58. package/config.test.ts +0 -15
  59. package/config.ts +0 -9
  60. package/coreframe.ts +0 -272
  61. package/db/client.ts +0 -72
  62. package/db/config.ts +0 -41
  63. package/db/drizzle-kit.test.ts +0 -27
  64. package/db/drizzle-kit.ts +0 -39
  65. package/db/ensure.ts +0 -67
  66. package/db/migrate-held.test.ts +0 -81
  67. package/db/migrate-held.ts +0 -166
  68. package/db/migrate.ts +0 -39
  69. package/db/project.ts +0 -28
  70. package/db/reset.ts +0 -24
  71. package/db/seed.ts +0 -38
  72. package/db/setup.ts +0 -18
  73. package/deploy/check-migrations.ts +0 -31
  74. package/deploy/checks.ts +0 -38
  75. package/deploy/config.test.ts +0 -24
  76. package/deploy/config.ts +0 -68
  77. package/deploy/migrations.test.ts +0 -110
  78. package/deploy/migrations.ts +0 -317
  79. package/deploy/pending-migrations.test.ts +0 -93
  80. package/deploy/pending-migrations.ts +0 -45
  81. package/deploy/tauri-release.test.ts +0 -196
  82. package/deploy/tauri-release.ts +0 -816
  83. package/deploy/version.test.ts +0 -29
  84. package/deploy/version.ts +0 -65
  85. package/deploy.test.ts +0 -101
  86. package/deploy.ts +0 -346
  87. package/dev.test.ts +0 -153
  88. package/dev.ts +0 -155
  89. package/image-generator.ts +0 -84
  90. package/project.ts +0 -6
  91. package/tsconfig.build.json +0 -12
  92. package/tsconfig.json +0 -20
  93. package/typecheck.ts +0 -55
  94. package/upgrade/check-skill-current.ts +0 -112
  95. package/upgrade/ensure-template-remote.ts +0 -79
  96. package/upgrade/fast-forward-template-files.ts +0 -408
@@ -1,119 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { createHash } from "node:crypto";
3
- import { readFile } from "node:fs/promises";
4
- import { collectHeldMigrationFiles, formatMigrationList } from "../deploy/migrations.js";
5
- import { createProjectDeployDatabase } from "./project.js";
6
- const CONFIRM_FLAG = "--confirm=run-held-migrations";
7
- const HELD_HEADER_FIELDS = ["-- Held migration:", "-- Safe after:", "-- Verification:"];
8
- export async function migrateHeldMigrations({ argv = process.argv.slice(2), database, env = process.env, } = {}) {
9
- const migrations = await collectHeldMigrationFiles();
10
- console.log("Held migration files:");
11
- console.log(formatMigrationList(migrations));
12
- if (!argv.includes(CONFIRM_FLAG)) {
13
- throw new Error(`Held migrations require explicit confirmation. Re-run with ${CONFIRM_FLAG}.`);
14
- }
15
- if (migrations.length === 0) {
16
- console.log("No held migrations to run.");
17
- return;
18
- }
19
- const activeDatabase = database ?? (await createProjectDeployDatabase({ env }));
20
- try {
21
- await ensureHeldMigrationJournal(activeDatabase);
22
- for (const migration of migrations) {
23
- const sql = await readFile(migration.path, "utf8");
24
- validateHeldMigrationHeader(sql, migration.relativePath);
25
- const sha256 = hashSql(sql);
26
- const applied = await activeDatabase.execute(heldMigrationSelectQuery(activeDatabase.dialect, migration.id));
27
- if (applied.rows.length === 1) {
28
- if (applied.rows[0]?.sha256 !== sha256) {
29
- throw new Error(`Held migration ${migration.relativePath} changed after it was applied.`);
30
- }
31
- console.log(`Skipping already-applied held migration ${migration.relativePath}`);
32
- continue;
33
- }
34
- console.log(`Applying held migration ${migration.relativePath}`);
35
- await runMigrationTransaction(activeDatabase, async (transactionDatabase) => {
36
- await transactionDatabase.execute(sql);
37
- await transactionDatabase.execute(heldMigrationInsertQuery(activeDatabase.dialect, migration.id, sha256));
38
- });
39
- }
40
- }
41
- finally {
42
- if (!database) {
43
- await activeDatabase.close?.();
44
- }
45
- }
46
- }
47
- export function validateHeldMigrationHeader(sql, relativePath) {
48
- const missing = HELD_HEADER_FIELDS.filter((field) => !sql.includes(field));
49
- if (missing.length > 0) {
50
- throw new Error(`${relativePath} is missing held migration header fields: ${missing.join(", ")}`);
51
- }
52
- }
53
- function hashSql(sql) {
54
- return createHash("sha256").update(sql).digest("hex");
55
- }
56
- async function ensureHeldMigrationJournal(database) {
57
- for (const statement of heldMigrationJournalStatements(database.dialect)) {
58
- await database.execute(statement);
59
- }
60
- }
61
- function heldMigrationJournalStatements(dialect) {
62
- switch (dialect) {
63
- case "postgres":
64
- return [
65
- "create schema if not exists drizzle",
66
- `create table if not exists drizzle.__held_migrations (
2
+ import{collectHeldMigrationFiles as e,formatMigrationList as t}from"../deploy/migrations.js";import{createProjectDeployDatabase as n}from"./project.js";import{readFile as r}from"node:fs/promises";import{createHash as i}from"node:crypto";const a=`--confirm=run-held-migrations`,o=[`-- Held migration:`,`-- Safe after:`,`-- Verification:`];async function s({argv:i=process.argv.slice(2),database:o,env:s=process.env}={}){let d=await e();if(console.log(`Held migration files:`),console.log(t(d)),!i.includes(a))throw Error(`Held migrations require explicit confirmation. Re-run with ${a}.`);if(d.length===0){console.log(`No held migrations to run.`);return}let m=o??await n({env:s});try{await u(m);for(let e of d){let t=await r(e.path,`utf8`);c(t,e.relativePath);let n=l(t),i=await m.execute(f(m.dialect,e.id));if(i.rows.length===1){if(i.rows[0]?.sha256!==n)throw Error(`Held migration ${e.relativePath} changed after it was applied.`);console.log(`Skipping already-applied held migration ${e.relativePath}`);continue}console.log(`Applying held migration ${e.relativePath}`),await h(m,async r=>{await r.execute(t),await r.execute(p(m.dialect,e.id,n))})}}finally{o||await m.close?.()}}function c(e,t){let n=o.filter(t=>!e.includes(t));if(n.length>0)throw Error(`${t} is missing held migration header fields: ${n.join(`, `)}`)}function l(e){return i(`sha256`).update(e).digest(`hex`)}async function u(e){for(let t of d(e.dialect))await e.execute(t)}function d(e){switch(e){case`postgres`:return[`create schema if not exists drizzle`,`create table if not exists drizzle.__held_migrations (
67
3
  id text primary key,
68
4
  sha256 text not null,
69
5
  applied_at timestamptz not null default now()
70
- )`,
71
- ];
72
- case "sqlite":
73
- return [
74
- `create table if not exists __held_migrations (
6
+ )`];case`sqlite`:return[`create table if not exists __held_migrations (
75
7
  id text primary key,
76
8
  sha256 text not null,
77
9
  applied_at text not null default current_timestamp
78
- )`,
79
- ];
80
- }
81
- }
82
- export function heldMigrationSelectQuery(dialect, id) {
83
- return `select sha256 from ${heldMigrationJournalTable(dialect)} where id = ${sqlString(id)}`;
84
- }
85
- export function heldMigrationInsertQuery(dialect, id, sha256) {
86
- return `insert into ${heldMigrationJournalTable(dialect)} (id, sha256) values (${sqlString(id)}, ${sqlString(sha256)})`;
87
- }
88
- function heldMigrationJournalTable(dialect) {
89
- switch (dialect) {
90
- case "postgres":
91
- return "drizzle.__held_migrations";
92
- case "sqlite":
93
- return "__held_migrations";
94
- }
95
- }
96
- async function runMigrationTransaction(database, run) {
97
- if (database.transaction) {
98
- await database.transaction(run);
99
- return;
100
- }
101
- await database.execute("begin");
102
- try {
103
- await run(database);
104
- await database.execute("commit");
105
- }
106
- catch (error) {
107
- await database.execute("rollback");
108
- throw error;
109
- }
110
- }
111
- function sqlString(value) {
112
- return `'${value.replaceAll("'", "''")}'`;
113
- }
114
- if (import.meta.main) {
115
- migrateHeldMigrations().catch((error) => {
116
- console.error(error);
117
- process.exit(1);
118
- });
119
- }
10
+ )`]}}function f(e,t){return`select sha256 from ${m(e)} where id = ${g(t)}`}function p(e,t,n){return`insert into ${m(e)} (id, sha256) values (${g(t)}, ${g(n)})`}function m(e){switch(e){case`postgres`:return`drizzle.__held_migrations`;case`sqlite`:return`__held_migrations`}}async function h(e,t){if(e.transaction){await e.transaction(t);return}await e.execute(`begin`);try{await t(e),await e.execute(`commit`)}catch(t){throw await e.execute(`rollback`),t}}function g(e){return`'${e.replaceAll(`'`,`''`)}'`}import.meta.main&&s().catch(e=>{console.error(e),process.exit(1)});export{p as heldMigrationInsertQuery,f as heldMigrationSelectQuery,s as migrateHeldMigrations,c as validateHeldMigrationHeader};
@@ -1,2 +1,4 @@
1
- #!/usr/bin/env node
2
- export declare function migrateLocalDb(): Promise<void>;
1
+ //#region db/migrate.d.ts
2
+ declare function migrateLocalDb(): Promise<void>;
3
+ //#endregion
4
+ export { migrateLocalDb };
@@ -1,25 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { access } from "node:fs/promises";
3
- import { resolve } from "node:path";
4
- import { migrate } from "drizzle-orm/pglite/migrator";
5
- import { importProjectModule } from "../project.js";
6
- import { LOCAL_DB_DIR, MIGRATIONS_FOLDER } from "./config.js";
7
- const migrationsFolder = resolve(MIGRATIONS_FOLDER);
8
- export async function migrateLocalDb() {
9
- await access(migrationsFolder);
10
- const { createLocalDb } = await importProjectModule("src/db/local.ts");
11
- const db = createLocalDb(LOCAL_DB_DIR);
12
- try {
13
- await migrate(db, { migrationsFolder });
14
- console.log(`Applied local migrations from ${migrationsFolder}`);
15
- }
16
- finally {
17
- await db.$client.close();
18
- }
19
- }
20
- if (import.meta.main) {
21
- migrateLocalDb().catch((error) => {
22
- console.error(error);
23
- process.exit(1);
24
- });
25
- }
2
+ import{importProjectModule as e}from"../project.js";import{LOCAL_DB_DIR as t,MIGRATIONS_FOLDER as n}from"./config.js";import{access as r}from"node:fs/promises";import{resolve as i}from"node:path";import{migrate as a}from"drizzle-orm/pglite/migrator";const o=i(n);async function s(){await r(o);let{createLocalDb:n}=await e(`src/db/local.ts`),i=n(t);try{await a(i,{migrationsFolder:o}),console.log(`Applied local migrations from ${o}`)}finally{await i.$client.close()}}import.meta.main&&s().catch(e=>{console.error(e),process.exit(1)});export{s as migrateLocalDb};
@@ -1,8 +1,20 @@
1
- import type { CoreframeDatabaseClient } from "./client.ts";
2
- export type CreateProjectDatabaseOptions = {
3
- env?: NodeJS.ProcessEnv;
1
+ import { DatabaseClient } from "./client.js";
2
+ import { DatabaseConfig } from "../config.js";
3
+ import { importProjectModule } from "../project.js";
4
+
5
+ //#region db/project.d.ts
6
+ type CreateProjectDatabaseOptions = {
7
+ config?: DatabaseConfig;
8
+ env?: NodeJS.ProcessEnv;
9
+ importProjectDependency?: ImportProjectDependency;
10
+ importProjectModule?: typeof importProjectModule;
4
11
  };
5
- export type ProjectDatabaseModule = {
6
- createDeployDatabase?(options?: CreateProjectDatabaseOptions): CoreframeDatabaseClient | Promise<CoreframeDatabaseClient>;
7
- };
8
- export declare function createProjectDeployDatabase(options?: CreateProjectDatabaseOptions): Promise<CoreframeDatabaseClient>;
12
+ type ImportProjectDependency = <T>(specifier: string) => Promise<T>;
13
+ declare function createProjectDeployDatabase({
14
+ config,
15
+ env,
16
+ importProjectDependency,
17
+ importProjectModule: importModule
18
+ }?: CreateProjectDatabaseOptions): Promise<DatabaseClient>;
19
+ //#endregion
20
+ export { CreateProjectDatabaseOptions, createProjectDeployDatabase };
@@ -1,9 +1 @@
1
- import { importProjectModule } from "../project.js";
2
- const projectDatabaseConfigPath = "scripts/coreframe.db.ts";
3
- export async function createProjectDeployDatabase(options = {}) {
4
- const module = await importProjectModule(projectDatabaseConfigPath);
5
- if (!module.createDeployDatabase) {
6
- throw new Error(`${projectDatabaseConfigPath} must export createDeployDatabase() for Coreframe database workflows.`);
7
- }
8
- return module.createDeployDatabase(options);
9
- }
1
+ import{readProjectConfig as e}from"../config.js";import{importProjectModule as t}from"../project.js";import{createDatabaseAdapter as n}from"./client.js";import{createRequire as r}from"node:module";import{resolve as i}from"node:path";import{pathToFileURL as a}from"node:url";const o=`src/db/relations.ts`;async function s({config:n,env:r=process.env,importProjectDependency:i=u,importProjectModule:a=t}={}){let o=(n??(await e()).database)?.dialect??`postgres`;if(o===`postgres`)return c({env:r,importModule:a,importProjectDependency:i});if(o===`sqlite`)return l({env:r,importModule:a,importProjectDependency:i});throw Error(`Unsupported database dialect "${o}".`)}async function c({env:e,importModule:t,importProjectDependency:r}){let i=e.DATABASE_URL;if(!i)throw Error(`DATABASE_URL is required to create the deploy database.`);let[{drizzle:a},{relations:s}]=await Promise.all([r(`drizzle-orm/node-postgres`),t(o)]),c=a({connection:{connectionString:i,max:1},relations:s});return n({database:c,dialect:`postgres`,close:()=>c.$client?.end?.()??Promise.resolve()})}async function l({env:e,importModule:t,importProjectDependency:r}){let i=e.TURSO_DATABASE_URL??e.DATABASE_URL;if(!i)throw Error(`TURSO_DATABASE_URL or DATABASE_URL is required to create the deploy database.`);let[{createClient:a},{drizzle:s},{relations:c}]=await Promise.all([r(`@libsql/client`),r(`drizzle-orm/libsql`),t(o)]),l=a({url:i,authToken:e.TURSO_AUTH_TOKEN});return n({database:s({client:l,relations:c}),dialect:`sqlite`,close:async()=>{await l.close?.()}})}async function u(e){return await import(a(r(i(`package.json`)).resolve(e)).href)}export{s as createProjectDeployDatabase};
@@ -1,2 +1,4 @@
1
- #!/usr/bin/env node
2
- export declare function resetLocalDb(): Promise<void>;
1
+ //#region db/reset.d.ts
2
+ declare function resetLocalDb(): Promise<void>;
3
+ //#endregion
4
+ export { resetLocalDb };
package/dist/db/reset.js CHANGED
@@ -1,19 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { rm } from "node:fs/promises";
3
- import { relative, resolve } from "node:path";
4
- import { LOCAL_DB_DIR } from "./config.js";
5
- export async function resetLocalDb() {
6
- const dataDir = resolve(LOCAL_DB_DIR);
7
- const relativeDataDir = relative(process.cwd(), dataDir);
8
- if (relativeDataDir === "" || relativeDataDir.startsWith("..")) {
9
- throw new Error(`Refusing to reset local database outside the project: ${dataDir}`);
10
- }
11
- await rm(dataDir, { force: true, recursive: true });
12
- console.log(`Removed local PGlite data at ${dataDir}`);
13
- }
14
- if (import.meta.main) {
15
- resetLocalDb().catch((error) => {
16
- console.error(error);
17
- process.exit(1);
18
- });
19
- }
2
+ import{LOCAL_DB_DIR as e}from"./config.js";import{rm as t}from"node:fs/promises";import{relative as n,resolve as r}from"node:path";async function i(){let i=r(e),a=n(process.cwd(),i);if(a===``||a.startsWith(`..`))throw Error(`Refusing to reset local database outside the project: ${i}`);await t(i,{force:!0,recursive:!0}),console.log(`Removed local PGlite data at ${i}`)}import.meta.main&&i().catch(e=>{console.error(e),process.exit(1)});export{i as resetLocalDb};
@@ -0,0 +1,22 @@
1
+ import { DatabaseDialect } from "./client.js";
2
+
3
+ //#region db/schema-push.d.ts
4
+ type SchemaPushPlan = {
5
+ sqlStatements: string[];
6
+ hints: Array<{
7
+ hint: string;
8
+ statement?: string;
9
+ }>;
10
+ apply(): Promise<void>;
11
+ };
12
+ type SchemaPushModule = {
13
+ pushSchema(schema: Record<string, unknown>, db: never, migrationsConfig?: {
14
+ table?: string;
15
+ schema?: string;
16
+ }): Promise<SchemaPushPlan>;
17
+ };
18
+ type ImportSchemaPushModule = (dialect: DatabaseDialect) => Promise<SchemaPushModule>;
19
+ declare function planLocalSchemaPush(dialect: DatabaseDialect, schema: Record<string, unknown>, db: unknown, importModule?: ImportSchemaPushModule): Promise<SchemaPushPlan>;
20
+ declare function inferSchemaDialect(schema: Record<string, unknown>): DatabaseDialect;
21
+ //#endregion
22
+ export { SchemaPushModule, SchemaPushPlan, inferSchemaDialect, planLocalSchemaPush };
@@ -0,0 +1 @@
1
+ import{createRequire as e}from"node:module";import{resolve as t}from"node:path";import{pathToFileURL as n}from"node:url";import{is as r}from"drizzle-orm";import{PgMaterializedView as i,PgTable as a,PgView as o}from"drizzle-orm/pg-core";import{SQLiteTable as s,SQLiteView as c}from"drizzle-orm/sqlite-core";const l={postgres:`drizzle-kit/payload/postgres`,sqlite:`drizzle-kit/payload/sqlite`};async function u(e,t,n,r=f){let{pushSchema:i}=await r(e);return i(t,n)}function d(e){let t=!1,n=!1;for(let r of Object.values(e))t||=p(r),n||=m(r);if(t&&n)throw Error(`Local database schema mixes PostgreSQL and SQLite entities.`);if(t)return`postgres`;if(n)return`sqlite`;throw Error(`Could not infer local database dialect from src/db/schema.ts.`)}async function f(r){return await import(n(e(t(`package.json`)).resolve(l[r])).href)}function p(e){return r(e,a)||r(e,o)||r(e,i)}function m(e){return r(e,s)||r(e,c)}export{d as inferSchemaDialect,u as planLocalSchemaPush};
package/dist/db/seed.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- #!/usr/bin/env node
2
- import type { SeedProfile } from "./config.ts";
3
- export declare function seedLocalDb(profile?: SeedProfile): Promise<void>;
1
+ import { SeedProfile } from "./config.js";
2
+
3
+ //#region db/seed.d.ts
4
+ declare function seedLocalDb(profile?: SeedProfile): Promise<void>;
5
+ //#endregion
6
+ export { seedLocalDb };
package/dist/db/seed.js CHANGED
@@ -1,23 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { importProjectModule } from "../project.js";
3
- import { getSeedProfile, LOCAL_DB_DIR } from "./config.js";
4
- export async function seedLocalDb(profile = getSeedProfile()) {
5
- const [{ createLocalDb }, { seedUsers }] = await Promise.all([
6
- importProjectModule("src/db/local.ts"),
7
- importProjectModule("scripts/db/seeds/users.ts"),
8
- ]);
9
- const db = createLocalDb(LOCAL_DB_DIR);
10
- try {
11
- await seedUsers(db, profile);
12
- console.log(`Seeded local database with "${profile}" profile`);
13
- }
14
- finally {
15
- await db.$client.close();
16
- }
17
- }
18
- if (import.meta.main) {
19
- seedLocalDb().catch((error) => {
20
- console.error(error);
21
- process.exit(1);
22
- });
23
- }
2
+ import{importProjectModule as e}from"../project.js";import{LOCAL_DB_DIR as t,getSeedProfile as n}from"./config.js";async function r(r=n()){let[{createLocalDb:i},{seedUsers:a}]=await Promise.all([e(`src/db/local.ts`),e(`scripts/db/seeds/users.ts`)]),o=i(t);try{await a(o,r),console.log(`Seeded local database with "${r}" profile`)}finally{await o.$client.close()}}import.meta.main&&r().catch(e=>{console.error(e),process.exit(1)});export{r as seedLocalDb};
@@ -1,3 +1,6 @@
1
- #!/usr/bin/env node
2
- import type { SeedProfile } from "./config.ts";
3
- export declare function setupLocalDb(profile?: SeedProfile): Promise<void>;
1
+ import { SeedProfile } from "./config.js";
2
+
3
+ //#region db/setup.d.ts
4
+ declare function setupLocalDb(profile?: SeedProfile): Promise<void>;
5
+ //#endregion
6
+ export { setupLocalDb };
package/dist/db/setup.js CHANGED
@@ -1,15 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { migrateLocalDb } from "./migrate.js";
3
- import { resetLocalDb } from "./reset.js";
4
- import { seedLocalDb } from "./seed.js";
5
- export async function setupLocalDb(profile = "small") {
6
- await resetLocalDb();
7
- await migrateLocalDb();
8
- await seedLocalDb(profile);
9
- }
10
- if (import.meta.main) {
11
- setupLocalDb().catch((error) => {
12
- console.error(error);
13
- process.exit(1);
14
- });
15
- }
2
+ import{seedLocalDb as e}from"./seed.js";import{migrateLocalDb as t}from"./migrate.js";import{resetLocalDb as n}from"./reset.js";async function r(r=`small`){await n(),await t(),await e(r)}import.meta.main&&r().catch(e=>{console.error(e),process.exit(1)});export{r as setupLocalDb};
@@ -1,2 +1,4 @@
1
- #!/usr/bin/env node
2
- export declare function checkDeployMigrations(): Promise<void>;
1
+ //#region deploy/check-migrations.d.ts
2
+ declare function checkDeployMigrations(): Promise<void>;
3
+ //#endregion
4
+ export { checkDeployMigrations };
@@ -1,18 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { collectDeployMigrationFiles, formatMigrationList, formatMigrationScanFailures, scanDeployMigrationFiles, } from "./migrations.js";
3
- export async function checkDeployMigrations() {
4
- const migrations = await collectDeployMigrationFiles();
5
- console.log("Deploy migration files:");
6
- console.log(formatMigrationList(migrations));
7
- const failures = await scanDeployMigrationFiles(migrations);
8
- if (failures.length > 0) {
9
- throw new Error(`Deploy migrations contain unsafe SQL. Move unsafe statements to held migrations.\n${formatMigrationScanFailures(failures)}`);
10
- }
11
- console.log("Deploy migrations passed safety checks.");
12
- }
13
- if (import.meta.main) {
14
- checkDeployMigrations().catch((error) => {
15
- console.error(error);
16
- process.exit(1);
17
- });
18
- }
2
+ import{collectDeployMigrationFiles as e,formatMigrationList as t,formatMigrationScanFailures as n,scanDeployMigrationFiles as r}from"./migrations.js";async function i(){let i=await e();console.log(`Deploy migration files:`),console.log(t(i));let a=await r(i);if(a.length>0)throw Error(`Deploy migrations contain unsafe SQL. Move unsafe statements to held migrations.\n${n(a)}`);console.log(`Deploy migrations passed safety checks.`)}import.meta.main&&i().catch(e=>{console.error(e),process.exit(1)});export{i as checkDeployMigrations};
@@ -1,2 +1,6 @@
1
- import type { DeployContext, ResolvedDeployConfig } from "./config.ts";
2
- export declare function runPostDeployChecks(config: ResolvedDeployConfig, context: DeployContext): Promise<void>;
1
+ import { DeployContext, ResolvedDeployConfig } from "./config.js";
2
+
3
+ //#region deploy/checks.d.ts
4
+ declare function runPostDeployChecks(config: ResolvedDeployConfig, context: DeployContext): Promise<void>;
5
+ //#endregion
6
+ export { runPostDeployChecks };
@@ -1,27 +1 @@
1
- export async function runPostDeployChecks(config, context) {
2
- const productionUrl = context.productionUrl ?? config.productionUrl;
3
- if (config.smokeChecks.length > 0 && !productionUrl) {
4
- console.log("Skipping HTTP smoke checks. Set DEPLOY_URL or productionUrl in deploy config.");
5
- }
6
- for (const check of config.smokeChecks) {
7
- if (!productionUrl && !check.url) {
8
- continue;
9
- }
10
- const url = check.url ?? new URL(check.path ?? "/", productionUrl).toString();
11
- const response = await fetch(url);
12
- if (!statusMatches(response.status, check.expectedStatus ?? "2xx")) {
13
- throw new Error(`${check.name} smoke check failed: ${url} returned ${response.status}.`);
14
- }
15
- console.log(`${check.name} smoke check passed: ${response.status} ${url}`);
16
- }
17
- await config.afterDeploy?.({ ...context, productionUrl });
18
- }
19
- function statusMatches(status, expected) {
20
- if (expected === "2xx") {
21
- return status >= 200 && status < 300;
22
- }
23
- if (Array.isArray(expected)) {
24
- return expected.includes(status);
25
- }
26
- return status === expected;
27
- }
1
+ async function e(e,n){let r=n.productionUrl??e.productionUrl;e.smokeChecks.length>0&&!r&&console.log(`Skipping HTTP smoke checks. Set DEPLOY_URL or productionUrl in deploy config.`);for(let n of e.smokeChecks){if(!r&&!n.url)continue;let e=n.url??new URL(n.path??`/`,r).toString(),i=await fetch(e);if(!t(i.status,n.expectedStatus??`2xx`))throw Error(`${n.name} smoke check failed: ${e} returned ${i.status}.`);console.log(`${n.name} smoke check passed: ${i.status} ${e}`)}await e.afterDeploy?.({...n,productionUrl:r})}function t(e,t){return t===`2xx`?e>=200&&e<300:Array.isArray(t)?t.includes(e):e===t}export{e as runPostDeployChecks};
@@ -1,50 +1,53 @@
1
- export type DeployContext = {
2
- environment: string;
3
- productionUrl?: string;
4
- releaseName: string;
5
- version: string;
1
+ //#region deploy/config.d.ts
2
+ type DeployContext = {
3
+ environment: string;
4
+ productionUrl?: string;
5
+ releaseName: string;
6
+ version: string;
6
7
  };
7
- export declare const tauriReleasePlatforms: readonly ["macos", "windows", "linux", "ios", "android"];
8
- export type TauriReleasePlatform = (typeof tauriReleasePlatforms)[number];
9
- export type TauriReleasePlatformConfig = {
10
- artifactGlobs?: string[];
11
- buildArgs?: string[];
12
- targetTriple?: string;
13
- updatePlatform?: string;
8
+ declare const tauriReleasePlatforms: readonly ["macos", "windows", "linux", "ios", "android"];
9
+ type TauriReleasePlatform = (typeof tauriReleasePlatforms)[number];
10
+ type TauriReleasePlatformConfig = {
11
+ artifactGlobs?: string[];
12
+ buildArgs?: string[];
13
+ targetTriple?: string;
14
+ updatePlatform?: string;
14
15
  };
15
- export type TauriReleaseConfig = {
16
- artifactDownloadDir?: string;
17
- b2Bucket?: string;
18
- latestManifestPath?: string;
19
- localPlatforms?: TauriReleasePlatform[];
20
- platform?: Partial<Record<TauriReleasePlatform, TauriReleasePlatformConfig>>;
21
- publicBaseUrl?: string;
22
- publicPathPrefix?: string;
23
- releaseNotesPath?: string;
24
- releasePath?: string;
25
- releaseUploadDir?: string;
26
- workflowPlatforms?: TauriReleasePlatform[];
27
- workflowName?: string;
28
- workflowPollIntervalMs?: number;
29
- workflowRef?: string;
30
- workflowTimeoutMs?: number;
16
+ type TauriReleaseConfig = {
17
+ artifactDownloadDir?: string;
18
+ b2Bucket?: string;
19
+ latestManifestPath?: string;
20
+ localPlatforms?: TauriReleasePlatform[];
21
+ platform?: Partial<Record<TauriReleasePlatform, TauriReleasePlatformConfig>>;
22
+ publicBaseUrl?: string;
23
+ publicPathPrefix?: string;
24
+ releaseNotesPath?: string;
25
+ releasePath?: string;
26
+ releaseUploadDir?: string;
27
+ workflowPlatforms?: TauriReleasePlatform[];
28
+ workflowName?: string;
29
+ workflowPollIntervalMs?: number;
30
+ workflowRef?: string;
31
+ workflowTimeoutMs?: number;
31
32
  };
32
- export type DeploySmokeCheck = {
33
- name: string;
34
- path?: string;
35
- url?: string;
36
- expectedStatus?: "2xx" | number | number[];
33
+ type DeploySmokeCheck = {
34
+ name: string;
35
+ path?: string;
36
+ url?: string;
37
+ expectedStatus?: "2xx" | number | number[];
37
38
  };
38
- export type DeployConfig = {
39
- afterDeploy?: (context: DeployContext) => Promise<void> | void;
40
- productionUrl?: string;
41
- smokeChecks?: DeploySmokeCheck[];
42
- tauriRelease?: TauriReleaseConfig;
39
+ type DeployConfig = {
40
+ afterDeploy?: (context: DeployContext) => Promise<void> | void;
41
+ productionUrl?: string;
42
+ smokeChecks?: DeploySmokeCheck[];
43
+ tauriRelease?: TauriReleaseConfig;
43
44
  };
44
- export type ResolvedDeployConfig = {
45
- afterDeploy?: (context: DeployContext) => Promise<void> | void;
46
- productionUrl?: string;
47
- smokeChecks: DeploySmokeCheck[];
48
- tauriRelease: TauriReleaseConfig;
45
+ type ResolvedDeployConfig = {
46
+ afterDeploy?: (context: DeployContext) => Promise<void> | void;
47
+ productionUrl?: string;
48
+ smokeChecks: DeploySmokeCheck[];
49
+ tauriRelease: TauriReleaseConfig;
49
50
  };
50
- export declare function resolveDeployConfig(config: DeployConfig, env?: NodeJS.ProcessEnv): ResolvedDeployConfig;
51
+ declare function resolveDeployConfig(config: DeployConfig, env?: NodeJS.ProcessEnv): ResolvedDeployConfig;
52
+ //#endregion
53
+ export { DeployConfig, DeployContext, DeploySmokeCheck, ResolvedDeployConfig, TauriReleaseConfig, TauriReleasePlatform, TauriReleasePlatformConfig, resolveDeployConfig, tauriReleasePlatforms };
@@ -1,9 +1 @@
1
- export const tauriReleasePlatforms = ["macos", "windows", "linux", "ios", "android"];
2
- export function resolveDeployConfig(config, env = process.env) {
3
- return {
4
- afterDeploy: config.afterDeploy,
5
- productionUrl: config.productionUrl ?? env.DEPLOY_URL ?? env.PRODUCTION_URL,
6
- smokeChecks: config.smokeChecks ?? [{ name: "home", path: "/" }],
7
- tauriRelease: config.tauriRelease ?? {},
8
- };
9
- }
1
+ const e=[`macos`,`windows`,`linux`,`ios`,`android`];function t(e,t=process.env){return{afterDeploy:e.afterDeploy,productionUrl:e.productionUrl??t.DEPLOY_URL??t.PRODUCTION_URL,smokeChecks:e.smokeChecks??[{name:`home`,path:`/`}],tauriRelease:e.tauriRelease??{}}}export{t as resolveDeployConfig,e as tauriReleasePlatforms};
@@ -1,21 +1,24 @@
1
- export type MigrationFile = {
2
- id: string;
3
- path: string;
4
- relativePath: string;
1
+ //#region deploy/migrations.d.ts
2
+ type MigrationFile = {
3
+ id: string;
4
+ path: string;
5
+ relativePath: string;
5
6
  };
6
- export type MigrationRisk = {
7
- code: string;
8
- line: number;
9
- match: string;
10
- reason: string;
7
+ type MigrationRisk = {
8
+ code: string;
9
+ line: number;
10
+ match: string;
11
+ reason: string;
11
12
  };
12
- export type MigrationScanResult = {
13
- migration: MigrationFile;
14
- risks: MigrationRisk[];
13
+ type MigrationScanResult = {
14
+ migration: MigrationFile;
15
+ risks: MigrationRisk[];
15
16
  };
16
- export declare function collectDeployMigrationFiles(cwd?: string): Promise<MigrationFile[]>;
17
- export declare function collectHeldMigrationFiles(cwd?: string): Promise<MigrationFile[]>;
18
- export declare function scanDeployMigrationFiles(migrations: MigrationFile[]): Promise<MigrationScanResult[]>;
19
- export declare function scanMigrationSql(sql: string): MigrationRisk[];
20
- export declare function formatMigrationScanFailures(results: MigrationScanResult[]): string;
21
- export declare function formatMigrationList(migrations: MigrationFile[]): string;
17
+ declare function collectDeployMigrationFiles(cwd?: string): Promise<MigrationFile[]>;
18
+ declare function collectHeldMigrationFiles(cwd?: string): Promise<MigrationFile[]>;
19
+ declare function scanDeployMigrationFiles(migrations: MigrationFile[]): Promise<MigrationScanResult[]>;
20
+ declare function scanMigrationSql(sql: string): MigrationRisk[];
21
+ declare function formatMigrationScanFailures(results: MigrationScanResult[]): string;
22
+ declare function formatMigrationList(migrations: MigrationFile[]): string;
23
+ //#endregion
24
+ export { MigrationFile, MigrationRisk, MigrationScanResult, collectDeployMigrationFiles, collectHeldMigrationFiles, formatMigrationList, formatMigrationScanFailures, scanDeployMigrationFiles, scanMigrationSql };