@collective-intelligence/external-apps-client-sdk 0.1.38 → 0.1.40
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 +35 -1
- package/dist/effect.d.ts +13 -3
- package/dist/effect.js +3 -3
- package/dist/{index-D_Ctkuhr.d.ts → index-CAYSljTO.d.ts} +8 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +29 -26
- package/dist/{resources-CftkAwlJ.d.ts → resources-CL3ZWaWz.d.ts} +75 -4
- package/dist/{resources-BhOgbxg5.js → resources-DJ1cTUBp.js} +5 -1
- package/dist/resources.d.ts +2 -2
- package/dist/resources.js +3 -3
- package/dist/{service-D-18nBUU.js → service-8gveUQPI.js} +148 -59
- package/dist/{service-DD58W3in.js → service-BJjQFasg.js} +153 -24
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -346,13 +346,44 @@ const unsubscribe = realtime.subscribe(
|
|
|
346
346
|
`lastEventId`; `close()` ends the connection and the page listeners.
|
|
347
347
|
- `createRealtimeClient` runs on the realtime service of `./effect`, in a
|
|
348
348
|
runtime of its own. Its listeners and callbacks run in the same call as the
|
|
349
|
-
page event, stream event or timer that causes them
|
|
349
|
+
page event, stream event or timer that causes them; with `revalidateUrl`, a
|
|
350
|
+
delivery calls them when the answer of its post arrives, or in the timer of
|
|
351
|
+
its 1-second wait. `access-changed` calls
|
|
350
352
|
`onAccessChanged` only, never `onReset`.
|
|
351
353
|
- A failed ticket request logs a warning, and a failed connection step logs an
|
|
352
354
|
error, through the Effect logger (the console by default). The connection
|
|
353
355
|
goes on: the backoff or the ping timeout reconnects. The warning shows a
|
|
354
356
|
relative `ticketUrl` on the placeholder origin `realtime-ticket.invalid`;
|
|
355
357
|
`fetch` gets `ticketUrl` as you wrote it.
|
|
358
|
+
- With `revalidateUrl` (the Revalidate Route of the server SDK BFF, for
|
|
359
|
+
example `/api/realtime/revalidate`), each delivery first posts its changes
|
|
360
|
+
there as `{ token, changes: { topic, id }[] }`, the latest change of each
|
|
361
|
+
record, so that the server revalidates its Next.js cache tags. The delivery
|
|
362
|
+
then waits for the answer, 1 second at most, and only after it calls the
|
|
363
|
+
listeners and `onReset`: a listener that reads through the server cache
|
|
364
|
+
(for example `router.refresh()`) reads the revalidated entry. A failed post
|
|
365
|
+
does not hold the listeners, and a slow one holds them for 1 second only.
|
|
366
|
+
A change that arrives during the wait goes to the next delivery. A delivery
|
|
367
|
+
of more than 100 changes posts bodies of 100 changes, because the route
|
|
368
|
+
takes no more; up to 4 bodies post at once, so a slow body does not hold
|
|
369
|
+
the others, and the 1-second wait covers them all. A `reset` or
|
|
370
|
+
`access-changed` event adds `reset: true` to the first body. The token is the `grantToken` of
|
|
371
|
+
the last ticket: the client keeps it in the memory of the tab, and each
|
|
372
|
+
ticket renews it. The token expires 10 minutes after the ticket, and a
|
|
373
|
+
stream can stay open longer: so 8 minutes after each token, while the
|
|
374
|
+
stream stays open, the client asks `ticketUrl` for a new ticket of the
|
|
375
|
+
same topics and keeps only its token. The stream stays open, and that
|
|
376
|
+
ticket goes unused. A failed renewal logs a warning, keeps the old token
|
|
377
|
+
and tries again after 15 seconds, 30 seconds, then every 60 seconds, and
|
|
378
|
+
at least after the `Retry-After` of the refusal; after a renewal that
|
|
379
|
+
succeeds, the 8-minute cycle goes on. A retry that would come after the
|
|
380
|
+
token expires does not run: the renewals stop until the next ticket, and
|
|
381
|
+
a delivery after the expiry posts nothing and calls the listeners at
|
|
382
|
+
once, because the Revalidate Route refuses an expired token. Without a
|
|
383
|
+
token in the ticket answer (a ticket route
|
|
384
|
+
without `secrets`) the client posts nothing. The resync after a cursorless
|
|
385
|
+
open posts nothing. A failed post logs a warning; `fetch` gets
|
|
386
|
+
`revalidateUrl` as you wrote it.
|
|
356
387
|
|
|
357
388
|
### Realtime on Effect
|
|
358
389
|
|
|
@@ -395,6 +426,9 @@ Effect.runFork(
|
|
|
395
426
|
visible. Provide `FetchHttpClient.Fetch` to use a different `fetch`.
|
|
396
427
|
- `HttpClient` resolves a relative `ticketUrl` against `location`. Outside a
|
|
397
428
|
browser, give an absolute `ticketUrl`.
|
|
429
|
+
- `layerRealtimeClient({ ticketUrl, revalidateUrl })` posts to the Revalidate
|
|
430
|
+
Route as `createRealtimeClient` does; a relative `revalidateUrl` also
|
|
431
|
+
resolves against `location`.
|
|
398
432
|
- Timers use `Clock` and the jitter uses `Random`, so a test can use `TestClock`
|
|
399
433
|
and a fixed `Random`.
|
|
400
434
|
|
package/dist/effect.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as RealtimeTopicFilter, B as layerProxyConfig, D as RunsValue, E as Runs, F as ExecuteResult, I as layerDirect, L as layerDirectConfig, N as CiClient, O as layer$4, P as CiClientValue, Q as RealtimeTopic, R as layerFromExecutor, T as RunFollowOptions, Z as RealtimeChange, f as DelegatedApplicationRuntimeOptions, j as CiStreamPage$1, p as DelegatedRuntimeState, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, z as layerProxy } from "./index-
|
|
1
|
+
import { Zt as ClientFetch, _ as layerLegacy, a as LegacyResourceClient, an as layerFederated, c as LegacyResourcesValue, cn as layerServerSessionConfig, d as ResourcesFromEntityTransportOptions, dn as CiError, f as ResourcesLayerOptions, fn as CiErrorCode, g as layerFromEntityTransport, h as layerConfig$3, hn as FederatedAuthErrorCode, i as makeEntityHttpExecute, in as FederatedAuthValue, l as ResourceEntityClient, m as layer$3, mn as FederatedAuthError, o as LegacyResources, on as layerFederatedConfig, p as ResourcesValue, pn as CiTransportError, rn as FederatedAuth, s as LegacyResourcesLayerOptions, sn as layerServerSession, u as Resources, v as layerLegacyConfig } from "./resources-CL3ZWaWz.js";
|
|
2
|
+
import { $ as RealtimeTopicFilter, B as layerProxyConfig, D as RunsValue, E as Runs, F as ExecuteResult, I as layerDirect, L as layerDirectConfig, N as CiClient, O as layer$4, P as CiClientValue, Q as RealtimeTopic, R as layerFromExecutor, T as RunFollowOptions, Z as RealtimeChange, f as DelegatedApplicationRuntimeOptions, j as CiStreamPage$1, p as DelegatedRuntimeState, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, z as layerProxy } from "./index-CAYSljTO.js";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
import * as Config from "effect/Config";
|
|
5
5
|
import * as Context from "effect/Context";
|
|
@@ -54,6 +54,16 @@ declare class RealtimeClient extends RealtimeClient_base {}
|
|
|
54
54
|
type RealtimeClientLayerOptions = Readonly<{
|
|
55
55
|
/** The application's ticket route, e.g. `/api/realtime/ticket`. */
|
|
56
56
|
ticketUrl: string;
|
|
57
|
+
/**
|
|
58
|
+
* The application's Revalidate Route, e.g. `/api/realtime/revalidate`. With
|
|
59
|
+
* it, each delivery first posts its changes there, and a `reset` or
|
|
60
|
+
* `access-changed` event posts `reset: true`, with the grant token of the
|
|
61
|
+
* last ticket, so that the server revalidates its cache tags. The delivery
|
|
62
|
+
* reaches the listeners when the post has its answer, or 1 s after the post
|
|
63
|
+
* at the latest. Without a grant token in the ticket answer nothing is
|
|
64
|
+
* posted.
|
|
65
|
+
*/
|
|
66
|
+
revalidateUrl?: string;
|
|
57
67
|
}>;
|
|
58
68
|
/** `RealtimeClient` with the `fetch` of `FetchHttpClient.Fetch` and the page of this runtime. */
|
|
59
69
|
declare const layer$2: (options: RealtimeClientLayerOptions) => Layer.Layer<RealtimeClient, never, never>;
|
|
@@ -129,4 +139,4 @@ declare class DelegatedRuntime extends DelegatedRuntime_base {}
|
|
|
129
139
|
declare const layer: (options: DelegatedApplicationRuntimeOptions) => Layer.Layer<FederatedAuth | CiClient | Runs | DelegatedRuntime, FederatedAuthError, never>;
|
|
130
140
|
/** `layer` with options that Effect `Config` reads. */
|
|
131
141
|
declare const layerConfig: (config: Config.Wrap<DelegatedApplicationRuntimeOptions>) => Layer.Layer<FederatedAuth | CiClient | Runs | DelegatedRuntime, FederatedAuthError | Config.ConfigError, never>;
|
|
132
|
-
export { CiClient, type CiClientValue, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, type DelegatedRuntimeValue, type ExecuteResult, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, type FederatedAuthValue, type FixedWorkflowRequest, FixedWorkflows, type FixedWorkflowsLayerOptions, type FixedWorkflowsValue, type LegacyResourceClient, LegacyResources, type LegacyResourcesLayerOptions, type LegacyResourcesValue, type RealtimeChange, RealtimeClient, type RealtimeClientLayerOptions, type RealtimeResync, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeUpdate, type ResourceEntityClient, Resources, type ResourcesFromEntityTransportOptions, type ResourcesLayerOptions, type ResourcesValue, type RunFollowOptions, Runs, type RunsValue, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, subscribe };
|
|
142
|
+
export { CiClient, type CiClientValue, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, type DelegatedRuntimeValue, type ExecuteResult, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, type FederatedAuthValue, type FixedWorkflowRequest, FixedWorkflows, type FixedWorkflowsLayerOptions, type FixedWorkflowsValue, type LegacyResourceClient, LegacyResources, type LegacyResourcesLayerOptions, type LegacyResourcesValue, type RealtimeChange, RealtimeClient, type RealtimeClientLayerOptions, type RealtimeResync, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeUpdate, type ResourceEntityClient, Resources, type ResourcesFromEntityTransportOptions, type ResourcesLayerOptions, type ResourcesValue, type RunFollowOptions, Runs, type RunsValue, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, makeEntityHttpExecute, subscribe };
|
package/dist/effect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-
|
|
1
|
+
import { D as CiTransportError, E as CiErrorCode, O as FederatedAuthError, T as CiError, a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$3, k as FederatedAuthErrorCode, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-8gveUQPI.js";
|
|
2
|
+
import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-BJjQFasg.js";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
/**
|
|
5
5
|
* The wire Schemas of the CI envelopes that `./effect` exports. The Type of
|
|
@@ -29,4 +29,4 @@ const CiStreamPage = Schema.Struct({
|
|
|
29
29
|
events: Schema.mutableKey(Schema.mutable(Schema.Array(Schema.JsonObject))),
|
|
30
30
|
nextCursor: Schema.mutableKey(Schema.NullOr(Schema.String))
|
|
31
31
|
});
|
|
32
|
-
export { CiClient, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, FixedWorkflows, LegacyResources, RealtimeClient, Resources, Runs, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, subscribe };
|
|
32
|
+
export { CiClient, CiError, CiErrorCode, CiErrorEnvelope, CiResult, CiStreamPage, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, DelegatedRuntime, FederatedAuth, FederatedAuthError, FederatedAuthErrorCode, FixedWorkflows, LegacyResources, RealtimeClient, Resources, Runs, layerDirect as layerCiClientDirect, layerDirectConfig as layerCiClientDirectConfig, layerFromExecutor as layerCiClientFromExecutor, layerProxy as layerCiClientProxy, layerProxyConfig as layerCiClientProxyConfig, layer as layerDelegatedRuntime, layerConfig as layerDelegatedRuntimeConfig, layerFederated as layerFederatedAuth, layerFederatedConfig as layerFederatedAuthConfig, layer$1 as layerFixedWorkflows, layerConfig$1 as layerFixedWorkflowsConfig, layerLegacy as layerLegacyResources, layerLegacyConfig as layerLegacyResourcesConfig, layer$2 as layerRealtimeClient, layerConfig$2 as layerRealtimeClientConfig, layer$3 as layerResources, layerConfig$3 as layerResourcesConfig, layerFromEntityTransport as layerResourcesFromEntityTransport, layer$4 as layerRuns, layerServerSession as layerServerSessionAuth, layerServerSessionConfig as layerServerSessionAuthConfig, makeEntityHttpExecute, subscribe };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { At as
|
|
1
|
+
import { At as JsonValue, Dt as CiError$2, Ft as ClientOperationInput, Gt as ConversationHistory, Ht as AgentInvokeTarget, It as ClientOperationMap, Jt as QueryFilter, Kt as JsonObject, Lt as ClientOperationOutput, Nt as ClientOperationDefinition, Pt as ClientOperationId, Rt as OperationExecutionOptions, Tt as ProxyTransportOptions, Ut as ApplicationRole, Wt as ConversationContinueTarget, Xt as WorkflowInvokeTarget, Yt as SearchQuery, Zt as ClientFetch, dn as CiError$1, en as FederatedAuthState, kt as CiResult, pn as CiTransportError, qt as KnowledgeQuery, tn as FederatedSessionIdentity, zt as TypedOperationExecutor } from "./resources-CL3ZWaWz.js";
|
|
2
|
+
import "effect/Clock";
|
|
2
3
|
import * as Config from "effect/Config";
|
|
3
4
|
import * as Context from "effect/Context";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
6
|
import * as Layer from "effect/Layer";
|
|
6
7
|
import "effect/Stream";
|
|
7
|
-
import "effect/Clock";
|
|
8
8
|
import "effect/ManagedRuntime";
|
|
9
9
|
/** One equality filter on a dotted data path of a topic's records. */
|
|
10
10
|
type RealtimeTopicFilter = Readonly<{
|
|
@@ -969,6 +969,12 @@ type RealtimeTimers = Readonly<{
|
|
|
969
969
|
type RealtimeClientOptions = Readonly<{
|
|
970
970
|
/** The application's ticket route, e.g. `/api/realtime/ticket`. */
|
|
971
971
|
ticketUrl: string;
|
|
972
|
+
/**
|
|
973
|
+
* The application's Revalidate Route, e.g. `/api/realtime/revalidate`. With
|
|
974
|
+
* it, each delivery also posts its changes there with the grant token of
|
|
975
|
+
* the last ticket, so that the server revalidates its cache tags.
|
|
976
|
+
*/
|
|
977
|
+
revalidateUrl?: string;
|
|
972
978
|
fetch?: ClientFetch;
|
|
973
979
|
eventSourceFactory?: RealtimeEventSourceFactory;
|
|
974
980
|
/** The page document; without it the page counts as always visible. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { $ as RealtimeTopicFilter, A as CiStreamEvent, C as followRun, G as RealtimeStreamEnd, H as createDirectTransport, J as createFetchEventSourceFactory, K as RealtimeStreamEvent, M as nextStreamCursor, Q as RealtimeTopic, S as FollowRunSource, U as RealtimeEventSource, V as DirectTransportOptions, W as RealtimeEventSourceFactory, X as RealtimeWindow, Y as RealtimeDocument, Z as RealtimeChange, _ as ClientSdkEntrypoint, a as RealtimeClientStatus, b as createClient, c as FixedWorkflowClient, d as DelegatedApplicationRuntime, et as realtimeTopicKey, f as DelegatedApplicationRuntimeOptions, g as ClientSdkClient, h as ClientDomains, i as RealtimeClientState, j as CiStreamPage, k as CiRunCancellation, l as FixedWorkflowClientOptions, m as createDelegatedApplicationRuntime, n as RealtimeClient, o as RealtimeTimers, p as DelegatedRuntimeState, q as RealtimeStreamHandlers, r as RealtimeClientOptions, s as createRealtimeClient, t as CiError, u as createFixedWorkflowClient, v as OrganizationClient, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, x as FollowRunOptions, y as clientSdkProtocolVersion } from "./index-
|
|
3
|
-
export { CiError, type CiErrorCode, type CiResult, type CiRunCancellation, type CiStreamEvent, type CiStreamPage, CiTransportError, type ClientDomains, type ClientFetch, type ClientOperationDefinition, type ClientOperationId, type ClientOperationInput, type ClientOperationMap, type ClientOperationOutput, type ClientSdkClient, type ClientSdkEntrypoint, DEFAULT_FOLLOW_RUN_DEADLINE_MS, type DelegatedApplicationRuntime, type DelegatedApplicationRuntimeOptions, type DelegatedRuntimeState, type DirectTransportOptions, type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type FederatedAuth, FederatedAuthError, type FederatedAuthErrorCode, type FederatedAuthOptions, type FederatedAuthState, type FederatedSessionIdentity, type FixedWorkflowClient, type FixedWorkflowClientOptions, type FollowRunOptions, type FollowRunSource, type IdempotencyKey, type JsonObject, type JsonValue, type KnowledgeQuery, type OperationExecutionOptions, type OperationRequest, type OperationSuccess, type OrganizationClient, type PortableResourceSchema, type ProxyAuthentication, type ProxyTransportOptions, type QueryFilter, type RealtimeChange, type RealtimeClient, type RealtimeClientOptions, type RealtimeClientState, type RealtimeClientStatus, type RealtimeDocument, type RealtimeEventSource, type RealtimeEventSourceFactory, type RealtimeStreamEnd, type RealtimeStreamEvent, type RealtimeStreamHandlers, type RealtimeTimers, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeWindow, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, type SearchQuery, type ServerSessionAuthOptions, type TypedOperationExecutor, type WorkflowInvokeTarget, clientOperationIds, clientSdkProtocolVersion, createClient, createDelegatedApplicationRuntime, createDirectTransport, createEntityHttpTransport, createEntityProtocol, createFederatedAuth, createFetchEventSourceFactory, createFixedWorkflowClient, createProxyTransport, createRealtimeClient, createResourceClient, createServerSessionAuth, followRun, isClientOperationId, isEntityReadLimitError, nextStreamCursor, realtimeTopicKey };
|
|
1
|
+
import { $ as ResourceDefinition, $t as FederatedAuthOptions, A as EntityFileFieldWrite, At as JsonValue, B as EntityRequest, Bt as clientOperationIds, C as EntityBatchInput, Ct as ResourceUpdateRequest, D as EntityClient, E as EntityBatchRefusedDetails, Et as createProxyTransport, F as EntityOperation, Ft as ClientOperationInput, G as EntityUploadSlot, H as EntityTransport, I as EntityOperationResult, It as ClientOperationMap, J as ResourceCapabilities, Jt as QueryFilter, K as IdempotencyKey, Kt as JsonObject, L as EntityPage, Lt as ClientOperationOutput, M as EntityFileWrite, Mt as OperationSuccess, N as EntityListQuery, Nt as ClientOperationDefinition, O as EntityCreateInput, Ot as CiErrorCode, P as EntityMemberValue, Pt as ClientOperationId, Q as ResourceCursor, Qt as FederatedAuth, R as EntityProtocol, Rt as OperationExecutionOptions, S as createResourceClient, St as ResourceTransportRequest, T as EntityBatchRefusal, Tt as ProxyTransportOptions, U as EntityUpdateInput, V as EntityRestoreInput, Vt as isClientOperationId, W as EntityUploadInput, X as ResourceCreateInput, Xt as WorkflowInvokeTarget, Y as ResourceClient, Yt as SearchQuery, Z as ResourceCreateRequest, Zt as ClientFetch, _t as ResourceRequestOptions, at as ResourceIdentityField, b as isEntityBatchRefusedError, bt as ResourceSort, ct as ResourceLifecycleRequest, dt as ResourceListResult, en as FederatedAuthState, et as ResourceError, ft as ResourceMutationInput, gt as ResourceRecordId, hn as FederatedAuthErrorCode, ht as ResourceRecord, it as ResourceId, j as EntityFileValue, jt as OperationRequest, k as EntityDeleteInput, kt as CiResult, ln as ServerSessionAuthOptions, lt as ResourceListQuery, mn as FederatedAuthError, mt as ResourcePaginationMode, n as EntityHttpTransportOptions, nn as createFederatedAuth, nt as ResourceFilter, ot as ResourceJsonValue, pn as CiTransportError, pt as ResourcePagination, q as PortableResourceSchema, qt as KnowledgeQuery, r as createEntityHttpTransport, rt as ResourceGetRequest, st as ResourceLifecycleInput, t as EntityHttpDestination, tn as FederatedSessionIdentity, tt as ResourceErrorCode, un as createServerSessionAuth, ut as ResourceListRequest, vt as ResourceResult, w as EntityBatchOp, wt as ProxyAuthentication, x as isEntityReadLimitError, xt as ResourceTransport, y as createEntityProtocol, yt as ResourceRevision, z as EntityReadLimitDetails, zt as TypedOperationExecutor } from "./resources-CL3ZWaWz.js";
|
|
2
|
+
import { $ as RealtimeTopicFilter, A as CiStreamEvent, C as followRun, G as RealtimeStreamEnd, H as createDirectTransport, J as createFetchEventSourceFactory, K as RealtimeStreamEvent, M as nextStreamCursor, Q as RealtimeTopic, S as FollowRunSource, U as RealtimeEventSource, V as DirectTransportOptions, W as RealtimeEventSourceFactory, X as RealtimeWindow, Y as RealtimeDocument, Z as RealtimeChange, _ as ClientSdkEntrypoint, a as RealtimeClientStatus, b as createClient, c as FixedWorkflowClient, d as DelegatedApplicationRuntime, et as realtimeTopicKey, f as DelegatedApplicationRuntimeOptions, g as ClientSdkClient, h as ClientDomains, i as RealtimeClientState, j as CiStreamPage, k as CiRunCancellation, l as FixedWorkflowClientOptions, m as createDelegatedApplicationRuntime, n as RealtimeClient, o as RealtimeTimers, p as DelegatedRuntimeState, q as RealtimeStreamHandlers, r as RealtimeClientOptions, s as createRealtimeClient, t as CiError, u as createFixedWorkflowClient, v as OrganizationClient, w as DEFAULT_FOLLOW_RUN_DEADLINE_MS, x as FollowRunOptions, y as clientSdkProtocolVersion } from "./index-CAYSljTO.js";
|
|
3
|
+
export { CiError, type CiErrorCode, type CiResult, type CiRunCancellation, type CiStreamEvent, type CiStreamPage, CiTransportError, type ClientDomains, type ClientFetch, type ClientOperationDefinition, type ClientOperationId, type ClientOperationInput, type ClientOperationMap, type ClientOperationOutput, type ClientSdkClient, type ClientSdkEntrypoint, DEFAULT_FOLLOW_RUN_DEADLINE_MS, type DelegatedApplicationRuntime, type DelegatedApplicationRuntimeOptions, type DelegatedRuntimeState, type DirectTransportOptions, type EntityBatchInput, type EntityBatchOp, type EntityBatchRefusal, type EntityBatchRefusedDetails, type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type FederatedAuth, FederatedAuthError, type FederatedAuthErrorCode, type FederatedAuthOptions, type FederatedAuthState, type FederatedSessionIdentity, type FixedWorkflowClient, type FixedWorkflowClientOptions, type FollowRunOptions, type FollowRunSource, type IdempotencyKey, type JsonObject, type JsonValue, type KnowledgeQuery, type OperationExecutionOptions, type OperationRequest, type OperationSuccess, type OrganizationClient, type PortableResourceSchema, type ProxyAuthentication, type ProxyTransportOptions, type QueryFilter, type RealtimeChange, type RealtimeClient, type RealtimeClientOptions, type RealtimeClientState, type RealtimeClientStatus, type RealtimeDocument, type RealtimeEventSource, type RealtimeEventSourceFactory, type RealtimeStreamEnd, type RealtimeStreamEvent, type RealtimeStreamHandlers, type RealtimeTimers, type RealtimeTopic, type RealtimeTopicFilter, type RealtimeWindow, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, type SearchQuery, type ServerSessionAuthOptions, type TypedOperationExecutor, type WorkflowInvokeTarget, clientOperationIds, clientSdkProtocolVersion, createClient, createDelegatedApplicationRuntime, createDirectTransport, createEntityHttpTransport, createEntityProtocol, createFederatedAuth, createFetchEventSourceFactory, createFixedWorkflowClient, createProxyTransport, createRealtimeClient, createResourceClient, createServerSessionAuth, followRun, isClientOperationId, isEntityBatchRefusedError, isEntityReadLimitError, nextStreamCursor, realtimeTopicKey };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-
|
|
3
|
-
import { t as createResourceClient } from "./resources-
|
|
1
|
+
import { A as errors_exports, C as isClientOperationId, D as CiTransportError, O as FederatedAuthError, b as proxyHttpOptions, d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol, v as directHttpOptions, w as toCiResult, x as clientOperationIds, y as makeHttpExecute } from "./service-8gveUQPI.js";
|
|
2
|
+
import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-BJjQFasg.js";
|
|
3
|
+
import { t as createResourceClient } from "./resources-DJ1cTUBp.js";
|
|
4
|
+
import * as Clock from "effect/Clock";
|
|
4
5
|
import * as Context from "effect/Context";
|
|
6
|
+
import * as Duration from "effect/Duration";
|
|
5
7
|
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Fiber from "effect/Fiber";
|
|
6
9
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
7
10
|
import * as Layer from "effect/Layer";
|
|
8
11
|
import * as Random from "effect/Random";
|
|
9
|
-
import * as Clock from "effect/Clock";
|
|
10
12
|
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
11
|
-
import * as Duration from "effect/Duration";
|
|
12
|
-
import * as Fiber from "effect/Fiber";
|
|
13
13
|
import { constVoid } from "effect/Function";
|
|
14
14
|
/**
|
|
15
15
|
* Internal; no entrypoint exports it. Runs one facade method:
|
|
@@ -382,33 +382,35 @@ const randomOf = (random) => ({
|
|
|
382
382
|
nextIntUnsafe: () => Math.floor(random() * Number.MAX_SAFE_INTEGER)
|
|
383
383
|
});
|
|
384
384
|
/**
|
|
385
|
-
* The origin on which the service requests the ticket
|
|
386
|
-
* a relative URL against `location`,
|
|
387
|
-
* `ticketUrl` as the app gave it before
|
|
388
|
-
* resolve it on a base of its own. So
|
|
389
|
-
*
|
|
385
|
+
* The origin on which the service requests the ticket and posts to the
|
|
386
|
+
* Revalidate Route. `HttpClient` resolves a relative URL against `location`,
|
|
387
|
+
* and fails without one. But `fetch` got `ticketUrl` as the app gave it before
|
|
388
|
+
* the service, and a custom `fetch` can resolve it on a base of its own. So
|
|
389
|
+
* the service requests each app URL on this origin, and `fetchOf` gives
|
|
390
|
+
* `fetch` the URL of the app in its place.
|
|
390
391
|
*/
|
|
391
|
-
const
|
|
392
|
-
/** `
|
|
393
|
-
const
|
|
392
|
+
const placeholderOrigin = "http://realtime-ticket.invalid/";
|
|
393
|
+
/** `url` on `placeholderOrigin`; `placeholderOrigin` itself for a string that is not a URL. */
|
|
394
|
+
const onPlaceholderOrigin = (url) => {
|
|
394
395
|
try {
|
|
395
|
-
return new URL(
|
|
396
|
+
return new URL(url, placeholderOrigin).href;
|
|
396
397
|
} catch {
|
|
397
|
-
return
|
|
398
|
+
return placeholderOrigin;
|
|
398
399
|
}
|
|
399
400
|
};
|
|
400
401
|
/**
|
|
401
402
|
* The `fetch` of the client as `FetchHttpClient.Fetch`, called as before the
|
|
402
|
-
* service: with a string URL, `ticketUrl` for the ticket request
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* types; nothing here
|
|
403
|
+
* service: with a string URL, `ticketUrl` for the ticket request and
|
|
404
|
+
* `revalidateUrl` for a revalidate post, and without the `duplex: undefined`
|
|
405
|
+
* that `FetchHttpClient` adds for a body that is not a stream. `preconnect`
|
|
406
|
+
* only completes the type of `fetch` under Bun's types; nothing here
|
|
407
|
+
* preconnects.
|
|
406
408
|
*/
|
|
407
|
-
const fetchOf = (fetch,
|
|
408
|
-
const
|
|
409
|
+
const fetchOf = (fetch, appUrls) => {
|
|
410
|
+
const requestUrls = new Map(appUrls.map((url) => [onPlaceholderOrigin(url), url]));
|
|
409
411
|
return Object.assign((input, init) => {
|
|
410
412
|
const href = input instanceof URL ? input.href : input;
|
|
411
|
-
const url = href
|
|
413
|
+
const url = href instanceof Request ? href : requestUrls.get(href) ?? href;
|
|
412
414
|
if (init === void 0 || !("duplex" in init)) return fetch(url, init);
|
|
413
415
|
const { duplex, ...rest } = init;
|
|
414
416
|
return duplex === void 0 ? fetch(url, rest) : fetch(url, init);
|
|
@@ -429,7 +431,8 @@ const createRealtimeClient = (options) => {
|
|
|
429
431
|
const { flush, scheduler } = makeSyncScheduler();
|
|
430
432
|
const runtime = ManagedRuntime.make(Layer.effect(FacadeConnection, makeConnection({
|
|
431
433
|
resyncOnAccessChange: false,
|
|
432
|
-
ticketUrl:
|
|
434
|
+
ticketUrl: onPlaceholderOrigin(options.ticketUrl),
|
|
435
|
+
...options.revalidateUrl !== void 0 && { revalidateUrl: onPlaceholderOrigin(options.revalidateUrl) }
|
|
433
436
|
})).pipe(Layer.provide([
|
|
434
437
|
FetchHttpClient.layer,
|
|
435
438
|
layerBrowser({
|
|
@@ -438,7 +441,7 @@ const createRealtimeClient = (options) => {
|
|
|
438
441
|
}),
|
|
439
442
|
options.eventSourceFactory === void 0 ? layer$3 : layerFromFactory(options.eventSourceFactory)
|
|
440
443
|
]), Layer.provide([
|
|
441
|
-
Layer.succeed(FetchHttpClient.Fetch, fetchOf(options.fetch ?? globalThis.fetch, options.ticketUrl)),
|
|
444
|
+
Layer.succeed(FetchHttpClient.Fetch, fetchOf(options.fetch ?? globalThis.fetch, [options.ticketUrl, options.revalidateUrl].filter((url) => url !== void 0))),
|
|
442
445
|
Layer.succeed(Clock.Clock, clockOf(options.timers ?? defaultTimers, flush)),
|
|
443
446
|
Layer.succeed(Random.Random, randomOf(options.random ?? Math.random))
|
|
444
447
|
])));
|
|
@@ -469,4 +472,4 @@ const createRealtimeClient = (options) => {
|
|
|
469
472
|
};
|
|
470
473
|
/** The class of an Expected Error that CI returns. */
|
|
471
474
|
const { CiError } = errors_exports;
|
|
472
|
-
export { CiError, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, FederatedAuthError, clientOperationIds, clientSdkProtocolVersion, createClient, createDelegatedApplicationRuntime, createDirectTransport, createEntityHttpTransport, createEntityProtocol, createFederatedAuth, createFetchEventSourceFactory, createFixedWorkflowClient, createProxyTransport, createRealtimeClient, createResourceClient, createServerSessionAuth, followRun, isClientOperationId, isEntityReadLimitError, nextStreamCursor, realtimeTopicKey };
|
|
475
|
+
export { CiError, CiTransportError, DEFAULT_FOLLOW_RUN_DEADLINE_MS, FederatedAuthError, clientOperationIds, clientSdkProtocolVersion, createClient, createDelegatedApplicationRuntime, createDirectTransport, createEntityHttpTransport, createEntityProtocol, createFederatedAuth, createFetchEventSourceFactory, createFixedWorkflowClient, createProxyTransport, createRealtimeClient, createResourceClient, createServerSessionAuth, followRun, isClientOperationId, isEntityBatchRefusedError, isEntityReadLimitError, nextStreamCursor, realtimeTopicKey };
|
|
@@ -701,6 +701,8 @@ type ResourceIdentityField = Readonly<{
|
|
|
701
701
|
type: "number" | "string";
|
|
702
702
|
}>;
|
|
703
703
|
type ResourceCapabilities = Readonly<{
|
|
704
|
+
/** All-or-nothing entity batches; each op also needs its own capability. */
|
|
705
|
+
batch?: boolean;
|
|
704
706
|
create?: boolean;
|
|
705
707
|
/** Common entity deletion is always soft deletion. */
|
|
706
708
|
delete?: boolean;
|
|
@@ -921,7 +923,7 @@ interface ResourceClient<Entity, Create = Entity, Update = Partial<Entity>> {
|
|
|
921
923
|
readonly update: (input: ResourceMutationInput<Update>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Entity>>>;
|
|
922
924
|
}
|
|
923
925
|
/** Common entity operations. Generic resource lifecycle/cursor APIs remain separate. */
|
|
924
|
-
type EntityOperation = "list_members" | "list" | "get" | "create" | "update" | "delete" | "restore" | "upload";
|
|
926
|
+
type EntityOperation = "list_members" | "list" | "get" | "create" | "update" | "delete" | "restore" | "upload" | "batch";
|
|
925
927
|
type EntityListQuery = Omit<ResourceListQuery, "pagination" | "includeDeleted"> & Readonly<{
|
|
926
928
|
pagination: Extract<ResourcePagination, {
|
|
927
929
|
mode: "page";
|
|
@@ -941,6 +943,46 @@ type EntityDeleteInput = ResourceLifecycleInput & Readonly<{
|
|
|
941
943
|
}>;
|
|
942
944
|
/** A restore of a soft-deleted record at the revision its delete gave. */
|
|
943
945
|
type EntityRestoreInput = EntityDeleteInput;
|
|
946
|
+
/** One op of an entity batch: the single write it stands for, without a key. */
|
|
947
|
+
type EntityBatchOp<Create = unknown, Patch = unknown> = Readonly<{
|
|
948
|
+
op: "create";
|
|
949
|
+
value: Create;
|
|
950
|
+
}> | Readonly<{
|
|
951
|
+
op: "update";
|
|
952
|
+
id: ResourceRecordId;
|
|
953
|
+
expectedRevision: ResourceRevision;
|
|
954
|
+
value: Patch;
|
|
955
|
+
}> | Readonly<{
|
|
956
|
+
op: "delete" | "restore";
|
|
957
|
+
id: ResourceRecordId;
|
|
958
|
+
expectedRevision: ResourceRevision;
|
|
959
|
+
}>;
|
|
960
|
+
/**
|
|
961
|
+
* 1 to 100 ops on the records of one resource, under one key. CI commits
|
|
962
|
+
* every op or none; the same key with the same ops replays the answer, and
|
|
963
|
+
* with other ops answers `conflict`.
|
|
964
|
+
*/
|
|
965
|
+
type EntityBatchInput<Create = unknown, Patch = unknown> = Readonly<{
|
|
966
|
+
idempotencyKey: IdempotencyKey;
|
|
967
|
+
ops: readonly EntityBatchOp<Create, Patch>[];
|
|
968
|
+
}>;
|
|
969
|
+
/** An op that CI refused; `id` is absent for a `create`. */
|
|
970
|
+
type EntityBatchRefusal = Readonly<{
|
|
971
|
+
index: number;
|
|
972
|
+
id?: ResourceRecordId;
|
|
973
|
+
reason: "conflict" | "forbidden" | "invalid_request" | "not_found";
|
|
974
|
+
}>;
|
|
975
|
+
/**
|
|
976
|
+
* The `details` of a refused batch, which CI wrote nothing for. The error
|
|
977
|
+
* `code` is the `reason` of the first refused op. `refused` holds the
|
|
978
|
+
* refused ops that CI found: CI checks the ops in stages and stops at the
|
|
979
|
+
* first stage that refuses an op, so an op that a later stage would refuse
|
|
980
|
+
* can be absent.
|
|
981
|
+
*/
|
|
982
|
+
type EntityBatchRefusedDetails = Readonly<{
|
|
983
|
+
reason: "batch_refused";
|
|
984
|
+
refused: readonly EntityBatchRefusal[];
|
|
985
|
+
}>;
|
|
944
986
|
/** A File upload request for one File field of the entity schema. */
|
|
945
987
|
type EntityUploadInput = Readonly<{
|
|
946
988
|
field: string;
|
|
@@ -1010,8 +1052,10 @@ type EntityRequest<Create = unknown, Patch = unknown> = EntityRequestIdentity &
|
|
|
1010
1052
|
operation: "restore";
|
|
1011
1053
|
}> & EntityRestoreInput) | (Readonly<{
|
|
1012
1054
|
operation: "upload";
|
|
1013
|
-
}> & EntityUploadInput)
|
|
1014
|
-
|
|
1055
|
+
}> & EntityUploadInput) | (Readonly<{
|
|
1056
|
+
operation: "batch";
|
|
1057
|
+
}> & EntityBatchInput<Create, Patch>));
|
|
1058
|
+
type EntityOperationResult<Value, Operation extends EntityOperation> = Operation extends "list_members" ? EntityPage<EntityMemberValue> : Operation extends "list" ? EntityPage<Value> : Operation extends "upload" ? EntityUploadSlot : Operation extends "batch" ? readonly ResourceRecord<Value>[] : ResourceRecord<Value>;
|
|
1015
1059
|
/** Codecs return safe typed failures without coercing values or performing I/O. */
|
|
1016
1060
|
type EntityProtocol<Value, Create = Value, Patch = Partial<Value>> = Readonly<{
|
|
1017
1061
|
decodeRequest: (input: unknown) => ResourceResult<EntityRequest<Create, Patch>>;
|
|
@@ -1042,6 +1086,15 @@ interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
|
1042
1086
|
readonly restore: (input: EntityRestoreInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
1043
1087
|
/** A single-use File upload slot; requires the `upload` capability. */
|
|
1044
1088
|
readonly upload: (input: EntityUploadInput, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityUploadSlot>>;
|
|
1089
|
+
/**
|
|
1090
|
+
* Commits every op or none, each by the rules of its single write;
|
|
1091
|
+
* requires the `batch` capability and the capability of each op. The
|
|
1092
|
+
* answer holds the record of each op in op order. A refused batch writes
|
|
1093
|
+
* nothing and lists the refused ops that CI found in
|
|
1094
|
+
* `EntityBatchRefusedDetails`. A second op on one record is `conflict`:
|
|
1095
|
+
* the caller cannot know the revision that the first op gives.
|
|
1096
|
+
*/
|
|
1097
|
+
readonly batch: (input: EntityBatchInput<Create, Patch>) => Promise<ResourceResult<readonly ResourceRecord<Value>[]>>;
|
|
1045
1098
|
}
|
|
1046
1099
|
type ClientOptions<Value, Create, Patch> = Readonly<{
|
|
1047
1100
|
definition: ResourceDefinition<Value, Create, Patch>;
|
|
@@ -1063,8 +1116,14 @@ declare const isEntityReadLimitError: (error: ResourceError) => error is Resourc
|
|
|
1063
1116
|
code: "invalid_request";
|
|
1064
1117
|
details: EntityReadLimitDetails;
|
|
1065
1118
|
}>;
|
|
1119
|
+
/** Narrow a decoded resource failure to a refused batch and its refused ops. */
|
|
1120
|
+
declare const isEntityBatchRefusedError: (error: ResourceError) => error is ResourceError & Readonly<{
|
|
1121
|
+
details: EntityBatchRefusedDetails;
|
|
1122
|
+
}>;
|
|
1066
1123
|
/** Common entity wire codec; transport and persistence remain with their owners. */
|
|
1067
1124
|
declare const createEntityProtocol: <Value, Create = Value, Patch = Partial<Value>>(definition: ResourceDefinition<Value, Create, Patch>) => EntityProtocol<Value, Create, Patch>;
|
|
1125
|
+
/** One entity request as its envelope; only a transport failure fails. */
|
|
1126
|
+
type EntityExecute = (request: EntityRequest, options: ResourceRequestOptions) => Effect.Effect<ResourceResult<unknown>, CiTransportError>;
|
|
1068
1127
|
type ResourceFailure = CiError$1 | CiTransportError;
|
|
1069
1128
|
/** The entity client of one Resource Definition for `./effect`. */
|
|
1070
1129
|
type ResourceEntityClient<Value, Create, Patch> = Readonly<{
|
|
@@ -1080,6 +1139,8 @@ type ResourceEntityClient<Value, Create, Patch> = Readonly<{
|
|
|
1080
1139
|
delete: (input: EntityDeleteInput) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
|
|
1081
1140
|
restore: (input: EntityRestoreInput) => Effect.Effect<ResourceRecord<Value>, ResourceFailure>;
|
|
1082
1141
|
upload: (input: EntityUploadInput) => Effect.Effect<EntityUploadSlot, ResourceFailure>;
|
|
1142
|
+
/** Every op or none; a refused batch fails with its refused ops in `details`. */
|
|
1143
|
+
batch: (input: EntityBatchInput<Create, Patch>) => Effect.Effect<readonly ResourceRecord<Value>[], ResourceFailure>;
|
|
1083
1144
|
}>;
|
|
1084
1145
|
type ResourcesValue = Readonly<{
|
|
1085
1146
|
/** The entity client of `definition`; a bad destination dies with `TypeError`. */
|
|
@@ -1160,6 +1221,16 @@ type EntityHttpTransportOptions = Readonly<{
|
|
|
1160
1221
|
authentication: ProxyAuthentication;
|
|
1161
1222
|
fetch?: ClientFetch;
|
|
1162
1223
|
}>;
|
|
1224
|
+
/**
|
|
1225
|
+
* The entity HTTP adapter of one destination, the `./effect` form of
|
|
1226
|
+
* `createEntityHttpTransport`: each request is an Effect that runs in the
|
|
1227
|
+
* fiber of its caller. Early cancellation and a failed login stay envelopes,
|
|
1228
|
+
* as the request was not sent; a request that does not reach the server, or
|
|
1229
|
+
* an answer that cannot be read, fails with `CiTransportError`. A
|
|
1230
|
+
* destination without its CI selectors, or an endpoint with credentials,
|
|
1231
|
+
* query or fragment, throws `TypeError`.
|
|
1232
|
+
*/
|
|
1233
|
+
declare const makeEntityHttpExecute: (options: EntityHttpTransportOptions) => EntityExecute;
|
|
1163
1234
|
/**
|
|
1164
1235
|
* The Vanilla Facade of the entity HTTP adapter, in a runtime of its own;
|
|
1165
1236
|
* `close` disposes it.
|
|
@@ -1167,4 +1238,4 @@ type EntityHttpTransportOptions = Readonly<{
|
|
|
1167
1238
|
declare const createEntityHttpTransport: (options: EntityHttpTransportOptions) => EntityTransport & Readonly<{
|
|
1168
1239
|
close: () => Promise<void>;
|
|
1169
1240
|
}>;
|
|
1170
|
-
export {
|
|
1241
|
+
export { ResourceDefinition as $, FederatedAuthOptions as $t, EntityFileFieldWrite as A, JsonValue as At, EntityRequest as B, clientOperationIds as Bt, EntityBatchInput as C, ResourceUpdateRequest as Ct, EntityClient as D, CiError as Dt, EntityBatchRefusedDetails as E, createProxyTransport as Et, EntityOperation as F, ClientOperationInput as Ft, EntityUploadSlot as G, ConversationHistory as Gt, EntityTransport as H, AgentInvokeTarget as Ht, EntityOperationResult as I, ClientOperationMap as It, ResourceCapabilities as J, QueryFilter as Jt, IdempotencyKey as K, JsonObject as Kt, EntityPage as L, ClientOperationOutput as Lt, EntityFileWrite as M, OperationSuccess as Mt, EntityListQuery as N, ClientOperationDefinition as Nt, EntityCreateInput as O, CiErrorCode as Ot, EntityMemberValue as P, ClientOperationId as Pt, ResourceCursor as Q, FederatedAuth as Qt, EntityProtocol as R, OperationExecutionOptions as Rt, createResourceClient as S, ResourceTransportRequest as St, EntityBatchRefusal as T, ProxyTransportOptions as Tt, EntityUpdateInput as U, ApplicationRole as Ut, EntityRestoreInput as V, isClientOperationId as Vt, EntityUploadInput as W, ConversationContinueTarget as Wt, ResourceCreateInput as X, WorkflowInvokeTarget as Xt, ResourceClient as Y, SearchQuery as Yt, ResourceCreateRequest as Z, ClientFetch as Zt, layerLegacy as _, ResourceRequestOptions as _t, LegacyResourceClient as a, layerFederated as an, ResourceIdentityField as at, isEntityBatchRefusedError as b, ResourceSort as bt, LegacyResourcesValue as c, layerServerSessionConfig as cn, ResourceLifecycleRequest as ct, ResourcesFromEntityTransportOptions as d, CiError$1 as dn, ResourceListResult as dt, FederatedAuthState as en, ResourceError as et, ResourcesLayerOptions as f, CiErrorCode$1 as fn, ResourceMutationInput as ft, layerFromEntityTransport as g, ResourceRecordId as gt, layerConfig as h, FederatedAuthErrorCode as hn, ResourceRecord as ht, makeEntityHttpExecute as i, FederatedAuthValue as in, ResourceId as it, EntityFileValue as j, OperationRequest as jt, EntityDeleteInput as k, CiResult as kt, ResourceEntityClient as l, ServerSessionAuthOptions as ln, ResourceListQuery as lt, layer as m, FederatedAuthError as mn, ResourcePaginationMode as mt, EntityHttpTransportOptions as n, createFederatedAuth as nn, ResourceFilter as nt, LegacyResources as o, layerFederatedConfig as on, ResourceJsonValue as ot, ResourcesValue as p, CiTransportError as pn, ResourcePagination as pt, PortableResourceSchema as q, KnowledgeQuery as qt, createEntityHttpTransport as r, FederatedAuth$1 as rn, ResourceGetRequest as rt, LegacyResourcesLayerOptions as s, layerServerSession as sn, ResourceLifecycleInput as st, EntityHttpDestination as t, FederatedSessionIdentity as tn, ResourceErrorCode as tt, Resources as u, createServerSessionAuth as un, ResourceListRequest as ut, layerLegacyConfig as v, ResourceResult as vt, EntityBatchOp as w, ProxyAuthentication as wt, isEntityReadLimitError as x, ResourceTransport as xt, createEntityProtocol as y, ResourceRevision as yt, EntityReadLimitDetails as z, TypedOperationExecutor as zt };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as CiTransportError, l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-8gveUQPI.js";
|
|
2
2
|
import * as Layer from "effect/Layer";
|
|
3
3
|
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
4
4
|
/**
|
|
@@ -24,6 +24,10 @@ const createCommonEntityClient = (options) => {
|
|
|
24
24
|
});
|
|
25
25
|
};
|
|
26
26
|
return {
|
|
27
|
+
batch: (input) => execute({
|
|
28
|
+
...input,
|
|
29
|
+
operation: "batch"
|
|
30
|
+
}),
|
|
27
31
|
close: () => runtime.dispose(),
|
|
28
32
|
create: (input) => execute({
|
|
29
33
|
...input,
|
package/dist/resources.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
export { type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type IdempotencyKey, type PortableResourceSchema, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityReadLimitError };
|
|
1
|
+
import { $ as ResourceDefinition, A as EntityFileFieldWrite, B as EntityRequest, C as EntityBatchInput, Ct as ResourceUpdateRequest, D as EntityClient, E as EntityBatchRefusedDetails, F as EntityOperation, G as EntityUploadSlot, H as EntityTransport, I as EntityOperationResult, J as ResourceCapabilities, K as IdempotencyKey, L as EntityPage, M as EntityFileWrite, N as EntityListQuery, O as EntityCreateInput, P as EntityMemberValue, Q as ResourceCursor, R as EntityProtocol, S as createResourceClient, St as ResourceTransportRequest, T as EntityBatchRefusal, U as EntityUpdateInput, V as EntityRestoreInput, W as EntityUploadInput, X as ResourceCreateInput, Y as ResourceClient, Z as ResourceCreateRequest, _t as ResourceRequestOptions, at as ResourceIdentityField, b as isEntityBatchRefusedError, bt as ResourceSort, ct as ResourceLifecycleRequest, dt as ResourceListResult, et as ResourceError, ft as ResourceMutationInput, gt as ResourceRecordId, ht as ResourceRecord, it as ResourceId, j as EntityFileValue, k as EntityDeleteInput, lt as ResourceListQuery, mt as ResourcePaginationMode, n as EntityHttpTransportOptions, nt as ResourceFilter, ot as ResourceJsonValue, pt as ResourcePagination, q as PortableResourceSchema, r as createEntityHttpTransport, rt as ResourceGetRequest, st as ResourceLifecycleInput, t as EntityHttpDestination, tt as ResourceErrorCode, ut as ResourceListRequest, vt as ResourceResult, w as EntityBatchOp, x as isEntityReadLimitError, xt as ResourceTransport, y as createEntityProtocol, yt as ResourceRevision, z as EntityReadLimitDetails } from "./resources-CL3ZWaWz.js";
|
|
2
|
+
export { type EntityBatchInput, type EntityBatchOp, type EntityBatchRefusal, type EntityBatchRefusedDetails, type EntityClient, type EntityCreateInput, type EntityDeleteInput, type EntityFileFieldWrite, type EntityFileValue, type EntityFileWrite, type EntityHttpDestination, type EntityHttpTransportOptions, type EntityListQuery, type EntityMemberValue, type EntityOperation, type EntityOperationResult, type EntityPage, type EntityProtocol, type EntityReadLimitDetails, type EntityRequest, type EntityRestoreInput, type EntityTransport, type EntityUpdateInput, type EntityUploadInput, type EntityUploadSlot, type IdempotencyKey, type PortableResourceSchema, type ResourceCapabilities, type ResourceClient, type ResourceCreateInput, type ResourceCreateRequest, type ResourceCursor, type ResourceDefinition, type ResourceError, type ResourceErrorCode, type ResourceFilter, type ResourceGetRequest, type ResourceId, type ResourceIdentityField, type ResourceJsonValue, type ResourceLifecycleInput, type ResourceLifecycleRequest, type ResourceListQuery, type ResourceListRequest, type ResourceListResult, type ResourceMutationInput, type ResourcePagination, type ResourcePaginationMode, type ResourceRecord, type ResourceRecordId, type ResourceRequestOptions, type ResourceResult, type ResourceRevision, type ResourceSort, type ResourceTransport, type ResourceTransportRequest, type ResourceUpdateRequest, createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
|
package/dist/resources.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { d as createEntityHttpTransport,
|
|
2
|
-
import { t as createResourceClient } from "./resources-
|
|
3
|
-
export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityReadLimitError };
|
|
1
|
+
import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-8gveUQPI.js";
|
|
2
|
+
import { t as createResourceClient } from "./resources-DJ1cTUBp.js";
|
|
3
|
+
export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
|
|
@@ -8043,6 +8043,18 @@ const memberQuerySchema = {
|
|
|
8043
8043
|
};
|
|
8044
8044
|
/** Narrow a decoded resource failure to its documented request-wide read limit. */
|
|
8045
8045
|
const isEntityReadLimitError = (error) => error.code === "invalid_request" && error.details?.reason === "read_limit_exceeded" && (error.details.budget === "work" || error.details.budget === "nodes" || error.details.budget === "relation_ids" || error.details.budget === "bytes");
|
|
8046
|
+
const batchRefusalReasons = [
|
|
8047
|
+
"conflict",
|
|
8048
|
+
"forbidden",
|
|
8049
|
+
"invalid_request",
|
|
8050
|
+
"not_found"
|
|
8051
|
+
];
|
|
8052
|
+
const isBatchRefusal = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && "index" in value && Number.isInteger(value.index) && "reason" in value && batchRefusalReasons.some((reason) => reason === value.reason);
|
|
8053
|
+
/** Narrow a decoded resource failure to a refused batch and its refused ops. */
|
|
8054
|
+
const isEntityBatchRefusedError = (error) => {
|
|
8055
|
+
const refused = error.details?.refused;
|
|
8056
|
+
return error.details?.reason === "batch_refused" && Array.isArray(refused) && refused.length > 0 && refused.every(isBatchRefusal);
|
|
8057
|
+
};
|
|
8046
8058
|
const operationKey = {
|
|
8047
8059
|
pattern: "^[\\w.-]{1,256}$",
|
|
8048
8060
|
type: "string"
|
|
@@ -8052,6 +8064,8 @@ const uploadText = {
|
|
|
8052
8064
|
minLength: 1,
|
|
8053
8065
|
type: "string"
|
|
8054
8066
|
};
|
|
8067
|
+
/** The most ops one entity batch takes. */
|
|
8068
|
+
const batchLimit = 100;
|
|
8055
8069
|
const requestSchema = (definition, operation, properties, optional = {}) => ({
|
|
8056
8070
|
additionalProperties: false,
|
|
8057
8071
|
properties: {
|
|
@@ -8090,6 +8104,10 @@ const createEntityProtocol = (definition) => {
|
|
|
8090
8104
|
strict: false
|
|
8091
8105
|
});
|
|
8092
8106
|
(0, import_dist.default)(ajv);
|
|
8107
|
+
const updateValue = { allOf: [{ $ref: "#/$defs/update" }, {
|
|
8108
|
+
minProperties: 1,
|
|
8109
|
+
type: "object"
|
|
8110
|
+
}] };
|
|
8093
8111
|
const validate = ajv.compile({
|
|
8094
8112
|
$defs: {
|
|
8095
8113
|
create: scopeSchema(definition.schemas.create ?? false, "#/$defs/create"),
|
|
@@ -8114,10 +8132,7 @@ const createEntityProtocol = (definition) => {
|
|
|
8114
8132
|
expectedRevision: identifier,
|
|
8115
8133
|
id: identifier,
|
|
8116
8134
|
idempotencyKey: operationKey,
|
|
8117
|
-
value:
|
|
8118
|
-
minProperties: 1,
|
|
8119
|
-
type: "object"
|
|
8120
|
-
}] }
|
|
8135
|
+
value: updateValue
|
|
8121
8136
|
}),
|
|
8122
8137
|
requestSchema(definition, "delete", {
|
|
8123
8138
|
expectedRevision: identifier,
|
|
@@ -8137,6 +8152,31 @@ const createEntityProtocol = (definition) => {
|
|
|
8137
8152
|
minimum: 0,
|
|
8138
8153
|
type: "integer"
|
|
8139
8154
|
}
|
|
8155
|
+
}),
|
|
8156
|
+
requestSchema(definition, "batch", {
|
|
8157
|
+
idempotencyKey: operationKey,
|
|
8158
|
+
ops: {
|
|
8159
|
+
items: { oneOf: [
|
|
8160
|
+
objectSchema({
|
|
8161
|
+
op: { const: "create" },
|
|
8162
|
+
value: { $ref: "#/$defs/create" }
|
|
8163
|
+
}),
|
|
8164
|
+
objectSchema({
|
|
8165
|
+
expectedRevision: identifier,
|
|
8166
|
+
id: identifier,
|
|
8167
|
+
op: { const: "update" },
|
|
8168
|
+
value: updateValue
|
|
8169
|
+
}),
|
|
8170
|
+
objectSchema({
|
|
8171
|
+
expectedRevision: identifier,
|
|
8172
|
+
id: identifier,
|
|
8173
|
+
op: { enum: ["delete", "restore"] }
|
|
8174
|
+
})
|
|
8175
|
+
] },
|
|
8176
|
+
maxItems: batchLimit,
|
|
8177
|
+
minItems: 1,
|
|
8178
|
+
type: "array"
|
|
8179
|
+
}
|
|
8140
8180
|
})
|
|
8141
8181
|
]
|
|
8142
8182
|
});
|
|
@@ -8158,55 +8198,83 @@ const createEntityProtocol = (definition) => {
|
|
|
8158
8198
|
"revision",
|
|
8159
8199
|
"value"
|
|
8160
8200
|
]);
|
|
8201
|
+
const errorFields = objectSchema({
|
|
8202
|
+
code: { enum: [
|
|
8203
|
+
"capability_not_supported",
|
|
8204
|
+
"conflict",
|
|
8205
|
+
"forbidden",
|
|
8206
|
+
"internal",
|
|
8207
|
+
"invalid_request",
|
|
8208
|
+
"not_found",
|
|
8209
|
+
"rate_limited",
|
|
8210
|
+
"transport_error",
|
|
8211
|
+
"unauthenticated",
|
|
8212
|
+
"unavailable",
|
|
8213
|
+
"upload_not_supported"
|
|
8214
|
+
] },
|
|
8215
|
+
details: { type: "object" },
|
|
8216
|
+
message: { type: "string" },
|
|
8217
|
+
outcome: { enum: [
|
|
8218
|
+
"not_dispatched",
|
|
8219
|
+
"rejected",
|
|
8220
|
+
"uncertain"
|
|
8221
|
+
] },
|
|
8222
|
+
retryable: { type: "boolean" }
|
|
8223
|
+
}, [
|
|
8224
|
+
"code",
|
|
8225
|
+
"message",
|
|
8226
|
+
"retryable"
|
|
8227
|
+
]);
|
|
8228
|
+
const errorConditions = [{
|
|
8229
|
+
if: {
|
|
8230
|
+
properties: { details: {
|
|
8231
|
+
properties: { reason: { const: "read_limit_exceeded" } },
|
|
8232
|
+
required: ["reason"]
|
|
8233
|
+
} },
|
|
8234
|
+
required: ["details"]
|
|
8235
|
+
},
|
|
8236
|
+
then: { properties: {
|
|
8237
|
+
code: { const: "invalid_request" },
|
|
8238
|
+
details: objectSchema({
|
|
8239
|
+
budget: { enum: [
|
|
8240
|
+
"work",
|
|
8241
|
+
"nodes",
|
|
8242
|
+
"relation_ids",
|
|
8243
|
+
"bytes"
|
|
8244
|
+
] },
|
|
8245
|
+
reason: { const: "read_limit_exceeded" }
|
|
8246
|
+
})
|
|
8247
|
+
} }
|
|
8248
|
+
}, {
|
|
8249
|
+
if: {
|
|
8250
|
+
properties: { details: {
|
|
8251
|
+
properties: { reason: { const: "batch_refused" } },
|
|
8252
|
+
required: ["reason"]
|
|
8253
|
+
} },
|
|
8254
|
+
required: ["details"]
|
|
8255
|
+
},
|
|
8256
|
+
then: { properties: {
|
|
8257
|
+
code: { enum: [...batchRefusalReasons] },
|
|
8258
|
+
details: objectSchema({
|
|
8259
|
+
reason: { const: "batch_refused" },
|
|
8260
|
+
refused: {
|
|
8261
|
+
items: objectSchema({
|
|
8262
|
+
id: identifier,
|
|
8263
|
+
index: {
|
|
8264
|
+
minimum: 0,
|
|
8265
|
+
type: "integer"
|
|
8266
|
+
},
|
|
8267
|
+
reason: { enum: [...batchRefusalReasons] }
|
|
8268
|
+
}, ["index", "reason"]),
|
|
8269
|
+
minItems: 1,
|
|
8270
|
+
type: "array"
|
|
8271
|
+
}
|
|
8272
|
+
})
|
|
8273
|
+
} }
|
|
8274
|
+
}];
|
|
8161
8275
|
const error = {
|
|
8162
|
-
...
|
|
8163
|
-
|
|
8164
|
-
"capability_not_supported",
|
|
8165
|
-
"conflict",
|
|
8166
|
-
"forbidden",
|
|
8167
|
-
"internal",
|
|
8168
|
-
"invalid_request",
|
|
8169
|
-
"not_found",
|
|
8170
|
-
"rate_limited",
|
|
8171
|
-
"transport_error",
|
|
8172
|
-
"unauthenticated",
|
|
8173
|
-
"unavailable",
|
|
8174
|
-
"upload_not_supported"
|
|
8175
|
-
] },
|
|
8176
|
-
details: { type: "object" },
|
|
8177
|
-
message: { type: "string" },
|
|
8178
|
-
outcome: { enum: [
|
|
8179
|
-
"not_dispatched",
|
|
8180
|
-
"rejected",
|
|
8181
|
-
"uncertain"
|
|
8182
|
-
] },
|
|
8183
|
-
retryable: { type: "boolean" }
|
|
8184
|
-
}, [
|
|
8185
|
-
"code",
|
|
8186
|
-
"message",
|
|
8187
|
-
"retryable"
|
|
8188
|
-
]),
|
|
8189
|
-
allOf: [{
|
|
8190
|
-
if: {
|
|
8191
|
-
properties: { details: {
|
|
8192
|
-
properties: { reason: { const: "read_limit_exceeded" } },
|
|
8193
|
-
required: ["reason"]
|
|
8194
|
-
} },
|
|
8195
|
-
required: ["details"]
|
|
8196
|
-
},
|
|
8197
|
-
then: { properties: {
|
|
8198
|
-
code: { const: "invalid_request" },
|
|
8199
|
-
details: objectSchema({
|
|
8200
|
-
budget: { enum: [
|
|
8201
|
-
"work",
|
|
8202
|
-
"nodes",
|
|
8203
|
-
"relation_ids",
|
|
8204
|
-
"bytes"
|
|
8205
|
-
] },
|
|
8206
|
-
reason: { const: "read_limit_exceeded" }
|
|
8207
|
-
})
|
|
8208
|
-
} }
|
|
8209
|
-
}]
|
|
8276
|
+
...errorFields,
|
|
8277
|
+
allOf: errorConditions
|
|
8210
8278
|
};
|
|
8211
8279
|
const liveRecord = {
|
|
8212
8280
|
...record,
|
|
@@ -8283,6 +8351,12 @@ const createEntityProtocol = (definition) => {
|
|
|
8283
8351
|
}
|
|
8284
8352
|
}));
|
|
8285
8353
|
const validateOperationResult = {
|
|
8354
|
+
batch: ajv.compile(resultSchema({
|
|
8355
|
+
items: record,
|
|
8356
|
+
maxItems: batchLimit,
|
|
8357
|
+
minItems: 1,
|
|
8358
|
+
type: "array"
|
|
8359
|
+
})),
|
|
8286
8360
|
create: validateRecord,
|
|
8287
8361
|
delete: validateDeleted,
|
|
8288
8362
|
get: validateRecord,
|
|
@@ -8399,6 +8473,14 @@ const encode = (request) => {
|
|
|
8399
8473
|
method: "POST",
|
|
8400
8474
|
path: "/uploads"
|
|
8401
8475
|
};
|
|
8476
|
+
case "batch": return {
|
|
8477
|
+
body: JSON.stringify({
|
|
8478
|
+
idempotencyKey: request.idempotencyKey,
|
|
8479
|
+
ops: request.ops
|
|
8480
|
+
}),
|
|
8481
|
+
method: "POST",
|
|
8482
|
+
path: "/records/batch"
|
|
8483
|
+
};
|
|
8402
8484
|
}
|
|
8403
8485
|
};
|
|
8404
8486
|
const failure$1 = (request, error) => ({
|
|
@@ -8430,11 +8512,13 @@ const envelopeOf = (response, result) => {
|
|
|
8430
8512
|
return result;
|
|
8431
8513
|
};
|
|
8432
8514
|
/**
|
|
8433
|
-
* The entity HTTP adapter of one destination
|
|
8434
|
-
*
|
|
8435
|
-
*
|
|
8436
|
-
*
|
|
8437
|
-
*
|
|
8515
|
+
* The entity HTTP adapter of one destination, the `./effect` form of
|
|
8516
|
+
* `createEntityHttpTransport`: each request is an Effect that runs in the
|
|
8517
|
+
* fiber of its caller. Early cancellation and a failed login stay envelopes,
|
|
8518
|
+
* as the request was not sent; a request that does not reach the server, or
|
|
8519
|
+
* an answer that cannot be read, fails with `CiTransportError`. A
|
|
8520
|
+
* destination without its CI selectors, or an endpoint with credentials,
|
|
8521
|
+
* query or fragment, throws `TypeError`.
|
|
8438
8522
|
*/
|
|
8439
8523
|
const makeEntityHttpExecute = (options) => {
|
|
8440
8524
|
const { destination, authentication } = options;
|
|
@@ -8543,6 +8627,7 @@ const createEntityHttpTransport = (options) => {
|
|
|
8543
8627
|
* moves each failed envelope to the typed channel for `./effect`.
|
|
8544
8628
|
*/
|
|
8545
8629
|
const capabilityOf = {
|
|
8630
|
+
batch: "batch",
|
|
8546
8631
|
create: "create",
|
|
8547
8632
|
delete: "delete",
|
|
8548
8633
|
get: "get",
|
|
@@ -8585,7 +8670,7 @@ const makeEntityCore = (options) => {
|
|
|
8585
8670
|
},
|
|
8586
8671
|
ok: false
|
|
8587
8672
|
});
|
|
8588
|
-
if (
|
|
8673
|
+
if ((request.value.operation === "batch" ? [capabilityOf.batch, ...request.value.ops.map(({ op }) => capabilityOf[op])] : [capabilityOf[request.value.operation]]).some((capability) => options.definition.capabilities[capability] !== true)) return Effect.succeed({
|
|
8589
8674
|
correlationId,
|
|
8590
8675
|
error: {
|
|
8591
8676
|
code: "capability_not_supported",
|
|
@@ -8733,6 +8818,10 @@ const makeResources = (executeOf, requestId) => Resources.of({ bind: (definition
|
|
|
8733
8818
|
});
|
|
8734
8819
|
const call = (effect) => Effect.flatMap(Effect.suspend(() => effect(core.requestId())), valueOf);
|
|
8735
8820
|
return {
|
|
8821
|
+
batch: (input) => call((id) => core.execute({
|
|
8822
|
+
...input,
|
|
8823
|
+
operation: "batch"
|
|
8824
|
+
}, id)),
|
|
8736
8825
|
create: (input) => call((id) => core.execute({
|
|
8737
8826
|
...input,
|
|
8738
8827
|
operation: "create"
|
|
@@ -8808,4 +8897,4 @@ const makeLegacy = (options) => LegacyResources.of({ bind: (definition) => {
|
|
|
8808
8897
|
const layerLegacy = (options) => Layer.succeed(LegacyResources, makeLegacy(options));
|
|
8809
8898
|
/** `layerLegacy` with options that Effect `Config` reads. */
|
|
8810
8899
|
const layerLegacyConfig = (config) => Layer.unwrap(Effect.map(Config.unwrap(config), layerLegacy));
|
|
8811
|
-
export {
|
|
8900
|
+
export { errors_exports as A, isClientOperationId as C, CiTransportError as D, CiErrorCode as E, FederatedAuthError as O, fromCiResult as S, CiError as T, backendErrorCode as _, layerConfig as a, proxyHttpOptions as b, layerLegacyConfig as c, createEntityHttpTransport as d, makeEntityHttpExecute as f, isEntityReadLimitError as g, isEntityBatchRefusedError as h, layer as i, ciErrorCodes as j, FederatedAuthErrorCode as k, makeEntityCore as l, createEntityProtocol as m, Resources as n, layerFromEntityTransport as o, runEntityRequest as p, fromEntityTransport as r, layerLegacy as s, LegacyResources as t, makeLegacyResourceCore as u, directHttpOptions as v, toCiResult as w, clientOperationIds as x, makeHttpExecute as y };
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as CiTransportError, O as FederatedAuthError, S as fromCiResult, T as CiError, _ as backendErrorCode, b as proxyHttpOptions, j as ciErrorCodes, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-8gveUQPI.js";
|
|
2
2
|
import * as Predicate from "effect/Predicate";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Arr from "effect/Array";
|
|
4
5
|
import * as Cause from "effect/Cause";
|
|
6
|
+
import * as Clock from "effect/Clock";
|
|
5
7
|
import * as Config from "effect/Config";
|
|
6
8
|
import * as Context from "effect/Context";
|
|
9
|
+
import * as Duration from "effect/Duration";
|
|
7
10
|
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Fiber from "effect/Fiber";
|
|
8
12
|
import * as FiberHandle from "effect/FiberHandle";
|
|
9
13
|
import * as FiberMap from "effect/FiberMap";
|
|
14
|
+
import * as FiberSet from "effect/FiberSet";
|
|
10
15
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
11
16
|
import * as HttpBody from "effect/http/HttpBody";
|
|
12
17
|
import * as HttpClient from "effect/http/HttpClient";
|
|
@@ -16,8 +21,8 @@ import * as Latch from "effect/Latch";
|
|
|
16
21
|
import * as Layer from "effect/Layer";
|
|
17
22
|
import * as Queue from "effect/Queue";
|
|
18
23
|
import * as Random from "effect/Random";
|
|
24
|
+
import * as Schedule from "effect/Schedule";
|
|
19
25
|
import * as Stream from "effect/Stream";
|
|
20
|
-
import * as Clock from "effect/Clock";
|
|
21
26
|
import * as Deferred from "effect/Deferred";
|
|
22
27
|
import * as Exit from "effect/Exit";
|
|
23
28
|
const emptyBlock = () => ({
|
|
@@ -443,7 +448,26 @@ const parseRealtimeChange = (data) => {
|
|
|
443
448
|
};
|
|
444
449
|
var RealtimeClient = class extends Context.Service()("@collective-intelligence/external-apps-client-sdk/RealtimeClient") {};
|
|
445
450
|
/** The answer of the ticket route, as far as the client reads it. */
|
|
446
|
-
const TicketAnswer = Schema.Struct({
|
|
451
|
+
const TicketAnswer = Schema.Struct({
|
|
452
|
+
grantToken: Schema.optionalKey(Schema.String),
|
|
453
|
+
streamUrl: Schema.String
|
|
454
|
+
});
|
|
455
|
+
/** The most changes of one revalidate body: the Revalidate Route takes no more. */
|
|
456
|
+
const revalidateMaxChanges = 100;
|
|
457
|
+
/** The most revalidate bodies of one delivery that post at once: a slow body does not hold the others. */
|
|
458
|
+
const revalidateConcurrency = 4;
|
|
459
|
+
/** The longest wait of a delivery for its revalidate post before it calls the listeners (Q107). */
|
|
460
|
+
const revalidateWaitMilliseconds = 1e3;
|
|
461
|
+
/** The ticket route seals each grant token for 10 minutes (Q82). */
|
|
462
|
+
const grantLifetimeMilliseconds = 6e5;
|
|
463
|
+
/** The wait from a grant token to its renewal: the tab renews it 2 minutes before it expires (Q108). */
|
|
464
|
+
const grantRenewalMilliseconds = 48e4;
|
|
465
|
+
/**
|
|
466
|
+
* The waits after a failed renewal: 15 s, 30 s, then 60 s each time, and at
|
|
467
|
+
* least the `Retry-After` of the refusal. A retry that would come at or after
|
|
468
|
+
* the expiry of the token does not run (Q108).
|
|
469
|
+
*/
|
|
470
|
+
const grantRetry = (current) => Schedule.min([Schedule.exponential("15 seconds"), Schedule.spaced("1 minute")]).pipe(Schedule.modifyDelay(({ duration, input }) => Effect.succeed(input._tag === "HttpClientError" ? Duration.max(duration, Duration.millis(retryAfterMilliseconds(input.response?.headers["retry-after"]) ?? 0)) : duration)), Schedule.while(({ duration, now }) => now + Duration.toMillis(duration) < (current()?.expiresAt ?? now)));
|
|
447
471
|
/** The least wait before a delivery: a burst of changes joins one delivery. */
|
|
448
472
|
const changeWindowMilliseconds = 250;
|
|
449
473
|
/** The random extra wait, so that the tabs of many users refetch apart. */
|
|
@@ -483,6 +507,9 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
483
507
|
const timers = yield* FiberMap.make();
|
|
484
508
|
const links = yield* FiberMap.make();
|
|
485
509
|
const delivery = yield* FiberHandle.make();
|
|
510
|
+
const revalidatePosts = yield* FiberSet.make();
|
|
511
|
+
/** The grant renewal of the current link. */
|
|
512
|
+
const renewal = yield* FiberHandle.make();
|
|
486
513
|
const closed = yield* Latch.make();
|
|
487
514
|
const registrations = /* @__PURE__ */ new Map();
|
|
488
515
|
const resyncListeners = /* @__PURE__ */ new Set();
|
|
@@ -490,6 +517,11 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
490
517
|
/** Per topic key, the latest change of each record, by last arrival. */
|
|
491
518
|
const pending = /* @__PURE__ */ new Map();
|
|
492
519
|
let resyncPending = false;
|
|
520
|
+
/** The grant of the last ticket: this tab's own token, in memory only. */
|
|
521
|
+
let grant;
|
|
522
|
+
/** Per topic key and record id, the changes to revalidate, by last arrival. */
|
|
523
|
+
const revalidations = /* @__PURE__ */ new Map();
|
|
524
|
+
let revalidateReset = false;
|
|
493
525
|
let machine = initialMachineState(yield* page.visible);
|
|
494
526
|
const send = (event) => Queue.offer(events, event);
|
|
495
527
|
const topicsChanged = () => {
|
|
@@ -499,25 +531,64 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
499
531
|
type: "topicsChanged"
|
|
500
532
|
});
|
|
501
533
|
};
|
|
502
|
-
/**
|
|
503
|
-
|
|
534
|
+
/**
|
|
535
|
+
* Posts the pending revalidation with the grant token, if the tab holds
|
|
536
|
+
* one that has not expired, and waits for the answers at most
|
|
537
|
+
* `revalidateWaitMilliseconds`. Its bodies post at once, and the wait
|
|
538
|
+
* covers all of them; a post that takes longer goes on after the wait.
|
|
539
|
+
* The Revalidate Route refuses an expired token, so the client does not
|
|
540
|
+
* post it, and the listeners do not wait.
|
|
541
|
+
*/
|
|
542
|
+
const postRevalidation = Clock.clockWith((clock) => {
|
|
543
|
+
const now = clock.currentTimeMillisUnsafe();
|
|
544
|
+
const { revalidateUrl } = options;
|
|
545
|
+
const changes = [...revalidations.values()];
|
|
546
|
+
const reset = revalidateReset;
|
|
547
|
+
revalidations.clear();
|
|
548
|
+
revalidateReset = false;
|
|
549
|
+
if (revalidateUrl === void 0 || grant === void 0 || grant.expiresAt <= now || changes.length === 0 && !reset) return Effect.void;
|
|
550
|
+
const { token } = grant;
|
|
551
|
+
const parts = changes.length === 0 ? [changes] : Arr.chunksOf(changes, revalidateMaxChanges);
|
|
552
|
+
const post = (part, index) => http.execute(HttpClientRequest.post(revalidateUrl, { body: HttpBody.raw(JSON.stringify({
|
|
553
|
+
changes: part,
|
|
554
|
+
token,
|
|
555
|
+
...reset && index === 0 && { reset }
|
|
556
|
+
}), { contentType: "application/json" }) })).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.catchTag("HttpClientError", (cause) => Effect.logWarning("The realtime revalidate post failed", cause)));
|
|
557
|
+
return FiberSet.run(revalidatePosts, Effect.forEach(parts, post, {
|
|
558
|
+
concurrency: revalidateConcurrency,
|
|
559
|
+
discard: true
|
|
560
|
+
}).pipe(Effect.provideService(FetchHttpClient.RequestInit, { credentials: "same-origin" }), Effect.provideService(HttpClient.TracerPropagationEnabled, false), surfaceDefects("The realtime revalidate post failed with a defect"))).pipe(Effect.flatMap((posts) => Effect.timeoutOption(Fiber.await(posts), revalidateWaitMilliseconds)), Effect.asVoid);
|
|
561
|
+
});
|
|
562
|
+
/**
|
|
563
|
+
* Delivers the pending changes, or the pending Resync, to the current
|
|
564
|
+
* listeners. With `revalidateUrl` it posts them first and calls the
|
|
565
|
+
* listeners after the answer, at most 1 s later (Q107): a listener that
|
|
566
|
+
* reads through the server cache then reads the revalidated entry.
|
|
567
|
+
*/
|
|
568
|
+
const deliver = Effect.suspend(() => {
|
|
504
569
|
const batches = [...pending];
|
|
570
|
+
const resynced = resyncPending;
|
|
505
571
|
pending.clear();
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
572
|
+
resyncPending = false;
|
|
573
|
+
return postRevalidation.pipe(Effect.andThen(Effect.sync(() => {
|
|
574
|
+
if (resynced) {
|
|
575
|
+
for (const onResync of resyncListeners) onResync();
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
for (const [key, changes] of batches) {
|
|
579
|
+
const batch = [...changes.values()];
|
|
580
|
+
for (const onChanges of registrations.get(key)?.listeners ?? []) onChanges(batch);
|
|
581
|
+
}
|
|
582
|
+
})));
|
|
515
583
|
});
|
|
584
|
+
/** Whether a change, a Resync or a revalidation waits for a delivery. */
|
|
585
|
+
const deliveryPending = () => pending.size > 0 || resyncPending || revalidations.size > 0 || revalidateReset;
|
|
516
586
|
/**
|
|
517
587
|
* The first change or Resync after a delivery schedules the next one; later
|
|
518
|
-
* ones join it without delaying it.
|
|
588
|
+
* ones join it without delaying it. What arrives while a delivery waits
|
|
589
|
+
* for its post gets the next delivery, after this one.
|
|
519
590
|
*/
|
|
520
|
-
const scheduleDelivery = FiberHandle.run(delivery, Random.nextIntBetween(0, changeJitterMilliseconds, { halfOpen: true }).pipe(Effect.flatMap((jitter) => Effect.sleep(changeWindowMilliseconds + jitter)), Effect.andThen(deliver), surfaceDefects("A realtime delivery failed with a defect")), { onlyIfMissing: true });
|
|
591
|
+
const scheduleDelivery = FiberHandle.run(delivery, Random.nextIntBetween(0, changeJitterMilliseconds, { halfOpen: true }).pipe(Effect.flatMap((jitter) => Effect.sleep(changeWindowMilliseconds + jitter)), Effect.andThen(deliver), Effect.repeat({ while: deliveryPending }), surfaceDefects("A realtime delivery failed with a defect")), { onlyIfMissing: true });
|
|
521
592
|
/**
|
|
522
593
|
* Replaces the pending changes with one Resync at the next delivery.
|
|
523
594
|
* Without a Resync listener no refetch covers them, so they stay.
|
|
@@ -527,6 +598,12 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
527
598
|
resyncPending = true;
|
|
528
599
|
return scheduleDelivery;
|
|
529
600
|
});
|
|
601
|
+
/** A `reset` or `access-changed` event: revalidate every topic of the token. */
|
|
602
|
+
const revalidateAll = Effect.suspend(() => {
|
|
603
|
+
if (options.revalidateUrl === void 0) return Effect.void;
|
|
604
|
+
revalidateReset = true;
|
|
605
|
+
return scheduleDelivery;
|
|
606
|
+
});
|
|
530
607
|
const route = (change) => Effect.suspend(() => {
|
|
531
608
|
const key = realtimeTopicKey(change.topic);
|
|
532
609
|
if (!registrations.has(key)) return Effect.void;
|
|
@@ -534,6 +611,14 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
534
611
|
changes.delete(change.id);
|
|
535
612
|
changes.set(change.id, change);
|
|
536
613
|
pending.set(key, changes);
|
|
614
|
+
if (options.revalidateUrl !== void 0) {
|
|
615
|
+
const revalidated = JSON.stringify([key, change.id]);
|
|
616
|
+
revalidations.delete(revalidated);
|
|
617
|
+
revalidations.set(revalidated, {
|
|
618
|
+
id: change.id,
|
|
619
|
+
topic: change.topic
|
|
620
|
+
});
|
|
621
|
+
}
|
|
537
622
|
return scheduleDelivery;
|
|
538
623
|
});
|
|
539
624
|
const handle = (event) => {
|
|
@@ -542,10 +627,10 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
542
627
|
const change = parseRealtimeChange(event.data);
|
|
543
628
|
return change === void 0 ? Effect.void : route(change);
|
|
544
629
|
}
|
|
545
|
-
case "reset": return resync;
|
|
630
|
+
case "reset": return resync.pipe(Effect.andThen(revalidateAll));
|
|
546
631
|
case "access-changed": return Effect.sync(() => {
|
|
547
632
|
for (const onAccessChanged of accessListeners) onAccessChanged();
|
|
548
|
-
}).pipe(Effect.andThen(options.resyncOnAccessChange ? resync : Effect.void));
|
|
633
|
+
}).pipe(Effect.andThen(options.resyncOnAccessChange ? resync : Effect.void), Effect.andThen(revalidateAll));
|
|
549
634
|
default: return Effect.void;
|
|
550
635
|
}
|
|
551
636
|
};
|
|
@@ -573,14 +658,56 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
573
658
|
default: return Effect.void;
|
|
574
659
|
}
|
|
575
660
|
};
|
|
576
|
-
/**
|
|
577
|
-
const
|
|
661
|
+
/** The ticket answer for the topics of `link`, on the same origin. */
|
|
662
|
+
const requestTicket = (link) => Effect.suspend(() => {
|
|
578
663
|
const topics = link.topics.flatMap((key) => {
|
|
579
664
|
const registration = registrations.get(key);
|
|
580
665
|
return registration === void 0 ? [] : [registration.topic];
|
|
581
666
|
});
|
|
582
|
-
|
|
583
|
-
|
|
667
|
+
return http.execute(HttpClientRequest.post(options.ticketUrl, { body: HttpBody.raw(JSON.stringify({ topics }), { contentType: "application/json" }) }));
|
|
668
|
+
}).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.flatMap(HttpClientResponse.schemaBodyJson(TicketAnswer)), Effect.provideService(FetchHttpClient.RequestInit, { credentials: "same-origin" }), Effect.provideService(HttpClient.TracerPropagationEnabled, false));
|
|
669
|
+
/**
|
|
670
|
+
* The stream URL of a ticket for `link`, and the grant of its token. The
|
|
671
|
+
* ticket route seals the token after the request starts, so the token is
|
|
672
|
+
* valid at least until 10 minutes after that start, on the clock of the
|
|
673
|
+
* tab.
|
|
674
|
+
*/
|
|
675
|
+
const requestGrant = Effect.fnUntraced(function* requestGrant(link) {
|
|
676
|
+
const requestedAt = yield* Clock.currentTimeMillis;
|
|
677
|
+
const { grantToken, streamUrl } = yield* requestTicket(link);
|
|
678
|
+
return {
|
|
679
|
+
grant: grantToken === void 0 ? void 0 : {
|
|
680
|
+
expiresAt: requestedAt + grantLifetimeMilliseconds,
|
|
681
|
+
token: grantToken
|
|
682
|
+
},
|
|
683
|
+
streamUrl
|
|
684
|
+
};
|
|
685
|
+
});
|
|
686
|
+
/**
|
|
687
|
+
* Renews the grant token of `link` once: a new ticket for its topics
|
|
688
|
+
* brings a new token, which takes the place of the old one when it
|
|
689
|
+
* arrives (Q108). The stream stays open, and the ticket goes unused. A
|
|
690
|
+
* failed renewal keeps the old token.
|
|
691
|
+
*/
|
|
692
|
+
const renewGrant = Effect.fn("RealtimeClient.renewGrant")(function* renewGrant(link) {
|
|
693
|
+
const { grant: renewed } = yield* requestGrant(link);
|
|
694
|
+
grant = renewed;
|
|
695
|
+
}, Effect.tapError((cause) => Effect.logWarning("The realtime grant renewal failed", cause)));
|
|
696
|
+
/**
|
|
697
|
+
* Renews the grant token of `link` 8 minutes after each token; a failed
|
|
698
|
+
* renewal tries again after the waits of `grantRetry`. When the token
|
|
699
|
+
* expires before the next try, the renewals of the link stop: its posts
|
|
700
|
+
* stop with the token, and the next ticket brings a new one.
|
|
701
|
+
*/
|
|
702
|
+
const renewGrants = (link) => renewGrant(link).pipe(Effect.retry(grantRetry(() => grant)), Effect.delay(grantRenewalMilliseconds), Effect.forever, Effect.ignore({
|
|
703
|
+
log: "Warn",
|
|
704
|
+
message: "The realtime grant renewal stopped: the grant token expires before the next try"
|
|
705
|
+
}), surfaceDefects("The realtime grant renewal failed with a defect", { linkId: link.id }));
|
|
706
|
+
/** Mints the ticket of `link`; a failed ticket waits at least its `Retry-After`. */
|
|
707
|
+
const ticket = Effect.fn("RealtimeClient.ticket")(function* ticket(link) {
|
|
708
|
+
const { grant: renewed, streamUrl } = yield* requestGrant(link);
|
|
709
|
+
grant = renewed;
|
|
710
|
+
if (options.revalidateUrl !== void 0 && grant !== void 0) yield* FiberHandle.run(renewal, renewGrants(link));
|
|
584
711
|
return {
|
|
585
712
|
linkId: link.id,
|
|
586
713
|
streamUrl,
|
|
@@ -589,7 +716,7 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
589
716
|
}, (effect, link) => effect.pipe(Effect.catchTags({
|
|
590
717
|
HttpClientError: (error) => failed(link, error, retryAfterMilliseconds(error.response?.headers["retry-after"])),
|
|
591
718
|
SchemaError: (error) => failed(link, error)
|
|
592
|
-
})
|
|
719
|
+
})));
|
|
593
720
|
const schedule = (timer, milliseconds, event) => FiberMap.run(timers, timer, Effect.sleep(milliseconds).pipe(Effect.andThen(send(event)), surfaceDefects("A realtime timer failed with a defect", { timer })));
|
|
594
721
|
const run = (command) => {
|
|
595
722
|
switch (command.type) {
|
|
@@ -612,7 +739,7 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
612
739
|
type: "streamEnded"
|
|
613
740
|
}))));
|
|
614
741
|
}
|
|
615
|
-
case "disconnect": return FiberMap.remove(links, command.linkId);
|
|
742
|
+
case "disconnect": return FiberMap.remove(links, command.linkId).pipe(Effect.andThen(FiberHandle.clear(renewal)));
|
|
616
743
|
case "resync": return resync;
|
|
617
744
|
default: return Effect.void;
|
|
618
745
|
}
|
|
@@ -638,6 +765,8 @@ const makeConnection = Effect.fn("RealtimeClient.makeConnection")(function* make
|
|
|
638
765
|
machine = transition(machine, { type: "close" }).state;
|
|
639
766
|
pending.clear();
|
|
640
767
|
resyncPending = false;
|
|
768
|
+
revalidations.clear();
|
|
769
|
+
revalidateReset = false;
|
|
641
770
|
}).pipe(Effect.andThen(closed.open)));
|
|
642
771
|
return {
|
|
643
772
|
closed: closed.await,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@collective-intelligence/external-apps-client-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "Framework-neutral client for Collective Intelligence external applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"ultracite": "7.10.7",
|
|
69
69
|
"vitest": "5.0.2"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "198553b0b3654e9c8b783533334d1a6a2156daae"
|
|
72
72
|
}
|