@prabhask5/stellar-engine 1.2.0 → 1.2.1

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 (40) hide show
  1. package/README.md +446 -373
  2. package/dist/bin/commands.d.ts +14 -0
  3. package/dist/bin/commands.d.ts.map +1 -0
  4. package/dist/bin/commands.js +68 -0
  5. package/dist/bin/commands.js.map +1 -0
  6. package/dist/bin/install-pwa.d.ts +20 -6
  7. package/dist/bin/install-pwa.d.ts.map +1 -1
  8. package/dist/bin/install-pwa.js +111 -234
  9. package/dist/bin/install-pwa.js.map +1 -1
  10. package/dist/config.d.ts +57 -12
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +257 -22
  13. package/dist/config.js.map +1 -1
  14. package/dist/database.d.ts +65 -0
  15. package/dist/database.d.ts.map +1 -1
  16. package/dist/database.js +105 -0
  17. package/dist/database.js.map +1 -1
  18. package/dist/entries/types.d.ts +4 -3
  19. package/dist/entries/types.d.ts.map +1 -1
  20. package/dist/entries/utils.d.ts +1 -0
  21. package/dist/entries/utils.d.ts.map +1 -1
  22. package/dist/entries/utils.js +8 -0
  23. package/dist/entries/utils.js.map +1 -1
  24. package/dist/entries/vite.d.ts +1 -1
  25. package/dist/entries/vite.d.ts.map +1 -1
  26. package/dist/index.d.ts +6 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +7 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/schema.d.ts +150 -0
  31. package/dist/schema.d.ts.map +1 -0
  32. package/dist/schema.js +891 -0
  33. package/dist/schema.js.map +1 -0
  34. package/dist/sw/build/vite-plugin.d.ts +93 -18
  35. package/dist/sw/build/vite-plugin.d.ts.map +1 -1
  36. package/dist/sw/build/vite-plugin.js +356 -22
  37. package/dist/sw/build/vite-plugin.js.map +1 -1
  38. package/dist/types.d.ts +139 -0
  39. package/dist/types.d.ts.map +1 -1
  40. package/package.json +3 -2
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview Central CLI entry point for stellar-engine.
4
+ *
5
+ * Routes CLI arguments to the appropriate command handler. Each command
6
+ * lives in its own file and is lazily imported only when matched.
7
+ *
8
+ * Available commands:
9
+ * - `stellar-engine install pwa` — Scaffold a complete offline-first SvelteKit PWA project
10
+ *
11
+ * @see {@link install-pwa.ts} for the `install pwa` command
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/bin/commands.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG"}
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview Central CLI entry point for stellar-engine.
4
+ *
5
+ * Routes CLI arguments to the appropriate command handler. Each command
6
+ * lives in its own file and is lazily imported only when matched.
7
+ *
8
+ * Available commands:
9
+ * - `stellar-engine install pwa` — Scaffold a complete offline-first SvelteKit PWA project
10
+ *
11
+ * @see {@link install-pwa.ts} for the `install pwa` command
12
+ */
13
+ import * as p from '@clack/prompts';
14
+ import color from 'picocolors';
15
+ // =============================================================================
16
+ // COMMAND REGISTRY
17
+ // =============================================================================
18
+ /**
19
+ * Available CLI commands. Add new entries here to register additional commands.
20
+ */
21
+ const COMMANDS = [
22
+ {
23
+ name: 'install pwa',
24
+ usage: 'stellar-engine install pwa',
25
+ description: 'Scaffold a complete offline-first SvelteKit PWA project'
26
+ }
27
+ ];
28
+ // =============================================================================
29
+ // HELP
30
+ // =============================================================================
31
+ /**
32
+ * Print the help screen listing all available commands.
33
+ */
34
+ function printHelp() {
35
+ p.intro(color.bold('\u2726 stellar-engine CLI'));
36
+ const commandList = COMMANDS.map((cmd) => `${color.cyan(cmd.usage)}\n${color.dim(cmd.description)}`).join('\n\n');
37
+ p.note(commandList, 'Available commands');
38
+ p.outro('Run a command to get started.');
39
+ }
40
+ // =============================================================================
41
+ // COMMAND ROUTING
42
+ // =============================================================================
43
+ /**
44
+ * Route CLI arguments to the appropriate command handler.
45
+ * Prints help and exits if the command is not recognised.
46
+ */
47
+ function routeCommand() {
48
+ const args = process.argv.slice(2);
49
+ const command = args.slice(0, 2).join(' ');
50
+ /* `install pwa` is a two-word command. */
51
+ if (command === 'install pwa') {
52
+ import('./install-pwa.js')
53
+ .then((m) => m.run())
54
+ .catch((err) => {
55
+ console.error('Error:', err);
56
+ process.exit(1);
57
+ });
58
+ return;
59
+ }
60
+ /* Unrecognised command or no args — show help */
61
+ printHelp();
62
+ process.exit(args.length === 0 ? 0 : 1);
63
+ }
64
+ // =============================================================================
65
+ // RUN
66
+ // =============================================================================
67
+ routeCommand();
68
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/bin/commands.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AACpC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,gFAAgF;AAChF,6CAA6C;AAC7C,gFAAgF;AAEhF;;GAEG;AACH,MAAM,QAAQ,GAA2D;IACvE;QACE,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,4BAA4B;QACnC,WAAW,EAAE,yDAAyD;KACvE;CACF,CAAC;AAEF,gFAAgF;AAChF,oCAAoC;AACpC,gFAAgF;AAEhF;;GAEG;AACH,SAAS,SAAS;IAChB,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC;IAEjD,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAC9B,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CACnE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACf,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;IAE1C,CAAC,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;AAC3C,CAAC;AAED,gFAAgF;AAChF,4CAA4C;AAC5C,gFAAgF;AAEhF;;;GAGG;AACH,SAAS,YAAY;IACnB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE3C,0CAA0C;IAC1C,IAAI,OAAO,KAAK,aAAa,EAAE,CAAC;QAC9B,MAAM,CAAC,kBAAkB,CAAC;aACvB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;aACpB,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QACL,OAAO;IACT,CAAC;IAED,iDAAiD;IACjD,SAAS,EAAE,CAAC;IACZ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,gFAAgF;AAChF,sCAAsC;AACtC,gFAAgF;AAEhF,YAAY,EAAE,CAAC"}
@@ -1,27 +1,41 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * @fileoverview CLI script that scaffolds a PWA SvelteKit project using stellar-engine.
2
+ * @fileoverview CLI command that scaffolds a PWA SvelteKit project using stellar-engine.
4
3
  *
