@zveltio/sdk 2.0.8 → 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 (157) hide show
  1. package/README.md +17 -4
  2. package/dist/build/index.d.ts +77 -0
  3. package/dist/build/index.d.ts.map +1 -0
  4. package/dist/build/index.js +157 -0
  5. package/dist/client.d.ts +103 -7
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +129 -28
  8. package/dist/core.d.ts.map +1 -1
  9. package/dist/core.js +21 -3
  10. package/dist/crdt.d.ts.map +1 -1
  11. package/dist/crdt.js +11 -2
  12. package/dist/ddl/index.d.ts +173 -0
  13. package/dist/ddl/index.d.ts.map +1 -0
  14. package/dist/ddl/index.js +33 -0
  15. package/dist/errors.d.ts +58 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +124 -0
  18. package/dist/extension/action-refusal.d.ts +27 -0
  19. package/dist/extension/action-refusal.d.ts.map +1 -0
  20. package/dist/extension/action-refusal.js +29 -0
  21. package/dist/extension/capabilities.d.ts +71 -0
  22. package/dist/extension/capabilities.d.ts.map +1 -0
  23. package/dist/extension/capabilities.js +79 -0
  24. package/dist/extension/dates.d.ts +7 -0
  25. package/dist/extension/dates.d.ts.map +1 -0
  26. package/dist/extension/dates.js +14 -0
  27. package/dist/extension/index.d.ts +1570 -10
  28. package/dist/extension/index.d.ts.map +1 -1
  29. package/dist/extension/index.js +17 -1
  30. package/dist/extension/jsonb.d.ts +62 -0
  31. package/dist/extension/jsonb.d.ts.map +1 -0
  32. package/dist/extension/jsonb.js +64 -0
  33. package/dist/extension/multipart.d.ts +58 -0
  34. package/dist/extension/multipart.d.ts.map +1 -0
  35. package/dist/extension/multipart.js +61 -0
  36. package/dist/extension/numeric.d.ts +94 -0
  37. package/dist/extension/numeric.d.ts.map +1 -0
  38. package/dist/extension/numeric.js +162 -0
  39. package/dist/extension/permission-gate.d.ts +52 -0
  40. package/dist/extension/permission-gate.d.ts.map +1 -0
  41. package/dist/extension/permission-gate.js +125 -0
  42. package/dist/extension/reserved-paths.d.ts +10 -0
  43. package/dist/extension/reserved-paths.d.ts.map +1 -0
  44. package/dist/extension/reserved-paths.js +23 -0
  45. package/dist/index.d.ts +4 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -0
  48. package/dist/local-store.d.ts +14 -1
  49. package/dist/local-store.d.ts.map +1 -1
  50. package/dist/local-store.js +93 -16
  51. package/dist/offline/index.d.ts +75 -0
  52. package/dist/offline/index.d.ts.map +1 -0
  53. package/dist/offline/index.js +251 -0
  54. package/dist/publish/index.d.ts +94 -0
  55. package/dist/publish/index.d.ts.map +1 -0
  56. package/dist/publish/index.js +153 -0
  57. package/dist/realtime.d.ts +25 -1
  58. package/dist/realtime.d.ts.map +1 -1
  59. package/dist/realtime.js +53 -5
  60. package/dist/rpc/index.d.ts +68 -0
  61. package/dist/rpc/index.d.ts.map +1 -0
  62. package/dist/rpc/index.js +63 -0
  63. package/dist/schema-codegen.d.ts +84 -0
  64. package/dist/schema-codegen.d.ts.map +1 -0
  65. package/dist/schema-codegen.js +503 -0
  66. package/dist/schema-watcher.d.ts +10 -2
  67. package/dist/schema-watcher.d.ts.map +1 -1
  68. package/dist/schema-watcher.js +26 -13
  69. package/dist/studio/index.d.ts +85 -0
  70. package/dist/studio/index.d.ts.map +1 -0
  71. package/dist/studio/index.js +183 -0
  72. package/dist/studio/slot-owner-registry.d.ts +13 -0
  73. package/dist/studio/slot-owner-registry.d.ts.map +1 -0
  74. package/dist/studio/slot-owner-registry.js +21 -0
  75. package/dist/svelte.d.ts +1 -1
  76. package/dist/svelte.d.ts.map +1 -1
  77. package/dist/svelte.js +4 -2
  78. package/dist/sync-manager.d.ts +49 -4
  79. package/dist/sync-manager.d.ts.map +1 -1
  80. package/dist/sync-manager.js +175 -24
  81. package/dist/testing/index.d.ts +121 -0
  82. package/dist/testing/index.d.ts.map +1 -0
  83. package/dist/testing/index.js +305 -0
  84. package/dist/testing/with-test-db.d.ts +119 -0
  85. package/dist/testing/with-test-db.d.ts.map +1 -0
  86. package/dist/testing/with-test-db.js +320 -0
  87. package/dist/tests/action-refusal.test.d.ts +2 -0
  88. package/dist/tests/action-refusal.test.d.ts.map +1 -0
  89. package/dist/tests/action-refusal.test.js +13 -0
  90. package/dist/tests/client.test.d.ts +2 -0
  91. package/dist/tests/client.test.d.ts.map +1 -0
  92. package/dist/tests/client.test.js +164 -0
  93. package/dist/tests/crdt-orset.test.d.ts +2 -0
  94. package/dist/tests/crdt-orset.test.d.ts.map +1 -0
  95. package/dist/tests/crdt-orset.test.js +23 -0
  96. package/dist/tests/local-store.test.js +44 -0
  97. package/dist/tests/migration-parse.test.d.ts +2 -0
  98. package/dist/tests/migration-parse.test.d.ts.map +1 -0
  99. package/dist/tests/migration-parse.test.js +17 -0
  100. package/dist/tests/multipart.test.d.ts +2 -0
  101. package/dist/tests/multipart.test.d.ts.map +1 -0
  102. package/dist/tests/multipart.test.js +37 -0
  103. package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
  104. package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
  105. package/dist/tests/offline-provider-crdt.test.js +206 -0
  106. package/dist/tests/realtime.test.d.ts +2 -0
  107. package/dist/tests/realtime.test.d.ts.map +1 -0
  108. package/dist/tests/realtime.test.js +220 -0
  109. package/dist/tests/reserved-paths.test.d.ts +2 -0
  110. package/dist/tests/reserved-paths.test.d.ts.map +1 -0
  111. package/dist/tests/reserved-paths.test.js +21 -0
  112. package/dist/tests/sync-manager.test.d.ts +2 -0
  113. package/dist/tests/sync-manager.test.d.ts.map +1 -0
  114. package/dist/tests/sync-manager.test.js +123 -0
  115. package/dist/tests/today-in.test.d.ts +2 -0
  116. package/dist/tests/today-in.test.d.ts.map +1 -0
  117. package/dist/tests/today-in.test.js +14 -0
  118. package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
  119. package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
  120. package/dist/tests/validate-manifest-actions.test.js +82 -0
  121. package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
  122. package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
  123. package/dist/tests/validate-manifest-dependencies.test.js +27 -0
  124. package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
  125. package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
  126. package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
  127. package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
  128. package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
  129. package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
  130. package/dist/tests/with-test-db.test.d.ts +2 -0
  131. package/dist/tests/with-test-db.test.d.ts.map +1 -0
  132. package/dist/tests/with-test-db.test.js +57 -0
  133. package/dist/types/index.d.ts.map +1 -1
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/utils.js +3 -1
  136. package/dist/validate/index.d.ts +148 -0
  137. package/dist/validate/index.d.ts.map +1 -0
  138. package/dist/validate/index.js +887 -0
  139. package/dist/validate/migration-parse.d.ts +22 -0
  140. package/dist/validate/migration-parse.d.ts.map +1 -0
  141. package/dist/validate/migration-parse.js +11 -0
  142. package/dist/validate/shared-message-keys.d.ts +16 -0
  143. package/dist/validate/shared-message-keys.d.ts.map +1 -0
  144. package/dist/validate/shared-message-keys.js +227 -0
  145. package/package.json +56 -4
  146. package/dist/client/Auth.d.ts +0 -19
  147. package/dist/client/Auth.d.ts.map +0 -1
  148. package/dist/client/Auth.js +0 -45
  149. package/dist/client/QueryBuilder.d.ts +0 -17
  150. package/dist/client/QueryBuilder.d.ts.map +0 -1
  151. package/dist/client/QueryBuilder.js +0 -76
  152. package/dist/client/RealtimeClient.d.ts +0 -22
  153. package/dist/client/RealtimeClient.d.ts.map +0 -1
  154. package/dist/client/RealtimeClient.js +0 -96
  155. package/dist/client/ZveltioClient.d.ts +0 -20
  156. package/dist/client/ZveltioClient.d.ts.map +0 -1
  157. package/dist/client/ZveltioClient.js +0 -78
