simetra 0.2.0 → 0.3.0-next.10
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/dist/channel-grant-BATD6oQu.js +15 -0
- package/dist/compiler/index.d.ts +732 -85
- package/dist/compiler/index.js +26488 -13752
- package/dist/data/centrifugo/index.d.ts +24 -0
- package/dist/data/centrifugo/index.js +173 -0
- package/dist/data/index.d.ts +27 -0
- package/dist/data/index.js +10115 -0
- package/dist/data/react/index.d.ts +103 -0
- package/dist/data/react/index.js +214 -0
- package/dist/grant-Zg0hmqK7.d.ts +11 -0
- package/dist/handle-C6PFsnUX.js +44 -0
- package/dist/holder-CkR-qRYU.d.ts +585 -0
- package/dist/model/index.d.ts +4396 -400
- package/dist/model/index.js +4425 -380
- package/dist/schema/index.d.ts +1545 -572
- package/dist/schema/index.js +8554 -4215
- package/dist/server/index.d.ts +710 -21
- package/dist/server/index.js +4663 -483
- package/dist/server/signals/index.d.ts +92 -0
- package/dist/server/signals/index.js +140 -0
- package/dist/shell/index.d.ts +112 -0
- package/dist/shell/index.js +159 -0
- package/dist/ui/index.d.ts +213 -0
- package/dist/ui/index.js +1098 -0
- package/package.json +75 -3
- package/schemas/accumulation-registers.schema.json +46 -5
- package/schemas/catalogs.schema.json +113 -33
- package/schemas/constants.schema.json +31 -5
- package/schemas/custom-tables.schema.json +24 -0
- package/schemas/documents.schema.json +86 -31
- package/schemas/functions.schema.json +129 -0
- package/schemas/information-registers.schema.json +47 -5
- package/schemas/project.schema.json +206 -1
- package/schemas/rights-sets.schema.json +19 -1
- package/schemas/roles.schema.json +23 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SignalTransport } from "simetra/model";
|
|
2
|
+
/**
|
|
3
|
+
* Thrown by a host token function to say the server refuses the token: the
|
|
4
|
+
* channel is outside the `authorizeChannels` grant, the grant has no user
|
|
5
|
+
* (`signals.no-user`), or the host endpoint answered 401 or 403. Any other
|
|
6
|
+
* failure (network, 5xx) is not a refusal and is retried by the client.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SignalAuthRefused extends Error {
|
|
9
|
+
constructor(message?: string);
|
|
10
|
+
}
|
|
11
|
+
/** Options of `createCentrifugoTransport`. */
|
|
12
|
+
export interface CentrifugoTransportOptions {
|
|
13
|
+
/** WebSocket endpoint of Centrifugo. */
|
|
14
|
+
url: string;
|
|
15
|
+
/** A connection token; rejects with `SignalAuthRefused` on a refusal. */
|
|
16
|
+
getConnectionToken(): Promise<string>;
|
|
17
|
+
/** A subscription token of one channel; rejects with `SignalAuthRefused` on a refusal. */
|
|
18
|
+
getChannelToken(channel: string): Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A `SignalTransport` over the `centrifuge` client: one client connection,
|
|
22
|
+
* one client subscription per channel shared by every holder of the channel.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createCentrifugoTransport(options: CentrifugoTransportOptions): SignalTransport;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Centrifuge, State, SubscriptionState, UnauthorizedError, disconnectedCodes, unsubscribedCodes } from "centrifuge";
|
|
2
|
+
// src/data/centrifugo/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown by a host token function to say the server refuses the token: the
|
|
5
|
+
* channel is outside the `authorizeChannels` grant, the grant has no user
|
|
6
|
+
* (`signals.no-user`), or the host endpoint answered 401 or 403. Any other
|
|
7
|
+
* failure (network, 5xx) is not a refusal and is retried by the client.
|
|
8
|
+
*/
|
|
9
|
+
var SignalAuthRefused = class extends Error {
|
|
10
|
+
constructor(message = "signal token refused") {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "SignalAuthRefused";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A `SignalTransport` over the `centrifuge` client: one client connection,
|
|
17
|
+
* one client subscription per channel shared by every holder of the channel.
|
|
18
|
+
*/
|
|
19
|
+
function createCentrifugoTransport(options) {
|
|
20
|
+
const entries = /* @__PURE__ */ new Map();
|
|
21
|
+
const holders = /* @__PURE__ */ new Set();
|
|
22
|
+
const subscribedHandlers = /* @__PURE__ */ new Set();
|
|
23
|
+
let closed = false;
|
|
24
|
+
let refusals = 0;
|
|
25
|
+
const refusalAsUnauthorized = (error) => {
|
|
26
|
+
if (error instanceof SignalAuthRefused) throw new UnauthorizedError("");
|
|
27
|
+
throw error;
|
|
28
|
+
};
|
|
29
|
+
const client = new Centrifuge(options.url, { getToken: () => options.getConnectionToken().catch(refusalAsUnauthorized) });
|
|
30
|
+
const failAll = (error) => {
|
|
31
|
+
for (const holder of [...holders]) holder.onError(error);
|
|
32
|
+
};
|
|
33
|
+
const failChannel = (channel, error) => {
|
|
34
|
+
const entry = entries.get(channel);
|
|
35
|
+
if (entry === void 0) return;
|
|
36
|
+
for (const holder of [...entry.holders]) holder.onError(error);
|
|
37
|
+
};
|
|
38
|
+
const end = (channel) => {
|
|
39
|
+
const entry = entries.get(channel);
|
|
40
|
+
if (entry === void 0) return;
|
|
41
|
+
entries.delete(channel);
|
|
42
|
+
client.removeSubscription(entry.sub);
|
|
43
|
+
for (const holder of entry.holders) holder.channels.delete(channel);
|
|
44
|
+
for (const holder of [...entry.holders]) holder.onError({
|
|
45
|
+
kind: "auth",
|
|
46
|
+
channel
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const create = (channel) => {
|
|
50
|
+
const sub = client.newSubscription(channel, { getToken: () => options.getChannelToken(channel).catch(refusalAsUnauthorized) });
|
|
51
|
+
const current = () => !closed && entries.get(channel)?.sub === sub;
|
|
52
|
+
sub.on("publication", (ctx) => {
|
|
53
|
+
if (!current()) return;
|
|
54
|
+
for (const holder of [...entries.get(channel)?.holders ?? []]) holder.onSignal(ctx.channel, ctx.data);
|
|
55
|
+
});
|
|
56
|
+
sub.on("subscribed", (ctx) => {
|
|
57
|
+
if (!current()) return;
|
|
58
|
+
const recovered = ctx.wasRecovering && ctx.recovered;
|
|
59
|
+
for (const handler of [...subscribedHandlers]) handler({
|
|
60
|
+
channel,
|
|
61
|
+
recovered
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
sub.on("unsubscribed", (ctx) => {
|
|
65
|
+
if (!current() || ctx.code === unsubscribedCodes.unsubscribeCalled) return;
|
|
66
|
+
end(channel);
|
|
67
|
+
});
|
|
68
|
+
sub.on("state", (ctx) => {
|
|
69
|
+
if (!current() || client.state !== State.Connected) return;
|
|
70
|
+
if (ctx.oldState === SubscriptionState.Subscribed && ctx.newState === SubscriptionState.Subscribing) failChannel(channel, {
|
|
71
|
+
kind: "transport",
|
|
72
|
+
channel
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
sub.on("error", () => {
|
|
76
|
+
if (!current() || sub.state === SubscriptionState.Subscribed) return;
|
|
77
|
+
failChannel(channel, {
|
|
78
|
+
kind: "transport",
|
|
79
|
+
channel
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return sub;
|
|
83
|
+
};
|
|
84
|
+
client.on("state", (ctx) => {
|
|
85
|
+
if (closed) return;
|
|
86
|
+
if (ctx.oldState === State.Connected) failAll({ kind: "transport" });
|
|
87
|
+
});
|
|
88
|
+
client.on("connected", () => {
|
|
89
|
+
refusals = 0;
|
|
90
|
+
});
|
|
91
|
+
client.on("error", () => {
|
|
92
|
+
if (closed || client.state === State.Connected) return;
|
|
93
|
+
failAll({ kind: "transport" });
|
|
94
|
+
});
|
|
95
|
+
client.on("disconnected", (ctx) => {
|
|
96
|
+
if (closed) return;
|
|
97
|
+
if (ctx.code !== disconnectedCodes.unauthorized) return failAll({
|
|
98
|
+
kind: "auth",
|
|
99
|
+
final: true
|
|
100
|
+
});
|
|
101
|
+
refusals++;
|
|
102
|
+
if (refusals > 1) return failAll({
|
|
103
|
+
kind: "auth",
|
|
104
|
+
final: true
|
|
105
|
+
});
|
|
106
|
+
failAll({ kind: "auth" });
|
|
107
|
+
client.setToken("");
|
|
108
|
+
client.connect();
|
|
109
|
+
});
|
|
110
|
+
client.connect();
|
|
111
|
+
return {
|
|
112
|
+
subscribe(channels, onSignal, onError) {
|
|
113
|
+
if (closed) return () => {};
|
|
114
|
+
const holder = {
|
|
115
|
+
channels: new Set(channels),
|
|
116
|
+
onSignal,
|
|
117
|
+
onError
|
|
118
|
+
};
|
|
119
|
+
holders.add(holder);
|
|
120
|
+
for (const channel of holder.channels) {
|
|
121
|
+
const entry = entries.get(channel);
|
|
122
|
+
if (entry !== void 0) {
|
|
123
|
+
entry.holders.add(holder);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const sub = create(channel);
|
|
127
|
+
entries.set(channel, {
|
|
128
|
+
sub,
|
|
129
|
+
holders: /* @__PURE__ */ new Set([holder])
|
|
130
|
+
});
|
|
131
|
+
sub.subscribe();
|
|
132
|
+
}
|
|
133
|
+
return () => {
|
|
134
|
+
if (!holders.delete(holder)) return;
|
|
135
|
+
for (const channel of holder.channels) {
|
|
136
|
+
const entry = entries.get(channel);
|
|
137
|
+
if (entry === void 0) continue;
|
|
138
|
+
entry.holders.delete(holder);
|
|
139
|
+
if (entry.holders.size > 0) continue;
|
|
140
|
+
entries.delete(channel);
|
|
141
|
+
client.removeSubscription(entry.sub);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
onSubscribed(handler) {
|
|
146
|
+
subscribedHandlers.add(handler);
|
|
147
|
+
return () => {
|
|
148
|
+
subscribedHandlers.delete(handler);
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
async refreshTokens(channels) {
|
|
152
|
+
if (closed) return;
|
|
153
|
+
const named = channels ?? [...entries.keys()];
|
|
154
|
+
for (const channel of named) {
|
|
155
|
+
const entry = entries.get(channel);
|
|
156
|
+
if (entry === void 0) continue;
|
|
157
|
+
client.removeSubscription(entry.sub);
|
|
158
|
+
entry.sub = create(channel);
|
|
159
|
+
entry.sub.subscribe();
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
close() {
|
|
163
|
+
if (closed) return;
|
|
164
|
+
closed = true;
|
|
165
|
+
for (const entry of entries.values()) client.removeSubscription(entry.sub);
|
|
166
|
+
entries.clear();
|
|
167
|
+
holders.clear();
|
|
168
|
+
subscribedHandlers.clear();
|
|
169
|
+
client.disconnect();
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export { SignalAuthRefused, createCentrifugoTransport };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { C as DataError, _ as RowMutation, a as UpdateOptions, c as DataRuntimeOptions, d as createDataRuntime, g as MutationState, h as MutationResult, i as writerOf, l as DataSnapshot, m as Mutation, n as createRuntimeHolder, o as DataLogEntry, p as CoreSnapshot, r as DataWriter, s as DataRuntime, t as RuntimeHolder, u as SnapshotMeta, w as DataErrorCode, x as ServerRow } from "../holder-CkR-qRYU.js";
|
|
2
|
+
import { DataRequest, DatabaseProvider, SourceAdapter, WireReadPart, WireReadParts } from "simetra/model";
|
|
3
|
+
/**
|
|
4
|
+
* The Server Function source adapter (P4-B spec §5.2): the parts go through
|
|
5
|
+
* the runtime transport wrapper as one `read` request; a failure of the whole
|
|
6
|
+
* request is a `CommandFailure` of the same code, a failure of a part stays
|
|
7
|
+
* in its item.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createServerFunctionAdapter(runtime: DataRuntime): ServerFunctionAdapter;
|
|
10
|
+
/**
|
|
11
|
+
* The Server Function adapter: besides the parts of its objects it takes the
|
|
12
|
+
* parts without an object (the catalog `version`), which the core source
|
|
13
|
+
* puts in the same request.
|
|
14
|
+
*/
|
|
15
|
+
interface ServerFunctionAdapter extends SourceAdapter {
|
|
16
|
+
read(items: readonly WireReadPart[]): Promise<WireReadParts>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Picks the source adapter: the application override, otherwise the default
|
|
20
|
+
* of the database profile (Server Function for every profile until B4).
|
|
21
|
+
*/
|
|
22
|
+
export declare function selectSource(options: {
|
|
23
|
+
profile: DatabaseProvider;
|
|
24
|
+
override?: SourceAdapter;
|
|
25
|
+
serverFunction: SourceAdapter;
|
|
26
|
+
}): SourceAdapter;
|
|
27
|
+
export { type CoreSnapshot, DataError, type DataErrorCode, type DataLogEntry, type DataRuntime, type DataRuntimeOptions, type DataSnapshot, type DataWriter, type Mutation, type MutationResult, type MutationState, type RowMutation, type RuntimeHolder, type ServerFunctionAdapter, type ServerRow, type SnapshotMeta, type UpdateOptions, createDataRuntime, createRuntimeHolder, writerOf };
|