@celobus/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.
- package/LICENSE +91 -0
- package/README.md +38 -2
- package/dist/access.d.ts +141 -0
- package/dist/access.js +232 -0
- package/dist/codec.d.ts +29 -0
- package/dist/codec.js +361 -0
- package/dist/cron.d.ts +2 -0
- package/dist/cron.js +113 -0
- package/dist/ctx.d.ts +644 -0
- package/dist/ctx.js +657 -0
- package/dist/db.d.ts +234 -0
- package/dist/db.js +495 -0
- package/dist/decimal.d.ts +39 -0
- package/dist/decimal.js +158 -0
- package/dist/declare.d.ts +311 -0
- package/dist/declare.js +78 -0
- package/dist/descriptor.d.ts +229 -0
- package/dist/descriptor.js +899 -0
- package/dist/errors.d.ts +65 -0
- package/dist/errors.js +114 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +34 -0
- package/dist/log.d.ts +39 -0
- package/dist/log.js +101 -0
- package/dist/names.d.ts +12 -0
- package/dist/names.js +41 -0
- package/dist/notify.d.ts +185 -0
- package/dist/notify.js +234 -0
- package/dist/platform.d.ts +61 -0
- package/dist/platform.js +47 -0
- package/dist/plugin.d.ts +43 -0
- package/dist/plugin.js +117 -0
- package/dist/query.d.ts +326 -0
- package/dist/query.js +794 -0
- package/dist/remote.d.ts +8 -0
- package/dist/remote.js +19 -0
- package/dist/schema.d.ts +487 -0
- package/dist/schema.js +405 -0
- package/dist/serve.d.ts +63 -0
- package/dist/serve.js +411 -0
- package/dist/sql.d.ts +13 -0
- package/dist/sql.js +33 -0
- package/dist/ui.d.ts +1867 -0
- package/dist/ui.js +3964 -0
- package/dist/viz-kinds.d.ts +12 -0
- package/dist/viz-kinds.js +14 -0
- package/package.json +33 -4
- package/proto/plugin.proto +994 -0
package/dist/schema.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// Declarations of data: field builders (`t.*`), messages, enums and entities, with the TypeScript types they
|
|
2
|
+
// infer. Builders are immutable: `.optional()` and `.describe()` return a new field, so one enum or message may
|
|
3
|
+
// be used in several places with different modifiers.
|
|
4
|
+
import { encodeFieldValue } from "./codec.js";
|
|
5
|
+
import { snake } from "./names.js";
|
|
6
|
+
/** A field of a message or an entity: its type `T`, whether it may be absent (`O`), a ref's target (`R`). */
|
|
7
|
+
export class Field {
|
|
8
|
+
spec;
|
|
9
|
+
isOptional;
|
|
10
|
+
description;
|
|
11
|
+
column;
|
|
12
|
+
constructor(
|
|
13
|
+
/** @internal */ spec,
|
|
14
|
+
/** @internal */ isOptional = false,
|
|
15
|
+
/** @internal */ description = "",
|
|
16
|
+
/** @internal */ column = {}) {
|
|
17
|
+
this.spec = spec;
|
|
18
|
+
this.isOptional = isOptional;
|
|
19
|
+
this.description = description;
|
|
20
|
+
this.column = column;
|
|
21
|
+
}
|
|
22
|
+
/** The field may be absent (`undefined` in TypeScript, omitted on the wire). Fields are required otherwise. */
|
|
23
|
+
optional() {
|
|
24
|
+
return new Field(this.spec, true, this.description, this.column);
|
|
25
|
+
}
|
|
26
|
+
/** The field's description (descriptor, documentation, MCP). */
|
|
27
|
+
describe(text) {
|
|
28
|
+
return new Field(this.spec, this.isOptional, text, this.column);
|
|
29
|
+
}
|
|
30
|
+
/** An entity column whose values are unique (among the rows that are not deleted, on a soft-delete entity). */
|
|
31
|
+
unique() {
|
|
32
|
+
return new Field(this.spec, this.isOptional, this.description, { ...this.column, unique: true });
|
|
33
|
+
}
|
|
34
|
+
/** An entity column with an index of its own (refs have one without it). */
|
|
35
|
+
index() {
|
|
36
|
+
return new Field(this.spec, this.isOptional, this.description, { ...this.column, index: true });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A text column searched by full text (`note.f.title.search('words')`), in a PostgreSQL text search language
|
|
40
|
+
* (`simple` by default: no stemming).
|
|
41
|
+
*/
|
|
42
|
+
searchable(language = "simple") {
|
|
43
|
+
return new Field(this.spec, this.isOptional, this.description, { ...this.column, searchable: language });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An entity column the platform keeps encrypted at rest with the workspace's key (never unique, indexed, filtered,
|
|
47
|
+
* sorted, a ref, the id, the label or read by declared SQL).
|
|
48
|
+
*/
|
|
49
|
+
encrypted() {
|
|
50
|
+
return new Field(this.spec, this.isOptional, this.description, { ...this.column, encrypted: true });
|
|
51
|
+
}
|
|
52
|
+
/** @internal A use of this field with its own identity (messages and entities copy their fields). */
|
|
53
|
+
use() {
|
|
54
|
+
return new Field(this.spec, this.isOptional, this.description, this.column);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A typed handle of a message's field, for UI declarations: `order.f.status` is a `FieldRef<Order, OrderStatus>`
|
|
59
|
+
* (`M` is the message's value type, `T` the field's value type without `undefined`). A handle of another message
|
|
60
|
+
* does not fit where a field of `M` is expected, so a wrong field name or message is a type error.
|
|
61
|
+
*/
|
|
62
|
+
export class FieldRef {
|
|
63
|
+
name;
|
|
64
|
+
field;
|
|
65
|
+
owner;
|
|
66
|
+
constructor(
|
|
67
|
+
/** The descriptor's (snake_case) field name. */
|
|
68
|
+
name,
|
|
69
|
+
/** @internal The field's declaration. */
|
|
70
|
+
field,
|
|
71
|
+
/** @internal The entity whose field this is (a query names its alias). */
|
|
72
|
+
owner) {
|
|
73
|
+
this.name = name;
|
|
74
|
+
this.field = field;
|
|
75
|
+
this.owner = owner;
|
|
76
|
+
}
|
|
77
|
+
compare(op, values) {
|
|
78
|
+
const inner = this.field.spec.kind === "array" ? this.field.spec.inner : this.field;
|
|
79
|
+
return new Filter({ condition: { field: this.name, op, values: values.map((v) => dbValue(encodeFieldValue(inner, v, this.name))) } }, this.owner);
|
|
80
|
+
}
|
|
81
|
+
/** @internal A comparison with another column (`eqCol` and the others). */
|
|
82
|
+
cmpCol(op, other) {
|
|
83
|
+
return new ColCmp(this, op, other);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* In a query (`ctx.query(..)`): this column equals another of the same type (a key and a ref to its entity, two
|
|
87
|
+
* refs to one entity, two strings); also what `joinOn` joins on.
|
|
88
|
+
*/
|
|
89
|
+
eqCol(other) {
|
|
90
|
+
return this.cmpCol("EQ", other);
|
|
91
|
+
}
|
|
92
|
+
/** Not equal (a null is not equal to a value). */
|
|
93
|
+
neCol(other) {
|
|
94
|
+
return this.cmpCol("NE", other);
|
|
95
|
+
}
|
|
96
|
+
ltCol(other) {
|
|
97
|
+
return this.cmpCol("LT", other);
|
|
98
|
+
}
|
|
99
|
+
leCol(other) {
|
|
100
|
+
return this.cmpCol("LE", other);
|
|
101
|
+
}
|
|
102
|
+
gtCol(other) {
|
|
103
|
+
return this.cmpCol("GT", other);
|
|
104
|
+
}
|
|
105
|
+
geCol(other) {
|
|
106
|
+
return this.cmpCol("GE", other);
|
|
107
|
+
}
|
|
108
|
+
/** Rows whose field equals `v` (`ctx.db(order).find(order.f.status.eq('paid'))`). */
|
|
109
|
+
eq(v) {
|
|
110
|
+
return this.compare("EQ", [v]);
|
|
111
|
+
}
|
|
112
|
+
/** Not equal (a null is not equal to a value). */
|
|
113
|
+
ne(v) {
|
|
114
|
+
return this.compare("NE", [v]);
|
|
115
|
+
}
|
|
116
|
+
lt(v) {
|
|
117
|
+
return this.compare("LT", [v]);
|
|
118
|
+
}
|
|
119
|
+
le(v) {
|
|
120
|
+
return this.compare("LE", [v]);
|
|
121
|
+
}
|
|
122
|
+
gt(v) {
|
|
123
|
+
return this.compare("GT", [v]);
|
|
124
|
+
}
|
|
125
|
+
ge(v) {
|
|
126
|
+
return this.compare("GE", [v]);
|
|
127
|
+
}
|
|
128
|
+
/** Any of the values. */
|
|
129
|
+
in(values) {
|
|
130
|
+
return this.compare("IN", values);
|
|
131
|
+
}
|
|
132
|
+
isNull() {
|
|
133
|
+
return this.compare("IS_NULL", []);
|
|
134
|
+
}
|
|
135
|
+
isNotNull() {
|
|
136
|
+
return this.compare("IS_NOT_NULL", []);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Full-text search of a `searchable` column: the words as a web search reads them (`"a phrase"`, `or`, `-word`),
|
|
140
|
+
* in the column's language. The platform refuses it (400 `invalid`) on a column that is not searchable.
|
|
141
|
+
*/
|
|
142
|
+
search(words) {
|
|
143
|
+
return new Filter({ condition: { field: this.name, op: "SEARCH", values: [{ stringValue: words }] } }, this.owner);
|
|
144
|
+
}
|
|
145
|
+
/** A case-insensitive substring of a text column, taken literally (`%` and `_` are no wildcards). */
|
|
146
|
+
contains(part) {
|
|
147
|
+
return new Filter({ condition: { field: this.name, op: "CONTAINS", values: [{ stringValue: part }] } }, this.owner);
|
|
148
|
+
}
|
|
149
|
+
asc() {
|
|
150
|
+
return new Order(this.name, false, this.owner);
|
|
151
|
+
}
|
|
152
|
+
desc() {
|
|
153
|
+
return new Order(this.name, true, this.owner);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Two columns compared (`a.eqCol(b)`): a query's condition, and what `joinOn` joins on. */
|
|
157
|
+
export class ColCmp {
|
|
158
|
+
left;
|
|
159
|
+
op;
|
|
160
|
+
right;
|
|
161
|
+
constructor(
|
|
162
|
+
/** @internal */ left,
|
|
163
|
+
/** @internal */ op,
|
|
164
|
+
/** @internal */ right) {
|
|
165
|
+
this.left = left;
|
|
166
|
+
this.op = op;
|
|
167
|
+
this.right = right;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/** A filter parameter (`DbValue`): the platform converts it to the column's type. */
|
|
171
|
+
function dbValue(v) {
|
|
172
|
+
if (typeof v === "boolean")
|
|
173
|
+
return { boolValue: v };
|
|
174
|
+
if (typeof v === "number")
|
|
175
|
+
return Number.isInteger(v) ? { intValue: String(v) } : { doubleValue: v };
|
|
176
|
+
if (typeof v === "string")
|
|
177
|
+
return { stringValue: v };
|
|
178
|
+
return { stringValue: JSON.stringify(v) };
|
|
179
|
+
}
|
|
180
|
+
/** A condition on the rows of `M`, from field handles; combined with `and`, `or`, `not`. */
|
|
181
|
+
export class Filter {
|
|
182
|
+
node;
|
|
183
|
+
source;
|
|
184
|
+
constructor(
|
|
185
|
+
/** @internal */ node,
|
|
186
|
+
/** @internal The entity whose columns it tests (a query names its alias). */
|
|
187
|
+
source) {
|
|
188
|
+
this.node = node;
|
|
189
|
+
this.source = source;
|
|
190
|
+
}
|
|
191
|
+
/** Every row. */
|
|
192
|
+
static all() {
|
|
193
|
+
return new Filter(undefined);
|
|
194
|
+
}
|
|
195
|
+
and(...others) {
|
|
196
|
+
return and(this, ...others);
|
|
197
|
+
}
|
|
198
|
+
or(...others) {
|
|
199
|
+
return or(this, ...others);
|
|
200
|
+
}
|
|
201
|
+
not() {
|
|
202
|
+
return not(this);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** All of the conditions. */
|
|
206
|
+
export function and(...filters) {
|
|
207
|
+
const items = filters.map((f) => f.node).filter((n) => n !== undefined);
|
|
208
|
+
const source = filters.find((f) => f.source)?.source;
|
|
209
|
+
if (items.length === 0)
|
|
210
|
+
return new Filter(undefined, source);
|
|
211
|
+
return new Filter(items.length === 1 ? items[0] : { and: { items } }, source);
|
|
212
|
+
}
|
|
213
|
+
/** Any of the conditions. */
|
|
214
|
+
export function or(...filters) {
|
|
215
|
+
const source = filters.find((f) => f.source)?.source;
|
|
216
|
+
if (filters.some((f) => f.node === undefined))
|
|
217
|
+
return new Filter(undefined, source);
|
|
218
|
+
const items = filters.map((f) => f.node);
|
|
219
|
+
return new Filter(items.length === 1 ? items[0] : { or: { items } }, source);
|
|
220
|
+
}
|
|
221
|
+
/** Not the condition. */
|
|
222
|
+
export function not(filter) {
|
|
223
|
+
return new Filter(filter.node === undefined ? { or: { items: [] } } : { not: filter.node }, filter.source);
|
|
224
|
+
}
|
|
225
|
+
/** A column the rows are ordered by. */
|
|
226
|
+
export class Order {
|
|
227
|
+
field;
|
|
228
|
+
desc;
|
|
229
|
+
source;
|
|
230
|
+
constructor(field, desc,
|
|
231
|
+
/** @internal The entity whose column it is (a query names its alias). */
|
|
232
|
+
source) {
|
|
233
|
+
this.field = field;
|
|
234
|
+
this.desc = desc;
|
|
235
|
+
this.source = source;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function fieldRefs(shape, owner) {
|
|
239
|
+
const out = {};
|
|
240
|
+
for (const [key, field] of Object.entries(shape))
|
|
241
|
+
out[key] = new FieldRef(snake(key), field, owner);
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
/** @internal The name each entity has in its plugin's descriptor, set when the plugin is described. */
|
|
245
|
+
export const entityNames = new WeakMap();
|
|
246
|
+
/** @internal Each entity's navigations by their (snake_case) names, set when the plugin is described. */
|
|
247
|
+
export const navigations = new WeakMap();
|
|
248
|
+
/** Maps fields to the descriptor path they were declared under, for `invalid(..).field(handle, ..)`. */
|
|
249
|
+
export const fieldKeys = new WeakMap();
|
|
250
|
+
function copyFields(shape) {
|
|
251
|
+
const out = {};
|
|
252
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
253
|
+
if (!(field instanceof Field))
|
|
254
|
+
throw new TypeError(`field ${key}: not a t.* builder`);
|
|
255
|
+
const copy = field.use();
|
|
256
|
+
fieldKeys.set(copy, key);
|
|
257
|
+
out[key] = copy;
|
|
258
|
+
}
|
|
259
|
+
return out;
|
|
260
|
+
}
|
|
261
|
+
/** A named message (`t.message('HelloRequest', {...})`), usable as an endpoint's input or output or as a field. */
|
|
262
|
+
export class MessageDef extends Field {
|
|
263
|
+
name;
|
|
264
|
+
messageDescription;
|
|
265
|
+
omitDefaults;
|
|
266
|
+
/** The fields as declared, each a handle for `invalid(..).field(message.fields.name, ..)`. */
|
|
267
|
+
fields;
|
|
268
|
+
/** Typed field handles for UI declarations (`order.f.status`). */
|
|
269
|
+
f;
|
|
270
|
+
constructor(name, shape,
|
|
271
|
+
/** the message's own description */
|
|
272
|
+
messageDescription = "",
|
|
273
|
+
/**
|
|
274
|
+
* Fields at their protobuf default (`""`, `0`, `false`, an empty list, a message whose JSON is `{}`) are left out
|
|
275
|
+
* of its JSON; an enum and an optional field with a value are still written (`t.message(.., { omitDefaults: true })`).
|
|
276
|
+
*/
|
|
277
|
+
omitDefaults = false) {
|
|
278
|
+
const spec = { kind: "message" };
|
|
279
|
+
super(spec);
|
|
280
|
+
this.name = name;
|
|
281
|
+
this.messageDescription = messageDescription;
|
|
282
|
+
this.omitDefaults = omitDefaults;
|
|
283
|
+
spec.message = this;
|
|
284
|
+
this.fields = copyFields(shape);
|
|
285
|
+
this.f = fieldRefs(this.fields);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/** A named enum (`t.enum('OrderStatus', ['placed', 'paid'])`); its values are strings on the wire and in code. */
|
|
289
|
+
export class EnumDef extends Field {
|
|
290
|
+
name;
|
|
291
|
+
values;
|
|
292
|
+
constructor(name, values) {
|
|
293
|
+
const spec = { kind: "enum" };
|
|
294
|
+
super(spec);
|
|
295
|
+
this.name = name;
|
|
296
|
+
this.values = values;
|
|
297
|
+
spec.enumDef = this;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* An entity of the directory: `platform.user`, `platform.group` (refs name them), and for queries
|
|
302
|
+
* `platform.groupMember`, `platform.roleAssignment` (`@celobus/sdk/platform`). `f` are its columns' handles.
|
|
303
|
+
*/
|
|
304
|
+
export class PlatformEntity {
|
|
305
|
+
ref;
|
|
306
|
+
/** Typed handles of the columns a query names (`platform.user.f.displayName`). */
|
|
307
|
+
f;
|
|
308
|
+
/** @internal */ columns;
|
|
309
|
+
constructor(ref, columns = {}) {
|
|
310
|
+
this.ref = ref;
|
|
311
|
+
this.columns = copyFields(columns);
|
|
312
|
+
this.f = fieldRefs(this.columns, this);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* An entity: one of the plugin's (`ctx.db(e)`), or a dependency's it reads (`ctx.query(e)`; `F` is `true`).
|
|
317
|
+
*/
|
|
318
|
+
export class EntityDef {
|
|
319
|
+
options;
|
|
320
|
+
columns;
|
|
321
|
+
key;
|
|
322
|
+
/**
|
|
323
|
+
* Typed field handles of the entity's message for UI declarations and filters (`note.f.id`, `note.f.title`), and of
|
|
324
|
+
* its system columns (`note.f.createdAt`; `deletedAt` and `version` when it has them).
|
|
325
|
+
*/
|
|
326
|
+
f;
|
|
327
|
+
constructor(options) {
|
|
328
|
+
this.options = options;
|
|
329
|
+
this.columns = copyFields(options.columns);
|
|
330
|
+
this.key = options.key ?? "uuid";
|
|
331
|
+
const system = { createdAt: scalar("timestamp"), updatedAt: scalar("timestamp") };
|
|
332
|
+
if (options.softDelete)
|
|
333
|
+
system.deletedAt = scalar("timestamp").optional();
|
|
334
|
+
if (options.version)
|
|
335
|
+
system.version = scalar("int64");
|
|
336
|
+
this.f = fieldRefs({ id: new Field({ kind: "ref", ref: this }), ...this.columns, ...system }, this);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
export function entity(options) {
|
|
340
|
+
return new EntityDef(options);
|
|
341
|
+
}
|
|
342
|
+
/** @internal The provider of a dependency's entity; `undefined` for an entity of this plugin. */
|
|
343
|
+
export function foreignPlugin(e) {
|
|
344
|
+
return e.options.plugin || undefined;
|
|
345
|
+
}
|
|
346
|
+
function scalar(type) {
|
|
347
|
+
return new Field({ kind: "scalar", scalar: type });
|
|
348
|
+
}
|
|
349
|
+
/** Field builders. Each maps to one descriptor type; the comment says the TypeScript and the wire type. */
|
|
350
|
+
export const t = {
|
|
351
|
+
/** string */
|
|
352
|
+
text: () => scalar("string"),
|
|
353
|
+
/** string (the length is not checked) */
|
|
354
|
+
varchar: (_length) => scalar("string"),
|
|
355
|
+
/** boolean */
|
|
356
|
+
bool: () => scalar("bool"),
|
|
357
|
+
/** int32: a JS number, an integer */
|
|
358
|
+
int: () => scalar("int32"),
|
|
359
|
+
/** int64: a JS bigint; a string on the wire */
|
|
360
|
+
bigint: () => scalar("int64"),
|
|
361
|
+
/** double: a JS number */
|
|
362
|
+
double: () => scalar("double"),
|
|
363
|
+
/** decimal: the SDK's `Decimal`; a string on the wire (precision and scale are not checked) */
|
|
364
|
+
decimal: (_precision, _scale) => scalar("decimal"),
|
|
365
|
+
/** uuid: a string in canonical form */
|
|
366
|
+
uuid: () => scalar("uuid"),
|
|
367
|
+
/** timestamp: a JS `Date`; an RFC 3339 string on the wire */
|
|
368
|
+
timestamp: () => scalar("timestamp"),
|
|
369
|
+
/** date: a `YYYY-MM-DD` string */
|
|
370
|
+
date: () => scalar("date"),
|
|
371
|
+
/** bytes: a `Uint8Array`; base64 on the wire */
|
|
372
|
+
bytes: () => scalar("bytes"),
|
|
373
|
+
/** json: any JSON value, typed as `T`; the value itself on the wire */
|
|
374
|
+
json: () => scalar("json"),
|
|
375
|
+
/** repeated: an array of the inner field's type (never absent: an empty array) */
|
|
376
|
+
array: (inner) => new Field({ kind: "array", inner }),
|
|
377
|
+
/**
|
|
378
|
+
* A reference to a row: its id as a string, whatever the target's key type (an `i64` key is its decimal
|
|
379
|
+
* string, as on the wire).
|
|
380
|
+
*/
|
|
381
|
+
ref: refBuilder,
|
|
382
|
+
/**
|
|
383
|
+
* A named message; also usable as a field (a nested message). `omitDefaults`: its fields at their protobuf default
|
|
384
|
+
* (`""`, `0`, `false`, an empty list, a message whose JSON is `{}`) are left out of the JSON it is written as (an
|
|
385
|
+
* enum, and an optional field that has a value, are still written), which trims the views a screen reads often.
|
|
386
|
+
*/
|
|
387
|
+
message: (name, fields, options) => new MessageDef(name, fields, options?.description ?? "", options?.omitDefaults ?? false),
|
|
388
|
+
/** `t.enum('Name', [...values])` declares an enum; `t.enum(def)` is a field of it. */
|
|
389
|
+
enum: enumBuilder,
|
|
390
|
+
};
|
|
391
|
+
function refBuilder(target, options = {}) {
|
|
392
|
+
const column = {};
|
|
393
|
+
if (options.nav)
|
|
394
|
+
column.nav = options.nav;
|
|
395
|
+
if (options.inverse)
|
|
396
|
+
column.inverse = options.inverse;
|
|
397
|
+
if (options.onDelete)
|
|
398
|
+
column.onDelete = options.onDelete;
|
|
399
|
+
return new Field({ kind: "ref", ref: target }, false, "", column);
|
|
400
|
+
}
|
|
401
|
+
function enumBuilder(nameOrDef, values) {
|
|
402
|
+
if (nameOrDef instanceof EnumDef)
|
|
403
|
+
return nameOrDef.use();
|
|
404
|
+
return new EnumDef(nameOrDef, [...(values ?? [])]);
|
|
405
|
+
}
|
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as grpc from "@grpc/grpc-js";
|
|
2
|
+
import { type SyscallSession, type WirePrincipal } from "./ctx.js";
|
|
3
|
+
import type { ResolvedEndpoint, Resolved } from "./descriptor.js";
|
|
4
|
+
import { type Logger } from "./log.js";
|
|
5
|
+
export interface Header {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
/** `Request` as the platform sends it. */
|
|
10
|
+
export interface WireRequest {
|
|
11
|
+
id: string;
|
|
12
|
+
method: string;
|
|
13
|
+
path: string;
|
|
14
|
+
query: string;
|
|
15
|
+
headers: Header[];
|
|
16
|
+
body: Buffer;
|
|
17
|
+
principal?: WirePrincipal | null;
|
|
18
|
+
}
|
|
19
|
+
export interface WireResponse {
|
|
20
|
+
status: number;
|
|
21
|
+
headers: Header[];
|
|
22
|
+
body: Buffer;
|
|
23
|
+
}
|
|
24
|
+
export interface ServeOptions {
|
|
25
|
+
/** Default `process.argv`; `--describe` prints the descriptor and exits. */
|
|
26
|
+
argv?: readonly string[];
|
|
27
|
+
/** Default `$CELOBUS_ADDR`, which the platform sets. */
|
|
28
|
+
addr?: string;
|
|
29
|
+
/** Handlers running at once; default 64 (the platform admits 64 per process). */
|
|
30
|
+
maxConcurrency?: number;
|
|
31
|
+
/** Drain SIGTERM/SIGINT and exit; default true. */
|
|
32
|
+
signals?: boolean;
|
|
33
|
+
/** Stops serving (drains, closes the session, resolves `serve()`), for tests and embedding. */
|
|
34
|
+
stop?: AbortSignal;
|
|
35
|
+
/** How long a drain waits for in-flight requests; default 10 s. */
|
|
36
|
+
drainMs?: number;
|
|
37
|
+
}
|
|
38
|
+
/** @internal What dispatch needs from the plugin. */
|
|
39
|
+
export interface ServeModel {
|
|
40
|
+
id: string;
|
|
41
|
+
version: string;
|
|
42
|
+
depends: string[];
|
|
43
|
+
resolved: Resolved;
|
|
44
|
+
log: Logger;
|
|
45
|
+
}
|
|
46
|
+
/** @internal The `celobus.v1.Celld` service, loaded from plugin.proto. */
|
|
47
|
+
export declare function celldDefinition(): grpc.ServiceClientConstructor;
|
|
48
|
+
/** @internal Serves one request: route, decode, run the handler under its deadline, encode, map errors. */
|
|
49
|
+
export declare function dispatch(model: ServeModel, routes: Map<string, ResolvedEndpoint>, session: SyscallSession, req: WireRequest, sessionSignal?: AbortSignal): Promise<WireResponse>;
|
|
50
|
+
/** `JobRun` as the platform sends it (64-bit numbers as strings). */
|
|
51
|
+
export interface WireJobRun {
|
|
52
|
+
runId: string;
|
|
53
|
+
job: string;
|
|
54
|
+
attempt: number;
|
|
55
|
+
maxAttempts: number;
|
|
56
|
+
payload: string;
|
|
57
|
+
principal?: WirePrincipal | null;
|
|
58
|
+
scheduledAtUnixMs: string | number;
|
|
59
|
+
timeoutMs: number;
|
|
60
|
+
requestId: string | number;
|
|
61
|
+
}
|
|
62
|
+
/** @internal Runs the session until stopped. */
|
|
63
|
+
export declare function runSession(model: ServeModel, options?: ServeOptions): Promise<void>;
|