@eskais/app-sdk 0.0.0-stage → 0.1.0

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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -2
  3. package/dist/action/action.d.ts +74 -0
  4. package/dist/action/action.js +106 -0
  5. package/dist/cli/cli.d.ts +2 -0
  6. package/dist/cli/cli.js +51 -0
  7. package/dist/cli/routes.d.ts +17 -0
  8. package/dist/cli/routes.js +36 -0
  9. package/dist/core/assume.d.ts +1 -0
  10. package/dist/core/assume.js +8 -0
  11. package/dist/core/constants.d.ts +302 -0
  12. package/dist/core/constants.js +156 -0
  13. package/dist/core/contracts.d.ts +100 -0
  14. package/dist/core/contracts.js +3 -0
  15. package/dist/core/data-labels.d.ts +196 -0
  16. package/dist/core/data-labels.js +345 -0
  17. package/dist/core/errors.d.ts +46 -0
  18. package/dist/core/errors.js +166 -0
  19. package/dist/core/guards.d.ts +9 -0
  20. package/dist/core/guards.js +14 -0
  21. package/dist/core/refusal.d.ts +30 -0
  22. package/dist/core/refusal.js +53 -0
  23. package/dist/draft/draft.d.ts +36 -0
  24. package/dist/draft/draft.js +87 -0
  25. package/dist/export/csv.d.ts +25 -0
  26. package/dist/export/csv.js +59 -0
  27. package/dist/import/csv-parse.d.ts +11 -0
  28. package/dist/import/csv-parse.js +70 -0
  29. package/dist/import/import.d.ts +102 -0
  30. package/dist/import/import.js +263 -0
  31. package/dist/index.d.ts +31 -0
  32. package/dist/index.js +30 -0
  33. package/dist/navigation/nav.d.ts +119 -0
  34. package/dist/navigation/nav.js +278 -0
  35. package/dist/navigation/router.d.ts +81 -0
  36. package/dist/navigation/router.js +249 -0
  37. package/dist/navigation/shortcuts.d.ts +37 -0
  38. package/dist/navigation/shortcuts.js +93 -0
  39. package/dist/next/index.d.ts +3 -0
  40. package/dist/next/index.js +3 -0
  41. package/dist/next/screen-hydration.d.ts +12 -0
  42. package/dist/next/screen-hydration.js +26 -0
  43. package/dist/next/screen.d.ts +25 -0
  44. package/dist/next/screen.js +44 -0
  45. package/dist/next/server/handler.d.ts +39 -0
  46. package/dist/next/server/handler.js +190 -0
  47. package/dist/next/server/index.d.ts +5 -0
  48. package/dist/next/server/index.js +5 -0
  49. package/dist/next/server/page.d.ts +57 -0
  50. package/dist/next/server/page.js +103 -0
  51. package/dist/next/server/prefetch.d.ts +29 -0
  52. package/dist/next/server/prefetch.js +97 -0
  53. package/dist/next/server/session.d.ts +12 -0
  54. package/dist/next/server/session.js +10 -0
  55. package/dist/next/use-next-router.d.ts +21 -0
  56. package/dist/next/use-next-router.js +104 -0
  57. package/dist/react/data-layer.d.ts +31 -0
  58. package/dist/react/data-layer.js +31 -0
  59. package/dist/react/hooks/use-action.d.ts +12 -0
  60. package/dist/react/hooks/use-action.js +67 -0
  61. package/dist/react/hooks/use-better-auth.d.ts +12 -0
  62. package/dist/react/hooks/use-better-auth.js +11 -0
  63. package/dist/react/hooks/use-draft.d.ts +5 -0
  64. package/dist/react/hooks/use-draft.js +17 -0
  65. package/dist/react/hooks/use-nav.d.ts +17 -0
  66. package/dist/react/hooks/use-nav.js +34 -0
  67. package/dist/react/hooks/use-resource.d.ts +69 -0
  68. package/dist/react/hooks/use-resource.js +218 -0
  69. package/dist/react/hooks/use-view.d.ts +6 -0
  70. package/dist/react/hooks/use-view.js +24 -0
  71. package/dist/react/index.d.ts +8 -0
  72. package/dist/react/index.js +8 -0
  73. package/dist/react/keys.d.ts +51 -0
  74. package/dist/react/keys.js +67 -0
  75. package/dist/resource/form-schema.d.ts +11 -0
  76. package/dist/resource/form-schema.js +51 -0
  77. package/dist/resource/relations.d.ts +99 -0
  78. package/dist/resource/relations.js +194 -0
  79. package/dist/resource/resource-relations.d.ts +44 -0
  80. package/dist/resource/resource-relations.js +141 -0
  81. package/dist/resource/resource-schema.d.ts +9 -0
  82. package/dist/resource/resource-schema.js +73 -0
  83. package/dist/resource/resource-types.d.ts +281 -0
  84. package/dist/resource/resource-types.js +1 -0
  85. package/dist/resource/resource.d.ts +11 -0
  86. package/dist/resource/resource.js +354 -0
  87. package/dist/resource/schema.d.ts +57 -0
  88. package/dist/resource/schema.js +115 -0
  89. package/dist/services/from-page-source.d.ts +15 -0
  90. package/dist/services/from-page-source.js +27 -0
  91. package/dist/services/memory-query.d.ts +8 -0
  92. package/dist/services/memory-query.js +165 -0
  93. package/dist/services/memory-service.d.ts +33 -0
  94. package/dist/services/memory-service.js +291 -0
  95. package/dist/services/rest-service.d.ts +62 -0
  96. package/dist/services/rest-service.js +220 -0
  97. package/dist/services/rng.d.ts +9 -0
  98. package/dist/services/rng.js +22 -0
  99. package/dist/services/spring-service.d.ts +58 -0
  100. package/dist/services/spring-service.js +132 -0
  101. package/dist/session/better-auth.d.ts +83 -0
  102. package/dist/session/better-auth.js +86 -0
  103. package/dist/session/session.d.ts +45 -0
  104. package/dist/session/session.js +36 -0
  105. package/dist/view/preferences.d.ts +35 -0
  106. package/dist/view/preferences.js +93 -0
  107. package/dist/view/view-types.d.ts +122 -0
  108. package/dist/view/view-types.js +1 -0
  109. package/dist/view/view-url.d.ts +7 -0
  110. package/dist/view/view-url.js +54 -0
  111. package/dist/view/view.d.ts +4 -0
  112. package/dist/view/view.js +392 -0
  113. package/package.json +85 -4
