simetra 0.2.0 → 0.3.0-next.1

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 (35) hide show
  1. package/dist/channel-grant-BATD6oQu.js +15 -0
  2. package/dist/compiler/index.d.ts +684 -77
  3. package/dist/compiler/index.js +24598 -13501
  4. package/dist/data/centrifugo/index.d.ts +24 -0
  5. package/dist/data/centrifugo/index.js +173 -0
  6. package/dist/data/index.d.ts +27 -0
  7. package/dist/data/index.js +9779 -0
  8. package/dist/data/react/index.d.ts +103 -0
  9. package/dist/data/react/index.js +214 -0
  10. package/dist/grant-Zg0hmqK7.d.ts +11 -0
  11. package/dist/handle-C6PFsnUX.js +44 -0
  12. package/dist/holder-CkR-qRYU.d.ts +585 -0
  13. package/dist/model/index.d.ts +4118 -476
  14. package/dist/model/index.js +4267 -380
  15. package/dist/schema/index.d.ts +1523 -572
  16. package/dist/schema/index.js +11698 -7402
  17. package/dist/server/index.d.ts +665 -21
  18. package/dist/server/index.js +4279 -426
  19. package/dist/server/signals/index.d.ts +92 -0
  20. package/dist/server/signals/index.js +140 -0
  21. package/dist/shell/index.d.ts +100 -0
  22. package/dist/shell/index.js +148 -0
  23. package/dist/ui/index.d.ts +213 -0
  24. package/dist/ui/index.js +1075 -0
  25. package/package.json +74 -3
  26. package/schemas/accumulation-registers.schema.json +46 -5
  27. package/schemas/catalogs.schema.json +110 -7
  28. package/schemas/constants.schema.json +31 -5
  29. package/schemas/custom-tables.schema.json +24 -0
  30. package/schemas/documents.schema.json +83 -5
  31. package/schemas/functions.schema.json +129 -0
  32. package/schemas/information-registers.schema.json +47 -5
  33. package/schemas/project.schema.json +11 -1
  34. package/schemas/rights-sets.schema.json +3 -1
  35. package/schemas/roles.schema.json +6 -2
