zitejs 0.9.32 → 0.9.34

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.
@@ -45,7 +45,7 @@ function regenerateAppApiTs(appDir) {
45
45
  if (!(0, fs_2.existsSync)(apiDir))
46
46
  return;
47
47
  const endpointFiles = (0, fs_2.readdirSync)(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
48
- const content = (0, lib_js_1.generateApiTs)(endpointFiles, getFlowId(appDir));
48
+ const content = (0, lib_js_1.generateApiTs)(endpointFiles);
49
49
  if (content) {
50
50
  const outDir = (0, path_1.join)('apps', appDir, '.zite');
51
51
  (0, fs_2.mkdirSync)(outDir, { recursive: true });
@@ -10,6 +10,7 @@ function getSdkCall() {
10
10
  }
11
11
  return fn;
12
12
  }
13
+ const DB_INTEGRATION_ID = 'databases';
13
14
  function getBaseId() {
14
15
  try {
15
16
  return globalThis.__ZITE_EXECUTION_CONFIG__?.baseId
@@ -19,43 +20,58 @@ function getBaseId() {
19
20
  return undefined;
20
21
  }
21
22
  }
22
- function createTableClient(integrationId, className) {
23
+ function resolveTableId(className) {
24
+ try {
25
+ const config = globalThis.__ZITE_EXECUTION_CONFIG__;
26
+ const tables = config?.integrationSettings?.[DB_INTEGRATION_ID]
27
+ ?.settings?.nameMappings?.tables;
28
+ if (!tables)
29
+ return className;
30
+ for (const [realId, entry] of Object.entries(tables)) {
31
+ if (entry.mapping?.sdkName === className)
32
+ return realId;
33
+ }
34
+ }
35
+ catch { }
36
+ return className;
37
+ }
38
+ function createTableClient(className) {
23
39
  return {
24
- findAll: (options) => getSdkCall()(integrationId, className, 'findAll', {
40
+ findAll: (options) => getSdkCall()(DB_INTEGRATION_ID, className, 'findAll', {
25
41
  baseId: getBaseId(),
26
- tableId: className,
42
+ tableId: resolveTableId(className),
27
43
  ...options,
28
44
  }),
29
- findOne: (recordId) => getSdkCall()(integrationId, className, 'findOne', {
45
+ findOne: (recordId) => getSdkCall()(DB_INTEGRATION_ID, className, 'findOne', {
30
46
  baseId: getBaseId(),
31
- tableId: className,
47
+ tableId: resolveTableId(className),
32
48
  ...(typeof recordId === 'string' ? { id: recordId } : recordId),
33
49
  }),
34
- create: (data) => getSdkCall()(integrationId, className, 'create', {
50
+ create: (data) => getSdkCall()(DB_INTEGRATION_ID, className, 'create', {
35
51
  baseId: getBaseId(),
36
- tableId: className,
52
+ tableId: resolveTableId(className),
37
53
  record: data,
38
54
  }),
39
- update: (id, data) => getSdkCall()(integrationId, className, 'update', {
55
+ update: (id, data) => getSdkCall()(DB_INTEGRATION_ID, className, 'update', {
40
56
  baseId: getBaseId(),
41
- tableId: className,
57
+ tableId: resolveTableId(className),
42
58
  id,
43
59
  record: data,
44
60
  }),
45
- delete: (id) => getSdkCall()(integrationId, className, 'delete', {
61
+ delete: (id) => getSdkCall()(DB_INTEGRATION_ID, className, 'delete', {
46
62
  baseId: getBaseId(),
47
- tableId: className,
63
+ tableId: resolveTableId(className),
48
64
  id,
49
65
  }),
50
- bulkCreate: (records) => getSdkCall()(integrationId, className, 'bulkCreate', {
66
+ bulkCreate: (records) => getSdkCall()(DB_INTEGRATION_ID, className, 'bulkCreate', {
51
67
  baseId: getBaseId(),
52
- tableId: className,
68
+ tableId: resolveTableId(className),
53
69
  records,
54
70
  }),
55
71
  };
56
72
  }
57
- function createSqlClient(integrationId) {
58
- return (params) => getSdkCall()(integrationId, 'Db', 'executeSql', { baseId: getBaseId(), ...params });
73
+ function createSqlClient() {
74
+ return (params) => getSdkCall()(DB_INTEGRATION_ID, 'Db', 'executeSql', { baseId: getBaseId(), ...params });
59
75
  }
60
76
  var index_js_1 = require("../caller/index.js");
61
77
  Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
@@ -61,7 +61,7 @@ function generateSchema(base) {
61
61
  }
62
62
  return schema;
63
63
  }
64
- function generateDbTs(base, schema, integrationId = 'databases') {
64
+ function generateDbTs(base, schema) {
65
65
  const lines = [];
66
66
  lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
67
67
  lines.push('//');
@@ -102,9 +102,9 @@ function generateDbTs(base, schema, integrationId = 'databases') {
102
102
  for (const table of base.tables ?? []) {
103
103
  const className = toPascalCase(table.name);
104
104
  const propName = toCamelCase(table.name);
105
- lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
105
+ lines.push(` ${propName}: createTableClient<${className}RecordType>('${className}'),`);
106
106
  }
107
- lines.push(` sql: createSqlClient('${integrationId}'),`);
107
+ lines.push(` sql: createSqlClient(),`);
108
108
  lines.push('};');
109
109
  lines.push('');
110
110
  return lines.join('\n');
@@ -150,7 +150,7 @@ function generateDbDts(base, schema) {
150
150
  lines.push('');
151
151
  return lines.join('\n');
152
152
  }
153
- function generateApiTs(endpointFiles, flowId) {
153
+ function generateApiTs(endpointFiles) {
154
154
  if (!endpointFiles || endpointFiles.length === 0)
155
155
  return null;
156
156
  const lines = [
@@ -166,11 +166,9 @@ function generateApiTs(endpointFiles, flowId) {
166
166
  lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
167
167
  endpointNames.push(camelName);
168
168
  }
169
- const flowIdArg = flowId ? `, '${flowId}'` : '';
170
169
  lines.push('');
171
- // Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
172
170
  for (const name of endpointNames) {
173
- lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
171
+ lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
174
172
  }
175
173
  lines.push('');
176
174
  // Inferred input/output types per endpoint (e.g. GetDashboardInputType, GetDashboardOutputType)
@@ -41,7 +41,7 @@ function regenerateAppApiTs(appDir) {
41
41
  if (!existsSync(apiDir))
42
42
  return;
43
43
  const endpointFiles = readdirSync(apiDir).filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
44
- const content = generateApiTs(endpointFiles, getFlowId(appDir));
44
+ const content = generateApiTs(endpointFiles);
45
45
  if (content) {
46
46
  const outDir = join('apps', appDir, '.zite');
47
47
  mkdirSync(outDir, { recursive: true });
@@ -21,8 +21,8 @@ export interface TableClient<T> {
21
21
  }>;
22
22
  bulkCreate(records: Partial<T>[]): Promise<T[]>;
23
23
  }
24
- export declare function createTableClient<T>(integrationId: string, className: string): TableClient<T>;
25
- export declare function createSqlClient(integrationId: string): (params: {
24
+ export declare function createTableClient<T>(className: string): TableClient<T>;
25
+ export declare function createSqlClient(): (params: {
26
26
  query?: string;
27
27
  sql?: string;
28
28
  params?: unknown[];
@@ -5,6 +5,7 @@ function getSdkCall() {
5
5
  }
6
6
  return fn;
7
7
  }
8
+ const DB_INTEGRATION_ID = 'databases';
8
9
  function getBaseId() {
9
10
  try {
10
11
  return globalThis.__ZITE_EXECUTION_CONFIG__?.baseId
@@ -14,42 +15,57 @@ function getBaseId() {
14
15
  return undefined;
15
16
  }
16
17
  }
17
- export function createTableClient(integrationId, className) {
18
+ function resolveTableId(className) {
19
+ try {
20
+ const config = globalThis.__ZITE_EXECUTION_CONFIG__;
21
+ const tables = config?.integrationSettings?.[DB_INTEGRATION_ID]
22
+ ?.settings?.nameMappings?.tables;
23
+ if (!tables)
24
+ return className;
25
+ for (const [realId, entry] of Object.entries(tables)) {
26
+ if (entry.mapping?.sdkName === className)
27
+ return realId;
28
+ }
29
+ }
30
+ catch { }
31
+ return className;
32
+ }
33
+ export function createTableClient(className) {
18
34
  return {
19
- findAll: (options) => getSdkCall()(integrationId, className, 'findAll', {
35
+ findAll: (options) => getSdkCall()(DB_INTEGRATION_ID, className, 'findAll', {
20
36
  baseId: getBaseId(),
21
- tableId: className,
37
+ tableId: resolveTableId(className),
22
38
  ...options,
23
39
  }),
24
- findOne: (recordId) => getSdkCall()(integrationId, className, 'findOne', {
40
+ findOne: (recordId) => getSdkCall()(DB_INTEGRATION_ID, className, 'findOne', {
25
41
  baseId: getBaseId(),
26
- tableId: className,
42
+ tableId: resolveTableId(className),
27
43
  ...(typeof recordId === 'string' ? { id: recordId } : recordId),
28
44
  }),
29
- create: (data) => getSdkCall()(integrationId, className, 'create', {
45
+ create: (data) => getSdkCall()(DB_INTEGRATION_ID, className, 'create', {
30
46
  baseId: getBaseId(),
31
- tableId: className,
47
+ tableId: resolveTableId(className),
32
48
  record: data,
33
49
  }),
34
- update: (id, data) => getSdkCall()(integrationId, className, 'update', {
50
+ update: (id, data) => getSdkCall()(DB_INTEGRATION_ID, className, 'update', {
35
51
  baseId: getBaseId(),
36
- tableId: className,
52
+ tableId: resolveTableId(className),
37
53
  id,
38
54
  record: data,
39
55
  }),
40
- delete: (id) => getSdkCall()(integrationId, className, 'delete', {
56
+ delete: (id) => getSdkCall()(DB_INTEGRATION_ID, className, 'delete', {
41
57
  baseId: getBaseId(),
42
- tableId: className,
58
+ tableId: resolveTableId(className),
43
59
  id,
44
60
  }),
45
- bulkCreate: (records) => getSdkCall()(integrationId, className, 'bulkCreate', {
61
+ bulkCreate: (records) => getSdkCall()(DB_INTEGRATION_ID, className, 'bulkCreate', {
46
62
  baseId: getBaseId(),
47
- tableId: className,
63
+ tableId: resolveTableId(className),
48
64
  records,
49
65
  }),
50
66
  };
51
67
  }
52
- export function createSqlClient(integrationId) {
53
- return (params) => getSdkCall()(integrationId, 'Db', 'executeSql', { baseId: getBaseId(), ...params });
68
+ export function createSqlClient() {
69
+ return (params) => getSdkCall()(DB_INTEGRATION_ID, 'Db', 'executeSql', { baseId: getBaseId(), ...params });
54
70
  }
55
71
  export { createCaller } from '../caller/index.js';
@@ -20,9 +20,9 @@ export type ZiteSchema = {
20
20
  export declare function toPascalCase(name: string): string;
21
21
  export declare function toCamelCase(name: string): string;
22
22
  export declare function generateSchema(base: BaseMetadata): ZiteSchema;
23
- export declare function generateDbTs(base: BaseMetadata, schema: ZiteSchema, integrationId?: string): string;
23
+ export declare function generateDbTs(base: BaseMetadata, schema: ZiteSchema): string;
24
24
  export declare function generateDbDts(base: BaseMetadata, schema: ZiteSchema): string;
25
- export declare function generateApiTs(endpointFiles: string[], flowId?: string): string | null;
25
+ export declare function generateApiTs(endpointFiles: string[]): string | null;
26
26
  export declare function generateUserTs(usersTableFields?: Array<{
27
27
  name: string;
28
28
  type: string;
@@ -50,7 +50,7 @@ export function generateSchema(base) {
50
50
  }
51
51
  return schema;
52
52
  }
53
- export function generateDbTs(base, schema, integrationId = 'databases') {
53
+ export function generateDbTs(base, schema) {
54
54
  const lines = [];
55
55
  lines.push('// Auto-generated by zitejs sync. Do not edit manually.');
56
56
  lines.push('//');
@@ -91,9 +91,9 @@ export function generateDbTs(base, schema, integrationId = 'databases') {
91
91
  for (const table of base.tables ?? []) {
92
92
  const className = toPascalCase(table.name);
93
93
  const propName = toCamelCase(table.name);
94
- lines.push(` ${propName}: createTableClient<${className}RecordType>('${integrationId}', '${className}'),`);
94
+ lines.push(` ${propName}: createTableClient<${className}RecordType>('${className}'),`);
95
95
  }
96
- lines.push(` sql: createSqlClient('${integrationId}'),`);
96
+ lines.push(` sql: createSqlClient(),`);
97
97
  lines.push('};');
98
98
  lines.push('');
99
99
  return lines.join('\n');
@@ -139,7 +139,7 @@ export function generateDbDts(base, schema) {
139
139
  lines.push('');
140
140
  return lines.join('\n');
141
141
  }
142
- export function generateApiTs(endpointFiles, flowId) {
142
+ export function generateApiTs(endpointFiles) {
143
143
  if (!endpointFiles || endpointFiles.length === 0)
144
144
  return null;
145
145
  const lines = [
@@ -155,11 +155,9 @@ export function generateApiTs(endpointFiles, flowId) {
155
155
  lines.push(`import ${camelName}Endpoint from '../src/api/${name}';`);
156
156
  endpointNames.push(camelName);
157
157
  }
158
- const flowIdArg = flowId ? `, '${flowId}'` : '';
159
158
  lines.push('');
160
- // Named exports for each endpoint (backwards compat with old zite-endpoints-sdk imports)
161
159
  for (const name of endpointNames) {
162
- lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}'${flowIdArg});`);
160
+ lines.push(`export const ${name} = createCaller(${name}Endpoint, '${name}');`);
163
161
  }
164
162
  lines.push('');
165
163
  // Inferred input/output types per endpoint (e.g. GetDashboardInputType, GetDashboardOutputType)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.32",
3
+ "version": "0.9.34",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",