5
4
  * Generates a complete project structure including:
6
5
  * - Build configuration (Vite, TypeScript, SvelteKit, ESLint, Prettier, Knip)
7
6
  * - PWA assets (manifest, offline page, placeholder icons)
8
7
  * - SvelteKit routes (home, login, setup wizard, profile, error, confirm)
9
8
  * - API endpoints (config, deploy, validate)
10
- * - Supabase database schema
9
+ * - Shared schema definition (single source of truth for Dexie + SQL + types)
11
10
  * - Git hooks via Husky
12
11
  *
13
12
  * Files are written non-destructively: existing files are skipped, not overwritten.
14
13
  *
15
- * Launches an interactive walkthrough when invoked as `stellar-engine install pwa`.
14
+ * Invoked via `stellar-engine install pwa` (routed by {@link commands.ts}).
16
15
  *
17
16
  * @example
18
17
  * ```bash
19
18
  * stellar-engine install pwa
20
19
  * ```
21
20
  *
22
- * @see {@link main} for the entry point
21
+ * @see {@link run} for the entry point
23
22
  * @see {@link runInteractiveSetup} for the interactive walkthrough
24
23
  * @see {@link writeIfMissing} for the non-destructive file write strategy
25
24
  */
26
- export {};
25
+ /**
26
+ * Main entry point for the CLI scaffolding tool.
27
+ *
28
+ * **Execution flow:**
29
+ * 1. Run interactive walkthrough to collect {@link InstallOptions}.
30
+ * 2. Write `package.json` (if missing).
31
+ * 3. Run `npm install` to fetch dependencies.
32
+ * 4. Write all template files by category with animated progress.
33
+ * 5. Initialise Husky and write the pre-commit hook.
34
+ * 6. Print a styled summary of created/skipped files and next steps.
35
+ *
36
+ * @returns A promise that resolves when scaffolding is complete.
37
+ *
38
+ * @throws {Error} If `npm install` or `npx husky init` fails.
39
+ */
40
+ export declare function run(): Promise<void>;
27
41
  //# sourceMappingURL=install-pwa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"install-pwa.d.ts","sourceRoot":"","sources":["../../src/bin/install-pwa.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
