@zveltio/sdk 3.0.0-beta.1 → 3.0.0-beta.100

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.
Files changed (151) hide show
  1. package/README.md +17 -4
  2. package/dist/client.d.ts +103 -7
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +117 -27
  5. package/dist/core.d.ts.map +1 -1
  6. package/dist/core.js +21 -3
  7. package/dist/crdt.d.ts.map +1 -1
  8. package/dist/crdt.js +11 -2
  9. package/dist/ddl/index.d.ts +20 -0
  10. package/dist/ddl/index.d.ts.map +1 -1
  11. package/dist/errors.d.ts +58 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +124 -0
  14. package/dist/extension/action-refusal.d.ts +27 -0
  15. package/dist/extension/action-refusal.d.ts.map +1 -0
  16. package/dist/extension/action-refusal.js +29 -0
  17. package/dist/extension/capabilities.d.ts +71 -0
  18. package/dist/extension/capabilities.d.ts.map +1 -0
  19. package/dist/extension/capabilities.js +79 -0
  20. package/dist/extension/dates.d.ts +7 -0
  21. package/dist/extension/dates.d.ts.map +1 -0
  22. package/dist/extension/dates.js +14 -0
  23. package/dist/extension/index.d.ts +1086 -38
  24. package/dist/extension/index.d.ts.map +1 -1
  25. package/dist/extension/index.js +16 -0
  26. package/dist/extension/jsonb.d.ts +62 -0
  27. package/dist/extension/jsonb.d.ts.map +1 -0
  28. package/dist/extension/jsonb.js +64 -0
  29. package/dist/extension/multipart.d.ts +58 -0
  30. package/dist/extension/multipart.d.ts.map +1 -0
  31. package/dist/extension/multipart.js +61 -0
  32. package/dist/extension/numeric.d.ts +94 -0
  33. package/dist/extension/numeric.d.ts.map +1 -0
  34. package/dist/extension/numeric.js +162 -0
  35. package/dist/extension/permission-gate.d.ts +15 -0
  36. package/dist/extension/permission-gate.d.ts.map +1 -1
  37. package/dist/extension/permission-gate.js +33 -1
  38. package/dist/extension/reserved-paths.d.ts +10 -0
  39. package/dist/extension/reserved-paths.d.ts.map +1 -0
  40. package/dist/extension/reserved-paths.js +23 -0
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -0
  44. package/dist/local-store.d.ts +14 -1
  45. package/dist/local-store.d.ts.map +1 -1
  46. package/dist/local-store.js +92 -13
  47. package/dist/offline/index.d.ts +25 -55
  48. package/dist/offline/index.d.ts.map +1 -1
  49. package/dist/offline/index.js +173 -157
  50. package/dist/publish/index.d.ts.map +1 -1
  51. package/dist/publish/index.js +6 -1
  52. package/dist/realtime.d.ts +25 -1
  53. package/dist/realtime.d.ts.map +1 -1
  54. package/dist/realtime.js +47 -3
  55. package/dist/rpc/index.d.ts.map +1 -1
  56. package/dist/rpc/index.js +2 -0
  57. package/dist/schema-codegen.d.ts +25 -1
  58. package/dist/schema-codegen.d.ts.map +1 -1
  59. package/dist/schema-codegen.js +141 -7
  60. package/dist/schema-watcher.d.ts +10 -2
  61. package/dist/schema-watcher.d.ts.map +1 -1
  62. package/dist/schema-watcher.js +25 -10
  63. package/dist/studio/index.d.ts +1 -0
  64. package/dist/studio/index.d.ts.map +1 -1
  65. package/dist/studio/index.js +3 -0
  66. package/dist/studio/slot-owner-registry.d.ts +13 -0
  67. package/dist/studio/slot-owner-registry.d.ts.map +1 -0
  68. package/dist/studio/slot-owner-registry.js +21 -0
  69. package/dist/svelte.d.ts +1 -1
  70. package/dist/svelte.d.ts.map +1 -1
  71. package/dist/svelte.js +4 -2
  72. package/dist/sync-manager.d.ts +49 -4
  73. package/dist/sync-manager.d.ts.map +1 -1
  74. package/dist/sync-manager.js +173 -15
  75. package/dist/testing/index.d.ts.map +1 -1
  76. package/dist/testing/index.js +23 -1
  77. package/dist/testing/with-test-db.d.ts +1 -1
  78. package/dist/testing/with-test-db.d.ts.map +1 -1
  79. package/dist/testing/with-test-db.js +22 -15
  80. package/dist/tests/action-refusal.test.d.ts +2 -0
  81. package/dist/tests/action-refusal.test.d.ts.map +1 -0
  82. package/dist/tests/action-refusal.test.js +13 -0
  83. package/dist/tests/client.test.d.ts +2 -0
  84. package/dist/tests/client.test.d.ts.map +1 -0
  85. package/dist/tests/client.test.js +164 -0
  86. package/dist/tests/crdt-orset.test.d.ts +2 -0
  87. package/dist/tests/crdt-orset.test.d.ts.map +1 -0
  88. package/dist/tests/crdt-orset.test.js +23 -0
  89. package/dist/tests/local-store.test.js +44 -0
  90. package/dist/tests/migration-parse.test.d.ts +2 -0
  91. package/dist/tests/migration-parse.test.d.ts.map +1 -0
  92. package/dist/tests/migration-parse.test.js +17 -0
  93. package/dist/tests/multipart.test.d.ts +2 -0
  94. package/dist/tests/multipart.test.d.ts.map +1 -0
  95. package/dist/tests/multipart.test.js +37 -0
  96. package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
  97. package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
  98. package/dist/tests/offline-provider-crdt.test.js +206 -0
  99. package/dist/tests/realtime.test.d.ts +2 -0
  100. package/dist/tests/realtime.test.d.ts.map +1 -0
  101. package/dist/tests/realtime.test.js +220 -0
  102. package/dist/tests/reserved-paths.test.d.ts +2 -0
  103. package/dist/tests/reserved-paths.test.d.ts.map +1 -0
  104. package/dist/tests/reserved-paths.test.js +21 -0
  105. package/dist/tests/sync-manager.test.d.ts +2 -0
  106. package/dist/tests/sync-manager.test.d.ts.map +1 -0
  107. package/dist/tests/sync-manager.test.js +123 -0
  108. package/dist/tests/today-in.test.d.ts +2 -0
  109. package/dist/tests/today-in.test.d.ts.map +1 -0
  110. package/dist/tests/today-in.test.js +14 -0
  111. package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
  112. package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
  113. package/dist/tests/validate-manifest-actions.test.js +82 -0
  114. package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
  115. package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
  116. package/dist/tests/validate-manifest-dependencies.test.js +27 -0
  117. package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
  118. package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
  119. package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
  120. package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
  121. package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
  122. package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
  123. package/dist/tests/with-test-db.test.d.ts +2 -0
  124. package/dist/tests/with-test-db.test.d.ts.map +1 -0
  125. package/dist/tests/with-test-db.test.js +57 -0
  126. package/dist/types/index.d.ts.map +1 -1
  127. package/dist/validate/index.d.ts +53 -0
  128. package/dist/validate/index.d.ts.map +1 -1
  129. package/dist/validate/index.js +693 -7
  130. package/dist/validate/migration-parse.d.ts +10 -5
  131. package/dist/validate/migration-parse.d.ts.map +1 -1
  132. package/dist/validate/migration-parse.js +1 -1
  133. package/dist/validate/shared-message-keys.d.ts +16 -0
  134. package/dist/validate/shared-message-keys.d.ts.map +1 -0
  135. package/dist/validate/shared-message-keys.js +227 -0
  136. package/package.json +8 -8
  137. package/dist/client/Auth.d.ts +0 -19
  138. package/dist/client/Auth.d.ts.map +0 -1
  139. package/dist/client/Auth.js +0 -45
  140. package/dist/client/QueryBuilder.d.ts +0 -17
  141. package/dist/client/QueryBuilder.d.ts.map +0 -1
  142. package/dist/client/QueryBuilder.js +0 -85
  143. package/dist/client/RealtimeClient.d.ts +0 -22
  144. package/dist/client/RealtimeClient.d.ts.map +0 -1
  145. package/dist/client/RealtimeClient.js +0 -98
  146. package/dist/client/ZveltioClient.d.ts +0 -20
  147. package/dist/client/ZveltioClient.d.ts.map +0 -1
  148. package/dist/client/ZveltioClient.js +0 -78
  149. package/dist/generate-types.d.ts +0 -37
  150. package/dist/generate-types.d.ts.map +0 -1
  151. package/dist/generate-types.js +0 -157
