@syncular/typegen 0.21.1 → 0.23.0

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/lower.js CHANGED
@@ -257,16 +257,20 @@ export function lowerProjection(sql, refs, ir, location, analyze, buildMap) {
257
257
  if (langName === resultName)
258
258
  return text;
259
259
  changed = true;
260
+ // Double-quote the alias. SQLite preserves the case of an unquoted alias,
261
+ // PostgreSQL folds it to lower case, so an unquoted `AS membershipId`
262
+ // returns `membershipid` from Postgres. Both preserve a quoted alias.
263
+ const alias = `"${langName.replaceAll('"', '""')}"`;
260
264
  const explicit = EXPLICIT_ALIAS_RE.exec(text);
261
265
  if (explicit !== null && explicit[2] === resultName) {
262
- return `${explicit[1].trim()} AS ${langName}`;
266
+ return `${explicit[1].trim()} AS ${alias}`;
263
267
  }
264
268
  const implicit = TRAILING_IDENT_RE.exec(text);
265
269
  if (implicit !== null && implicit[2] === resultName) {
266
270
  // Implicit alias (`expr name`) — swap the trailing identifier.
267
- return `${implicit[1].trim()} AS ${langName}`;
271
+ return `${implicit[1].trim()} AS ${alias}`;
268
272
  }
269
- return `${text} AS ${langName}`;
273
+ return `${text} AS ${alias}`;
270
274
  });
271
275
  if (!changed) {
272
276
  return { sql, changed: false, sqlNames: names, langNames };
package/dist/query.js CHANGED
@@ -675,9 +675,13 @@ function splitSelectList(sql) {
675
675
  continue;
676
676
  // `expr AS alias` or `expr alias` (trailing bare identifier). Only treat
677
677
  // a trailing word as an alias when the expr has more than that word.
678
- const asMatch = /^(.*?)\s+AS\s+([A-Za-z_][A-Za-z0-9_]*)$/i.exec(raw);
678
+ // Projection lowering emits the alias double-quoted, so accept both.
679
+ const asMatch = /^(.*?)\s+AS\s+(?:"((?:[^"]|"")*)"|([A-Za-z_][A-Za-z0-9_]*))$/i.exec(raw);
679
680
  if (asMatch !== null) {
680
- items.push({ expr: asMatch[1].trim(), alias: asMatch[2] });
681
+ items.push({
682
+ expr: asMatch[1].trim(),
683
+ alias: (asMatch[2] ?? asMatch[3]).replaceAll('""', '"'),
684
+ });
681
685
  }