@@ -0,0 +1,54 @@
1
+ import { assumeType } from "../core/assume.js";
2
+ import { SortDirection } from "../core/constants.js";
3
+ import { isBoolean, isNumber, isOneOf, isRecord, isString, valuesOf } from "../core/guards.js";
4
+ import { isActive } from "../services/memory-query.js";
5
+ function canonical(value) {
6
+ if (Array.isArray(value))
7
+ return value.map(canonical);
8
+ if (!isRecord(value))
9
+ return value;
10
+ return Object.fromEntries(Object.keys(value)
11
+ .toSorted()
12
+ .map((key) => [key, canonical(value[key])]));
13
+ }
14
+ export function same(a, b) {
15
+ return a === b || JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
16
+ }
17
+ export function compact(filter) {
18
+ const entries = Object.entries(filter).filter(([, value]) => isActive(value));
19
+ // Workaround: dropping unset keys from a `Partial<F>` leaves a `Partial<F>`, which `Object.fromEntries` can't type.
20
+ return assumeType(Object.fromEntries(entries));
21
+ }
22
+ const sortDirections = valuesOf(SortDirection);
23
+ export function encodeSort(sort) {
24
+ return sort.map((spec) => `${spec.field}.${spec.direction}`).join(",");
25
+ }
26
+ export function decodeSort(raw) {
27
+ if (raw === null)
28
+ return undefined;
29
+ return raw
30
+ .split(",")
31
+ .map((part) => {
32
+ const at = part.lastIndexOf(".");
33
+ const direction = part.slice(at + 1);
34
+ return at > 0 && isOneOf(sortDirections, direction) ? { field: part.slice(0, at), direction } : undefined;
35
+ })
36
+ .filter((spec) => spec !== undefined);
37
+ }
38
+ export function encodeValue(value) {
39
+ if (Array.isArray(value))
40
+ return value.map((entry) => (isString(entry) ? entry : JSON.stringify(entry)));
41
+ if (isString(value))
42
+ return [value];
43
+ if (isNumber(value) || isBoolean(value))
44
+ return [String(value)];
45
+ return [JSON.stringify(value)];
46
+ }
47
+ export function parseJson(raw) {
48
+ try {
49
+ return JSON.parse(raw);
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
@@ -0,0 +1,4 @@
1
+ import type { Resource } from "../resource/resource.js";
2
+ import type { View, ViewOptions } from "./view-types.js";
3
+ export type * from "./view-types.js";
4
+ export declare function defineView<T, Id, F>(resource: Resource<T, Id, F>, options?: ViewOptions<NoInfer<F>>): View<T, F, Id>;
@@ -0,0 +1,392 @@
1
+ import { assumeType } from "../core/assume.js";
2
+ import { ActionTargetKind, FilterKind, SelectionKind, SelectionMode, TargetKind } from "../core/constants.js";
3
+ import { isRecord, isString } from "../core/guards.js";
4
+ import { isActive } from "../services/memory-query.js";
5
+ import { localViews } from "./preferences.js";
6
+ import { compact, decodeSort, encodeSort, encodeValue, parseJson, same } from "./view-url.js";
7
+ import { refuse } from "../core/refusal.js";
8
+ import { joinPath } from "../navigation/router.js";
9
+ export function defineView(resource, options = {}) {
10
+ const prefix = options.urlPrefix ?? "";
11
+ const scopes = options.scopes ?? [];
12
+ const presets = options.presets ?? [];
13
+ const selectionMode = options.selection ?? SelectionMode.multiple;
14
+ const store = options.store ?? localViews();
15
+ const preferences = options.preferences;
16
+ const defaultFilter = () => {
17
+ const entries = resource
18
+ .filters()
19
+ .flatMap((definition) => (definition.default === undefined ? [] : [[definition.key, definition.default]]));
20
+ // Workaround: the declared defaults are values of `F`'s keys.
21
+ return assumeType(Object.fromEntries(entries));
22
+ };
23
+ const initial = {
24
+ filter: defaultFilter(),
25
+ search: "",
26
+ sort: resource.defaultSort,
27
+ page: 1,
28
+ size: options.size ?? 25,
29
+ scope: scopes[0]?.id,
30
+ };
31
+ let snapshot = { state: initial, selection: { kind: SelectionKind.ids, ids: [] }, views: [] };
32
+ let saves = 0;
33
+ const listeners = new Set();
34
+ const emit = () => {
35
+ for (const listener of listeners)
36
+ listener();
37
+ };
38
+ const write = (next) => {
39
+ snapshot = { ...snapshot, ...next };
40
+ emit();
41
+ };
42
+ function setState(patch) {
43
+ const current = snapshot.state;
44
+ const next = { ...current, ...patch };
45
+ if (patch.filter !== undefined)
46
+ next.filter = compact(patch.filter);
47
+ const narrowed = (patch.filter !== undefined && !same(patch.filter, current.filter)) ||
48
+ (patch.search !== undefined && patch.search !== current.search) ||
49
+ (patch.scope !== undefined && patch.scope !== current.scope);
50
+ const resets = narrowed ||
51
+ (patch.sort !== undefined && !same(patch.sort, current.sort)) ||
52
+ (patch.size !== undefined && patch.size !== current.size);
53
+ if (resets && patch.page === undefined)
54
+ next.page = 1;
55
+ if (same(next, current))
56
+ return;
57
+ const selection = narrowed && snapshot.selection.kind === SelectionKind.query
58
+ ? { kind: SelectionKind.ids, ids: [] }
59
+ : snapshot.selection;
60
+ write({ state: next, selection });
61
+ }
62
+ const filterKeys = () => new Set(resource.filters().map((definition) => definition.key));
63
+ function scopeFilter() {
64
+ return scopes.find((scope) => scope.id === snapshot.state.scope)?.filter ?? {};
65
+ }
66
+ function filter() {
67
+ return compact({ ...options.baseFilter, ...scopeFilter(), ...snapshot.state.filter });
68
+ }
69
+ function toParams(state, current) {
70
+ const params = new URLSearchParams();
71
+ const owned = (name) => name.startsWith(prefix) && ownedNames.has(name.slice(prefix.length));
72
+ for (const [name, value] of current)
73
+ if (!owned(name))
74
+ params.append(name, value);
75
+ if (state.search !== "")
76
+ params.set(`${prefix}q`, state.search);
77
+ if (!same(state.sort, resource.defaultSort) && state.sort.length > 0)
78
+ params.set(`${prefix}sort`, encodeSort(state.sort));
79
+ if (state.page !== 1)
80
+ params.set(`${prefix}page`, String(state.page));
81
+ if (state.size !== initial.size)
82
+ params.set(`${prefix}size`, String(state.size));
83
+ if (state.scope !== undefined && state.scope !== initial.scope)
84
+ params.set(`${prefix}scope`, state.scope);
85
+ if (state.view !== undefined)
86
+ params.set(`${prefix}view`, state.view);
87
+ if (state.columns)
88
+ params.set(`${prefix}cols`, state.columns.join(","));
89
+ for (const [key, value] of Object.entries(state.filter)) {
90
+ if (!isActive(value) || same(value, defaultOf(key)))
91
+ continue;
92
+ for (const entry of encodeValue(value))
93
+ params.append(`${prefix}${key}`, entry);
94
+ }
95
+ return params;
96
+ }
97
+ function defaultOf(key) {
98
+ const defaults = initial.filter;
99
+ return isRecord(defaults) ? defaults[key] : undefined;
100
+ }
101
+ const ownedNames = new Set(["q", "sort", "page", "size", "scope", "view", "cols", ...filterKeys()]);
102
+ function fromParams(params) {
103
+ const read = (name) => params.get(`${prefix}${name}`);
104
+ const filterEntries = [];
105
+ for (const definition of resource.filters()) {
106
+ const values = params.getAll(`${prefix}${definition.key}`);
107
+ const first = values[0];
108
+ if (first === undefined) {
109
+ if (definition.default !== undefined)
110
+ filterEntries.push([definition.key, definition.default]);
111
+ continue;
112
+ }
113
+ if (definition.kind === FilterKind.multiSelect)
114
+ filterEntries.push([definition.key, values]);
115
+ else if (definition.kind === FilterKind.boolean)
116
+ filterEntries.push([definition.key, first === "true"]);
117
+ else if (definition.kind === FilterKind.dateRange || definition.kind === FilterKind.numberRange)
118
+ filterEntries.push([definition.key, parseJson(first)]);
119
+ else
120
+ filterEntries.push([definition.key, first]);
121
+ }
122
+ const page = Number(read("page") ?? "1");
123
+ const size = Number(read("size") ?? String(initial.size));
124
+ const scope = read("scope");
125
+ const columns = read("cols");
126
+ return {
127
+ // Workaround: the URL's values are read by each declared filter's kind, so they are values of `F`'s keys.
128
+ filter: assumeType(Object.fromEntries(filterEntries)),
129
+ search: read("q") ?? "",
130
+ sort: decodeSort(read("sort")) ?? resource.defaultSort,
131
+ page: Number.isInteger(page) && page > 0 ? page : 1,
132
+ size: Number.isInteger(size) && size > 0 ? size : initial.size,
133
+ scope: scope !== null && scopes.some((entry) => entry.id === scope) ? scope : initial.scope,
134
+ view: read("view") ?? undefined,
135
+ columns: columns === null ? snapshot.state.columns : columns.split(",").filter(Boolean),
136
+ };
137
+ }
138
+ if (options.search !== undefined && options.url !== false)
139
+ snapshot = { ...snapshot, state: fromParams(new URLSearchParams(options.search)) };
140
+ const selection = {
141
+ get: () => snapshot.selection,
142
+ select(ids) {
143
+ const chosen = selectionMode === SelectionMode.single ? ids.slice(-1) : [...new Set(ids)];
144
+ write({ selection: { kind: SelectionKind.ids, ids: chosen } });
145
+ },
146
+ toggle(id, selected) {
147
+ const current = snapshot.selection;
148
+ if (current.kind === SelectionKind.query) {
149
+ const except = new Set(current.except);
150
+ if (selected ?? except.has(id))
151
+ except.delete(id);
152
+ else
153
+ except.add(id);
154
+ write({ selection: { kind: SelectionKind.query, except: [...except] } });
155
+ return;
156
+ }
157
+ const ids = new Set(selectionMode === SelectionMode.single ? [] : current.ids);
158
+ const on = selected ?? !current.ids.includes(id);
159
+ if (on)
160
+ ids.add(id);
161
+ else
162
+ ids.delete(id);
163
+ write({ selection: { kind: SelectionKind.ids, ids: [...ids] } });
164
+ },
165
+ selectAllMatching() {
166
+ write({ selection: { kind: SelectionKind.query, except: [] } });
167
+ },
168
+ clear() {
169
+ write({ selection: { kind: SelectionKind.ids, ids: [] } });
170
+ },
171
+ count(total) {
172
+ const current = snapshot.selection;
173
+ if (current.kind === SelectionKind.ids)
174
+ return current.ids.length;
175
+ return total === undefined ? undefined : Math.max(0, total - current.except.length);
176
+ },
177
+ has(id) {
178
+ const current = snapshot.selection;
179
+ return current.kind === SelectionKind.ids ? current.ids.includes(id) : !current.except.includes(id);
180
+ },
181
+ target() {
182
+ const current = snapshot.selection;
183
+ if (current.kind === SelectionKind.ids)
184
+ return { kind: TargetKind.ids, ids: current.ids };
185
+ const search = snapshot.state.search;
186
+ return { kind: TargetKind.query, filter: filter(), ...(search === "" ? {} : { search }), except: current.except };
187
+ },
188
+ actionTarget(rows) {
189
+ const current = snapshot.selection;
190
+ if (current.kind === SelectionKind.query) {
191
+ const search = snapshot.state.search;
192
+ return {
193
+ kind: ActionTargetKind.query,
194
+ filter: filter(),
195
+ ...(search === "" ? {} : { search }),
196
+ except: current.except,
197
+ };
198
+ }
199
+ const wanted = new Set(current.ids);
200
+ return { kind: ActionTargetKind.rows, rows: rows.filter((row) => wanted.has(resource.idKey(resource.idOf(row)))) };
201
+ },
202
+ };
203
+ const findView = (id) => snapshot.views.find((view) => view.id === id) ?? presets.find((preset) => preset.id === id);
204
+ const viewState = (state) => ({
205
+ ...initial,
206
+ ...state,
207
+ filter: compact(state.filter ?? {}),
208
+ page: 1,
209
+ });
210
+ const differs = (state, from) => !same(compact(state.filter), compact(from.filter)) ||
211
+ state.search !== from.search ||
212
+ !same(state.sort, from.sort) ||
213
+ state.scope !== from.scope ||
214
+ !same(state.columns ?? null, from.columns ?? null);
215
+ const savedState = () => {
216
+ const { filter: own, sort, columns, scope, search } = snapshot.state;
217
+ return {
218
+ filter: own,
219
+ sort,
220
+ search,
221
+ ...(columns ? { columns } : {}),
222
+ ...(scope === undefined ? {} : { scope }),
223
+ };
224
+ };
225
+ const storeView = async (next, context) => {
226
+ const saved = await store.save(next, context);
227
+ write({ views: snapshot.views.map((view) => (view.id === saved.id ? saved : view)) });
228
+ return saved;
229
+ };
230
+ const savedView = (id) => {
231
+ const found = snapshot.views.find((view) => view.id === id);
232
+ if (!found)
233
+ throw new Error(`No saved view named "${id}".`);
234
+ return found;
235
+ };
236
+ const views = {
237
+ list: () => snapshot.views,
238
+ async load(context) {
239
+ const loaded = await store.list(resource.key, context);
240
+ write({ views: loaded });
241
+ const chosen = loaded.find((view) => view.isDefault === true);
242
+ if (chosen && snapshot.state.view === undefined && !differs(snapshot.state, initial))
243
+ views.apply(chosen.id);
244
+ return loaded;
245
+ },
246
+ async save(label, context, extra = {}) {
247
+ const saved = await store.save({
248
+ id: `${resource.key}-${Date.now().toString(36)}${(saves++).toString(36)}`,
249
+ label,
250
+ resource: resource.key,
251
+ state: savedState(),
252
+ ...extra,
253
+ }, context);
254
+ write({ views: [...snapshot.views.filter((view) => view.id !== saved.id), saved] });
255
+ setState({ view: saved.id });
256
+ return saved;
257
+ },
258
+ apply(id) {
259
+ const found = findView(id);
260
+ if (!found)
261
+ return refuse(`no view named "${id}"`);
262
+ setState({ ...viewState(found.state), view: id });
263
+ return true;
264
+ },
265
+ current: () => snapshot.state.view,
266
+ modified() {
267
+ const id = snapshot.state.view;
268
+ const found = id === undefined ? undefined : findView(id);
269
+ return found !== undefined && differs(snapshot.state, viewState(found.state));
270
+ },
271
+ checkSaved(id) {
272
+ if (snapshot.views.some((view) => view.id === id))
273
+ return true;
274
+ if (presets.some((preset) => preset.id === id))
275
+ return refuse(`"${id}" is a preset from the code`);
276
+ return refuse(`no view named "${id}"`);
277
+ },
278
+ async update(id, context) {
279
+ const saved = await storeView({ ...savedView(id), state: savedState() }, context);
280
+ setState({ view: saved.id });
281
+ return saved;
282
+ },
283
+ rename: (id, label, context) => storeView({ ...savedView(id), label }, context),
284
+ async setDefault(id, context) {
285
+ if (id !== undefined)
286
+ savedView(id);
287
+ const changed = snapshot.views.filter((view) => (view.isDefault === true) !== (view.id === id));
288
+ for (const view of changed) {
289
+ // oxlint-disable-next-line no-await-in-loop -- a store may keep one file per resource, so writes go one by one
290
+ await storeView({ ...view, isDefault: view.id === id }, context);
291
+ }
292
+ },
293
+ defaultView: () => snapshot.views.find((view) => view.isDefault === true),
294
+ async remove(id, context) {
295
+ await store.remove(id, context);
296
+ write({ views: snapshot.views.filter((view) => view.id !== id) });
297
+ if (snapshot.state.view === id)
298
+ setState({ view: undefined });
299
+ },
300
+ };
301
+ return {
302
+ resource,
303
+ options,
304
+ scopes,
305
+ presets,
306
+ selectionMode,
307
+ local: options.store === undefined,
308
+ getSnapshot: () => snapshot,
309
+ getState: () => snapshot.state,
310
+ subscribe(listener) {
311
+ listeners.add(listener);
312
+ return () => {
313
+ listeners.delete(listener);
314
+ };
315
+ },
316
+ setState,
317
+ setFilter(key, value) {
318
+ setState({ filter: { ...snapshot.state.filter, [key]: value } });
319
+ },
320
+ clearFilters() {
321
+ setState({ filter: {} });
322
+ },
323
+ setSearch: (search) => setState({ search }),
324
+ setSort: (sort) => setState({ sort }),
325
+ setPage: (page) => setState({ page }),
326
+ setSize: (size) => setState({ size }),
327
+ setScope: (scope) => setState({ scope }),
328
+ setColumns(columns) {
329
+ setState({ columns });
330
+ void preferences?.set(`columns:${resource.key}`, columns ?? null);
331
+ },
332
+ filter,
333
+ query() {
334
+ const { search, sort, size, page } = snapshot.state;
335
+ return { filter: filter(), search: search === "" ? undefined : search, sort, size, position: { page } };
336
+ },
337
+ checkFilter(key) {
338
+ return filterKeys().has(key) ? true : refuse(`no filter named "${key}"`);
339
+ },
340
+ checkPage(page, pageCount) {
341
+ if (!Number.isInteger(page) || page < 1)
342
+ return refuse("pages start at 1");
343
+ if (pageCount !== undefined && page > pageCount)
344
+ return refuse(pageCount === 1 ? "there is 1 page" : `there are ${String(pageCount)} pages`);
345
+ return true;
346
+ },
347
+ selection,
348
+ views,
349
+ attach(router) {
350
+ const cleanups = [];
351
+ if (preferences && snapshot.state.columns === undefined) {
352
+ void Promise.resolve(preferences.get(`columns:${resource.key}`)).then((stored) => {
353
+ if (Array.isArray(stored) && stored.every(isString) && snapshot.state.columns === undefined)
354
+ setState({ columns: stored });
355
+ });
356
+ }
357
+ if (options.url === false)
358
+ return () => { };
359
+ const location = () => router.location();
360
+ const readUrl = () => {
361
+ const next = fromParams(new URLSearchParams(location().search));
362
+ if (!same(next, snapshot.state))
363
+ setState(next);
364
+ };
365
+ readUrl();
366
+ let writing = false;
367
+ cleanups.push(router.subscribe(() => {
368
+ if (!writing)
369
+ readUrl();
370
+ }));
371
+ const writeUrl = () => {
372
+ const current = location();
373
+ const params = toParams(snapshot.state, new URLSearchParams(current.search));
374
+ const search = params.toString();
375
+ const next = search === "" ? "" : `?${search}`;
376
+ if (next === current.search)
377
+ return;
378
+ writing = true;
379
+ router.navigate(joinPath({ pathname: current.pathname, search: next }), { replace: true });
380
+ writing = false;
381
+ };
382
+ listeners.add(writeUrl);
383
+ cleanups.push(() => {
384
+ listeners.delete(writeUrl);
385
+ });
386
+ return () => {
387
+ for (const cleanup of cleanups)
388
+ cleanup();
389
+ };
390
+ },
391
+ };
392
+ }
package/package.json CHANGED
@@ -1,6 +1,87 @@
1
1
  {
2
2
  "name": "@eskais/app-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "A declarative application layer over Eskais UI: resources, actions, views, navigation and permissions, with React hooks on TanStack Query and Next.js App Router pages.",
5
+ "keywords": [
6
+ "admin",
7
+ "agents",
8
+ "backoffice",
9
+ "crud",
10
+ "eskais-ui",
11
+ "nextjs",
12
+ "react",
13
+ "tanstack-query"
14
+ ],
15
+ "homepage": "https://ui.eskais.com/docs/app-sdk/",
16
+ "bugs": {
17
+ "url": "https://github.com/p-otero/eskais-ui/issues"
18
+ },
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/p-otero/eskais-ui.git",
23
+ "directory": "packages/app-sdk"
24
+ },
25
+ "bin": {
26
+ "app-sdk": "dist/cli/cli.js"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "type": "module",
32
+ "sideEffects": false,
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./react": {
40
+ "types": "./dist/react/index.d.ts",
41
+ "default": "./dist/react/index.js"
42
+ },
43
+ "./next": {
44
+ "types": "./dist/next/index.d.ts",
45
+ "default": "./dist/next/index.js"
46
+ },
47
+ "./next/server": {
48
+ "types": "./dist/next/server/index.d.ts",
49
+ "default": "./dist/next/server/index.js"
50
+ },
51
+ "./package.json": "./package.json"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "provenance": true
56
+ },
57
+ "scripts": {
58
+ "build": "node build.mjs"
59
+ },
60
+ "peerDependencies": {
61
+ "@tanstack/react-query": "^5.0.0",
62
+ "@tanstack/react-router": "^1.0.0",
63
+ "next": "^15.0.0 || ^16.0.0",
64
+ "react": "^19.0.0",
65
+ "zod": "^4.0.0"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "@tanstack/react-query": {
69
+ "optional": true
70
+ },
71
+ "@tanstack/react-router": {
72
+ "optional": true
73
+ },
74
+ "next": {
75
+ "optional": true
76
+ },
77
+ "react": {
78
+ "optional": true
79
+ },
80
+ "zod": {
81
+ "optional": true
82
+ }
83
+ },
84
+ "engines": {
85
+ "node": ">=22.18.0"
86
+ }
87
+ }