1
+ {"version":3,"file":"install-pwa.d.ts","sourceRoot":"","sources":["../../src/bin/install-pwa.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAs+IH;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CA6JzC"}
@@ -1,25 +1,24 @@
1
- #!/usr/bin/env node
2
1
  /**
3
- * @fileoverview CLI script that scaffolds a PWA SvelteKit project using stellar-engine.
2
+ * @fileoverview CLI command that scaffolds a PWA SvelteKit project using stellar-engine.
4
3
  *
5
4
  * Generates a complete project structure including:
6
5
  * - Build configuration (Vite, TypeScript, SvelteKit, ESLint, Prettier, Knip)
7
6
  * - PWA assets (manifest, offline page, placeholder icons)
8
7
  * - SvelteKit routes (home, login, setup wizard, profile, error, confirm)
9
8
  * - API endpoints (config, deploy, validate)
10
- * - Supabase database schema
9
+ * - Shared schema definition (single source of truth for Dexie + SQL + types)
11
10
  * - Git hooks via Husky
12
11
  *
13
12
  * Files are written non-destructively: existing files are skipped, not overwritten.
14
13
  *
15
- * Launches an interactive walkthrough when invoked as `stellar-engine install pwa`.
14
+ * Invoked via `stellar-engine install pwa` (routed by {@link commands.ts}).
16
15
  *
17
16
  * @example
18
17
  * ```bash
19
18
  * stellar-engine install pwa
20
19
  * ```
21
20
  *
22
- * @see {@link main} for the entry point
21
+ * @see {@link run} for the entry point
23
22
  * @see {@link runInteractiveSetup} for the interactive walkthrough
24
23
  * @see {@link writeIfMissing} for the non-destructive file write strategy
25
24
  */
@@ -249,7 +248,7 @@ import { defineConfig } from 'vite';
249
248
  export default defineConfig({
250
249
  plugins: [
251
250
  sveltekit(),
252
- stellarPWA({ prefix: '${opts.prefix}', name: '${opts.name}' })
251
+ stellarPWA({ prefix: '${opts.prefix}', name: '${opts.name}', schema: true })
253
252
  ],
254
253
  build: {
255
254
  rollupOptions: {
@@ -917,6 +916,7 @@ vite.config.js.timestamp-*
917
916
  vite.config.ts.timestamp-*
918
917
  static/sw.js
919
918
  static/asset-manifest.json
919
+ src/lib/types.generated.ts
920
920
  `;
921
921
  }
922
922
  // ---------------------------------------------------------------------------
@@ -1015,158 +1015,6 @@ function generateEmailPlaceholder(title) {
1015
1015
  `;
1016
1016
  }
1017
1017
  // ---------------------------------------------------------------------------
1018
- // SUPABASE SCHEMA GENERATOR
1019
- // ---------------------------------------------------------------------------
1020
- /**
1021
- * Generate the Supabase database schema SQL including helper functions,
1022
- * the `trusted_devices` table, and commented-out example table patterns.
1023
- *
1024
- * @param opts - The install options containing `name`.
1025
- * @returns The SQL source for `supabase-schema.sql`.
1026
- */
1027
- function generateSupabaseSchema(opts) {
1028
- return `-- ${opts.name} Database Schema for Supabase
1029
- -- Copy and paste this entire file into your Supabase SQL Editor
1030
-
1031
- -- ============================================================
1032
- -- EXTENSIONS
1033
- -- ============================================================
1034
-
1035
- create extension if not exists "uuid-ossp";
1036
-
1037
- -- ============================================================
1038
- -- HELPER FUNCTIONS
1039
- -- ============================================================
1040
-
1041
- -- Function to automatically set user_id on insert
1042
- create or replace function set_user_id()
1043
- returns trigger as $$
1044
- begin
1045
- new.user_id := auth.uid();
1046
- return new;
1047
- end;
1048
- $$ language plpgsql security definer set search_path = '';
1049
-
1050
- -- Function to automatically update updated_at timestamp
1051
- create or replace function update_updated_at_column()
1052
- returns trigger as $$
1053
- begin
1054
- new.updated_at = timezone('utc'::text, now());
1055
- return new;
1056
- end;
1057
- $$ language plpgsql set search_path = '';
1058
-
1059
- -- ============================================================
1060
- -- YOUR TABLES HERE
1061
- -- ============================================================
1062
- -- Example table showing the required column pattern:
1063
- --
1064
- -- create table items (
1065
- -- id uuid default uuid_generate_v4() primary key,
1066
- -- user_id uuid references auth.users(id) on delete cascade,
1067
- -- name text not null,
1068
- -- completed boolean default false not null,
1069
- -- "order" double precision default 0 not null,
1070
- -- created_at timestamp with time zone default timezone('utc'::text, now()) not null,
1071
- -- updated_at timestamp with time zone default timezone('utc'::text, now()) not null,
1072
- -- deleted boolean default false not null,
1073
- -- _version integer default 1 not null,
1074
- -- device_id text
1075
- -- );
1076
- --
1077
- -- alter table items enable row level security;
1078
- -- create policy "Users can manage own items" on items for all using (auth.uid() = user_id);
1079
- --
1080
- -- create trigger set_user_id_items before insert on items for each row execute function set_user_id();
1081
- -- create trigger update_items_updated_at before update on items for each row execute function update_updated_at_column();
1082
- --
1083
- -- create index idx_items_user_id on items(user_id);
1084
- -- create index idx_items_order on items("order");
1085
- -- create index idx_items_updated_at on items(updated_at);
1086
- -- create index idx_items_deleted on items(deleted) where deleted = false;
1087
-
1088
- -- ============================================================
1089
- -- TRUSTED DEVICES (required for device verification)
1090
- -- ============================================================
1091
-
1092
- create table trusted_devices (
1093
- id uuid default gen_random_uuid() primary key,
1094
- user_id uuid references auth.users(id) on delete cascade not null,
1095
- device_id text not null,
1096
- device_label text,
1097
- trusted_at timestamptz default now() not null,
1098
- last_used_at timestamptz default now() not null,
1099
- unique(user_id, device_id)
1100
- );
1101
-
1102
- alter table trusted_devices enable row level security;
1103
- create policy "Users can manage own devices" on trusted_devices for all using (auth.uid() = user_id);
1104
-
1105
- create trigger set_user_id_trusted_devices before insert on trusted_devices for each row execute function set_user_id();
1106
- create trigger update_trusted_devices_updated_at before update on trusted_devices for each row execute function update_updated_at_column();
1107
-
1108
- create index idx_trusted_devices_user_id on trusted_devices(user_id);
1109
-
1110
- -- ============================================================
1111
- -- REALTIME: Enable real-time subscriptions for all tables
1112
- -- ============================================================
1113
- -- Enable realtime for your tables:
1114
- -- alter publication supabase_realtime add table items;
1115
-
1116
- alter publication supabase_realtime add table trusted_devices;
1117
-
1118
- -- ============================================================
1119
- -- CRDT DOCUMENT STORAGE (optional — only needed for collaborative editing)
1120
- -- ============================================================
1121
- -- Stores Yjs CRDT document state for collaborative real-time editing.
1122
- -- Each row represents the latest merged state of a single collaborative document.
1123
- -- The engine persists full Yjs binary state periodically (every ~30s), not per keystroke.
1124
- -- Real-time updates between clients are distributed via Supabase Broadcast (WebSocket),
1125
- -- so this table is only for durable persistence and offline-to-online reconciliation.
1126
- --
1127
- -- Key columns:
1128
- -- state — Full Yjs document state (Y.encodeStateAsUpdate), base64 encoded
1129
- -- state_vector — Yjs state vector (Y.encodeStateVector) for efficient delta computation
1130
- -- state_size — Byte size of state column, used for monitoring and compaction decisions
1131
- -- device_id — Identifies which device last persisted, used for echo suppression
1132
- --
1133
- -- To enable: add \`crdt: {}\` to your initEngine() config.
1134
- -- To skip: delete or comment out this section if you don't need collaborative editing.
1135
-
1136
- create table crdt_documents (
1137
- id uuid primary key default gen_random_uuid(),
1138
- page_id uuid not null,
1139
- state text not null,
1140
- state_vector text not null,
1141
- state_size integer not null default 0,
1142
- user_id uuid not null references auth.users(id),
1143
- device_id text not null,
1144
- updated_at timestamptz not null default now(),
1145
- created_at timestamptz not null default now()
1146
- );
1147
-
1148
- alter table crdt_documents enable row level security;
1149
-
1150
- create policy "Users can manage own CRDT documents"
1151
- on crdt_documents for all
1152
- using (auth.uid() = user_id);
1153
-
1154
- create trigger set_crdt_documents_user_id
1155
- before insert on crdt_documents
1156
- for each row execute function set_user_id();
1157
-
1158
- create trigger update_crdt_documents_updated_at
1159
- before update on crdt_documents
1160
- for each row execute function update_updated_at_column();
1161
-
1162
- create index idx_crdt_documents_page_id on crdt_documents(page_id);
1163
- create index idx_crdt_documents_user_id on crdt_documents(user_id);
1164
-
1165
- -- Unique constraint per page per user (upsert target for persistence)
1166
- create unique index idx_crdt_documents_page_user on crdt_documents(page_id, user_id);
1167
- `;
1168
- }
1169
- // ---------------------------------------------------------------------------
1170
1018
  // ESLINT CONFIG GENERATOR
1171
1019
  // ---------------------------------------------------------------------------
1172
1020
  /**
@@ -1349,6 +1197,7 @@ import { initEngine, startSyncEngine, supabase } from '@prabhask5/stellar-engine
1349
1197
  import { initConfig } from '@prabhask5/stellar-engine/config';
1350
1198
  import { resolveAuthState, lockSingleUser } from '@prabhask5/stellar-engine/auth';
1351
1199
  import { resolveRootLayout } from '@prabhask5/stellar-engine/kit';
1200
+ import { schema } from '$lib/schema';
1352
1201
  import { demoConfig } from '$lib/demo/config';
1353
1202
  import type { AuthMode, OfflineCredentials, Session } from '@prabhask5/stellar-engine/types';
1354
1203
  import type { LayoutLoad } from './$types';
@@ -1366,30 +1215,28 @@ export const prerender = false;
1366
1215
  // ENGINE BOOTSTRAP
1367
1216
  // =============================================================================
1368
1217
 
1369
- // TODO: Configure initEngine() with your app-specific database schema.
1370
- // Call initEngine({...}) at module scope (guarded by \`if (browser)\`).
1371
- // See the stellar-engine documentation for the full config interface.
1372
- //
1373
- // Example:
1374
- // if (browser) {
1375
- // initEngine({
1376
- // tables: [
1377
- // { supabaseName: 'items', columns: 'id,user_id,name,...' }
1378
- // ],
1379
- // database: {
1380
- // name: '${opts.name.replace(/[^a-zA-Z0-9]/g, '')}DB',
1381
- // versions: [
1382
- // { version: 1, stores: { items: 'id, user_id, created_at, updated_at' } }
1383
- // ]
1384
- // },
1385
- // supabase,
1386
- // prefix: '${opts.prefix}',
1387
- // auth: { singleUser: { gateType: 'code', codeLength: 6 } },
1388
- // demo: demoConfig,
1389
- // onAuthStateChange: (event, session) => { /* handle auth events */ },
1390
- // onAuthKicked: async () => { await lockSingleUser(); goto('/login'); }
1391
- // });
1392
- // }
1218
+ /**
1219
+ * Initialize the sync engine at module scope (runs once on first navigation).
1220
+ * The schema in $lib/schema.ts is the single source of truth — it drives:
1221
+ * - Dexie (IndexedDB) stores and versioning
1222
+ * - TypeScript types auto-generated at src/lib/types.generated.ts
1223
+ * - Supabase schema auto-migrated during \`npm run dev\`
1224
+ */
1225
+ if (browser) {
1226
+ initEngine({
1227
+ prefix: '${opts.prefix}',
1228
+ schema,
1229
+ auth: { gateType: 'code' },
1230
+ demo: demoConfig,
1231
+ onAuthStateChange: (event, session) => {
1232
+ // TODO: Handle auth events (e.g., analytics, logging)
1233
+ },
1234
+ onAuthKicked: async () => {
1235
+ await lockSingleUser();
1236
+ goto('/login');
1237
+ }
1238
+ });
1239
+ }
1393
1240
 
1394
1241
  // =============================================================================
1395
1242
  // LAYOUT DATA TYPE
@@ -4490,6 +4337,78 @@ export const demoConfig: DemoConfig = {
4490
4337
  };
4491
4338
  `;
4492
4339
  }
4340
+ /**
4341
+ * Generate the shared schema definition file.
4342
+ *
4343
+ * This is the single source of truth for the app's database schema:
4344
+ * - `initEngine({ schema })` reads it at runtime for Dexie stores
4345
+ * - The Vite plugin auto-generates TypeScript types on save
4346
+ * - The Vite plugin auto-migrates Supabase when .env has SUPABASE_SERVICE_ROLE_KEY
4347
+ *
4348
+ * @returns The TypeScript source for `src/lib/schema.ts`.
4349
+ */
4350
+ function generateSchemaFile(_opts) {
4351
+ return `/**
4352
+ * @fileoverview Schema definition — single source of truth.
4353
+ *
4354
+ * Edit this file and save. During \`npm run dev\`:
4355
+ * - TypeScript types auto-generate at src/lib/types.generated.ts
4356
+ * - Supabase schema auto-migrates (when .env has SUPABASE_SERVICE_ROLE_KEY)
4357
+ * - Dexie (IndexedDB) auto-upgrades on next page load
4358
+ *
4359
+ * Each key is a Supabase table name (snake_case). Values are either:
4360
+ * - A string of Dexie indexes (system indexes are auto-appended)
4361
+ * - An object with full config (indexes, singleton, fields, etc.)
4362
+ *
4363
+ * @see https://github.com/nicekiwi/stellar-engine for documentation
4364
+ */
4365
+
4366
+ import type { SchemaDefinition } from '@prabhask5/stellar-engine/types';
4367
+
4368
+ /**
4369
+ * App schema — add your tables here.
4370
+ *
4371
+ * Examples:
4372
+ * items: 'category_id, order'
4373
+ * settings: { singleton: true }
4374
+ * tasks: {
4375
+ * indexes: 'project_id, order',
4376
+ * fields: {
4377
+ * title: 'string',
4378
+ * completed: 'boolean',
4379
+ * project_id: 'uuid',
4380
+ * order: 'number',
4381
+ * },
4382
+ * }
4383
+ */
4384
+ export const schema: SchemaDefinition = {
4385
+ // TODO: Add your tables here
4386
+ // example_items: 'order',
4387
+ };
4388
+ `;
4389
+ }
4390
+ /**
4391
+ * Generate the `.env` file with placeholder Supabase credentials.
4392
+ *
4393
+ * @returns The `.env` file content with commented placeholders.
4394
+ */
4395
+ function generateEnvFile() {
4396
+ return `PUBLIC_SUPABASE_URL= # Your Supabase project URL
4397
+ PUBLIC_SUPABASE_PUBLISHABLE_DEFAULT_KEY= # Supabase anon/public key
4398
+ SUPABASE_SERVICE_ROLE_KEY= # Supabase service role key (enables auto-migration)
4399
+ `;
4400
+ }
4401
+ /**
4402
+ * Generate the initial `types.generated.ts` placeholder so imports don't
4403
+ * break before the first dev server run auto-generates the real file.
4404
+ *
4405
+ * @returns The TypeScript source for `src/lib/types.generated.ts`.
4406
+ */
4407
+ function generateTypesPlaceholder() {
4408
+ return `/** AUTO-GENERATED by stellar-engine — do not edit manually. */
4409
+ // Run \`npm run dev\` to auto-generate types from src/lib/schema.ts
4410
+ `;
4411
+ }
4493
4412
  function generateAppTypes() {
4494
4413
  return `/**
4495
4414
  * @fileoverview Type barrel — re-exports from stellar-engine plus app-specific types.
@@ -4505,46 +4424,6 @@ export type { SyncStatus, AuthMode, OfflineCredentials } from '@prabhask5/stella
4505
4424
  `;
4506
4425
  }
4507
4426
  // =============================================================================
4508
- // COMMAND ROUTING
4509
- // =============================================================================
4510
- /**
4511
- * Available CLI commands. Add new entries here to register additional commands.
4512
- */
4513
- const COMMANDS = [
4514
- {
4515
- name: 'install pwa',
4516
- usage: 'stellar-engine install pwa',
4517
- description: 'Scaffold a complete offline-first SvelteKit PWA project'
4518
- }
4519
- ];
4520
- /**
4521
- * Print the help screen listing all available commands.
4522
- */
4523
- function printHelp() {
4524
- p.intro(color.bold('\u2726 stellar-engine CLI'));
4525
- const commandList = COMMANDS.map((cmd) => `${color.cyan(cmd.usage)}\n${color.dim(cmd.description)}`).join('\n\n');
4526
- p.note(commandList, 'Available commands');
4527
- p.outro('Run a command to get started.');
4528
- }
4529
- /**
4530
- * Route CLI arguments to the appropriate command handler.
4531
- * Prints help and exits if the command is not recognised.
4532
- */
4533
- function routeCommand() {
4534
- const args = process.argv.slice(2);
4535
- const command = args.slice(0, 2).join(' ');
4536
- if (command === 'install pwa') {
4537
- main().catch((err) => {
4538
- console.error('Error:', err);
4539
- process.exit(1);
4540
- });
4541
- return;
4542
- }
4543
- /* Unrecognised command or no args — show help */
4544
- printHelp();
4545
- process.exit(args.length === 0 ? 0 : 1);
4546
- }
4547
- // =============================================================================
4548
4427
  // MAIN FUNCTION
4549
4428
  // =============================================================================
4550
4429
  /**
@@ -4585,7 +4464,7 @@ function writeGroup(entries, cwd, createdFiles, skippedFiles, label, spinner, ru
4585
4464
  *
4586
4465
  * @throws {Error} If `npm install` or `npx husky init` fails.
4587
4466
  */
4588
- async function main() {
4467
+ export async function run() {
4589
4468
  const opts = await runInteractiveSetup();
4590
4469
  const cwd = process.cwd();
4591
4470
  const createdFiles = [];
@@ -4614,7 +4493,8 @@ async function main() {
4614
4493
  ['.prettierrc', generatePrettierrc()],
4615
4494
  ['.prettierignore', generatePrettierignore()],
4616
4495
  ['knip.json', generateKnipJson()],
4617
- ['.gitignore', generateGitignore()]
4496
+ ['.gitignore', generateGitignore()],
4497
+ ['.env', generateEnvFile()]
4618
4498
  ]
4619
4499
  },
4620
4500
  {
@@ -4639,8 +4519,7 @@ async function main() {
4639
4519
  ['static/icons/apple-touch.svg', generatePlaceholderSvg('#6c5ce7', firstLetter)],
4640
4520
  ['static/change-email.html', generateEmailPlaceholder('Change Email')],
4641
4521
  ['static/device-verification-email.html', generateEmailPlaceholder('Device Verification')],
4642
- ['static/signup-email.html', generateEmailPlaceholder('Signup Email')],
4643
- ['supabase-schema.sql', generateSupabaseSchema(opts)]
4522
+ ['static/signup-email.html', generateEmailPlaceholder('Signup Email')]
4644
4523
  ]
4645
4524
  },
4646
4525
  {
@@ -4675,6 +4554,8 @@ async function main() {
4675
4554
  {
4676
4555
  label: 'Library & components',
4677
4556
  entries: [
4557
+ ['src/lib/schema.ts', generateSchemaFile(opts)],
4558
+ ['src/lib/types.generated.ts', generateTypesPlaceholder()],
4678
4559
  ['src/lib/types.ts', generateAppTypes()],
4679
4560
  ['src/lib/components/UpdatePrompt.svelte', generateUpdatePromptComponent()],
4680
4561
  ['src/lib/demo/mockData.ts', generateDemoMockData()],
@@ -4703,15 +4584,11 @@ async function main() {
4703
4584
  ].join('\n'), 'Setup complete!');
4704
4585
  p.log.step([
4705
4586
  color.bold('Next steps:'),
4706
- ' 1. Set up Supabase and add .env with your keys',
4707
- ' 2. Run supabase-schema.sql in Supabase SQL Editor',
4708
- ' 3. Add app icons in static/icons/',
4709
- ` 4. Start building: ${color.cyan('npm run dev')}`
4587
+ ` 1. Add your Supabase credentials to ${color.cyan('.env')}`,
4588
+ ` 2. Define your tables in ${color.cyan('src/lib/schema.ts')}`,
4589
+ ` 3. Run ${color.cyan('npm run dev')} \u2014 types and Supabase schema update automatically`,
4590
+ ' 4. Add app icons in static/icons/'
4710
4591
  ].join('\n'));
4711
4592
  p.outro('Happy building!');
4712
4593
  }
4713
- // =============================================================================
4714
- // RUN
4715
- // =============================================================================
4716
- routeCommand();
4717
4594
  //# sourceMappingURL=install-pwa.js.map