@@ -1,78 +0,0 @@
1
- import { QueryBuilder } from './QueryBuilder.js';
2
- import { Auth } from './Auth.js';
3
- import { RealtimeClient } from './RealtimeClient.js';
4
- export class ZveltioClient {
5
- auth;
6
- realtime;
7
- config;
8
- constructor(config) {
9
- this.config = config;
10
- this.auth = new Auth(config);
11
- this.realtime = new RealtimeClient(config.baseUrl);
12
- }
13
- // Fluent query builder
14
- from(collection) {
15
- return new QueryBuilder(collection, this.config);
16
- }
17
- // Direct CRUD methods
18
- async list(collection, options) {
19
- return this.from(collection).query(options);
20
- }
21
- async get(collection, id) {
22
- const res = await this.request(`/api/data/${collection}/${id}`);
23
- return res.record;
24
- }
25
- async create(collection, data) {
26
- const res = await this.request(`/api/data/${collection}`, {
27
- method: 'POST',
28
- body: JSON.stringify(data),
29
- });
30
- return res.record;
31
- }
32
- async update(collection, id, data) {
33
- const res = await this.request(`/api/data/${collection}/${id}`, {
34
- method: 'PATCH',
35
- body: JSON.stringify(data),
36
- });
37
- return res.record;
38
- }
39
- async replace(collection, id, data) {
40
- const res = await this.request(`/api/data/${collection}/${id}`, {
41
- method: 'PUT',
42
- body: JSON.stringify(data),
43
- });
44
- return res.record;
45
- }
46
- async delete(collection, id) {
47
- return this.request(`/api/data/${collection}/${id}`, {
48
- method: 'DELETE',
49
- });
50
- }
51
- // Raw request helper
52
- async request(path, init) {
53
- const headers = {
54
- 'Content-Type': 'application/json',
55
- ...init?.headers,
56
- };
57
- if (this.config.apiKey) {
58
- headers['X-API-Key'] = this.config.apiKey;
59
- }
60
- const res = await fetch(`${this.config.baseUrl}${path}`, {
61
- ...init,
62
- credentials: 'include',
63
- headers,
64
- });
65
- if (res.status === 401) {
66
- this.config.onUnauthorized?.();
67
- throw new Error('Unauthorized');
68
- }
69
- if (!res.ok) {
70
- const err = await res.json().catch(() => ({ error: res.statusText }));
71
- throw new Error(err.error || `Request failed: ${res.status}`);
72
- }
73
- return res.json();
74
- }
75
- }
76
- export function createClient(config) {
77
- return new ZveltioClient(config);
78
- }
@@ -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"}
@@ -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
- }