682
686
  else {
683
687
  items.push({ expr: raw, alias: undefined });
package/dist/sql.js CHANGED
@@ -604,6 +604,15 @@ function parseCreateTable(cursor, tables, droppedTables, source, options) {
604
604
  if (pkColumn === undefined) {
605
605
  throw new TypegenError(source, `table ${name}: primary key ${JSON.stringify(primaryKey)} is not a column`);
606
606
  }
607
+ // §2.4 primary-key eligibility: a primary key MUST render to a `rowId`
608
+ // string every implementation produces identically and local storage
609
+ // resolves without deferring to a SQLite build.
610
+ if (pkColumn.type !== 'string' &&
611
+ pkColumn.type !== 'integer' &&
612
+ pkColumn.type !== 'boolean' &&
613
+ pkColumn.type !== 'json') {
614
+ throw new TypegenError(source, `table ${name}: primary key ${JSON.stringify(primaryKey)} has an ineligible column type ${JSON.stringify(pkColumn.type)}; a primary key must be string, integer, boolean, or json`);
615
+ }
607
616
  const finalColumns = columns.map((c) => c.name === primaryKey ? { ...c, nullable: false } : c);
608
617
  const table = {
609
618
  name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/typegen",
3
- "version": "0.21.1",
3
+ "version": "0.23.0",
4
4
  "description": "Syncular schema-to-TypeScript type generator and the `syncular` CLI",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -56,9 +56,9 @@
56
56
  "!dist/**/*.test.d.ts"
57
57
  ],
58
58
  "dependencies": {
59
- "@syncular/core": "0.21.1"
59
+ "@syncular/core": "0.23.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@syncular/server": "0.21.1"
62
+ "@syncular/server": "0.23.0"
63
63
  }
64
64
  }
package/src/lower.ts CHANGED
@@ -306,16 +306,20 @@ export function lowerProjection(
306
306
  const langName = langNames[index] as string;
307
307
  if (langName === resultName) return text;
308
308
  changed = true;
309
+ // Double-quote the alias. SQLite preserves the case of an unquoted alias,
310
+ // PostgreSQL folds it to lower case, so an unquoted `AS membershipId`
311
+ // returns `membershipid` from Postgres. Both preserve a quoted alias.
312
+ const alias = `"${langName.replaceAll('"', '""')}"`;
309
313
  const explicit = EXPLICIT_ALIAS_RE.exec(text);
310
314
  if (explicit !== null && explicit[2] === resultName) {
311
- return `${(explicit[1] as string).trim()} AS ${langName}`;
315
+ return `${(explicit[1] as string).trim()} AS ${alias}`;
312
316
  }
313
317
  const implicit = TRAILING_IDENT_RE.exec(text);
314
318
  if (implicit !== null && implicit[2] === resultName) {
315
319
  // Implicit alias (`expr name`) — swap the trailing identifier.
316
- return `${(implicit[1] as string).trim()} AS ${langName}`;
320
+ return `${(implicit[1] as string).trim()} AS ${alias}`;
317
321
  }
318
- return `${text} AS ${langName}`;
322
+ return `${text} AS ${alias}`;
319
323
  });
320
324
  if (!changed) {
321
325
  return { sql, changed: false, sqlNames: names, langNames };
package/src/query.ts CHANGED
@@ -983,9 +983,16 @@ function splitSelectList(sql: string): SelectItem[] | null {
983
983
  if (raw.length === 0) continue;
984
984
  // `expr AS alias` or `expr alias` (trailing bare identifier). Only treat
985
985
  // a trailing word as an alias when the expr has more than that word.
986
- const asMatch = /^(.*?)\s+AS\s+([A-Za-z_][A-Za-z0-9_]*)$/i.exec(raw);
986
+ // Projection lowering emits the alias double-quoted, so accept both.
987
+ const asMatch =
988
+ /^(.*?)\s+AS\s+(?:"((?:[^"]|"")*)"|([A-Za-z_][A-Za-z0-9_]*))$/i.exec(
989
+ raw,
990
+ );
987
991
  if (asMatch !== null) {
988
- items.push({ expr: (asMatch[1] as string).trim(), alias: asMatch[2] });
992
+ items.push({
993
+ expr: (asMatch[1] as string).trim(),
994
+ alias: (asMatch[2] ?? (asMatch[3] as string)).replaceAll('""', '"'),
995
+ });
989
996
  } else {
990
997
  items.push({ expr: raw, alias: undefined });
991
998
  }
package/src/sql.ts CHANGED
@@ -795,6 +795,20 @@ function parseCreateTable(
795
795
  `table ${name}: primary key ${JSON.stringify(primaryKey)} is not a column`,
796
796
  );
797
797
  }
798
+ // §2.4 primary-key eligibility: a primary key MUST render to a `rowId`
799
+ // string every implementation produces identically and local storage
800
+ // resolves without deferring to a SQLite build.
801
+ if (
802
+ pkColumn.type !== 'string' &&
803
+ pkColumn.type !== 'integer' &&
804
+ pkColumn.type !== 'boolean' &&
805
+ pkColumn.type !== 'json'
806
+ ) {
807
+ throw new TypegenError(
808
+ source,
809
+ `table ${name}: primary key ${JSON.stringify(primaryKey)} has an ineligible column type ${JSON.stringify(pkColumn.type)}; a primary key must be string, integer, boolean, or json`,
810
+ );
811
+ }
798
812
  const finalColumns = columns.map((c) =>
799
813
  c.name === primaryKey ? { ...c, nullable: false } : c,
800
814
  );