@syncular/typegen 0.83.0 → 0.85.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.
@@ -1,4 +1,4 @@
1
- import { snakeToCamel } from './naming.js';
1
+ import { pascalCase, snakeToCamel, stringLiteral, typeName } from './naming.js';
2
2
  import { syqlInput, } from './query.js';
3
3
  const DART_TYPE = {
4
4
  string: 'String',
@@ -10,19 +10,7 @@ const DART_TYPE = {
10
10
  blob_ref: 'String',
11
11
  crdt: 'List<int>',
12
12
  };
13
- function pascalCase(name) {
14
- return name
15
- .split(/[_-]+/)
16
- .filter((p) => p.length > 0)
17
- .map((p) => p.charAt(0).toUpperCase() + p.slice(1))
18
- .join('');
19
- }
20
- function typeName(name) {
21
- return name.charAt(0).toUpperCase() + name.slice(1);
22
- }
23
- function quote(value) {
24
- return `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\$/g, '\\$')}'`;
25
- }
13
+ const quote = (value) => stringLiteral(value, 'dart');
26
14
  function rowAccessor(column) {
27
15
  const key = `row[${quote(column.langName)}]`;
28
16
  switch (column.type) {
@@ -1,4 +1,4 @@
1
- import { snakeToCamel } from './naming.js';
1
+ import { snakeToCamel, stringLiteral, typeName } from './naming.js';
2
2
  import { syqlInput, } from './query.js';
3
3
  const KOTLIN_TYPE = {
4
4
  string: 'String',
@@ -10,12 +10,7 @@ const KOTLIN_TYPE = {
10
10
  blob_ref: 'String',
11
11
  crdt: 'ByteArray',
12
12
  };
13
- function typeName(name) {
14
- return name.charAt(0).toUpperCase() + name.slice(1);
15
- }
16
- function quote(value) {
17
- return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\$/g, '\\$')}"`;
18
- }
13
+ const quote = (value) => stringLiteral(value, 'kotlin');
19
14
  function rowAccessor(column) {
20
15
  const key = `row[${quote(column.langName)}]`;
21
16
  switch (column.type) {
@@ -1,4 +1,4 @@
1
- import { snakeToCamel } from './naming.js';
1
+ import { snakeToCamel, stringLiteral, typeName } from './naming.js';
2
2
  import { syqlInput, } from './query.js';
3
3
  const SWIFT_TYPE = {
4
4
  string: 'String',
@@ -14,13 +14,7 @@ const SYQL_SWIFT_TYPE = {
14
14
  ...SWIFT_TYPE,
15
15
  integer: 'Int64',
16
16
  };
17
- /** The query function/type name: already camelCase; PascalCase for the type. */
18
- function typeName(name) {
19
- return name.charAt(0).toUpperCase() + name.slice(1);
20
- }
21
- function quote(value) {
22
- return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
23
- }
17
+ const quote = (value) => stringLiteral(value, 'swift');
24
18
  function rowAccessor(column) {
25
19
  const key = `row[${quote(column.langName)}]`;
26
20
  switch (column.type) {
package/dist/naming.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare function snakeToCamel(name: string): string;
8
8
  * each with its first character upper-cased (`project_tasks` →
9
9
  * `ProjectTasks`). */
10
10
  export declare function pascalCase(name: string): string;
11
+ /** Upper-cases the first character of an already camelCase name. */
12
+ export declare function typeName(name: string): string;
11
13
  /** `value` as a string literal of a schema emitter's language. Swift and
12
14
  * Kotlin delimit with `"`, TS and Dart with `'`; Kotlin and Dart also escape
13
15
  * the `$` that would start an interpolation. */
package/dist/naming.js CHANGED
@@ -50,6 +50,10 @@ export function pascalCase(name) {
50
50
  .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
51
51
  .join('');
52
52
  }
53
+ /** Upper-cases the first character of an already camelCase name. */
54
+ export function typeName(name) {
55
+ return name.charAt(0).toUpperCase() + name.slice(1);
56
+ }
53
57
  /** `value` as a string literal of a schema emitter's language. Swift and
54
58
  * Kotlin delimit with `"`, TS and Dart with `'`; Kotlin and Dart also escape
55
59
  * the `$` that would start an interpolation. */
package/dist/query.d.ts CHANGED
@@ -225,9 +225,6 @@ export declare function syqlInput(query: AnalyzedQuery, name: string): QuerySyql
225
225
  * offending segment, so a stray `List.sql` or `Billing/` fails at generate time.
226
226
  */
227
227
  export declare function queryNameFromPath(relPath: string): string;
228
- /** Back-compat flat-file helper: `list-todos.sql` → `listTodos`. Rejects a
229
- * path with folders (use {@link queryNameFromPath} for nested queries). */
230
- export declare function queryNameFromFile(file: string): string;
231
228
  /** Validate a `-- name:` override is a camelCase identifier (loud otherwise). */
232
229
  export declare function validateOverrideName(name: string, location: string): string;
233
230
  export interface SplitStatement {
package/dist/query.js CHANGED
@@ -172,14 +172,6 @@ export function queryNameFromPath(relPath) {
172
172
  .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
173
173
  .join(''));
174
174
  }
175
- /** Back-compat flat-file helper: `list-todos.sql` → `listTodos`. Rejects a
176
- * path with folders (use {@link queryNameFromPath} for nested queries). */
177
- export function queryNameFromFile(file) {
178
- if (file.includes('/') || file.includes('\\')) {
179
- throw new TypegenError(file, `queryNameFromFile takes a flat filename; got a path ${JSON.stringify(file)} — use queryNameFromPath`);
180
- }
181
- return queryNameFromPath(file);
182
- }
183
175
  /** Validate a `-- name:` override is a camelCase identifier (loud otherwise). */
184
176
  export function validateOverrideName(name, location) {
185
177
  if (!CAMEL_IDENT_RE.test(name)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/typegen",
3
- "version": "0.83.0",
3
+ "version": "0.85.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.83.0"
59
+ "@syncular/core": "0.85.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@syncular/server": "0.83.0"
62
+ "@syncular/server": "0.85.0"
63
63
  }
64
64
  }
@@ -8,7 +8,7 @@
8
8
  * Header carries the IR hash for byte-exact `--check`.
9
9
  */
10
10
  import type { IrColumnType } from './ir';
11
- import { snakeToCamel } from './naming';
11
+ import { pascalCase, snakeToCamel, stringLiteral, typeName } from './naming';
12
12
  import {
13
13
  type AnalyzedQuery,
14
14
  type QueryColumn,
@@ -27,21 +27,7 @@ const DART_TYPE: Readonly<Record<IrColumnType, string>> = {
27
27
  crdt: 'List<int>',
28
28
  };
29
29
 
30
- function pascalCase(name: string): string {
31
- return name
32
- .split(/[_-]+/)
33
- .filter((p) => p.length > 0)
34
- .map((p) => p.charAt(0).toUpperCase() + p.slice(1))
35
- .join('');
36
- }
37
-
38
- function typeName(name: string): string {
39
- return name.charAt(0).toUpperCase() + name.slice(1);
40
- }
41
-
42
- function quote(value: string): string {
43
- return `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\$/g, '\\$')}'`;
44
- }
30
+ const quote = (value: string) => stringLiteral(value, 'dart');
45
31
 
46
32
  function rowAccessor(column: QueryColumn): string {
47
33
  const key = `row[${quote(column.langName)}]`;
@@ -12,7 +12,7 @@
12
12
  * byte-exact `--check`.
13
13
  */
14
14
  import type { IrColumnType } from './ir';
15
- import { snakeToCamel } from './naming';
15
+ import { snakeToCamel, stringLiteral, typeName } from './naming';
16
16
  import {
17
17
  type AnalyzedQuery,
18
18
  type QueryColumn,
@@ -31,13 +31,7 @@ const KOTLIN_TYPE: Readonly<Record<IrColumnType, string>> = {
31
31
  crdt: 'ByteArray',
32
32
  };
33
33
 
34
- function typeName(name: string): string {
35
- return name.charAt(0).toUpperCase() + name.slice(1);
36
- }
37
-
38
- function quote(value: string): string {
39
- return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\$/g, '\\$')}"`;
40
- }
34
+ const quote = (value: string) => stringLiteral(value, 'kotlin');
41
35
 
42
36
  function rowAccessor(column: QueryColumn): string {
43
37
  const key = `row[${quote(column.langName)}]`;
@@ -13,7 +13,7 @@
13
13
  * bytes decode). Header carries the IR hash for byte-exact `--check`.
14
14
  */
15
15
  import type { IrColumnType } from './ir';
16
- import { snakeToCamel } from './naming';
16
+ import { snakeToCamel, stringLiteral, typeName } from './naming';
17
17
  import {
18
18
  type AnalyzedQuery,
19
19
  type QueryColumn,
@@ -36,14 +36,7 @@ const SYQL_SWIFT_TYPE: Readonly<Record<IrColumnType, string>> = {
36
36
  integer: 'Int64',
37
37
  };
38
38
 
39
- /** The query function/type name: already camelCase; PascalCase for the type. */
40
- function typeName(name: string): string {
41
- return name.charAt(0).toUpperCase() + name.slice(1);
42
- }
43
-
44
- function quote(value: string): string {
45
- return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
46
- }
39
+ const quote = (value: string) => stringLiteral(value, 'swift');
47
40
 
48
41
  function rowAccessor(column: QueryColumn): string {
49
42
  const key = `row[${quote(column.langName)}]`;
package/src/naming.ts CHANGED
@@ -56,6 +56,11 @@ export function pascalCase(name: string): string {
56
56
  .join('');
57
57
  }
58
58
 
59
+ /** Upper-cases the first character of an already camelCase name. */
60
+ export function typeName(name: string): string {
61
+ return name.charAt(0).toUpperCase() + name.slice(1);
62
+ }
63
+
59
64
  /** `value` as a string literal of a schema emitter's language. Swift and
60
65
  * Kotlin delimit with `"`, TS and Dart with `'`; Kotlin and Dart also escape
61
66
  * the `$` that would start an interpolation. */
package/src/query.ts CHANGED
@@ -428,18 +428,6 @@ export function queryNameFromPath(relPath: string): string {
428
428
  );
429
429
  }
430
430
 
431
- /** Back-compat flat-file helper: `list-todos.sql` → `listTodos`. Rejects a
432
- * path with folders (use {@link queryNameFromPath} for nested queries). */
433
- export function queryNameFromFile(file: string): string {
434
- if (file.includes('/') || file.includes('\\')) {
435
- throw new TypegenError(
436
- file,
437
- `queryNameFromFile takes a flat filename; got a path ${JSON.stringify(file)} — use queryNameFromPath`,
438
- );
439
- }
440
- return queryNameFromPath(file);
441
- }
442
-
443
431
  /** Validate a `-- name:` override is a camelCase identifier (loud otherwise). */
444
432
  export function validateOverrideName(name: string, location: string): string {
445
433
  if (!CAMEL_IDENT_RE.test(name)) {