@zveltio/sdk 3.0.0-beta.4 → 3.0.0-beta.68
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/client/Auth.d.ts.map +1 -1
- package/dist/client/Auth.js +3 -0
- package/dist/client/QueryBuilder.d.ts.map +1 -1
- package/dist/client/QueryBuilder.js +4 -0
- package/dist/client/ZveltioClient.d.ts.map +1 -1
- package/dist/client/ZveltioClient.js +5 -0
- package/dist/client.d.ts +4 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +30 -13
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +21 -3
- package/dist/crdt.d.ts.map +1 -1
- package/dist/crdt.js +11 -2
- package/dist/ddl/index.d.ts.map +1 -1
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +124 -0
- package/dist/extension/index.d.ts +419 -19
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/index.js +3 -0
- package/dist/extension/jsonb.d.ts +62 -0
- package/dist/extension/jsonb.d.ts.map +1 -0
- package/dist/extension/jsonb.js +64 -0
- package/dist/extension/multipart.d.ts +58 -0
- package/dist/extension/multipart.d.ts.map +1 -0
- package/dist/extension/multipart.js +61 -0
- package/dist/extension/numeric.d.ts +94 -0
- package/dist/extension/numeric.d.ts.map +1 -0
- package/dist/extension/numeric.js +162 -0
- package/dist/extension/permission-gate.d.ts +15 -0
- package/dist/extension/permission-gate.d.ts.map +1 -1
- package/dist/extension/permission-gate.js +33 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/local-store.d.ts +5 -0
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-store.js +62 -10
- package/dist/offline/index.d.ts +3 -3
- package/dist/offline/index.js +51 -15
- package/dist/publish/index.d.ts.map +1 -1
- package/dist/publish/index.js +6 -1
- package/dist/realtime.d.ts +9 -1
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +15 -2
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +2 -0
- package/dist/schema-codegen.d.ts +3 -1
- package/dist/schema-codegen.d.ts.map +1 -1
- package/dist/schema-codegen.js +41 -7
- package/dist/schema-watcher.d.ts +1 -1
- package/dist/schema-watcher.js +1 -1
- package/dist/studio/index.d.ts +1 -0
- package/dist/studio/index.d.ts.map +1 -1
- package/dist/studio/index.js +3 -0
- package/dist/studio/slot-owner-registry.d.ts +13 -0
- package/dist/studio/slot-owner-registry.d.ts.map +1 -0
- package/dist/studio/slot-owner-registry.js +21 -0
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +4 -2
- package/dist/sync-manager.d.ts +30 -4
- package/dist/sync-manager.d.ts.map +1 -1
- package/dist/sync-manager.js +101 -15
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +23 -1
- package/dist/testing/with-test-db.d.ts.map +1 -1
- package/dist/testing/with-test-db.js +21 -14
- package/dist/tests/client.test.d.ts +2 -0
- package/dist/tests/client.test.d.ts.map +1 -0
- package/dist/tests/client.test.js +55 -0
- package/dist/tests/crdt-orset.test.d.ts +2 -0
- package/dist/tests/crdt-orset.test.d.ts.map +1 -0
- package/dist/tests/crdt-orset.test.js +23 -0
- package/dist/tests/local-store.test.js +44 -0
- package/dist/tests/multipart.test.d.ts +2 -0
- package/dist/tests/multipart.test.d.ts.map +1 -0
- package/dist/tests/multipart.test.js +37 -0
- package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
- package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
- package/dist/tests/offline-provider-crdt.test.js +119 -0
- package/dist/tests/realtime.test.d.ts +2 -0
- package/dist/tests/realtime.test.d.ts.map +1 -0
- package/dist/tests/realtime.test.js +39 -0
- package/dist/tests/sync-manager.test.d.ts +2 -0
- package/dist/tests/sync-manager.test.d.ts.map +1 -0
- package/dist/tests/sync-manager.test.js +65 -0
- package/dist/tests/with-test-db.test.d.ts +2 -0
- package/dist/tests/with-test-db.test.d.ts.map +1 -0
- package/dist/tests/with-test-db.test.js +57 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/validate/index.d.ts +49 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +494 -7
- package/dist/validate/shared-message-keys.d.ts +16 -0
- package/dist/validate/shared-message-keys.d.ts.map +1 -0
- package/dist/validate/shared-message-keys.js +227 -0
- package/package.json +7 -7
- package/dist/generate-types.d.ts +0 -37
- package/dist/generate-types.d.ts.map +0 -1
- package/dist/generate-types.js +0 -157
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED — do not edit. Run `bun run scripts/sync-shared-message-keys.ts`.
|
|
3
|
+
*
|
|
4
|
+
* The subset of the Studio's core message catalogue that extensions may use
|
|
5
|
+
* in SDUI schemas without shipping the key themselves: the generic vocabulary
|
|
6
|
+
* (`common.*`) plus the shared extension helpers (`ext.*`).
|
|
7
|
+
*
|
|
8
|
+
* An extension that needs anything else must ship it in its own
|
|
9
|
+
* `studio/messages/{locale}.json` — otherwise it renders correctly only on a
|
|
10
|
+
* host whose core catalogue happens to know about it, which is not a property
|
|
11
|
+
* an installable extension should depend on.
|
|
12
|
+
*
|
|
13
|
+
* Source: packages/studio/messages/core/en.json (211 keys)
|
|
14
|
+
*/
|
|
15
|
+
export const SHARED_MESSAGE_KEYS = new Set([
|
|
16
|
+
'common.accessRestricted',
|
|
17
|
+
'common.actions',
|
|
18
|
+
'common.add',
|
|
19
|
+
'common.added',
|
|
20
|
+
'common.aiStudio',
|
|
21
|
+
'common.approve',
|
|
22
|
+
'common.assign',
|
|
23
|
+
'common.bulkActions',
|
|
24
|
+
'common.cancel',
|
|
25
|
+
'common.cancelEdit',
|
|
26
|
+
'common.clear',
|
|
27
|
+
'common.clearSelection',
|
|
28
|
+
'common.close',
|
|
29
|
+
'common.col.account',
|
|
30
|
+
'common.col.active',
|
|
31
|
+
'common.col.address',
|
|
32
|
+
'common.col.amount',
|
|
33
|
+
'common.col.balance',
|
|
34
|
+
'common.col.bank',
|
|
35
|
+
'common.col.bcc',
|
|
36
|
+
'common.col.category',
|
|
37
|
+
'common.col.cc',
|
|
38
|
+
'common.col.channel',
|
|
39
|
+
'common.col.client',
|
|
40
|
+
'common.col.code',
|
|
41
|
+
'common.col.collection',
|
|
42
|
+
'common.col.company',
|
|
43
|
+
'common.col.created',
|
|
44
|
+
'common.col.credit',
|
|
45
|
+
'common.col.currency',
|
|
46
|
+
'common.col.date',
|
|
47
|
+
'common.col.days',
|
|
48
|
+
'common.col.debit',
|
|
49
|
+
'common.col.department',
|
|
50
|
+
'common.col.description',
|
|
51
|
+
'common.col.docNumber',
|
|
52
|
+
'common.col.dueDate',
|
|
53
|
+
'common.col.duration',
|
|
54
|
+
'common.col.email',
|
|
55
|
+
'common.col.employee',
|
|
56
|
+
'common.col.enabled',
|
|
57
|
+
'common.col.end',
|
|
58
|
+
'common.col.event',
|
|
59
|
+
'common.col.field',
|
|
60
|
+
'common.col.file',
|
|
61
|
+
'common.col.from',
|
|
62
|
+
'common.col.hireDate',
|
|
63
|
+
'common.col.host',
|
|
64
|
+
'common.col.iban',
|
|
65
|
+
'common.col.index',
|
|
66
|
+
'common.col.key',
|
|
67
|
+
'common.col.label',
|
|
68
|
+
'common.col.leaveType',
|
|
69
|
+
'common.col.locale',
|
|
70
|
+
'common.col.message',
|
|
71
|
+
'common.col.method',
|
|
72
|
+
'common.col.model',
|
|
73
|
+
'common.col.name',
|
|
74
|
+
'common.col.notes',
|
|
75
|
+
'common.col.number',
|
|
76
|
+
'common.col.paid',
|
|
77
|
+
'common.col.parent',
|
|
78
|
+
'common.col.password',
|
|
79
|
+
'common.col.path',
|
|
80
|
+
'common.col.phone',
|
|
81
|
+
'common.col.port',
|
|
82
|
+
'common.col.position',
|
|
83
|
+
'common.col.price',
|
|
84
|
+
'common.col.priority',
|
|
85
|
+
'common.col.product',
|
|
86
|
+
'common.col.project',
|
|
87
|
+
'common.col.provider',
|
|
88
|
+
'common.col.quantity',
|
|
89
|
+
'common.col.reason',
|
|
90
|
+
'common.col.recipient',
|
|
91
|
+
'common.col.records',
|
|
92
|
+
'common.col.required',
|
|
93
|
+
'common.col.resource',
|
|
94
|
+
'common.col.role',
|
|
95
|
+
'common.col.sku',
|
|
96
|
+
'common.col.slug',
|
|
97
|
+
'common.col.start',
|
|
98
|
+
'common.col.status',
|
|
99
|
+
'common.col.subject',
|
|
100
|
+
'common.col.taxId',
|
|
101
|
+
'common.col.template',
|
|
102
|
+
'common.col.ticket',
|
|
103
|
+
'common.col.time',
|
|
104
|
+
'common.col.title',
|
|
105
|
+
'common.col.to',
|
|
106
|
+
'common.col.total',
|
|
107
|
+
'common.col.type',
|
|
108
|
+
'common.col.unique',
|
|
109
|
+
'common.col.unit',
|
|
110
|
+
'common.col.user',
|
|
111
|
+
'common.col.username',
|
|
112
|
+
'common.col.validUntil',
|
|
113
|
+
'common.col.value',
|
|
114
|
+
'common.col.vat',
|
|
115
|
+
'common.col.vendor',
|
|
116
|
+
'common.col.version',
|
|
117
|
+
'common.col.warehouse',
|
|
118
|
+
'common.col.year',
|
|
119
|
+
'common.collectionRequired',
|
|
120
|
+
'common.confirm',
|
|
121
|
+
'common.copied',
|
|
122
|
+
'common.copy',
|
|
123
|
+
'common.copyShort',
|
|
124
|
+
'common.create',
|
|
125
|
+
'common.delete',
|
|
126
|
+
'common.deleteCount',
|
|
127
|
+
'common.deleteFailed',
|
|
128
|
+
'common.discard',
|
|
129
|
+
'common.dismiss',
|
|
130
|
+
'common.dismissNotification',
|
|
131
|
+
'common.done',
|
|
132
|
+
'common.download',
|
|
133
|
+
'common.edit',
|
|
134
|
+
'common.emptyDash',
|
|
135
|
+
'common.failed',
|
|
136
|
+
'common.fields',
|
|
137
|
+
'common.filter.admin',
|
|
138
|
+
'common.filter.all',
|
|
139
|
+
'common.filter.allStatuses',
|
|
140
|
+
'common.filter.auth',
|
|
141
|
+
'common.filter.data',
|
|
142
|
+
'common.format',
|
|
143
|
+
'common.generate',
|
|
144
|
+
'common.loadFailed',
|
|
145
|
+
'common.loading',
|
|
146
|
+
'common.logout',
|
|
147
|
+
'common.manage',
|
|
148
|
+
'common.mergeFailed',
|
|
149
|
+
'common.nameRequired',
|
|
150
|
+
'common.new',
|
|
151
|
+
'common.next',
|
|
152
|
+
'common.no',
|
|
153
|
+
'common.noResults',
|
|
154
|
+
'common.notFound',
|
|
155
|
+
'common.op.delete',
|
|
156
|
+
'common.op.insert',
|
|
157
|
+
'common.op.update',
|
|
158
|
+
'common.open',
|
|
159
|
+
'common.optional',
|
|
160
|
+
'common.optionalParen',
|
|
161
|
+
'common.other',
|
|
162
|
+
'common.pageOf',
|
|
163
|
+
'common.post',
|
|
164
|
+
'common.prev',
|
|
165
|
+
'common.publish',
|
|
166
|
+
'common.rangeOf',
|
|
167
|
+
'common.refresh',
|
|
168
|
+
'common.reject',
|
|
169
|
+
'common.remove',
|
|
170
|
+
'common.rename',
|
|
171
|
+
'common.reorder',
|
|
172
|
+
'common.required',
|
|
173
|
+
'common.resetFailed',
|
|
174
|
+
'common.retry',
|
|
175
|
+
'common.revoke',
|
|
176
|
+
'common.save',
|
|
177
|
+
'common.saveFailed',
|
|
178
|
+
'common.saved',
|
|
179
|
+
'common.saving',
|
|
180
|
+
'common.search',
|
|
181
|
+
'common.selectCollection',
|
|
182
|
+
'common.selectPlaceholder',
|
|
183
|
+
'common.selected',
|
|
184
|
+
'common.send',
|
|
185
|
+
'common.somethingWrong',
|
|
186
|
+
'common.status.approved',
|
|
187
|
+
'common.status.cancelled',
|
|
188
|
+
'common.status.draft',
|
|
189
|
+
'common.status.pending',
|
|
190
|
+
'common.status.reimbursed',
|
|
191
|
+
'common.status.rejected',
|
|
192
|
+
'common.status.submitted',
|
|
193
|
+
'common.submit',
|
|
194
|
+
'common.sync',
|
|
195
|
+
'common.testConnection',
|
|
196
|
+
'common.typeToSearch',
|
|
197
|
+
'common.undo',
|
|
198
|
+
'common.unexpectedError',
|
|
199
|
+
'common.unknownError',
|
|
200
|
+
'common.upload',
|
|
201
|
+
'common.uploadFailed',
|
|
202
|
+
'common.uploading',
|
|
203
|
+
'common.verifyingPermissions',
|
|
204
|
+
'common.view',
|
|
205
|
+
'common.viewAll',
|
|
206
|
+
'common.yes',
|
|
207
|
+
'ext.approved',
|
|
208
|
+
'ext.confirm.deleteForm',
|
|
209
|
+
'ext.confirm.deleteNamed',
|
|
210
|
+
'ext.confirm.removeSearchIndex',
|
|
211
|
+
'ext.confirmDelete',
|
|
212
|
+
'ext.copied',
|
|
213
|
+
'ext.copyFailed',
|
|
214
|
+
'ext.created',
|
|
215
|
+
'ext.deleted',
|
|
216
|
+
'ext.errorPrefix',
|
|
217
|
+
'ext.linkCopied',
|
|
218
|
+
'ext.loadFailed',
|
|
219
|
+
'ext.rejected',
|
|
220
|
+
'ext.reveal.copy',
|
|
221
|
+
'ext.reveal.note',
|
|
222
|
+
'ext.reveal.title',
|
|
223
|
+
'ext.saveFailed',
|
|
224
|
+
'ext.saved',
|
|
225
|
+
'ext.sent',
|
|
226
|
+
'ext.submitted',
|
|
227
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zveltio/sdk",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.68",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -61,15 +61,15 @@
|
|
|
61
61
|
"test": "bun test --preload ./src/tests/setup.ts"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"idb": "^8.0.
|
|
64
|
+
"idb": "^8.0.3"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@testcontainers/postgresql": "^11.
|
|
68
|
-
"@types/pg": "^8.
|
|
67
|
+
"@testcontainers/postgresql": "^11.14.0",
|
|
68
|
+
"@types/pg": "^8.23.1",
|
|
69
69
|
"fake-indexeddb": "^6.2.5",
|
|
70
|
-
"hono": "^4.
|
|
71
|
-
"kysely": "^0.
|
|
72
|
-
"pg": "^8.
|
|
70
|
+
"hono": "^4.13.8",
|
|
71
|
+
"kysely": "^0.29.6",
|
|
72
|
+
"pg": "^8.23.0",
|
|
73
73
|
"typescript": "^5.4.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
package/dist/generate-types.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* generate-types.ts
|
|
3
|
-
*
|
|
4
|
-
* Programmatic type generator for Zveltio collections.
|
|
5
|
-
* Fetches collection schemas from a running Zveltio engine and generates
|
|
6
|
-
* TypeScript interface declarations with full type information.
|
|
7
|
-
*
|
|
8
|
-
* Usage (programmatic):
|
|
9
|
-
* import { generateTypes } from '@zveltio/sdk/generate-types';
|
|
10
|
-
* const dts = await generateTypes({ url: 'http://localhost:3000', apiKey: 'sk-...' });
|
|
11
|
-
* await fs.writeFile('./types/zveltio.d.ts', dts);
|
|
12
|
-
*
|
|
13
|
-
* Usage (CLI):
|
|
14
|
-
* zveltio generate-types --output ./types/zveltio.d.ts
|
|
15
|
-
* zveltio types --output ./types/zveltio.d.ts
|
|
16
|
-
*/
|
|
17
|
-
export interface GenerateTypesOptions {
|
|
18
|
-
/** Zveltio engine URL (default: http://localhost:3000) */
|
|
19
|
-
url?: string;
|
|
20
|
-
/** API key for authentication */
|
|
21
|
-
apiKey?: string;
|
|
22
|
-
/** Only generate types for this collection */
|
|
23
|
-
collection?: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Generates TypeScript declarations for all (or one) Zveltio collection(s).
|
|
27
|
-
*
|
|
28
|
-
* Returns the `.d.ts` file content as a string. The caller is responsible for
|
|
29
|
-
* writing it to disk.
|
|
30
|
-
*
|
|
31
|
-
* The engine endpoint `/api/admin/types` is used when available (returns
|
|
32
|
-
* pre-generated TS from the server's field-type registry). If the endpoint
|
|
33
|
-
* fails or is unavailable this function falls back to generating types from
|
|
34
|
-
* the collection schema returned by `/api/collections`.
|
|
35
|
-
*/
|
|
36
|
-
export declare function generateTypes(options?: GenerateTypesOptions): Promise<string>;
|
|
37
|
-
//# sourceMappingURL=generate-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../src/generate-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0HH,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyDvF"}
|
package/dist/generate-types.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* generate-types.ts
|
|
3
|
-
*
|
|
4
|
-
* Programmatic type generator for Zveltio collections.
|
|
5
|
-
* Fetches collection schemas from a running Zveltio engine and generates
|
|
6
|
-
* TypeScript interface declarations with full type information.
|
|
7
|
-
*
|
|
8
|
-
* Usage (programmatic):
|
|
9
|
-
* import { generateTypes } from '@zveltio/sdk/generate-types';
|
|
10
|
-
* const dts = await generateTypes({ url: 'http://localhost:3000', apiKey: 'sk-...' });
|
|
11
|
-
* await fs.writeFile('./types/zveltio.d.ts', dts);
|
|
12
|
-
*
|
|
13
|
-
* Usage (CLI):
|
|
14
|
-
* zveltio generate-types --output ./types/zveltio.d.ts
|
|
15
|
-
* zveltio types --output ./types/zveltio.d.ts
|
|
16
|
-
*/
|
|
17
|
-
// ── Field type → TypeScript type mapping ─────────────────────────────────────
|
|
18
|
-
const FIELD_TYPE_MAP = {
|
|
19
|
-
text: 'string',
|
|
20
|
-
textarea: 'string',
|
|
21
|
-
richtext: 'string',
|
|
22
|
-
markdown: 'string',
|
|
23
|
-
email: 'string',
|
|
24
|
-
url: 'string',
|
|
25
|
-
password: 'string',
|
|
26
|
-
slug: 'string',
|
|
27
|
-
uuid: 'string',
|
|
28
|
-
color: 'string',
|
|
29
|
-
number: 'number',
|
|
30
|
-
integer: 'number',
|
|
31
|
-
decimal: 'number',
|
|
32
|
-
float: 'number',
|
|
33
|
-
currency: 'number',
|
|
34
|
-
percentage: 'number',
|
|
35
|
-
boolean: 'boolean',
|
|
36
|
-
toggle: 'boolean',
|
|
37
|
-
date: 'string', // ISO 8601 date string
|
|
38
|
-
datetime: 'string', // ISO 8601 datetime string
|
|
39
|
-
time: 'string',
|
|
40
|
-
timestamp: 'string',
|
|
41
|
-
json: 'Record<string, unknown>',
|
|
42
|
-
jsonb: 'Record<string, unknown>',
|
|
43
|
-
object: 'Record<string, unknown>',
|
|
44
|
-
array: 'unknown[]',
|
|
45
|
-
tags: 'string[]',
|
|
46
|
-
select: 'string',
|
|
47
|
-
multiselect: 'string[]',
|
|
48
|
-
relation: 'string', // UUID of related record
|
|
49
|
-
file: 'string', // storage path
|
|
50
|
-
image: 'string', // storage path
|
|
51
|
-
point: '{ lat: number; lng: number }',
|
|
52
|
-
geojson: 'GeoJSON.Geometry',
|
|
53
|
-
};
|
|
54
|
-
function fieldTypeToTs(fieldType) {
|
|
55
|
-
return FIELD_TYPE_MAP[fieldType.toLowerCase()] ?? 'unknown';
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Converts a collection name (snake_case) to a PascalCase interface name.
|
|
59
|
-
* Examples: "my_orders" → "MyOrders", "products" → "Products"
|
|
60
|
-
*/
|
|
61
|
-
function toPascalCase(name) {
|
|
62
|
-
return name
|
|
63
|
-
.split(/[_\s-]+/)
|
|
64
|
-
.map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())
|
|
65
|
-
.join('');
|
|
66
|
-
}
|
|
67
|
-
function generateCollectionInterface(col) {
|
|
68
|
-
const interfaceName = toPascalCase(col.name) + 'Collection';
|
|
69
|
-
const fields = col.fields ?? [];
|
|
70
|
-
const lines = [];
|
|
71
|
-
if (col.description) {
|
|
72
|
-
lines.push(`/** ${col.description} */`);
|
|
73
|
-
}
|
|
74
|
-
lines.push(`export interface ${interfaceName} {`);
|
|
75
|
-
lines.push(` /** Internal record ID (UUID) */`);
|
|
76
|
-
lines.push(` id: string;`);
|
|
77
|
-
for (const field of fields) {
|
|
78
|
-
if (field.description) {
|
|
79
|
-
lines.push(` /** ${field.description} */`);
|
|
80
|
-
}
|
|
81
|
-
const tsType = fieldTypeToTs(field.type);
|
|
82
|
-
const optional = field.required ? '' : '?';
|
|
83
|
-
lines.push(` ${field.name}${optional}: ${tsType};`);
|
|
84
|
-
}
|
|
85
|
-
lines.push(` /** ISO 8601 creation timestamp */`);
|
|
86
|
-
lines.push(` created_at: string;`);
|
|
87
|
-
lines.push(` /** ISO 8601 last-updated timestamp */`);
|
|
88
|
-
lines.push(` updated_at: string;`);
|
|
89
|
-
lines.push(`}`);
|
|
90
|
-
return lines.join('\n');
|
|
91
|
-
}
|
|
92
|
-
function generateIndexInterface(collections) {
|
|
93
|
-
const lines = [];
|
|
94
|
-
lines.push(`/** Index of all Zveltio collections — use with \`ZveltioClient<ZveltioCollections>\` */`);
|
|
95
|
-
lines.push(`export interface ZveltioCollections {`);
|
|
96
|
-
for (const col of collections) {
|
|
97
|
-
const interfaceName = toPascalCase(col.name) + 'Collection';
|
|
98
|
-
const comment = col.display_name || col.name;
|
|
99
|
-
lines.push(` /** ${comment} */`);
|
|
100
|
-
lines.push(` ${col.name}: ${interfaceName};`);
|
|
101
|
-
}
|
|
102
|
-
lines.push(`}`);
|
|
103
|
-
return lines.join('\n');
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Generates TypeScript declarations for all (or one) Zveltio collection(s).
|
|
107
|
-
*
|
|
108
|
-
* Returns the `.d.ts` file content as a string. The caller is responsible for
|
|
109
|
-
* writing it to disk.
|
|
110
|
-
*
|
|
111
|
-
* The engine endpoint `/api/admin/types` is used when available (returns
|
|
112
|
-
* pre-generated TS from the server's field-type registry). If the endpoint
|
|
113
|
-
* fails or is unavailable this function falls back to generating types from
|
|
114
|
-
* the collection schema returned by `/api/collections`.
|
|
115
|
-
*/
|
|
116
|
-
export async function generateTypes(options = {}) {
|
|
117
|
-
const engineUrl = (options.url ?? process.env.ZVELTIO_URL ?? 'http://localhost:3000').replace(/\/$/, '');
|
|
118
|
-
const apiKey = options.apiKey ?? process.env.ZVELTIO_API_KEY ?? '';
|
|
119
|
-
const headers = {};
|
|
120
|
-
if (apiKey)
|
|
121
|
-
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
122
|
-
// ── Try fast path: engine pre-generates types ────────────────────────────
|
|
123
|
-
try {
|
|
124
|
-
const path = options.collection
|
|
125
|
-
? `/api/admin/types/${encodeURIComponent(options.collection)}`
|
|
126
|
-
: '/api/admin/types';
|
|
127
|
-
const res = await fetch(`${engineUrl}${path}`, { headers });
|
|
128
|
-
if (res.ok) {
|
|
129
|
-
return await res.text();
|
|
130
|
-
}
|
|
131
|
-
// Fall through to manual generation on 404/401/500
|
|
132
|
-
if (res.status !== 404) {
|
|
133
|
-
console.warn(`[generate-types] Engine /api/admin/types returned ${res.status}, falling back to manual generation.`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
// Engine unreachable or endpoint absent — use fallback
|
|
138
|
-
}
|
|
139
|
-
// ── Fallback: fetch schema and generate types locally ────────────────────
|
|
140
|
-
const collectionsUrl = options.collection
|
|
141
|
-
? `${engineUrl}/api/collections/${encodeURIComponent(options.collection)}`
|
|
142
|
-
: `${engineUrl}/api/collections`;
|
|
143
|
-
const res = await fetch(collectionsUrl, { headers });
|
|
144
|
-
if (!res.ok) {
|
|
145
|
-
throw new Error(`Failed to fetch collections from ${collectionsUrl}: ${res.status} ${res.statusText}`);
|
|
146
|
-
}
|
|
147
|
-
const data = (await res.json());
|
|
148
|
-
const collections = Array.isArray(data.collections)
|
|
149
|
-
? data.collections.filter((c) => !c.is_system)
|
|
150
|
-
: data.collection
|
|
151
|
-
? [data.collection]
|
|
152
|
-
: [];
|
|
153
|
-
const header = `// Auto-generated by Zveltio\n// Do not edit manually — run: zveltio generate-types\n// Generated: ${new Date().toISOString()}\n`;
|
|
154
|
-
const interfaces = collections.map(generateCollectionInterface).join('\n\n');
|
|
155
|
-
const indexType = options.collection ? '' : '\n\n' + generateIndexInterface(collections);
|
|
156
|
-
return `${header}\n${interfaces}${indexType}\n`;
|
|
157
|
-
}
|