@@ -0,0 +1,103 @@
1
+ import { C as DataError, S as ViewSnapshot, _ as RowMutation, b as SectionLine, f as CloseReason, g as MutationState, h as MutationResult, m as Mutation, r as DataWriter, t as RuntimeHolder, v as RowState, x as ServerRow, y as RowView } from "../../holder-CkR-qRYU.js";
2
+ import { CommandError, Filter, OrderBy } from "simetra/model";
3
+ import { ReactNode } from "react";
4
+ /** Gives the hooks of `children` the runtime of `holder` (P4-B spec §6.4). */
5
+ export declare function DataRuntimeProvider(props: {
6
+ holder: RuntimeHolder;
7
+ children?: ReactNode;
8
+ }): import("react").FunctionComponentElement<import("react").ProviderProps<RuntimeHolder | undefined>>;
9
+ interface UseRowInput {
10
+ /** Logical object name `"<kind>.<name>"`. */
11
+ object: string;
12
+ /** The row key. */
13
+ id: string;
14
+ /** Tabular sections to read with the header. */
15
+ tabularSections?: readonly string[];
16
+ }
17
+ /** One tabular section of a card. */
18
+ interface CardSection {
19
+ readonly lines: readonly SectionLine[];
20
+ /** All lines are loaded and belong to the header version shown. */
21
+ readonly complete: boolean;
22
+ readonly ownerState: RowState;
23
+ }
24
+ interface UseRowResult {
25
+ /** The header; `undefined` until it is read, `removed` keeps the place. */
26
+ readonly row: RowView | undefined;
27
+ readonly tabularSections: Readonly<Record<string, CardSection>>;
28
+ /** The confirmed version of the header. */
29
+ readonly version: number | undefined;
30
+ /**
31
+ * The only editability fact for T5 (P4-B spec §6.1): `false` while the
32
+ * header is not whole — its version differs from the one of a section,
33
+ * the row carries a stale mark (`row.stale`) or any field is `stale`, a
34
+ * view `needsRefresh`, the values are `hidden` — or while the object is
35
+ * marked stale-client (`isStale`).
36
+ */
37
+ readonly editable: boolean;
38
+ readonly status: ViewSnapshot["status"];
39
+ readonly error?: CommandError | DataError;
40
+ readonly reason?: CloseReason | "access-changed";
41
+ readonly needsRefresh: boolean;
42
+ /**
43
+ * The object is marked stale-client (see `UseRowsResult.isStale`); the
44
+ * staleness of the header is `row.state` and `row.staleFields`.
45
+ */
46
+ readonly isStale: boolean;
47
+ /** Re-reads the views of the card, as `UseRowsResult.refresh` does. */
48
+ refresh(): void;
49
+ }
50
+ /** One card: the header row and the requested tabular sections. */
51
+ export declare function useRow(input: UseRowInput): UseRowResult;
52
+ interface UseRowsInput {
53
+ /** Logical object name `"<kind>.<name>"`. */
54
+ object: string;
55
+ where?: Filter;
56
+ orderBy?: OrderBy;
57
+ /** Attributes of a single-target `Ref` whose rows come with each row. */
58
+ include?: readonly string[];
59
+ }
60
+ /** The result of {@link useRows}: one immutable snapshot and its actions. */
61
+ interface UseRowsResult {
62
+ readonly rows: readonly RowView[];
63
+ readonly status: ViewSnapshot["status"];
64
+ readonly error?: CommandError | DataError;
65
+ readonly reason?: CloseReason | "access-changed";
66
+ readonly strategy?: "full" | "window";
67
+ readonly truncated?: boolean;
68
+ readonly atStart?: boolean;
69
+ readonly atEnd?: boolean;
70
+ readonly hasNewRows: boolean;
71
+ readonly needsRefresh: boolean;
72
+ /**
73
+ * The object is marked stale-client (P4-B spec §6.4, §10): this build no
74
+ * longer matches the server contract of its kernel and no write passes.
75
+ * Row staleness is another fact: `RowView.state` `stale`, `staleFields`.
76
+ */
77
+ readonly isStale: boolean;
78
+ /** Window only: changes with every new composition; a list host remounts by it. */
79
+ readonly chain?: number;
80
+ /** Window only: where the host scrolls when a new chain replaces the old one. */
81
+ readonly target?: "start" | "end" | "keep";
82
+ setVisibleRange(range: {
83
+ first: number;
84
+ last: number;
85
+ }): void;
86
+ loadBefore(): void;
87
+ loadAfter(): void;
88
+ refresh(): void;
89
+ showNew(): void;
90
+ }
91
+ /**
92
+ * The rows of an object: `full` or `window` by the runtime `residency`. The
93
+ * result is the same object while the view is unchanged; no Suspense.
94
+ */
95
+ export declare function useRows(input: UseRowsInput): UseRowsResult;
96
+ /**
97
+ * The {@link DataWriter} of the runtime the provider's holder holds (P4-B
98
+ * spec §7.1). After `replace` the hook returns the writer of the new
99
+ * runtime; while the holder has none, every mutation settles with the close
100
+ * reason (`disposed` before the first runtime) and is never sent.
101
+ */
102
+ export declare function useWriter(): DataWriter;
103
+ export type { CardSection, CloseReason, DataWriter, Mutation, MutationResult, MutationState, RowMutation, RowState, RowView, SectionLine, ServerRow, UseRowInput, UseRowResult, UseRowsInput, UseRowsResult };
@@ -0,0 +1,214 @@
1
+ import { a as runtimeHandleOf, n as closedMutation } from "../../handle-C6PFsnUX.js";
2
+ import { createContext, createElement, useContext, useMemo, useSyncExternalStore } from "react";
3
+ // src/data/react/provider.ts
4
+ const HolderContext = createContext(void 0);
5
+ /** Gives the hooks of `children` the runtime of `holder` (P4-B spec §6.4). */
6
+ function DataRuntimeProvider(props) {
7
+ return createElement(HolderContext.Provider, { value: props.holder }, props.children);
8
+ }
9
+ /** The holder of the nearest provider; throws without one. */
10
+ function useHolder() {
11
+ const holder = useContext(HolderContext);
12
+ if (holder === void 0) throw new Error("simetra/data/react: no DataRuntimeProvider above this hook");
13
+ return holder;
14
+ }
15
+ function useCoreSource() {
16
+ const holder = useHolder();
17
+ const runtime = useSyncExternalStore(holder.subscribe, holder.current, holder.current);
18
+ const reason = useSyncExternalStore(holder.subscribe, holder.closed, holder.closed);
19
+ return runtime === void 0 ? {
20
+ core: void 0,
21
+ reason
22
+ } : { core: runtimeHandleOf(runtime).core };
23
+ }
24
+ // src/data/react/views.ts
25
+ const LOADING = {
26
+ status: "loading",
27
+ rows: [],
28
+ hasNewRows: false,
29
+ needsRefresh: false
30
+ };
31
+ const NO_SNAPSHOTS = [];
32
+ const IDLE = {
33
+ subscribe: () => () => {},
34
+ getSnapshot: () => NO_SNAPSHOTS,
35
+ handles: []
36
+ };
37
+ const closedSnapshots = /* @__PURE__ */ new Map();
38
+ function closedSnapshot(reason) {
39
+ if (reason === void 0) return [LOADING];
40
+ let snapshot = closedSnapshots.get(reason);
41
+ if (snapshot === void 0) {
42
+ snapshot = [{
43
+ ...LOADING,
44
+ status: "purged",
45
+ reason
46
+ }];
47
+ closedSnapshots.set(reason, snapshot);
48
+ }
49
+ return snapshot;
50
+ }
51
+ function combine(handles) {
52
+ let last;
53
+ return {
54
+ handles,
55
+ subscribe(listener) {
56
+ const releases = [];
57
+ try {
58
+ for (const handle of handles) releases.push(handle.subscribe(listener));
59
+ } catch (error) {
60
+ for (const release of releases) release();
61
+ throw error;
62
+ }
63
+ return () => {
64
+ for (const release of releases) release();
65
+ };
66
+ },
67
+ getSnapshot() {
68
+ const next = handles.map((handle) => handle.getSnapshot());
69
+ if (last !== void 0 && last.length === next.length && last.every((snapshot, i) => snapshot === next[i])) return last;
70
+ last = next;
71
+ return next;
72
+ }
73
+ };
74
+ }
75
+ /**
76
+ * Reads the views `specs` of the core as one snapshot array. A synchronous
77
+ * refusal of a spec (`DataError`, `TypeError`) is thrown while rendering, to
78
+ * the error boundary (P4-B spec §6.4).
79
+ */
80
+ function useViews(source, specs, specKey) {
81
+ const { core } = source;
82
+ const reason = core === void 0 ? source.reason : void 0;
83
+ const store = useMemo(() => core === void 0 ? IDLE : combine(specs(core).map((s) => core.view(s))), [core, specKey]);
84
+ const snapshots = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
85
+ return {
86
+ snapshots: core === void 0 ? closedSnapshot(reason) : snapshots,
87
+ handles: store.handles
88
+ };
89
+ }
90
+ // src/data/react/use-row.ts
91
+ const PRECEDENCE = [
92
+ "purged",
93
+ "error",
94
+ "loading",
95
+ "refreshing"
96
+ ];
97
+ function combineStatus(snapshots, hasRow) {
98
+ for (const status of PRECEDENCE) if (snapshots.some((s) => s.status === status)) return status === "loading" && hasRow ? "refreshing" : status;
99
+ return "ready";
100
+ }
101
+ /** One card: the header row and the requested tabular sections. */
102
+ function useRow(input) {
103
+ const source = useCoreSource();
104
+ const { object, id } = input;
105
+ const sections = input.tabularSections ?? [];
106
+ const { snapshots, handles } = useViews(source, () => [{
107
+ kind: "card",
108
+ object,
109
+ key: id
110
+ }, ...sections.map((section) => ({
111
+ kind: "section",
112
+ object,
113
+ owner: id,
114
+ section
115
+ }))], JSON.stringify([
116
+ object,
117
+ id,
118
+ sections
119
+ ]));
120
+ return useMemo(() => {
121
+ const row = snapshots[0].rows[0];
122
+ const tabularSections = {};
123
+ sections.forEach((name, i) => {
124
+ const section = snapshots[i + 1]?.section;
125
+ if (section !== void 0) tabularSections[name] = {
126
+ lines: section.lines,
127
+ complete: section.complete,
128
+ ownerState: section.ownerState
129
+ };
130
+ });
131
+ const live = row !== void 0 && row.state !== "removed" ? row : void 0;
132
+ const needsRefresh = snapshots.some((s) => s.needsRefresh);
133
+ const isStale = snapshots.some((s) => s.isStale === true);
134
+ const failed = snapshots.find((s) => s.error !== void 0);
135
+ const closed = snapshots.find((s) => s.reason !== void 0);
136
+ return {
137
+ row,
138
+ tabularSections,
139
+ version: live?.version,
140
+ editable: live !== void 0 && live.hidden === void 0 && live.stale === void 0 && live.staleFields.length === 0 && !needsRefresh && !isStale && sections.every((_, i) => snapshots[i + 1]?.section?.ownerVersion === live.version),
141
+ status: combineStatus(snapshots, row !== void 0),
142
+ ...failed?.error === void 0 ? {} : { error: failed.error },
143
+ ...closed?.reason === void 0 ? {} : { reason: closed.reason },
144
+ needsRefresh,
145
+ isStale,
146
+ refresh: () => {
147
+ for (const handle of handles) handle.refresh();
148
+ }
149
+ };
150
+ }, [snapshots, handles]);
151
+ }
152
+ // src/data/react/use-rows.ts
153
+ const noop = () => {};
154
+ function toResult(snapshot, handle) {
155
+ return {
156
+ ...snapshot,
157
+ isStale: snapshot.isStale === true,
158
+ setVisibleRange: handle ? (r) => handle.setVisibleRange(r) : noop,
159
+ loadBefore: handle ? () => handle.loadBefore() : noop,
160
+ loadAfter: handle ? () => handle.loadAfter() : noop,
161
+ refresh: handle ? () => handle.refresh() : noop,
162
+ showNew: handle ? () => handle.showNew() : noop
163
+ };
164
+ }
165
+ /**
166
+ * The rows of an object: `full` or `window` by the runtime `residency`. The
167
+ * result is the same object while the view is unchanged; no Suspense.
168
+ */
169
+ function useRows(input) {
170
+ const source = useCoreSource();
171
+ const { object, where, orderBy, include } = input;
172
+ const { snapshots, handles } = useViews(source, (core) => [{
173
+ kind: core.residencyOf(object),
174
+ object,
175
+ where,
176
+ orderBy,
177
+ include
178
+ }], JSON.stringify([
179
+ object,
180
+ where ?? null,
181
+ orderBy ?? null,
182
+ include ?? null
183
+ ]));
184
+ const snapshot = snapshots[0];
185
+ const handle = handles[0];
186
+ return useMemo(() => toResult(snapshot, handle), [snapshot, handle]);
187
+ }
188
+ // src/data/react/use-writer.ts
189
+ const closedWriters = /* @__PURE__ */ new Map();
190
+ /**
191
+ * The writer of a holder without a runtime: every mutation settles with the
192
+ * close reason and is never sent.
193
+ */
194
+ function closedWriter(reason) {
195
+ let writer = closedWriters.get(reason);
196
+ if (writer === void 0) {
197
+ writer = Object.freeze({ update: () => closedMutation(reason) });
198
+ closedWriters.set(reason, writer);
199
+ }
200
+ return writer;
201
+ }
202
+ /**
203
+ * The {@link DataWriter} of the runtime the provider's holder holds (P4-B
204
+ * spec §7.1). After `replace` the hook returns the writer of the new
205
+ * runtime; while the holder has none, every mutation settles with the close
206
+ * reason (`disposed` before the first runtime) and is never sent.
207
+ */
208
+ function useWriter() {
209
+ const holder = useHolder();
210
+ const runtime = useSyncExternalStore(holder.subscribe, holder.current, holder.current);
211
+ const reason = useSyncExternalStore(holder.subscribe, holder.closed, holder.closed);
212
+ return runtime === void 0 ? closedWriter(reason ?? "disposed") : runtimeHandleOf(runtime).writer;
213
+ }
214
+ export { DataRuntimeProvider, useRow, useRows, useWriter };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The permission to sign signal tokens: the subject (`current_user_id()`, or
3
+ * `null` for an invalid user) and the channels `runtime.authorizeChannels`
4
+ * allowed it. Only that function produces one; a plain object of the same
5
+ * shape is refused by the token port.
6
+ */
7
+ interface ChannelGrant {
8
+ readonly subject: string | null;
9
+ readonly channels: readonly string[];
10
+ }
11
+ export { ChannelGrant as t };
@@ -0,0 +1,44 @@
1
+ import { LIMIT_REASONS } from "simetra/model";
2
+ // src/data/runtime/handle.ts
3
+ const handles = /* @__PURE__ */ new WeakMap();
4
+ /** Binds the handle to a runtime; called once by `createDataRuntime`. */
5
+ function bindRuntimeHandle(runtime, handle) {
6
+ handles.set(runtime, handle);
7
+ }
8
+ /** The handle of a runtime made by `createDataRuntime`. */
9
+ function runtimeHandleOf(runtime) {
10
+ const handle = handles.get(runtime);
11
+ if (handle === void 0) throw new Error("not a data runtime made by createDataRuntime");
12
+ return handle;
13
+ }
14
+ // src/data/store/closed-mutation.ts
15
+ let mutationSeq = 0;
16
+ /** The id of a new mutation, unique across every runtime of the page. */
17
+ const nextMutationId = () => `m${++mutationSeq}`;
18
+ /**
19
+ * The refusal a mutation settles with once its runtime is closed: the same
20
+ * error the transport wrapper gives a request after the close. Only a changed
21
+ * session is `unauthenticated`; the rest, `connection-refused` included (the
22
+ * signal transport lost its credentials for good, the session itself did not
23
+ * change), is `unavailable`.
24
+ */
25
+ function closedError(reason) {
26
+ return reason === "session-changed" ? {
27
+ code: "command.unauthenticated",
28
+ reason: LIMIT_REASONS.sessionChanged
29
+ } : {
30
+ code: "command.unavailable",
31
+ reason: LIMIT_REASONS.disposed
32
+ };
33
+ }
34
+ /** A mutation of a closed runtime: settled with the close, never sent. */
35
+ function closedMutation(reason) {
36
+ return Object.freeze({
37
+ id: nextMutationId(),
38
+ settled: Promise.resolve({
39
+ ok: false,
40
+ error: closedError(reason)
41
+ })
42
+ });
43
+ }
44
+ export { runtimeHandleOf as a, bindRuntimeHandle as i, closedMutation as n, nextMutationId as r, closedError as t };