@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.
- package/README.md +17 -4
- package/dist/build/index.d.ts +77 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +157 -0
- package/dist/client.d.ts +103 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +129 -28
- 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 +173 -0
- package/dist/ddl/index.d.ts.map +1 -0
- package/dist/ddl/index.js +33 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +124 -0
- package/dist/extension/action-refusal.d.ts +27 -0
- package/dist/extension/action-refusal.d.ts.map +1 -0
- package/dist/extension/action-refusal.js +29 -0
- package/dist/extension/capabilities.d.ts +71 -0
- package/dist/extension/capabilities.d.ts.map +1 -0
- package/dist/extension/capabilities.js +79 -0
- package/dist/extension/dates.d.ts +7 -0
- package/dist/extension/dates.d.ts.map +1 -0
- package/dist/extension/dates.js +14 -0
- package/dist/extension/index.d.ts +1570 -10
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/index.js +17 -1
- 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 +52 -0
- package/dist/extension/permission-gate.d.ts.map +1 -0
- package/dist/extension/permission-gate.js +125 -0
- package/dist/extension/reserved-paths.d.ts +10 -0
- package/dist/extension/reserved-paths.d.ts.map +1 -0
- package/dist/extension/reserved-paths.js +23 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/local-store.d.ts +14 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-store.js +93 -16
- package/dist/offline/index.d.ts +75 -0
- package/dist/offline/index.d.ts.map +1 -0
- package/dist/offline/index.js +251 -0
- package/dist/publish/index.d.ts +94 -0
- package/dist/publish/index.d.ts.map +1 -0
- package/dist/publish/index.js +153 -0
- package/dist/realtime.d.ts +25 -1
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +53 -5
- package/dist/rpc/index.d.ts +68 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +63 -0
- package/dist/schema-codegen.d.ts +84 -0
- package/dist/schema-codegen.d.ts.map +1 -0
- package/dist/schema-codegen.js +503 -0
- package/dist/schema-watcher.d.ts +10 -2
- package/dist/schema-watcher.d.ts.map +1 -1
- package/dist/schema-watcher.js +26 -13
- package/dist/studio/index.d.ts +85 -0
- package/dist/studio/index.d.ts.map +1 -0
- package/dist/studio/index.js +183 -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 +49 -4
- package/dist/sync-manager.d.ts.map +1 -1
- package/dist/sync-manager.js +175 -24
- package/dist/testing/index.d.ts +121 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +305 -0
- package/dist/testing/with-test-db.d.ts +119 -0
- package/dist/testing/with-test-db.d.ts.map +1 -0
- package/dist/testing/with-test-db.js +320 -0
- package/dist/tests/action-refusal.test.d.ts +2 -0
- package/dist/tests/action-refusal.test.d.ts.map +1 -0
- package/dist/tests/action-refusal.test.js +13 -0
- 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 +164 -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/migration-parse.test.d.ts +2 -0
- package/dist/tests/migration-parse.test.d.ts.map +1 -0
- package/dist/tests/migration-parse.test.js +17 -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 +206 -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 +220 -0
- package/dist/tests/reserved-paths.test.d.ts +2 -0
- package/dist/tests/reserved-paths.test.d.ts.map +1 -0
- package/dist/tests/reserved-paths.test.js +21 -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 +123 -0
- package/dist/tests/today-in.test.d.ts +2 -0
- package/dist/tests/today-in.test.d.ts.map +1 -0
- package/dist/tests/today-in.test.js +14 -0
- package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
- package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-actions.test.js +82 -0
- package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
- package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-dependencies.test.js +27 -0
- package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
- package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
- package/dist/tests/validate-sdui-data-endpoints.test.js +41 -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/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -1
- package/dist/validate/index.d.ts +148 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +887 -0
- package/dist/validate/migration-parse.d.ts +22 -0
- package/dist/validate/migration-parse.d.ts.map +1 -0
- package/dist/validate/migration-parse.js +11 -0
- 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 +56 -4
- package/dist/client/Auth.d.ts +0 -19
- package/dist/client/Auth.d.ts.map +0 -1
- package/dist/client/Auth.js +0 -45
- package/dist/client/QueryBuilder.d.ts +0 -17
- package/dist/client/QueryBuilder.d.ts.map +0 -1
- package/dist/client/QueryBuilder.js +0 -76
- package/dist/client/RealtimeClient.d.ts +0 -22
- package/dist/client/RealtimeClient.d.ts.map +0 -1
- package/dist/client/RealtimeClient.js +0 -96
- package/dist/client/ZveltioClient.d.ts +0 -20
- package/dist/client/ZveltioClient.d.ts.map +0 -1
- package/dist/client/ZveltioClient.js +0 -78
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio SDK surface (S3-02 + S3-03 + early S4-07 prep).
|
|
3
|
+
*
|
|
4
|
+
* Pure helpers for Studio extension authors:
|
|
5
|
+
* - `makeFormProxy` / `applyFormAlterHooks` — form-alter pipeline that
|
|
6
|
+
* `<Form>` renderers in core Studio call before render. Hooks add
|
|
7
|
+
* fields, hide fields, reorder, attach validators.
|
|
8
|
+
* - `sortSlotContributions` — stable priority-asc sort used by
|
|
9
|
+
* `<Slot name>` to order extension contributions.
|
|
10
|
+
*
|
|
11
|
+
* The reactive registries themselves (Svelte 5 `$state`) live in
|
|
12
|
+
* `packages/studio/src/lib/extension-api.svelte.ts`. They import this
|
|
13
|
+
* module so the algorithm is one source of truth, while the studio side
|
|
14
|
+
* owns the runtime state.
|
|
15
|
+
*
|
|
16
|
+
* Exported via `@zveltio/sdk/studio`. Extension Svelte bundles can
|
|
17
|
+
* import-and-call too — useful for advanced authors who want to apply
|
|
18
|
+
* alters against their own custom forms.
|
|
19
|
+
*/
|
|
20
|
+
import type { FormAlterAPI, FormAlterHook, FormSchema, SlotContribution, StudioRoute, StudioFieldType, AssetPreviewHandler } from '../extension/index.js';
|
|
21
|
+
interface FormProxy extends FormAlterAPI {
|
|
22
|
+
/** Commit the mutated schema after all hooks ran. */
|
|
23
|
+
commit(): FormSchema;
|
|
24
|
+
}
|
|
25
|
+
export declare function makeFormProxy(initial: FormSchema): FormProxy;
|
|
26
|
+
/**
|
|
27
|
+
* Run every registered hook against the schema and return the result.
|
|
28
|
+
* Exception-safe: a throwing hook is logged and skipped, the rest still run.
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyFormAlterHooks(hooks: FormAlterHook[], schema: FormSchema, ctx?: Record<string, unknown>): FormSchema;
|
|
31
|
+
/**
|
|
32
|
+
* Sort slot contributions deterministically: priority asc (lower first),
|
|
33
|
+
* then registration order (stable sort).
|
|
34
|
+
*/
|
|
35
|
+
export declare function sortSlotContributions<T extends {
|
|
36
|
+
priority?: number;
|
|
37
|
+
}>(items: T[]): T[];
|
|
38
|
+
export { removeOwnerFromSlots, registerOwnedOnSlot, type OwnedSlotContribution, } from './slot-owner-registry.js';
|
|
39
|
+
/** Register a top-level Studio page contributed by this extension. */
|
|
40
|
+
export declare function registerRoute(route: StudioRoute): void;
|
|
41
|
+
/**
|
|
42
|
+
* Register a Svelte component into a named composition slot (S3-03).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* import { registerSlot } from '@zveltio/sdk/studio';
|
|
46
|
+
* import RevenueWidget from './widgets/RevenueWidget.svelte';
|
|
47
|
+
*
|
|
48
|
+
* registerSlot('dashboard.widgets', {
|
|
49
|
+
* component: RevenueWidget,
|
|
50
|
+
* priority: 10,
|
|
51
|
+
* visible: (ctx) => (ctx.user as any)?.roles?.includes('finance'),
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
export declare function registerSlot(name: string, contribution: SlotContribution): void;
|
|
55
|
+
/**
|
|
56
|
+
* Register a Drupal-style form-alter hook (S3-02).
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* import { registerFormAlter } from '@zveltio/sdk/studio';
|
|
60
|
+
*
|
|
61
|
+
* registerFormAlter('core:user-edit', (form) => {
|
|
62
|
+
* form.addField({ after: 'email', field: { name: 'phone', type: 'tel' } });
|
|
63
|
+
* form.hideField('legacy_pin');
|
|
64
|
+
* });
|
|
65
|
+
*/
|
|
66
|
+
export declare function registerFormAlter(formId: string, hook: FormAlterHook): void;
|
|
67
|
+
/** Register a custom Studio field type contributed by this extension. */
|
|
68
|
+
export declare function registerFieldType(ft: StudioFieldType): void;
|
|
69
|
+
/**
|
|
70
|
+
* Register a custom preview handler for asset URLs / MIME types.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* import { registerAssetPreview } from '@zveltio/sdk/studio';
|
|
74
|
+
* import PdfPreview from './PdfPreview.svelte';
|
|
75
|
+
*
|
|
76
|
+
* registerAssetPreview({
|
|
77
|
+
* match: (a) => a.mimeType === 'application/pdf',
|
|
78
|
+
* component: PdfPreview,
|
|
79
|
+
* });
|
|
80
|
+
*/
|
|
81
|
+
export declare function registerAssetPreview(handler: AssetPreviewHandler): void;
|
|
82
|
+
/** Engine base URL — pre-installed by Studio for cross-origin fetches. */
|
|
83
|
+
export declare function getEngineUrl(): string;
|
|
84
|
+
export type { StudioExtensionAPI, StudioRoute, StudioFieldType, AssetPreviewHandler, SlotContribution, FormAlterHook, FormAlterAPI, FormSchema, FormField, } from '../extension/index.js';
|
|
85
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/studio/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,UAAU,EAEV,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAE/B,UAAU,SAAU,SAAQ,YAAY;IACtC,qDAAqD;IACrD,MAAM,IAAI,UAAU,CAAC;CACtB;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAoE5D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,aAAa,EAAE,EACtB,MAAM,EAAE,UAAU,EAClB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAChC,UAAU,CAWZ;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAGtF;AAED,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC;AAqClC,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAEtD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAE/E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAE3E;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,eAAe,GAAG,IAAI,CAE3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAEvE;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,IAAI,MAAM,CAIrC;AAID,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,SAAS,GACV,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio SDK surface (S3-02 + S3-03 + early S4-07 prep).
|
|
3
|
+
*
|
|
4
|
+
* Pure helpers for Studio extension authors:
|
|
5
|
+
* - `makeFormProxy` / `applyFormAlterHooks` — form-alter pipeline that
|
|
6
|
+
* `<Form>` renderers in core Studio call before render. Hooks add
|
|
7
|
+
* fields, hide fields, reorder, attach validators.
|
|
8
|
+
* - `sortSlotContributions` — stable priority-asc sort used by
|
|
9
|
+
* `<Slot name>` to order extension contributions.
|
|
10
|
+
*
|
|
11
|
+
* The reactive registries themselves (Svelte 5 `$state`) live in
|
|
12
|
+
* `packages/studio/src/lib/extension-api.svelte.ts`. They import this
|
|
13
|
+
* module so the algorithm is one source of truth, while the studio side
|
|
14
|
+
* owns the runtime state.
|
|
15
|
+
*
|
|
16
|
+
* Exported via `@zveltio/sdk/studio`. Extension Svelte bundles can
|
|
17
|
+
* import-and-call too — useful for advanced authors who want to apply
|
|
18
|
+
* alters against their own custom forms.
|
|
19
|
+
*/
|
|
20
|
+
export function makeFormProxy(initial) {
|
|
21
|
+
// Deep-copy fields so hooks can mutate without leaking to the original.
|
|
22
|
+
const fields = initial.fields.map((f) => ({
|
|
23
|
+
...f,
|
|
24
|
+
validators: [...(f.validators ?? [])],
|
|
25
|
+
}));
|
|
26
|
+
const hiddenSet = new Set();
|
|
27
|
+
return {
|
|
28
|
+
get fields() {
|
|
29
|
+
return fields;
|
|
30
|
+
},
|
|
31
|
+
addField({ after, before, field }) {
|
|
32
|
+
if (!field?.name) {
|
|
33
|
+
console.warn('[form-alter] addField: field.name is required');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (fields.some((f) => f.name === field.name)) {
|
|
37
|
+
console.warn(`[form-alter] addField: field "${field.name}" already exists — use mutate-by-name instead`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const target = after ?? before;
|
|
41
|
+
const cloned = { ...field, validators: [...(field.validators ?? [])] };
|
|
42
|
+
if (target) {
|
|
43
|
+
const idx = fields.findIndex((f) => f.name === target);
|
|
44
|
+
if (idx < 0) {
|
|
45
|
+
// Anchor not found → push to end. Warn so the author knows.
|
|
46
|
+
console.warn(`[form-alter] addField: anchor "${target}" not found; appending "${field.name}" at end`);
|
|
47
|
+
fields.push(cloned);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const at = after ? idx + 1 : idx;
|
|
51
|
+
fields.splice(at, 0, cloned);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
fields.push(cloned);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
hideField(name) {
|
|
59
|
+
hiddenSet.add(name);
|
|
60
|
+
},
|
|
61
|
+
reorder(order) {
|
|
62
|
+
// Reorder only what's in `order`. Fields not mentioned keep their
|
|
63
|
+
// original relative order, appended after the reordered block.
|
|
64
|
+
const byName = new Map(fields.map((f) => [f.name, f]));
|
|
65
|
+
const reorderedKnown = order.map((n) => byName.get(n)).filter(Boolean);
|
|
66
|
+
const remaining = fields.filter((f) => !order.includes(f.name));
|
|
67
|
+
fields.length = 0;
|
|
68
|
+
fields.push(...reorderedKnown, ...remaining);
|
|
69
|
+
},
|
|
70
|
+
addValidator(fieldName, validator) {
|
|
71
|
+
const f = fields.find((x) => x.name === fieldName);
|
|
72
|
+
if (!f) {
|
|
73
|
+
console.warn(`[form-alter] addValidator: field "${fieldName}" not found`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
f.validators = [...(f.validators ?? []), validator];
|
|
77
|
+
},
|
|
78
|
+
commit() {
|
|
79
|
+
// Materialize hidden state. `hidden: true` keeps the field in the
|
|
80
|
+
// schema so server-side defaults still apply; renderers skip rendering.
|
|
81
|
+
const out = fields.map((f) => (hiddenSet.has(f.name) ? { ...f, hidden: true } : f));
|
|
82
|
+
return { ...initial, fields: out };
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run every registered hook against the schema and return the result.
|
|
88
|
+
* Exception-safe: a throwing hook is logged and skipped, the rest still run.
|
|
89
|
+
*/
|
|
90
|
+
export function applyFormAlterHooks(hooks, schema, ctx = {}) {
|
|
91
|
+
if (hooks.length === 0)
|
|
92
|
+
return schema;
|
|
93
|
+
const proxy = makeFormProxy(schema);
|
|
94
|
+
for (const hook of hooks) {
|
|
95
|
+
try {
|
|
96
|
+
hook(proxy, ctx);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error('[form-alter] hook threw:', err);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return proxy.commit();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sort slot contributions deterministically: priority asc (lower first),
|
|
106
|
+
* then registration order (stable sort).
|
|
107
|
+
*/
|
|
108
|
+
export function sortSlotContributions(items) {
|
|
109
|
+
// We rely on Array.prototype.sort being stable (TC39 since 2019).
|
|
110
|
+
return items.slice().sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
111
|
+
}
|
|
112
|
+
export { removeOwnerFromSlots, registerOwnedOnSlot, } from './slot-owner-registry.js';
|
|
113
|
+
function getStudioGlobal() {
|
|
114
|
+
if (typeof window === 'undefined')
|
|
115
|
+
return null;
|
|
116
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
117
|
+
const g = window.__zveltio;
|
|
118
|
+
if (!g) {
|
|
119
|
+
console.warn('[zveltio/sdk/studio] window.__zveltio is not installed. Is the bundle running inside Studio?');
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return g;
|
|
123
|
+
}
|
|
124
|
+
/** Register a top-level Studio page contributed by this extension. */
|
|
125
|
+
export function registerRoute(route) {
|
|
126
|
+
getStudioGlobal()?.registerRoute(route);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Register a Svelte component into a named composition slot (S3-03).
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* import { registerSlot } from '@zveltio/sdk/studio';
|
|
133
|
+
* import RevenueWidget from './widgets/RevenueWidget.svelte';
|
|
134
|
+
*
|
|
135
|
+
* registerSlot('dashboard.widgets', {
|
|
136
|
+
* component: RevenueWidget,
|
|
137
|
+
* priority: 10,
|
|
138
|
+
* visible: (ctx) => (ctx.user as any)?.roles?.includes('finance'),
|
|
139
|
+
* });
|
|
140
|
+
*/
|
|
141
|
+
export function registerSlot(name, contribution) {
|
|
142
|
+
getStudioGlobal()?.registerSlot(name, contribution);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Register a Drupal-style form-alter hook (S3-02).
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* import { registerFormAlter } from '@zveltio/sdk/studio';
|
|
149
|
+
*
|
|
150
|
+
* registerFormAlter('core:user-edit', (form) => {
|
|
151
|
+
* form.addField({ after: 'email', field: { name: 'phone', type: 'tel' } });
|
|
152
|
+
* form.hideField('legacy_pin');
|
|
153
|
+
* });
|
|
154
|
+
*/
|
|
155
|
+
export function registerFormAlter(formId, hook) {
|
|
156
|
+
getStudioGlobal()?.registerFormAlter(formId, hook);
|
|
157
|
+
}
|
|
158
|
+
/** Register a custom Studio field type contributed by this extension. */
|
|
159
|
+
export function registerFieldType(ft) {
|
|
160
|
+
getStudioGlobal()?.registerFieldType(ft);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Register a custom preview handler for asset URLs / MIME types.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* import { registerAssetPreview } from '@zveltio/sdk/studio';
|
|
167
|
+
* import PdfPreview from './PdfPreview.svelte';
|
|
168
|
+
*
|
|
169
|
+
* registerAssetPreview({
|
|
170
|
+
* match: (a) => a.mimeType === 'application/pdf',
|
|
171
|
+
* component: PdfPreview,
|
|
172
|
+
* });
|
|
173
|
+
*/
|
|
174
|
+
export function registerAssetPreview(handler) {
|
|
175
|
+
getStudioGlobal()?.registerAssetPreview(handler);
|
|
176
|
+
}
|
|
177
|
+
/** Engine base URL — pre-installed by Studio for cross-origin fetches. */
|
|
178
|
+
export function getEngineUrl() {
|
|
179
|
+
if (typeof window === 'undefined')
|
|
180
|
+
return '';
|
|
181
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
182
|
+
return window.__ZVELTIO_ENGINE_URL__ || getStudioGlobal()?.engineUrl || '';
|
|
183
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SlotContribution } from '../extension/index.js';
|
|
2
|
+
/** Owner tag set by compile-time `contribute.ts` modules; absent on legacy window.__zveltio calls. */
|
|
3
|
+
export type OwnedSlotContribution = SlotContribution & {
|
|
4
|
+
owner?: string;
|
|
5
|
+
};
|
|
6
|
+
/** Remove every contribution registered by `owner` across all slot names. */
|
|
7
|
+
export declare function removeOwnerFromSlots(slots: Record<string, OwnedSlotContribution[]>, owner: string): Record<string, OwnedSlotContribution[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Register (or replace) a single owner's contribution on one slot.
|
|
10
|
+
* Prior entries from the same owner on that slot are dropped first.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerOwnedOnSlot(slots: Record<string, OwnedSlotContribution[]>, owner: string, slotName: string, contribution: SlotContribution): Record<string, OwnedSlotContribution[]>;
|
|
13
|
+
//# sourceMappingURL=slot-owner-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot-owner-registry.d.ts","sourceRoot":"","sources":["../../src/studio/slot-owner-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,sGAAsG;AACtG,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,EAC9C,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAOzC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,EAC9C,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,gBAAgB,GAC7B,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAMzC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Remove every contribution registered by `owner` across all slot names. */
|
|
2
|
+
export function removeOwnerFromSlots(slots, owner) {
|
|
3
|
+
const out = {};
|
|
4
|
+
for (const [name, list] of Object.entries(slots)) {
|
|
5
|
+
const kept = list.filter((c) => c.owner !== owner);
|
|
6
|
+
if (kept.length > 0)
|
|
7
|
+
out[name] = kept;
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register (or replace) a single owner's contribution on one slot.
|
|
13
|
+
* Prior entries from the same owner on that slot are dropped first.
|
|
14
|
+
*/
|
|
15
|
+
export function registerOwnedOnSlot(slots, owner, slotName, contribution) {
|
|
16
|
+
const out = { ...slots };
|
|
17
|
+
const prev = out[slotName] ?? [];
|
|
18
|
+
const kept = prev.filter((c) => c.owner !== owner);
|
|
19
|
+
out[slotName] = [...kept, { ...contribution, owner }];
|
|
20
|
+
return out;
|
|
21
|
+
}
|
package/dist/svelte.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ```svelte
|
|
7
7
|
* <script lang="ts">
|
|
8
8
|
* import { SyncManager } from '@zveltio/sdk';
|
|
9
|
-
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk
|
|
9
|
+
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk';
|
|
10
10
|
*
|
|
11
11
|
* let todos = $state<any[]>([]);
|
|
12
12
|
* const unsub = useSyncCollection(sync, 'todos', (records) => { todos = records; });
|
package/dist/svelte.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"svelte.d.ts","sourceRoot":"","sources":["../src/svelte.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,UAAU,EAAE,MAAM,EAElB,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,GAC/B,MAAM,IAAI,CAGZ;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,EACnF,UAAU,SAAO,GAChB,MAAM,IAAI,CAeZ"}
|
package/dist/svelte.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ```svelte
|
|
7
7
|
* <script lang="ts">
|
|
8
8
|
* import { SyncManager } from '@zveltio/sdk';
|
|
9
|
-
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk
|
|
9
|
+
* import { useSyncCollection, useSyncStatus } from '@zveltio/sdk';
|
|
10
10
|
*
|
|
11
11
|
* let todos = $state<any[]>([]);
|
|
12
12
|
* const unsub = useSyncCollection(sync, 'todos', (records) => { todos = records; });
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* Calls `setter` immediately with current state and on each update.
|
|
24
24
|
* Returns the unsubscribe function.
|
|
25
25
|
*/
|
|
26
|
-
export function useSyncCollection(sync, collection,
|
|
26
|
+
export function useSyncCollection(sync, collection,
|
|
27
|
+
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
28
|
+
setter) {
|
|
27
29
|
const col = sync.collection(collection);
|
|
28
30
|
return col.subscribe(setter);
|
|
29
31
|
}
|
package/dist/sync-manager.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export declare class SyncManager {
|
|
|
20
20
|
private syncTimer;
|
|
21
21
|
private isOnline;
|
|
22
22
|
private isSyncing;
|
|
23
|
+
/** Set by `stop()`; `start()` checks it after every await it makes. */
|
|
24
|
+
private stopped;
|
|
25
|
+
private readonly onOnline;
|
|
26
|
+
private readonly onOffline;
|
|
23
27
|
private listeners;
|
|
24
28
|
constructor(client: ZveltioClient, config?: SyncManagerConfig);
|
|
25
29
|
start(realtimeUrl?: string): Promise<void>;
|
|
@@ -32,22 +36,22 @@ export declare class SyncManager {
|
|
|
32
36
|
collection(name: string): {
|
|
33
37
|
/** List records — reads LOCAL instantly */
|
|
34
38
|
list: () => Promise<{
|
|
35
|
-
_syncStatus: "
|
|
39
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
36
40
|
id: string;
|
|
37
41
|
}[]>;
|
|
38
42
|
/** Get one record — reads LOCAL instantly */
|
|
39
43
|
get: (id: string) => Promise<{
|
|
40
|
-
_syncStatus: "
|
|
44
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
41
45
|
id: string;
|
|
42
46
|
} | null>;
|
|
43
47
|
/** Create — writes LOCAL + queues sync */
|
|
44
48
|
create: (data: Record<string, any>) => Promise<{
|
|
45
|
-
_syncStatus: "
|
|
49
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
46
50
|
id: string;
|
|
47
51
|
}>;
|
|
48
52
|
/** Update — writes LOCAL + queues sync */
|
|
49
53
|
update: (id: string, data: Record<string, any>) => Promise<{
|
|
50
|
-
_syncStatus: "
|
|
54
|
+
_syncStatus: "conflict" | "synced" | "pending";
|
|
51
55
|
id: string;
|
|
52
56
|
}>;
|
|
53
57
|
/** Delete — soft delete LOCAL + queues sync */
|
|
@@ -62,12 +66,53 @@ export declare class SyncManager {
|
|
|
62
66
|
/** Force sync now (non-blocking) */
|
|
63
67
|
syncNow(): Promise<void>;
|
|
64
68
|
private notifyListeners;
|
|
69
|
+
/**
|
|
70
|
+
* Open the local store without starting background sync.
|
|
71
|
+
*
|
|
72
|
+
* `start()` opens the store, attaches online/offline listeners, connects
|
|
73
|
+
* realtime and installs a periodic timer. A caller driving `pull()` and
|
|
74
|
+
* `push()` explicitly — the `OfflineProvider` contract in `offline/` — wants
|
|
75
|
+
* the store and none of the rest, and a timer firing `syncNow()` underneath it
|
|
76
|
+
* makes "how many operations did that push send" unanswerable.
|
|
77
|
+
*/
|
|
78
|
+
open(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Pull rows for the named collections from the server into the local store.
|
|
81
|
+
*
|
|
82
|
+
* There was no way to do this. Records reached the local store only through
|
|
83
|
+
* realtime events, one at a time, which means a client that was offline while
|
|
84
|
+
* a row was created never learns it exists: it missed the event and nothing
|
|
85
|
+
* ever asks the server what it has. `syncNow()` is push-only despite the name.
|
|
86
|
+
*
|
|
87
|
+
* Reads `POST /api/sync/pull`, which returns what changed since the cursors
|
|
88
|
+
* kept in the local store, deletes included. Paging `list()` instead — what
|
|
89
|
+
* this did before — never removed anything: a row deleted on the server
|
|
90
|
+
* stayed in every local store that had pulled it.
|
|
91
|
+
*
|
|
92
|
+
* A collection pulled for the first time, or one the server answers with
|
|
93
|
+
* `resync`, loses its synced local rows before the page is applied; local
|
|
94
|
+
* edits not yet pushed stay. `/api/sync` takes sessions only, so a client
|
|
95
|
+
* authenticated by an API key (403) falls back to paging `list()`, without
|
|
96
|
+
* deletes.
|
|
97
|
+
*/
|
|
98
|
+
pull(collections: string[], pageSize?: number): Promise<number>;
|
|
99
|
+
private pullChanges;
|
|
100
|
+
/** Pages through `list()`; stops on the first page that comes back short. */
|
|
101
|
+
private pullPages;
|
|
65
102
|
/** Status: pending operations count, conflicts count */
|
|
66
103
|
getStatus(): Promise<{
|
|
67
104
|
pending: number;
|
|
68
105
|
conflicts: number;
|
|
69
106
|
isOnline: boolean;
|
|
70
107
|
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Delete everything the local store holds — records, pending writes, blobs,
|
|
110
|
+
* pull positions — so the next user of this browser neither sees this user's
|
|
111
|
+
* data nor sends this user's queued writes under their own session. Call it
|
|
112
|
+
* after sign-out (a sync started then is refused and stores nothing); call
|
|
113
|
+
* `syncNow()` before sign-out to push what is pending, which is lost otherwise.
|
|
114
|
+
*/
|
|
115
|
+
clearLocalData(): Promise<void>;
|
|
71
116
|
stop(): Promise<void>;
|
|
72
117
|
}
|
|
73
118
|
//# sourceMappingURL=sync-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../src/sync-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../src/sync-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAUjD,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IAEpD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC9C,mHAAmH;IACnH,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;CAC7C;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAa;IAC1B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,QAAQ,CAAgC;IAChD,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,SAAS,CAA+C;IAChE,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAAkB;IACnC,uEAAuE;IACvE,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGvB;IACF,OAAO,CAAC,QAAQ,CAAC,SAAS,CAExB;IAEF,OAAO,CAAC,SAAS,CAAyD;gBAE9D,MAAM,EAAE,aAAa,EAAE,MAAM,GAAE,iBAAsB;IAY3D,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BhD;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM;QAEnB,2CAA2C;;;;;QAU3C,6CAA6C;kBAC7B,MAAM;;;;QAUtB,0CAA0C;uBAErB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;QAYxC,0CAA0C;qBAEvB,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;QAapD,+CAA+C;qBAC5B,MAAM;QAMzB,qDAAqD;8BAE/B,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI;QA8C9C,8CAA8C;;QAK9C,kCAAkC;8BAEN,MAAM,gBAAgB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;IAQzE,oCAAoC;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAwGhB,eAAe;IAmB7B;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;;;;;;;;;;;;;;;;OAkBG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,SAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAgBpD,WAAW;IAoCzB,6EAA6E;YAC/D,SAAS;IAsBvB,wDAAwD;IAClD,SAAS,IAAI,OAAO,CAAC;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;IAUF;;;;;;OAMG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAY5B"}
|