@stardeck-customer-apps/data-store-sdk 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md CHANGED
@@ -354,3 +354,4 @@ try {
354
354
  - **Tables auto-generate** `id` (UUID), `created_at`, and `updated_at` columns. Don't include these in create table definitions.
355
355
  - **Column deletes are soft-deletes.** The column is renamed to `_deleted_{name}_{timestamp}` and can be restored.
356
356
  - **Type changes are restricted** to safe widening conversions (e.g., integer → bigint, boolean → text).
357
+ - **Generated column types: `bigint`/`numeric`/`decimal` map to `string`, not `number`.** `node-postgres` returns these as strings to avoid silent JS precision loss past `Number.MAX_SAFE_INTEGER`, so the generated types are `string` by design (`integer`/`smallint`/`real`/`double precision` stay `number`). `jsonb`/`json` come through as `unknown`. Cast at the boundary (`Number(row.size_bytes)`) or give the column a real type in your derived app type — don't assume `number`.
@@ -88,18 +88,29 @@ async function introspectSchemaSnapshot(executor) {
88
88
  ORDER BY tc.table_name, tc.constraint_name, ku.ordinal_position`
89
89
  ),
90
90
  executor.query(
91
- `SELECT tc.constraint_name, tc.table_name, ku.column_name,
92
- ccu.table_name AS referenced_table, ccu.column_name AS referenced_column,
93
- rc.delete_rule, rc.update_rule
94
- FROM information_schema.table_constraints tc
95
- JOIN information_schema.key_column_usage ku
96
- ON tc.constraint_name = ku.constraint_name AND tc.table_schema = ku.table_schema
97
- JOIN information_schema.constraint_column_usage ccu
98
- ON tc.constraint_name = ccu.constraint_name AND tc.table_schema = ccu.table_schema
99
- JOIN information_schema.referential_constraints rc
100
- ON tc.constraint_name = rc.constraint_name AND tc.table_schema = rc.constraint_schema
101
- WHERE tc.table_schema = 'public' AND tc.constraint_type = 'FOREIGN KEY'
102
- ORDER BY tc.table_name, tc.constraint_name, ku.ordinal_position`
91
+ // Read column pairings from pg_catalog: information_schema's
92
+ // constraint_column_usage is uncorrelated with key_column_usage, so
93
+ // joining them for a composite FK produces a cross product. Unnesting
94
+ // conkey/confkey together WITH ORDINALITY keeps referencing↔referenced
95
+ // columns paired and ordered.
96
+ `SELECT con.conname AS constraint_name,
97
+ rel.relname AS table_name,
98
+ att.attname AS column_name,
99
+ frel.relname AS referenced_table,
100
+ fatt.attname AS referenced_column,
101
+ CASE con.confdeltype WHEN 'a' THEN 'NO ACTION' WHEN 'r' THEN 'RESTRICT'
102
+ WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' END AS delete_rule,
103
+ CASE con.confupdtype WHEN 'a' THEN 'NO ACTION' WHEN 'r' THEN 'RESTRICT'
104
+ WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' END AS update_rule
105
+ FROM pg_constraint con
106
+ JOIN pg_class rel ON rel.oid = con.conrelid
107
+ JOIN pg_namespace ns ON ns.oid = rel.relnamespace
108
+ JOIN pg_class frel ON frel.oid = con.confrelid
109
+ JOIN LATERAL unnest(con.conkey, con.confkey) WITH ORDINALITY AS cols(conkey, confkey, ord) ON true
110
+ JOIN pg_attribute att ON att.attrelid = con.conrelid AND att.attnum = cols.conkey
111
+ JOIN pg_attribute fatt ON fatt.attrelid = con.confrelid AND fatt.attnum = cols.confkey
112
+ WHERE ns.nspname = 'public' AND con.contype = 'f'
113
+ ORDER BY rel.relname, con.conname, cols.ord`
103
114
  ),
104
115
  executor.query(
105
116
  `SELECT rel.relname AS table_name, con.conname AS name,
@@ -339,8 +350,12 @@ async function introspectSchema(connectionString) {
339
350
  }
340
351
  function generateTypeScript(tables) {
341
352
  const lines = [
342
- "// Auto-generated by @stardeck-customer-apps/data-store-sdk",
343
- "// Do not edit manually \u2014 regenerate with: npx stardeck-data-store generate-types",
353
+ "// AUTO-GENERATED by @stardeck-customer-apps/data-store-sdk \u2014 DO NOT EDIT.",
354
+ "// This file is overwritten in full on every run of:",
355
+ "// npx stardeck-data-store generate-types",
356
+ "// Anything you add here (hand-written or derived types) WILL BE LOST on the next",
357
+ "// regeneration. Put those in a separate file that imports from this one, e.g.",
358
+ "// src/lib/<domain>-types.ts importing the table types or DB from this file.",
344
359
  "",
345
360
  'import type { Generated } from "kysely";',
346
361
  ""
@@ -65,18 +65,29 @@ async function introspectSchemaSnapshot(executor) {
65
65
  ORDER BY tc.table_name, tc.constraint_name, ku.ordinal_position`
66
66
  ),
67
67
  executor.query(
68
- `SELECT tc.constraint_name, tc.table_name, ku.column_name,
69
- ccu.table_name AS referenced_table, ccu.column_name AS referenced_column,
70
- rc.delete_rule, rc.update_rule
71
- FROM information_schema.table_constraints tc
72
- JOIN information_schema.key_column_usage ku
73
- ON tc.constraint_name = ku.constraint_name AND tc.table_schema = ku.table_schema
74
- JOIN information_schema.constraint_column_usage ccu
75
- ON tc.constraint_name = ccu.constraint_name AND tc.table_schema = ccu.table_schema
76
- JOIN information_schema.referential_constraints rc
77
- ON tc.constraint_name = rc.constraint_name AND tc.table_schema = rc.constraint_schema
78
- WHERE tc.table_schema = 'public' AND tc.constraint_type = 'FOREIGN KEY'
79
- ORDER BY tc.table_name, tc.constraint_name, ku.ordinal_position`
68
+ // Read column pairings from pg_catalog: information_schema's
69
+ // constraint_column_usage is uncorrelated with key_column_usage, so
70
+ // joining them for a composite FK produces a cross product. Unnesting
71
+ // conkey/confkey together WITH ORDINALITY keeps referencing↔referenced
72
+ // columns paired and ordered.
73
+ `SELECT con.conname AS constraint_name,
74
+ rel.relname AS table_name,
75
+ att.attname AS column_name,
76
+ frel.relname AS referenced_table,
77
+ fatt.attname AS referenced_column,
78
+ CASE con.confdeltype WHEN 'a' THEN 'NO ACTION' WHEN 'r' THEN 'RESTRICT'
79
+ WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' END AS delete_rule,
80
+ CASE con.confupdtype WHEN 'a' THEN 'NO ACTION' WHEN 'r' THEN 'RESTRICT'
81
+ WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' END AS update_rule
82
+ FROM pg_constraint con
83
+ JOIN pg_class rel ON rel.oid = con.conrelid
84
+ JOIN pg_namespace ns ON ns.oid = rel.relnamespace
85
+ JOIN pg_class frel ON frel.oid = con.confrelid
86
+ JOIN LATERAL unnest(con.conkey, con.confkey) WITH ORDINALITY AS cols(conkey, confkey, ord) ON true
87
+ JOIN pg_attribute att ON att.attrelid = con.conrelid AND att.attnum = cols.conkey
88
+ JOIN pg_attribute fatt ON fatt.attrelid = con.confrelid AND fatt.attnum = cols.confkey
89
+ WHERE ns.nspname = 'public' AND con.contype = 'f'
90
+ ORDER BY rel.relname, con.conname, cols.ord`
80
91
  ),
81
92
  executor.query(
82
93
  `SELECT rel.relname AS table_name, con.conname AS name,
@@ -316,8 +327,12 @@ async function introspectSchema(connectionString) {
316
327
  }
317
328
  function generateTypeScript(tables) {
318
329
  const lines = [
319
- "// Auto-generated by @stardeck-customer-apps/data-store-sdk",
320
- "// Do not edit manually \u2014 regenerate with: npx stardeck-data-store generate-types",
330
+ "// AUTO-GENERATED by @stardeck-customer-apps/data-store-sdk \u2014 DO NOT EDIT.",
331
+ "// This file is overwritten in full on every run of:",
332
+ "// npx stardeck-data-store generate-types",
333
+ "// Anything you add here (hand-written or derived types) WILL BE LOST on the next",
334
+ "// regeneration. Put those in a separate file that imports from this one, e.g.",
335
+ "// src/lib/<domain>-types.ts importing the table types or DB from this file.",
321
336
  "",
322
337
  'import type { Generated } from "kysely";',
323
338
  ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stardeck-customer-apps/data-store-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "SDK for accessing Stardeck data stores from deployed projects",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",