@party-stack/ontology-server 0.12.1 → 0.14.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/README.md +12 -3
- package/lib/authorization.js +1 -1
- package/lib/bindingFence.d.ts +5 -0
- package/lib/bindingFence.d.ts.map +1 -1
- package/lib/bindingFence.js +24 -3
- package/lib/bindingFence.js.map +1 -1
- package/lib/composition.d.ts +5 -17
- package/lib/composition.d.ts.map +1 -1
- package/lib/definitionProjection.d.ts.map +1 -1
- package/lib/definitionProjection.js +4 -4
- package/lib/definitionProjection.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/internalAccess.js +1 -4
- package/lib/internalAccess.js.map +1 -1
- package/lib/operations.d.ts +35 -166
- package/lib/operations.d.ts.map +1 -1
- package/lib/operations.js +3 -55
- package/lib/operations.js.map +1 -1
- package/lib/replicaBootstrap.d.ts +20 -26
- package/lib/replicaBootstrap.d.ts.map +1 -1
- package/lib/replicaBootstrap.js +78 -42
- package/lib/replicaBootstrap.js.map +1 -1
- package/lib/routing.d.ts +49 -19
- package/lib/routing.d.ts.map +1 -1
- package/lib/routing.js +80 -52
- package/lib/routing.js.map +1 -1
- package/lib/rpc.d.ts +655 -767
- package/lib/rpc.d.ts.map +1 -1
- package/lib/rpc.js +128 -35
- package/lib/rpc.js.map +1 -1
- package/lib/rpcLocal.d.ts.map +1 -1
- package/lib/rpcLocal.js +6 -1
- package/lib/rpcLocal.js.map +1 -1
- package/lib/rpcWorker.d.ts.map +1 -1
- package/lib/rpcWorker.js +4 -1
- package/lib/rpcWorker.js.map +1 -1
- package/package.json +7 -7
package/lib/rpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","names":["OntologyDescription"],"sources":["../src/rpc.ts"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","names":["OntologyDescription"],"sources":["../src/rpc.ts"],"mappings":";;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gB,cAAc,MAAM;;;;;;qBAc9C,oCAAiC,QAhB9B,mBAAiB,UACf,0BACT,OAAO,OAAO,gBAAgB,cAAc,MAAM"}
|
package/lib/rpc.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { RpcActivity } from "./rpcActivity.js";
|
|
2
|
-
import { expectedBindingHeaders, withExpectedBinding } from "./bindingFence.js";
|
|
2
|
+
import { expectedBindingHeaders, expectedDefinitionHeader, withExpectedBinding } from "./bindingFence.js";
|
|
3
3
|
import { OntologyErrorProjection, errorProjectionLayer, projectActionFailure, projectStateFailures } from "./errorProjection.js";
|
|
4
4
|
import { OntologyOperationRpcs, makeOntologyOperationsClient, ontologyOperationHandlers } from "./operations.js";
|
|
5
5
|
import { makeRpcBackend } from "./rpcBackend.js";
|
|
6
6
|
import { BackendError, classifyBackendFailure } from "@party-stack/ontology-backend";
|
|
7
7
|
import { ClientStateCodec, ClientSubmissionCodec, ClientViewCodec, CompiledSubsetCodec, ObjectSelectionCodec } from "@party-stack/ontology-backend/protocol";
|
|
8
|
-
import { Cause, Context, Deferred, Effect, Exit, Layer, PubSub, Schema, Stream, SubscriptionRef } from "effect";
|
|
8
|
+
import { Cause, Context, Deferred, Effect, Exit, Layer, PubSub, Random, Schedule, Schema, Stream, SubscriptionRef } from "effect";
|
|
9
9
|
import { Rpc, RpcClient, RpcGroup, RpcMiddleware, RpcSchema } from "effect/rpc";
|
|
10
|
+
import { ontologyDefinitionContractHash, ontologyDefinitionHash, ontologyDefinitionSignature } from "@party-stack/ontology-storage";
|
|
10
11
|
import { Table } from "@party-stack/ontology-storage/tables";
|
|
11
|
-
import {
|
|
12
|
-
import { ontologyDefinitionContractHash, ontologyDefinitionContractSignature, ontologyDefinitionHash, ontologyDefinitionSignature } from "@party-stack/ontology-storage";
|
|
12
|
+
import { systemOntology } from "@party-stack/ontology-replica";
|
|
13
13
|
import { objectSubset } from "@party-stack/ontology-backend/subset";
|
|
14
14
|
import { ClientLeaseSchema, ClientSessionSchema, ClientTokenSchema } from "@party-stack/ontology-backend/clients";
|
|
15
15
|
import { DeliveryFrameCodec, DeliveryPositionSchema } from "@party-stack/ontology-backend/delivery";
|
|
16
|
-
import { OntologyDescriptionCodec } from "@party-stack/ontology-backend/description";
|
|
16
|
+
import { OntologyDescriptionCodec, ontologyProtocolVersion } from "@party-stack/ontology-backend/description";
|
|
17
|
+
import { makeMetadataBackend, pull } from "@party-stack/ontology-backend/meta";
|
|
18
|
+
import metaOntology from "@party-stack/ontology-spec/meta";
|
|
17
19
|
//#region src/rpc.ts
|
|
18
20
|
const Counter = Schema.Int.check(Schema.isBetween({
|
|
19
21
|
minimum: 0,
|
|
@@ -195,12 +197,13 @@ const baseOntologyRpcHandlers = (options) => {
|
|
|
195
197
|
})
|
|
196
198
|
}) : void 0;
|
|
197
199
|
const definitionHash = options.ir && signature !== void 0 ? yield* ontologyDefinitionHash(options.ir).pipe(Effect.mapError((cause) => classifyBackendFailure("describe", cause))) : void 0;
|
|
200
|
+
const contractHash = options.ir && signature !== void 0 ? yield* ontologyDefinitionContractHash(options.ir).pipe(Effect.mapError((cause) => classifyBackendFailure("describe", cause))) : void 0;
|
|
198
201
|
return {
|
|
199
|
-
version:
|
|
202
|
+
version: ontologyProtocolVersion,
|
|
200
203
|
replication: clientSync && options.source ? "speculative" : "committed",
|
|
201
204
|
definitionHash,
|
|
205
|
+
contractHash,
|
|
202
206
|
sourceId: options.source?.sourceId ?? options.backend?.sourceId ?? "stateless",
|
|
203
|
-
ir: options.ir,
|
|
204
207
|
context: options.context,
|
|
205
208
|
supportsIdempotency: options.source?.supportsIdempotency ?? options.backend?.supportsIdempotency ?? false,
|
|
206
209
|
delivery: !snapshots && committedDelivery,
|
|
@@ -210,7 +213,8 @@ const baseOntologyRpcHandlers = (options) => {
|
|
|
210
213
|
watchSubset: clientSync && Boolean(operationOptions.backend?.watchSubset || options.ir?.objectTypes.some((type) => typeof operationOptions.backend?.refresh?.(objectSubset(type.name))?.pollIntervalMs === "number")),
|
|
211
214
|
actionParameterResolution: Boolean(options.backend?.resolveActionParameters || options.replica),
|
|
212
215
|
queries: Boolean(options.backend),
|
|
213
|
-
|
|
216
|
+
system: Boolean(options.replica),
|
|
217
|
+
meta: Boolean(options.ir),
|
|
214
218
|
attachments: options.backend ? options.backend.attachments && { stage: Boolean(options.backend.attachments.stage) } : options.replica ? { stage: true } : void 0,
|
|
215
219
|
encrypted: Boolean(options.backend ? options.backend.encrypted : options.replica)
|
|
216
220
|
};
|
|
@@ -324,9 +328,9 @@ const resourceHeader = "x-party-stack-resource";
|
|
|
324
328
|
const ontologyRpcHandlers = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
325
329
|
const scope = yield* Effect.scope;
|
|
326
330
|
const ordinary = yield* Layer.buildWithScope(baseOntologyRpcHandlers(options), scope);
|
|
327
|
-
const
|
|
331
|
+
const system = yield* Effect.cached(Effect.gen(function* () {
|
|
328
332
|
if (!options.replica) return yield* new BackendError({
|
|
329
|
-
operation: "
|
|
333
|
+
operation: "system",
|
|
330
334
|
kind: "NotImplemented",
|
|
331
335
|
retryable: false,
|
|
332
336
|
message: "This endpoint does not own downloads."
|
|
@@ -334,38 +338,68 @@ const ontologyRpcHandlers = (options) => Layer.unwrap(Effect.gen(function* () {
|
|
|
334
338
|
const backend = yield* options.replica.demand.pins.backend;
|
|
335
339
|
return yield* Layer.buildWithScope(baseOntologyRpcHandlers({
|
|
336
340
|
backend,
|
|
337
|
-
ir:
|
|
341
|
+
ir: systemOntology,
|
|
338
342
|
context: options.context,
|
|
339
343
|
enableRealtime: options.enableRealtime,
|
|
340
344
|
errors: options.errors,
|
|
341
|
-
authorize: (_, headers) => options.authorize({ operation: "
|
|
345
|
+
authorize: (_, headers) => options.authorize({ operation: "System" }, headers)
|
|
346
|
+
}), scope);
|
|
347
|
+
}));
|
|
348
|
+
const describeAccess = (headers) => options.authorize({ operation: "Describe" }, headers);
|
|
349
|
+
const meta = yield* Effect.cached(Effect.gen(function* () {
|
|
350
|
+
if (!options.ir) return yield* new BackendError({
|
|
351
|
+
operation: "meta",
|
|
352
|
+
kind: "NotImplemented",
|
|
353
|
+
retryable: false,
|
|
354
|
+
message: "This endpoint has no definition to describe."
|
|
355
|
+
});
|
|
356
|
+
const replica = options.replica;
|
|
357
|
+
const boundTo = replica?.ir;
|
|
358
|
+
return yield* Layer.buildWithScope(baseOntologyRpcHandlers({
|
|
359
|
+
backend: makeMetadataBackend(options.ir, { ...replica && { replaced: replica.definition.changes.pipe(Stream.filter((ir) => ir !== boundTo), Stream.take(1)) } }),
|
|
360
|
+
ir: metaOntology,
|
|
361
|
+
enableRealtime: options.enableRealtime,
|
|
362
|
+
errors: options.errors,
|
|
363
|
+
authorize: (_, headers) => describeAccess(headers)
|
|
342
364
|
}), scope);
|
|
343
365
|
}));
|
|
344
366
|
const handlers = Object.fromEntries([...OntologyRpcs.requests].map(([tag, rpc]) => {
|
|
345
367
|
const invoke = (payload, request) => Effect.gen(function* () {
|
|
346
368
|
const resource = request.headers[resourceHeader];
|
|
347
|
-
if (resource !== void 0 && resource !== "
|
|
369
|
+
if (resource !== void 0 && resource !== "system" && resource !== "meta") return yield* new BackendError({
|
|
348
370
|
operation: "ontology.resource",
|
|
349
371
|
kind: "NotFound",
|
|
350
372
|
retryable: false,
|
|
351
373
|
message: "Unknown ontology resource."
|
|
352
374
|
});
|
|
353
|
-
if (resource === "
|
|
354
|
-
const context = resource === "
|
|
375
|
+
if (resource === "system") yield* options.authorize({ operation: "System" }, request.headers);
|
|
376
|
+
const context = resource === "system" ? yield* system : resource === "meta" ? yield* meta : ordinary;
|
|
355
377
|
return (yield* OntologyRpcs.accessHandler(tag).pipe(Effect.provideContext(context)))(payload, request);
|
|
356
378
|
});
|
|
357
379
|
return [tag, RpcSchema.isStreamSchema(rpc.successSchema) ? (payload, request) => Stream.unwrap(invoke(payload, request).pipe(Effect.map((result) => result))) : (payload, request) => Effect.flatten(invoke(payload, request).pipe(Effect.map((result) => result)))];
|
|
358
380
|
}));
|
|
359
381
|
return Layer.merge(OntologyRpcs.toLayer(handlers), errorProjectionLayer(options));
|
|
360
382
|
}));
|
|
361
|
-
const
|
|
383
|
+
const resourceDefinitions = {
|
|
384
|
+
system: systemOntology,
|
|
385
|
+
meta: metaOntology
|
|
386
|
+
};
|
|
387
|
+
const selectResource = (client, resource) => Object.fromEntries([...OntologyRpcs.requests.keys()].map((tag) => [tag, (payload, settings) => Reflect.apply(Reflect.get(client, tag), client, [payload, {
|
|
362
388
|
...settings,
|
|
363
389
|
headers: {
|
|
364
390
|
...settings?.headers,
|
|
365
|
-
[resourceHeader]:
|
|
391
|
+
[resourceHeader]: resource
|
|
366
392
|
}
|
|
367
393
|
}])]));
|
|
368
394
|
const unavailable = (cause) => classifyBackendFailure("remote.protocol", cause);
|
|
395
|
+
/** A fresh description must speak this client's protocol: an older server describes its
|
|
396
|
+
* definition differently and has no `meta` resource. */
|
|
397
|
+
const requireProtocol = (description) => description.version === ontologyProtocolVersion ? Effect.succeed(description) : Effect.fail(new BackendError({
|
|
398
|
+
operation: "remote.describe",
|
|
399
|
+
kind: "NotImplemented",
|
|
400
|
+
retryable: false,
|
|
401
|
+
message: `The server speaks ontology protocol version ${description.version}; this client needs version ${ontologyProtocolVersion}.`
|
|
402
|
+
}));
|
|
369
403
|
const copyDescription = (description) => Effect.try({
|
|
370
404
|
try: () => Schema.decodeUnknownSync(Description)(Schema.encodeSync(Description)(description)),
|
|
371
405
|
catch: (cause) => new BackendError({
|
|
@@ -389,7 +423,8 @@ const protocolIdentity = (description) => ({
|
|
|
389
423
|
watchSubset: Boolean(description.watchSubset),
|
|
390
424
|
actionParameterResolution: Boolean(description.actionParameterResolution),
|
|
391
425
|
queries: Boolean(description.queries),
|
|
392
|
-
|
|
426
|
+
system: Boolean(description.system),
|
|
427
|
+
meta: Boolean(description.meta),
|
|
393
428
|
attachments: Boolean(description.attachments),
|
|
394
429
|
stageAttachments: Boolean(description.attachments?.stage),
|
|
395
430
|
encrypted: Boolean(description.encrypted)
|
|
@@ -417,7 +452,7 @@ const checkBootstrapBinding = (accepted, fresh) => Effect.gen(function* () {
|
|
|
417
452
|
const definitionFailure = Symbol("OntologyClient.definitionFailure");
|
|
418
453
|
/** HTTP byte operations use the same incompatibility notification as typed RPC. */
|
|
419
454
|
const observeOntologyClientFailure = (client, work) => work.pipe(Effect.tapError((error) => client.definition[definitionFailure]?.(error) ?? Effect.void));
|
|
420
|
-
const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, options) {
|
|
455
|
+
const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, ir, options) {
|
|
421
456
|
const scope = yield* Effect.scope;
|
|
422
457
|
const state = yield* SubscriptionRef.make({
|
|
423
458
|
status: options?.description ? "retained" : "current",
|
|
@@ -437,7 +472,8 @@ const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, opti
|
|
|
437
472
|
});
|
|
438
473
|
if (incompatible(error) && (previous.status !== "incompatible" || previous.error?.kind !== error.kind)) yield* notify(error).pipe(Effect.catchCause((cause) => Effect.logError("Ontology incompatibility callback failed", cause)), Effect.forkIn(scope), Effect.asVoid);
|
|
439
474
|
});
|
|
440
|
-
const
|
|
475
|
+
const schemaHash = ir ? yield* ontologyDefinitionContractHash(ir).pipe(Effect.mapError((cause) => classifyBackendFailure("remote.definition", cause))) : description.contractHash;
|
|
476
|
+
const validate = options?.validate ?? ((fresh) => fresh.contractHash === schemaHash ? Effect.void : Effect.fail(new BackendError({
|
|
441
477
|
operation: "remote.definition",
|
|
442
478
|
kind: "SchemaMismatch",
|
|
443
479
|
retryable: false,
|
|
@@ -450,7 +486,7 @@ const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, opti
|
|
|
450
486
|
const check = SubscriptionRef.update(state, (current) => ({
|
|
451
487
|
...current,
|
|
452
488
|
refreshing: true
|
|
453
|
-
})).pipe(Effect.andThen(raw.Describe().pipe(Effect.mapError(unavailable))), Effect.tap((fresh) => checkBootstrapBinding(description, fresh)), Effect.tap(validate), Effect.tap(() => SubscriptionRef.set(state, {
|
|
489
|
+
})).pipe(Effect.andThen(raw.Describe().pipe(Effect.mapError(unavailable), Effect.flatMap(requireProtocol))), Effect.tap((fresh) => checkBootstrapBinding(description, fresh)), Effect.tap(validate), Effect.tap(() => SubscriptionRef.set(state, {
|
|
454
490
|
status: "current",
|
|
455
491
|
refreshing: false
|
|
456
492
|
})), Effect.onExit((exit) => Effect.gen(function* () {
|
|
@@ -469,8 +505,10 @@ const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, opti
|
|
|
469
505
|
if (error.kind === "SourceMismatch") return;
|
|
470
506
|
yield* refresh.pipe(Effect.catchCause(() => Effect.void), Effect.forkIn(scope), Effect.asVoid);
|
|
471
507
|
});
|
|
472
|
-
const headers =
|
|
473
|
-
|
|
508
|
+
const headers = {
|
|
509
|
+
...expectedBindingHeaders(description),
|
|
510
|
+
...schemaHash !== void 0 ? { [expectedDefinitionHeader]: schemaHash } : {}
|
|
511
|
+
};
|
|
474
512
|
const checkFrame = Effect.fnUntraced(function* (frame) {
|
|
475
513
|
if (frame.metadata) {
|
|
476
514
|
if (frame.metadata.sourceId !== description.sourceId) return yield* new BackendError({
|
|
@@ -479,8 +517,7 @@ const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, opti
|
|
|
479
517
|
retryable: false,
|
|
480
518
|
message: "The delivered ontology source changed."
|
|
481
519
|
});
|
|
482
|
-
|
|
483
|
-
if (expected !== void 0 && frame.metadata.schemaHash !== expected) return yield* new BackendError({
|
|
520
|
+
if (schemaHash !== void 0 && frame.metadata.schemaHash !== schemaHash) return yield* new BackendError({
|
|
484
521
|
operation: "remote.definition",
|
|
485
522
|
kind: "SchemaMismatch",
|
|
486
523
|
retryable: false,
|
|
@@ -509,6 +546,44 @@ const makeDefinitionClient = Effect.fnUntraced(function* (raw, description, opti
|
|
|
509
546
|
}
|
|
510
547
|
};
|
|
511
548
|
});
|
|
549
|
+
/**
|
|
550
|
+
* Read the definition an endpoint describes from its `meta` resource. The rows are read in one
|
|
551
|
+
* request, but the endpoint may change definition between `Describe` and the read: the result
|
|
552
|
+
* must hash to the described definition, or the endpoint is described again.
|
|
553
|
+
*/
|
|
554
|
+
const readDefinition = Effect.fnUntraced(function* (client, described, open) {
|
|
555
|
+
let description = described;
|
|
556
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
557
|
+
const ir = yield* Effect.scoped(Effect.flatMap(open(client, { resource: "meta" }), (meta) => pull(meta.backend)));
|
|
558
|
+
if ((yield* ontologyDefinitionHash(ir).pipe(Effect.mapError((cause) => classifyBackendFailure("remote.definition", cause)))) === description.definitionHash) return {
|
|
559
|
+
description,
|
|
560
|
+
ir
|
|
561
|
+
};
|
|
562
|
+
description = yield* client.Describe().pipe(Effect.mapError(unavailable), Effect.flatMap(requireProtocol));
|
|
563
|
+
}
|
|
564
|
+
return yield* new BackendError({
|
|
565
|
+
operation: "remote.definition",
|
|
566
|
+
kind: "Unavailable",
|
|
567
|
+
retryable: true,
|
|
568
|
+
message: "The ontology definition changed while it was being read."
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
/**
|
|
572
|
+
* While someone follows the definition status, notice a new definition without waiting for a
|
|
573
|
+
* request to fail: watch the endpoint's metadata. Without realtime the endpoint offers no watch,
|
|
574
|
+
* and the next request after a change reports it instead.
|
|
575
|
+
*/
|
|
576
|
+
const watchDefinition = (definition, metaBackend) => {
|
|
577
|
+
const check = Effect.andThen(Effect.flatMap(Random.nextIntBetween(0, 2e3), (delay) => Effect.sleep(delay)), Effect.ignore(definition.refresh));
|
|
578
|
+
const watch = Stream.unwrap(Effect.gen(function* () {
|
|
579
|
+
const events = (yield* metaBackend).watchSubset?.(objectSubset("Ontology"));
|
|
580
|
+
return events ? Stream.concat(Stream.make(void 0), yield* events) : Stream.empty;
|
|
581
|
+
})).pipe(Stream.retry(($) => $(Schedule.spaced("5 seconds")).pipe(Schedule.jittered, Schedule.while(({ input }) => input.retryable)))).pipe(Stream.mapEffect(() => check), Stream.catchCause(() => Stream.empty), Stream.drain);
|
|
582
|
+
return {
|
|
583
|
+
...definition,
|
|
584
|
+
changes: Stream.merge(definition.changes, watch, { haltStrategy: "left" })
|
|
585
|
+
};
|
|
586
|
+
};
|
|
512
587
|
const makeProtocolClient = (accept) => {
|
|
513
588
|
const open = Effect.fn("RemoteOntology.protocol")(function* (client, options) {
|
|
514
589
|
return yield* openProtocolClient(client, options, accept, open);
|
|
@@ -524,28 +599,46 @@ const makeOntologyProtocolClient = makeProtocolClient(copyDescription);
|
|
|
524
599
|
*/
|
|
525
600
|
const makeTrustedOntologyProtocolClient = makeProtocolClient(Effect.succeed);
|
|
526
601
|
const openProtocolClient = Effect.fnUntraced(function* (client, options, accept, open) {
|
|
527
|
-
const
|
|
528
|
-
if (options?.
|
|
602
|
+
const base = client;
|
|
603
|
+
if (options?.resource) client = selectResource(client, options.resource);
|
|
604
|
+
let description = yield* options?.description ? accept(options.description) : client.Describe().pipe(Effect.mapError(unavailable), Effect.flatMap(requireProtocol));
|
|
605
|
+
let ir = options?.ir ?? (options?.resource ? resourceDefinitions[options.resource] : void 0);
|
|
606
|
+
if (!ir && options?.localDefinition && description.definitionHash !== void 0) {
|
|
607
|
+
const local = yield* options.localDefinition;
|
|
608
|
+
if ((local && (yield* Effect.orElseSucceed(ontologyDefinitionHash(local), () => void 0))) === description.definitionHash) ir = local;
|
|
609
|
+
}
|
|
610
|
+
if (options?.description && !ir) return yield* new BackendError({
|
|
529
611
|
operation: "remote.bootstrap",
|
|
530
612
|
kind: "InvalidConfiguration",
|
|
531
613
|
retryable: false,
|
|
532
|
-
message: "A retained ontology description
|
|
614
|
+
message: "A retained ontology description needs the definition it was accepted with."
|
|
533
615
|
});
|
|
534
|
-
|
|
535
|
-
const
|
|
616
|
+
if (!ir && description.meta) ({description, ir} = yield* readDefinition(client, description, open));
|
|
617
|
+
const described = yield* makeDefinitionClient(client, description, ir, options);
|
|
618
|
+
const systemBackend = description.system && !options?.resource ? open(base, {
|
|
619
|
+
resource: "system",
|
|
620
|
+
networks: options?.networks
|
|
621
|
+
}).pipe(Effect.map((resource) => resource.backend)) : void 0;
|
|
622
|
+
const metaBackend = description.meta && !options?.resource ? open(base, {
|
|
623
|
+
resource: "meta",
|
|
624
|
+
networks: options?.networks
|
|
625
|
+
}).pipe(Effect.map((resource) => resource.backend)) : void 0;
|
|
536
626
|
client = described.client;
|
|
537
627
|
const operations = yield* makeOntologyOperationsClient(client);
|
|
538
628
|
const common = {
|
|
539
629
|
description,
|
|
540
|
-
definition: described.definition,
|
|
630
|
+
definition: metaBackend && !options?.resource ? watchDefinition(described.definition, metaBackend) : described.definition,
|
|
541
631
|
operations,
|
|
542
|
-
|
|
543
|
-
|
|
632
|
+
systemBackend,
|
|
633
|
+
metaBackend,
|
|
544
634
|
sourceId: description.sourceId,
|
|
545
635
|
definitionHash: description.definitionHash,
|
|
546
|
-
ir
|
|
636
|
+
ir,
|
|
547
637
|
context: description.context,
|
|
548
|
-
backend:
|
|
638
|
+
backend: {
|
|
639
|
+
...makeRpcBackend(client, description, operations),
|
|
640
|
+
...options?.networks && { networks: options.networks }
|
|
641
|
+
}
|
|
549
642
|
};
|
|
550
643
|
if (description.replication === "committed") return {
|
|
551
644
|
...common,
|