@@ -0,0 +1,82 @@
1
+ // `zveltio extension validate` refuses the actions and jobs the engine would refuse at load.
2
+ import { describe, expect, it } from 'bun:test';
3
+ import { validateManifest } from '../validate/index.js';
4
+ const base = {
5
+ name: 'a',
6
+ displayName: 'A',
7
+ category: 'custom',
8
+ description: 'd',
9
+ version: '1.0.0',
10
+ resources: ['ext:a'],
11
+ };
12
+ const input = { type: 'object' };
13
+ const action = {
14
+ name: 'convertLead',
15
+ permission: { resource: 'ext:a' },
16
+ input,
17
+ enqueues: ['notify'],
18
+ };
19
+ const job = { name: 'notify', input, retry: { limit: 3 } };
20
+ const errors = (extra) => validateManifest({ manifest: { ...base, ...extra } })
21
+ .filter((e) => e.code === 'MANIFEST_BAD_ACTION' || e.code === 'MANIFEST_BAD_JOB')
22
+ .map((e) => e.message);
23
+ describe('manifest actions and jobs', () => {
24
+ it('accepts a well-formed action that enqueues a declared job', () => {
25
+ expect(errors({ actions: [action], jobs: [job] })).toEqual([]);
26
+ });
27
+ it('refuses what the engine schema refuses', () => {
28
+ expect(errors({ actions: [action] })).toEqual([
29
+ 'action "convertLead" enqueues "notify", which is not in jobs',
30
+ ]);
31
+ expect(errors({ actions: [{ ...action, permission: { resource: 'ext:b' } }], jobs: [job] })).toHaveLength(1);
32
+ expect(errors({ actions: [action, action], jobs: [job] })).toHaveLength(1);
33
+ expect(errors({ actions: [{ ...action, name: 'Convert' }], jobs: [job] })).toHaveLength(1);
34
+ expect(errors({ actions: [{ ...action, input: 'x' }], jobs: [job] })).toHaveLength(1);
35
+ expect(errors({ actions: [{ ...action, writes: 'contacts' }], jobs: [job] })).toHaveLength(1);
36
+ expect(errors({ actions: {}, jobs: [job] })).toHaveLength(1);
37
+ expect(errors({ jobs: [{ ...job, retry: { limit: 11 } }] })).toHaveLength(1);
38
+ expect(errors({ jobs: [{ ...job, retry: { backoff: 'yes' } }] })).toHaveLength(1);
39
+ });
40
+ it('takes fromPublicRoutes naming publicRoutes entries only (ADR 0018)', () => {
41
+ const hooked = { ...job, fromPublicRoutes: ['/webhooks/stripe'] };
42
+ expect(errors({ jobs: [hooked], publicRoutes: ['/webhooks/stripe'] })).toEqual([]);
43
+ expect(errors({ jobs: [hooked] })).toEqual([
44
+ 'job "notify" names "/webhooks/stripe" in fromPublicRoutes, which is not a publicRoutes entry',
45
+ ]);
46
+ expect(errors({ jobs: [{ ...job, fromPublicRoutes: '/webhooks/stripe' }] })).toHaveLength(1);
47
+ expect(errors({
48
+ jobs: [{ ...job, fromPublicRoutes: ['/webhooks/*'] }],
49
+ publicRoutes: ['/webhooks/*'],
50
+ })).toEqual([
51
+ 'job "notify" names "/webhooks/*" in fromPublicRoutes; name one route, without "*"',
52
+ ]);
53
+ });
54
+ it('takes calls of a required dependency’s actions, as <extension>.<action> (ADR 0014)', () => {
55
+ const calling = { ...action, calls: ['finance/invoicing.recordPayment'] };
56
+ const deps = [{ name: 'finance/invoicing' }];
57
+ expect(errors({ actions: [calling], jobs: [job], dependencies: deps })).toEqual([]);
58
+ expect(errors({ actions: [calling], jobs: [job] })).toEqual([
59
+ 'action "convertLead" calls "finance/invoicing.recordPayment", but "finance/invoicing" is not in dependencies or optionalDependencies',
60
+ ]);
61
+ expect(errors({ actions: [calling], jobs: [job], optionalDependencies: deps })).toEqual([]);
62
+ const bad = (calls) => errors({ actions: [{ ...action, calls }], jobs: [job], dependencies: deps });
63
+ expect(bad(['finance/invoicing'])).toHaveLength(1);
64
+ expect(bad(['finance/invoicing.Pay'])).toHaveLength(1);
65
+ expect(bad('finance/invoicing.recordPayment')).toHaveLength(1);
66
+ });
67
+ it('accepts an action gated on a collection the actions or jobs read or write', () => {
68
+ const gated = { ...action, permission: { resource: 'leads' } };
69
+ expect(errors({ actions: [{ ...gated, writes: ['leads'] }], jobs: [job] })).toEqual([]);
70
+ expect(errors({ actions: [gated], jobs: [{ ...job, reads: ['leads'] }] })).toEqual([]);
71
+ expect(errors({ actions: [gated], jobs: [job] })).toHaveLength(1);
72
+ });
73
+ });
74
+ describe('manifest collections', () => {
75
+ const bad = (collections) => validateManifest({ manifest: { ...base, collections } }).filter((e) => e.code === 'MANIFEST_BAD_COLLECTIONS');
76
+ it('takes collection names, once each', () => {
77
+ expect(bad(['tasks', 'task_lists'])).toEqual([]);
78
+ expect(bad('tasks')).toHaveLength(1);
79
+ expect(bad(['Tasks'])).toHaveLength(1);
80
+ expect(bad(['tasks', 'tasks'])).toHaveLength(1);
81
+ });
82
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate-manifest-dependencies.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-manifest-dependencies.test.d.ts","sourceRoot":"","sources":["../../src/tests/validate-manifest-dependencies.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ // `zveltio extension validate` checks both dependency lists the broker reads.
2
+ import { describe, expect, it } from 'bun:test';
3
+ import { validateManifest } from '../validate/index.js';
4
+ const base = {
5
+ name: 'a',
6
+ displayName: 'A',
7
+ category: 'custom',
8
+ description: 'd',
9
+ version: '1.0.0',
10
+ };
11
+ const codes = (extra) => validateManifest({ manifest: { ...base, ...extra } })
12
+ .filter((e) => e.code === 'MANIFEST_BAD_DEPENDENCY')
13
+ .map((e) => e.message);
14
+ describe('manifest dependencies / optionalDependencies', () => {
15
+ it('accepts both lists', () => {
16
+ expect(codes({
17
+ dependencies: [{ name: 'crm', minVersion: '1.0.0' }],
18
+ optionalDependencies: [{ name: 'ai' }],
19
+ })).toEqual([]);
20
+ });
21
+ it('refuses a malformed entry, a bad minVersion and a name in both lists', () => {
22
+ expect(codes({ optionalDependencies: 'ai' })).toHaveLength(1);
23
+ expect(codes({ optionalDependencies: [{ minVersion: '1.0.0' }] })[0]).toContain('has no name');
24
+ expect(codes({ optionalDependencies: [{ name: 'ai', minVersion: 'x' }] })[0]).toContain('not semver');
25
+ expect(codes({ dependencies: [{ name: 'ai' }], optionalDependencies: [{ name: 'ai' }] })[0]).toContain('"ai" is listed in "dependencies" and "optionalDependencies"');
26
+ });
27
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate-manifest-forward-credentials.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-manifest-forward-credentials.test.d.ts","sourceRoot":"","sources":["../../src/tests/validate-manifest-forward-credentials.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ // `zveltio extension validate` refuses the forwardCredentials the engine would refuse.
2
+ import { describe, expect, it } from 'bun:test';
3
+ import { validateManifest } from '../validate/index.js';
4
+ const base = {
5
+ name: 'a',
6
+ displayName: 'A',
7
+ category: 'custom',
8
+ description: 'd',
9
+ version: '1.0.0',
10
+ publicRoutes: ['/scim/*'],
11
+ };
12
+ const errors = (forwardCredentials) => validateManifest({ manifest: { ...base, forwardCredentials } }).filter((e) => e.code === 'MANIFEST_BAD_FORWARD_CREDENTIALS');
13
+ describe('manifest forwardCredentials', () => {
14
+ it('accepts a credential header on a public route', () => {
15
+ expect(errors({ '/scim/*': ['authorization'] })).toEqual([]);
16
+ });
17
+ it('refuses an unknown header, a non-public route and a non-object', () => {
18
+ expect(errors({ '/scim/*': ['stripe-signature'] })).toHaveLength(1);
19
+ expect(errors({ '/admin/*': ['cookie'] })).toHaveLength(1);
20
+ expect(errors(['authorization'])).toHaveLength(1);
21
+ });
22
+ // The engine's schema takes arrays only, and refused at load what this passed.
23
+ it('refuses a bare header name where the engine wants a list', () => {
24
+ expect(errors({ '/scim/*': 'authorization' })).toHaveLength(1);
25
+ });
26
+ });
27
+ describe('manifest apiKeyRoutes', () => {
28
+ const routeErrors = (apiKeyRoutes) => validateManifest({ manifest: { ...base, apiKeyRoutes } }).filter((e) => e.code === 'MANIFEST_BAD_API_KEY_ROUTE');
29
+ it('accepts a list of method + pattern', () => {
30
+ expect(routeErrors(['GET /items'])).toEqual([]);
31
+ });
32
+ it('refuses a bare string where the engine wants a list', () => {
33
+ expect(routeErrors('GET /items')).toHaveLength(1);
34
+ });
35
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate-sdui-data-endpoints.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-sdui-data-endpoints.test.d.ts","sourceRoot":"","sources":["../../src/tests/validate-sdui-data-endpoints.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ // A declarative page may name the data API of a collection its extension declares
2
+ // (ADR 0012), and of no other; every other core endpoint stays foreign.
3
+ import { describe, expect, it } from 'bun:test';
4
+ import { validateSduiSchema } from '../validate/index.js';
5
+ const foreign = (endpoint, collections) => validateSduiSchema({
6
+ schema: { title: 't', resources: [{ name: 'r', dataSource: endpoint }] },
7
+ extName: 'projects/management',
8
+ collections,
9
+ })
10
+ .filter((e) => e.code === 'SDUI_ENDPOINT_FOREIGN')
11
+ .map((e) => e.message.split('"')[1]);
12
+ describe('SDUI data API endpoints', () => {
13
+ it('allows its own collection and one of its records', () => {
14
+ for (const e of [
15
+ '/api/data/projects',
16
+ '/api/data/projects?limit=5',
17
+ '/api/data/projects/{id}',
18
+ '/api/data/projects/:id',
19
+ '/api/data/tasks/0b9c5c3e-1d2a-4f6b-9a1e-2c3d4e5f6a7b',
20
+ ]) {
21
+ expect(foreign(e, ['projects', 'tasks'])).toEqual([]);
22
+ }
23
+ });
24
+ it('refuses a collection it does not declare, and any data path without a declaration', () => {
25
+ expect(foreign('/api/data/invoices', ['projects'])).toEqual(['/api/data/invoices']);
26
+ expect(foreign('/api/data/projects')).toEqual(['/api/data/projects']);
27
+ });
28
+ it('refuses every other path, a deeper one and a dot segment included', () => {
29
+ for (const e of [
30
+ '/api/users',
31
+ '/api/data',
32
+ '/api/data/projects/{id}/history',
33
+ '/api/data/projects/../users',
34
+ '/api/data/projects/..',
35
+ '/api/collections/projects',
36
+ '/api/data/Projects',
37
+ ]) {
38
+ expect(foreign(e, ['projects'])).toEqual([e]);
39
+ }
40
+ });
41
+ });
@@ -0,0 +1,2 @@
1
+ import './setup';
2
+ //# sourceMappingURL=with-test-db.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-test-db.test.d.ts","sourceRoot":"","sources":["../../src/tests/with-test-db.test.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC"}
@@ -0,0 +1,57 @@
1
+ import './setup';
2
+ import { describe, it, expect } from 'bun:test';
3
+ import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, } from 'kysely';
4
+ import { applyMigrationStrings } from '../testing/with-test-db.js';
5
+ /**
6
+ * The harness other suites trust.
7
+ *
8
+ * A Zveltio migration keeps its rollback in the same file behind a `-- DOWN`
9
+ * marker, and the documented way to use this helper is to glob
10
+ * `engine/migrations/*.sql` and hand every file to it. Running the whole file
11
+ * creates the schema and then drops it again inside the same call.
12
+ */
13
+ function recordingDb(sink) {
14
+ const connection = {
15
+ async executeQuery(compiled) {
16
+ sink.push(compiled.sql);
17
+ return { rows: [] };
18
+ },
19
+ async *streamQuery() { },
20
+ };
21
+ const driver = {
22
+ async init() { },
23
+ async acquireConnection() {
24
+ return connection;
25
+ },
26
+ async beginTransaction() { },
27
+ async commitTransaction() { },
28
+ async rollbackTransaction() { },
29
+ async releaseConnection() { },
30
+ async destroy() { },
31
+ };
32
+ return new Kysely({
33
+ dialect: {
34
+ createAdapter: () => new PostgresAdapter(),
35
+ createDriver: () => driver,
36
+ createIntrospector: (db) => new PostgresIntrospector(db),
37
+ createQueryCompiler: () => new PostgresQueryCompiler(),
38
+ },
39
+ });
40
+ }
41
+ describe('applyMigrationStrings', () => {
42
+ it('does not run the DOWN half of a migration', async () => {
43
+ const executed = [];
44
+ const db = recordingDb(executed);
45
+ await applyMigrationStrings(db, ['CREATE TABLE zvd_t (id TEXT);\n-- DOWN\nDROP TABLE zvd_t;']);
46
+ expect(executed.join('\n')).toContain('CREATE TABLE');
47
+ expect(executed.join('\n'), 'the rollback ran against the schema it had just created').not.toContain('DROP TABLE');
48
+ await db.destroy();
49
+ });
50
+ it('still runs every statement of a file with no DOWN section', async () => {
51
+ const executed = [];
52
+ const db = recordingDb(executed);
53
+ await applyMigrationStrings(db, ['CREATE TABLE a (id TEXT);\nCREATE TABLE b (id TEXT);']);
54
+ expect(executed).toHaveLength(2);
55
+ await db.destroy();
56
+ });
57
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG;IACpC,OAAO,EAAE,CAAC,EAAE,CAAC;IACb,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC,MAAM,EAAE,CAAC,CAAC;CACX;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC,MAAM,EAAE,CAAC,CAAC;CACX;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,M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,CAAC;IACtC,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,GAAG,CAAC;IACV,SAAS,EAAE,MAAM,CAAC;CACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAUrC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAYrC"}
package/dist/utils.js CHANGED
@@ -14,6 +14,8 @@ export function generateUUID() {
14
14
  const bytes = crypto.getRandomValues(new Uint8Array(16));
15
15
  bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4
16
16
  bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant bits
17
- const hex = Array.from(bytes).map((b) => b.toString(16).padStart(2, '0')).join('');
17
+ const hex = Array.from(bytes)
18
+ .map((b) => b.toString(16).padStart(2, '0'))
19
+ .join('');
18
20
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
19
21
  }
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Pre-publish validators for Zveltio extensions (S4-04).
3
+ *
4
+ * Pure functions — no Node-specific imports, no Zod runtime. Designed so the
5
+ * CLI (`zveltio extension validate`) can call them on file contents read from
6
+ * disk, the engine can call them on uploaded archives, and registry code can
7
+ * call them on publish. Each returns a `ValidationResult` with structured
8
+ * diagnostics instead of throwing, so the CLI can print all problems at once.
9
+ *
10
+ * What's checked:
11
+ * - manifest.json shape (required fields, semver, sane category)
12
+ * - name matches the folder path it lives in
13
+ * - peerDependencies appear on the platform allow-list
14
+ * - migration SQL files parse + table coverage looks sane
15
+ * - destructive DDL in migrations has a `-- DOWN` section
16
+ * - bundle size stays within quota
17
+ *
18
+ * Out of scope (deferred):
19
+ * - Loading the extension module to inspect its default export. Requires
20
+ * a Bun runtime + sandbox. CLI's `validate` cannot guarantee correctness
21
+ * for runtime contracts; that's what `extension types` (S4-01) + `tsc`
22
+ * gives you locally.
23
+ * - Building the Studio bundle. Too slow; pair with `zveltio extension build`
24
+ * which can call validate as a sub-step.
25
+ */
26
+ export { SHARED_MESSAGE_KEYS } from './shared-message-keys.js';
27
+ export interface ValidationError {
28
+ /** Stable machine-readable code (e.g. `MANIFEST_NAME_MISMATCH`). */
29
+ code: string;
30
+ /** Operator-facing message. */
31
+ message: string;
32
+ /** Optional file path the error applies to, relative to the extension root. */
33
+ file?: string;
34
+ /** `warning` items are surfaced but do NOT fail validation (`result.ok`). */
35
+ severity?: 'error' | 'warning';
36
+ }
37
+ export interface ValidationResult {
38
+ ok: boolean;
39
+ errors: ValidationError[];
40
+ /** Counts surfaced for human-readable summaries. */
41
+ stats: {
42
+ tables: number;
43
+ migrations: number;
44
+ peerDeps: number;
45
+ };
46
+ }
47
+ export interface ManifestValidationInput {
48
+ /** Parsed JSON object (or `null` if file couldn't be read). */
49
+ manifest: unknown;
50
+ /** Folder path slug — e.g. `'finance/invoicing'`. Used for name-match. */
51
+ expectedName?: string;
52
+ }
53
+ export declare function validateManifest(input: ManifestValidationInput): ValidationError[];
54
+ export interface PeerDepsValidationInput {
55
+ /** From manifest.json: `{ "lodash": "^4.0.0", ... }` (or undefined). */
56
+ peerDependencies: Record<string, string> | undefined;
57
+ /** The platform allow-list (caller supplies it — see peer-deps-allowlist.ts). */
58
+ allowedPackages: ReadonlySet<string>;
59
+ }
60
+ export declare function validatePeerDependencies(input: PeerDepsValidationInput): ValidationError[];
61
+ export interface MigrationsValidationInput {
62
+ /** Pairs of (filename, sql contents). Filename is just for diagnostics. */
63
+ files: Array<{
64
+ filename: string;
65
+ sql: string;
66
+ }>;
67
+ /** When `true`, every migration with destructive DDL must have a -- DOWN section. */
68
+ requireDownForDestructive?: boolean;
69
+ }
70
+ export declare function validateMigrations(input: MigrationsValidationInput): ValidationError[];
71
+ export interface FilePresenceInput {
72
+ /** Mapping of relative path → existence boolean. Caller does the disk hit. */
73
+ paths: Record<string, boolean>;
74
+ /** Paths that MUST exist. */
75
+ required: string[];
76
+ }
77
+ export declare function validateFilePresence(input: FilePresenceInput): ValidationError[];
78
+ export interface BundleSizeInput {
79
+ /** Size of the extension folder (excluding node_modules), in bytes. */
80
+ bundleBytes: number;
81
+ /** Override the default cap (50 MB). */
82
+ bundleSizeKbMax?: number;
83
+ }
84
+ export declare function validateBundleSize(input: BundleSizeInput): ValidationError[];
85
+ /** Read-only core endpoints a schema is legitimately allowed to call (relation
86
+ * pickers etc.). Keep this list tiny and read-only. */
87
+ export declare const SDUI_SHARED_READ_ALLOWLIST: ReadonlySet<string>;
88
+ /**
89
+ * Schema keys whose value is user-visible text.
90
+ *
91
+ * The host renders these through `t()`, which looks the string up in the
92
+ * message bundle and falls back to the literal. That fallback is why a typo is
93
+ * invisible at runtime: the user simply sees `auth.saml.ui.begin_certificate`
94
+ * rendered as a placeholder. Catching it here is the only place it is cheap.
95
+ */
96
+ export declare const SDUI_I18N_SLOTS: readonly string[];
97
+ export interface SduiValidationInput {
98
+ /** Parsed schema JSON (a PageSchema or SettingsSchema). */
99
+ schema: unknown;
100
+ /** Owning extension name, e.g. `finance/invoicing`. */
101
+ extName: string;
102
+ /** Route paths the extension's engine actually serves, relative to its mount
103
+ * (e.g. `['/invoices', '/invoices/:id/pay']`). The CLI extracts these from
104
+ * `engine/**` source; pass `undefined` to skip the path-existence check
105
+ * (foreign-namespace check still runs). */
106
+ providedRoutes?: string[];
107
+ /** Extension names this one declares as dependencies (manifest.dependencies).
108
+ * A schema may read a dependency's `/ext/<dep>/` routes (relation pickers),
109
+ * which is otherwise treated as foreign. */
110
+ dependencies?: string[];
111
+ /** The collections this extension and its dependencies declare (manifest
112
+ * `collections`, ADR 0012): a schema may name `/api/data/<collection>` and
113
+ * `/api/data/<collection>/<id>` for these, and for no other collection. */
114
+ collections?: string[];
115
+ /** Message keys this schema may resolve against: the extension's own
116
+ * `studio/messages/en.json` keys, unioned with `SHARED_MESSAGE_KEYS`.
117
+ * Omit to skip the i18n checks (endpoint checks still run). */
118
+ messageKeys?: Iterable<string>;
119
+ /** For diagnostics. */
120
+ file?: string;
121
+ }
122
+ export declare function validateSduiSchema(input: SduiValidationInput): ValidationError[];
123
+ /** Extract route paths an extension serves from its engine source text.
124
+ *
125
+ * Heuristic over `.get/post/put/patch/delete('…')` and `.route('/prefix', …)`
126
+ * mounts. Nested Hono sub-apps (e.g. `app.route('/query', aiQueryRoutes)`) used
127
+ * to be invisible here, so schemas pointing at the real `/query/history` path
128
+ * failed `SDUI_ENDPOINT_UNKNOWN` while a wrong bare `/history` falsely passed.
129
+ *
130
+ * Mounts register `/prefix` and `/prefix/*`; matching allows any path under that
131
+ * prefix (see `isProvidedRoute`). Parsing each factory body is intentionally
132
+ * avoided — route handlers often contain regexes/`${…}` that defeat brace
133
+ * matching. */
134
+ export declare function extractEngineRoutes(engineSourceTexts: string[]): string[];
135
+ export interface ValidateExtensionInput {
136
+ manifest: ManifestValidationInput;
137
+ peerDeps: PeerDepsValidationInput;
138
+ migrations: MigrationsValidationInput;
139
+ filePresence: FilePresenceInput;
140
+ bundleSize?: BundleSizeInput;
141
+ /** Numbers used to fill the result's `stats` for human summaries. */
142
+ stats: {
143
+ tables: number;
144
+ migrations: number;
145
+ };
146
+ }
147
+ export declare function validateExtension(input: ValidateExtensionInput): ValidationResult;
148
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAK/D,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE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