@opetope/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/README.ru.md +246 -0
- package/dist/abort-compat.d.ts +10 -0
- package/dist/abort-compat.js +2 -0
- package/dist/abort-compat.js.map +1 -0
- package/dist/adapter-method.d.ts +27 -0
- package/dist/attachment-lifecycle-cleanup.d.ts +3 -0
- package/dist/attachment-lifecycle-cleanup.js +2 -0
- package/dist/attachment-lifecycle-cleanup.js.map +1 -0
- package/dist/attachment-lifecycle-contract.d.ts +260 -0
- package/dist/attachment-lifecycle-contract.js +2 -0
- package/dist/attachment-lifecycle-contract.js.map +1 -0
- package/dist/attachment-lifecycle-helpers.d.ts +34 -0
- package/dist/attachment-lifecycle-helpers.js +2 -0
- package/dist/attachment-lifecycle-helpers.js.map +1 -0
- package/dist/attachment-lifecycle-machine.d.ts +3 -0
- package/dist/attachment-lifecycle-machine.js +2 -0
- package/dist/attachment-lifecycle-machine.js.map +1 -0
- package/dist/attachment-lifecycle-mailbox.d.ts +10 -0
- package/dist/attachment-lifecycle-mailbox.js +2 -0
- package/dist/attachment-lifecycle-mailbox.js.map +1 -0
- package/dist/attachment-lifecycle-open.d.ts +3 -0
- package/dist/attachment-lifecycle-open.js +2 -0
- package/dist/attachment-lifecycle-open.js.map +1 -0
- package/dist/attachment-lifecycle.d.ts +4 -0
- package/dist/attachment-lifecycle.js +2 -0
- package/dist/attachment-lifecycle.js.map +1 -0
- package/dist/attachment.d.ts +49 -0
- package/dist/attachment.js +2 -0
- package/dist/attachment.js.map +1 -0
- package/dist/call-authority.d.ts +26 -0
- package/dist/call-controller-support.d.ts +77 -0
- package/dist/call-controller-support.js +2 -0
- package/dist/call-controller-support.js.map +1 -0
- package/dist/call-controller.d.ts +49 -0
- package/dist/call-controller.js +2 -0
- package/dist/call-controller.js.map +1 -0
- package/dist/call-execution-inspection.d.ts +26 -0
- package/dist/call-execution-inspection.js +2 -0
- package/dist/call-execution-inspection.js.map +1 -0
- package/dist/call-executor-factory.d.ts +5 -0
- package/dist/call-executor-factory.js +2 -0
- package/dist/call-executor-factory.js.map +1 -0
- package/dist/call-executor-record.d.ts +66 -0
- package/dist/call-executor-record.js +2 -0
- package/dist/call-executor-record.js.map +1 -0
- package/dist/call-executor-support.d.ts +25 -0
- package/dist/call-executor-support.js +2 -0
- package/dist/call-executor-support.js.map +1 -0
- package/dist/call-executor-types.d.ts +56 -0
- package/dist/call-executor-waiters.d.ts +23 -0
- package/dist/call-executor-waiters.js +2 -0
- package/dist/call-executor-waiters.js.map +1 -0
- package/dist/call-executor.d.ts +6 -0
- package/dist/call-executor.js +2 -0
- package/dist/call-executor.js.map +1 -0
- package/dist/call-invocation.d.ts +61 -0
- package/dist/call-invocation.js +2 -0
- package/dist/call-invocation.js.map +1 -0
- package/dist/call-lane.d.ts +28 -0
- package/dist/call-lane.js +2 -0
- package/dist/call-lane.js.map +1 -0
- package/dist/call-target-result.d.ts +22 -0
- package/dist/call-target-result.js +2 -0
- package/dist/call-target-result.js.map +1 -0
- package/dist/call-target.d.ts +42 -0
- package/dist/call-target.js +2 -0
- package/dist/call-target.js.map +1 -0
- package/dist/call.d.ts +11 -0
- package/dist/call.js +2 -0
- package/dist/call.js.map +1 -0
- package/dist/contribution-hub.d.ts +100 -0
- package/dist/contribution-hub.js +2 -0
- package/dist/contribution-hub.js.map +1 -0
- package/dist/contribution-transaction.d.ts +20 -0
- package/dist/contribution-transaction.js +2 -0
- package/dist/contribution-transaction.js.map +1 -0
- package/dist/contribution.d.ts +64 -0
- package/dist/contribution.js +2 -0
- package/dist/contribution.js.map +1 -0
- package/dist/data-scheduler.d.ts +4 -0
- package/dist/data-scheduler.js +2 -0
- package/dist/data-scheduler.js.map +1 -0
- package/dist/errors.d.ts +56 -0
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity.d.ts +6 -0
- package/dist/identity.js +2 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +46 -0
- package/dist/internal.js +2 -0
- package/dist/internal.js.map +1 -0
- package/dist/lifetime.d.ts +19 -0
- package/dist/lifetime.js +2 -0
- package/dist/lifetime.js.map +1 -0
- package/dist/model-context.d.ts +155 -0
- package/dist/model.d.ts +21 -0
- package/dist/model.js +2 -0
- package/dist/model.js.map +1 -0
- package/dist/platform-compat.d.ts +9 -0
- package/dist/platform-compat.js +2 -0
- package/dist/platform-compat.js.map +1 -0
- package/dist/port.d.ts +26 -0
- package/dist/port.js +2 -0
- package/dist/port.js.map +1 -0
- package/dist/reactive-collection.d.ts +27 -0
- package/dist/reactive-collection.js +2 -0
- package/dist/reactive-collection.js.map +1 -0
- package/dist/reactive-node.d.ts +62 -0
- package/dist/reactive-node.js +2 -0
- package/dist/reactive-node.js.map +1 -0
- package/dist/reactive-scheduler-control.d.ts +34 -0
- package/dist/reactive-scheduler-control.js +2 -0
- package/dist/reactive-scheduler-control.js.map +1 -0
- package/dist/reactive-scheduler.d.ts +18 -0
- package/dist/reactive-scheduler.js +2 -0
- package/dist/reactive-scheduler.js.map +1 -0
- package/dist/reactive.d.ts +41 -0
- package/dist/reactive.js +2 -0
- package/dist/reactive.js.map +1 -0
- package/dist/readable.d.ts +13 -0
- package/dist/readable.js +2 -0
- package/dist/readable.js.map +1 -0
- package/dist/resource.d.ts +82 -0
- package/dist/type-helpers.d.ts +14 -0
- package/package.json +66 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { CallAuthoritySource } from './call-authority.js';
|
|
2
|
+
import type { Call, CallContext } from './call-target.js';
|
|
3
|
+
import { FeatureError } from './errors.js';
|
|
4
|
+
import type { DeclarationId } from './identity.js';
|
|
5
|
+
import type { Readable } from './readable.js';
|
|
6
|
+
declare const attachmentReadinessRefBrand: unique symbol;
|
|
7
|
+
declare const attachmentReadinessPermitBrand: unique symbol;
|
|
8
|
+
type AttachmentReadinessSnapshot = {
|
|
9
|
+
readonly kind: 'inactive';
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'ready';
|
|
12
|
+
};
|
|
13
|
+
interface AttachmentReadinessRef extends Readable<AttachmentReadinessSnapshot> {
|
|
14
|
+
readonly [attachmentReadinessRefBrand]: true;
|
|
15
|
+
readonly id: DeclarationId;
|
|
16
|
+
}
|
|
17
|
+
interface AttachmentReadinessPermit {
|
|
18
|
+
readonly [attachmentReadinessPermitBrand]: true;
|
|
19
|
+
}
|
|
20
|
+
interface AttachmentReadinessDiagnostics {
|
|
21
|
+
readonly authorityListeners: number;
|
|
22
|
+
readonly disposed: boolean;
|
|
23
|
+
readonly listeners: number;
|
|
24
|
+
readonly openPending: boolean;
|
|
25
|
+
readonly status: AttachmentReadinessSnapshot['kind'];
|
|
26
|
+
}
|
|
27
|
+
interface AttachmentReadinessController {
|
|
28
|
+
readonly beginOpen: () => AttachmentReadinessPermit;
|
|
29
|
+
readonly diagnostics: () => AttachmentReadinessDiagnostics;
|
|
30
|
+
readonly dispose: () => void;
|
|
31
|
+
readonly publishInactive: (reason?: FeatureError) => void;
|
|
32
|
+
readonly publishReady: (permit: AttachmentReadinessPermit) => void;
|
|
33
|
+
readonly ref: AttachmentReadinessRef;
|
|
34
|
+
}
|
|
35
|
+
declare const reportDetachedError: (error: unknown) => void;
|
|
36
|
+
declare function createAttachmentReadinessController(options: {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
}): AttachmentReadinessController;
|
|
39
|
+
declare function getAttachmentCallAuthoritySource(ref: AttachmentReadinessRef): CallAuthoritySource;
|
|
40
|
+
declare function bindCallTargetToAttachment<Input, Output>(target: Call<Input, Output>, ref: AttachmentReadinessRef): Call<Input, Output>;
|
|
41
|
+
declare function mintAttachmentCallTarget<Input, Output>(options: {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly owner: CallAuthoritySource;
|
|
44
|
+
readonly run: (input: Input, context: CallContext) => Output | PromiseLike<Output>;
|
|
45
|
+
readonly within: AttachmentReadinessRef;
|
|
46
|
+
}): Call<Input, Output>;
|
|
47
|
+
export type { AttachmentReadinessRef, AttachmentReadinessSnapshot };
|
|
48
|
+
export { bindCallTargetToAttachment, createAttachmentReadinessController, getAttachmentCallAuthoritySource, mintAttachmentCallTarget, reportDetachedError, };
|
|
49
|
+
export type { AttachmentReadinessController, AttachmentReadinessDiagnostics, AttachmentReadinessPermit };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{bindCallTargetLifetime as B,createCallTargetLifetimeBinding as E,mintCallTargetWithLifetimeBinding as P}from"./call-target.js";import{FeatureError as O}from"./errors.js";import{declarationId as W}from"./identity.js";const I=Symbol("opetope.attachment-readiness-ref"),M=Symbol("opetope.attachment-readiness-permit"),T=Object.freeze({kind:"inactive"}),j=()=>{},g=new WeakMap,k=new WeakMap,R=new WeakMap,w=e=>{if(typeof reportError=="function")try{reportError(e);return}catch{}setTimeout(()=>{throw e})};function $(e,t){for(const{listener:i}of[...e]){if(!t())return;try{i()}catch(n){w(n)}}}function x(e,t){for(const{listener:i}of[...e])try{i(t)}catch(n){w(n)}}function D(){let e;return Object.freeze({assertCurrent(){if(e!==void 0)throw e},invalidate(t){e===void 0&&(e=t)},isCurrent(){return e===void 0}})}function F(){const e={active:!0},t=Object.freeze({[M]:!0});return R.set(t,e),{permit:t,state:e}}function q(e,t,i){if(i())return j;const n={listener:t};e.add(n);let r=!0;return()=>{r&&(r=!1,e.delete(n))}}function G(e,t,i){if(i())return j;const n={listener:t};e.add(n);let r=!0;return()=>{r&&(r=!1,e.delete(n))}}function H(e){const t=W(e.id),i=new Set,n=new Set;let r=!1,u,f=!1,l=T,o;const d=[];let c=Object.freeze({kind:"inactive",reason:new O("retired",t),revision:0});const v=Object.freeze({getSnapshot:()=>c,subscribe(s){return G(i,s,()=>r)}}),p=Object.freeze({[I]:!0,getSnapshot(){return l},id:t,subscribe(s){return q(n,s,()=>r)}}),C={lifetimeBinding:E(v,p),source:v};g.set(p,C);const b=()=>{o!==void 0&&(o.state.active=!1,o=void 0)},y=()=>{i.clear(),n.clear()},S=s=>{const a=c;c=s;const h=Object.freeze({current:s,previous:a});if(d.push(h),!f){for(f=!0;d.length>0;){let m=0;for(;m<d.length;){const A=d[m];m+=1,A!==void 0&&x(i,A)}d.length=0;const L=c.revision;$(n,()=>c.revision===L)}f=!1,r&&y()}},z=(s=new O("retired",t))=>{b();const a=u;a!==void 0&&(u=void 0,a.invalidate(s),l=T,S(Object.freeze({kind:"inactive",reason:s,revision:c.revision+1})))};return Object.freeze({beginOpen(){if(r)throw new TypeError(`Attachment readiness ${t} is disposed.`);if(u!==void 0)throw new TypeError(`Attachment readiness ${t} is already ready.`);return b(),o=F(),o.permit},diagnostics(){return Object.freeze({authorityListeners:i.size,disposed:r,listeners:n.size,openPending:o!==void 0,status:l.kind})},dispose:()=>{r||(r=!0,z(),b(),f||y())},publishInactive:z,publishReady(s){if(r)throw new TypeError(`Attachment readiness ${t} is disposed.`);const a=R.get(s);if((o==null?void 0:o.permit)!==s||a===void 0||!a.active)throw new TypeError(`Attachment readiness ${t} received a stale open permit.`);a.active=!1,o=void 0;const h=D();u=h,l=Object.freeze({kind:"ready"}),S(Object.freeze({authority:h,kind:"ready",revision:c.revision+1}))},ref:p})}function J(e,t){const i=g.get(t);if(i===void 0)throw new TypeError("AttachmentReadinessRef is not authentic.");return B(e,i.lifetimeBinding)}function K(e){const t=e.within;if(!g.has(t))throw new TypeError("AttachmentReadinessRef is not authentic.");const i=e.owner;let n=k.get(t);n===void 0&&(n=new WeakMap,k.set(t,n));let r=n.get(i);return r===void 0&&(r=E(i,t),n.set(i,r)),P({id:e.id,run:e.run},r)}export{J as bindCallTargetToAttachment,H as createAttachmentReadinessController,K as mintAttachmentCallTarget,w as reportDetachedError};
|
|
2
|
+
//# sourceMappingURL=attachment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment.js","sources":["../src/attachment.ts"],"sourcesContent":["import type {\n CallAuthority,\n CallAuthoritySource,\n CallAuthoritySourceEvent,\n CallAuthoritySourceSnapshot,\n} from './call-authority';\nimport {\n bindCallTargetLifetime,\n createCallTargetLifetimeBinding,\n mintCallTargetWithLifetimeBinding,\n} from './call-target';\nimport type { Call, CallContext, CallTargetLifetimeBinding } from './call-target';\nimport { FeatureError } from './errors';\nimport type { DeclarationId } from './identity';\nimport { declarationId } from './identity';\nimport type { Readable } from './readable';\n\nconst attachmentReadinessRefBrand = Symbol('opetope.attachment-readiness-ref');\nconst attachmentReadinessPermitBrand = Symbol('opetope.attachment-readiness-permit');\n\ntype AttachmentReadinessSnapshot = { readonly kind: 'inactive' } | { readonly kind: 'ready' };\n\ninterface AttachmentReadinessRef extends Readable<AttachmentReadinessSnapshot> {\n readonly [attachmentReadinessRefBrand]: true;\n readonly id: DeclarationId;\n}\n\ninterface AttachmentReadinessPermit {\n readonly [attachmentReadinessPermitBrand]: true;\n}\n\ninterface AttachmentReadinessDiagnostics {\n readonly authorityListeners: number;\n readonly disposed: boolean;\n readonly listeners: number;\n readonly openPending: boolean;\n readonly status: AttachmentReadinessSnapshot['kind'];\n}\n\ninterface AttachmentReadinessController {\n readonly beginOpen: () => AttachmentReadinessPermit;\n readonly diagnostics: () => AttachmentReadinessDiagnostics;\n readonly dispose: () => void;\n readonly publishInactive: (reason?: FeatureError) => void;\n readonly publishReady: (permit: AttachmentReadinessPermit) => void;\n readonly ref: AttachmentReadinessRef;\n}\n\ntype AttachmentAuthority = CallAuthority & {\n readonly invalidate: (reason: FeatureError) => void;\n};\n\ntype PublicListenerRegistration = { readonly listener: () => void };\ntype AuthorityListenerRegistration = { readonly listener: (event: CallAuthoritySourceEvent) => void };\n\ntype PermitState = { active: boolean };\n\ntype AttachmentDefinition = {\n readonly lifetimeBinding: CallTargetLifetimeBinding;\n readonly source: CallAuthoritySource;\n};\n\nconst inactiveSnapshot = Object.freeze({ kind: 'inactive' as const });\nconst noop = (): void => undefined;\nconst definitions = new WeakMap<AttachmentReadinessRef, AttachmentDefinition>();\nconst ownerCallBindings = new WeakMap<\n AttachmentReadinessRef,\n WeakMap<CallAuthoritySource, CallTargetLifetimeBinding>\n>();\nconst permits = new WeakMap<AttachmentReadinessPermit, PermitState>();\n\nconst reportDetachedError = (error: unknown): void => {\n if (typeof reportError === 'function') {\n try {\n reportError(error);\n\n return;\n } catch {\n // A broken global reporter must not break attachment publication.\n }\n }\n\n setTimeout(() => {\n throw error;\n });\n};\n\nfunction publishPublicListeners(listeners: Set<PublicListenerRegistration>, isCurrentRevision: () => boolean): void {\n for (const { listener } of [...listeners]) {\n if (!isCurrentRevision()) return;\n\n try {\n listener();\n } catch (error) {\n reportDetachedError(error);\n }\n }\n}\n\nfunction publishAuthorityListeners(\n listeners: Set<AuthorityListenerRegistration>,\n event: CallAuthoritySourceEvent,\n): void {\n for (const { listener } of [...listeners]) {\n try {\n listener(event);\n } catch (error) {\n reportDetachedError(error);\n }\n }\n}\n\nfunction makeAuthority(): AttachmentAuthority {\n let inactiveReason: FeatureError | undefined;\n\n return Object.freeze({\n assertCurrent(): void {\n if (inactiveReason !== undefined) throw inactiveReason;\n },\n invalidate(reason: FeatureError): void {\n if (inactiveReason === undefined) inactiveReason = reason;\n },\n isCurrent(): boolean {\n return inactiveReason === undefined;\n },\n });\n}\n\nfunction makePermit(): { readonly permit: AttachmentReadinessPermit; readonly state: PermitState } {\n const state = { active: true };\n const permit = Object.freeze({ [attachmentReadinessPermitBrand]: true as const });\n permits.set(permit, state);\n\n return { permit, state };\n}\n\nfunction subscribePublic(\n listeners: Set<PublicListenerRegistration>,\n listener: () => void,\n isDisposed: () => boolean,\n): () => void {\n if (isDisposed()) return noop;\n\n const registration = { listener };\n listeners.add(registration);\n let subscribed = true;\n\n return (): void => {\n if (!subscribed) return;\n\n subscribed = false;\n listeners.delete(registration);\n };\n}\n\nfunction subscribeAuthority(\n listeners: Set<AuthorityListenerRegistration>,\n listener: (event: CallAuthoritySourceEvent) => void,\n isDisposed: () => boolean,\n): () => void {\n if (isDisposed()) return noop;\n\n const registration = { listener };\n listeners.add(registration);\n let subscribed = true;\n\n return (): void => {\n if (!subscribed) return;\n\n subscribed = false;\n listeners.delete(registration);\n };\n}\n\nfunction createAttachmentReadinessController(options: { readonly id: string }): AttachmentReadinessController {\n // This is the narrow readiness/fence seam used by lowering. Opening, rollback,\n // adopted disposers and failed-close quarantine belong to the later attachment lifecycle machine.\n const ownerId = declarationId(options.id);\n const authorityListeners = new Set<AuthorityListenerRegistration>();\n const listeners = new Set<PublicListenerRegistration>();\n let disposed = false;\n let currentAuthority: AttachmentAuthority | undefined;\n let publishingSource = false;\n let publicSnapshot: AttachmentReadinessSnapshot = inactiveSnapshot;\n let pendingPermit: { readonly permit: AttachmentReadinessPermit; readonly state: PermitState } | undefined;\n const pendingSourceEvents: CallAuthoritySourceEvent[] = [];\n const initialSourceSnapshot = Object.freeze({\n kind: 'inactive' as const,\n reason: new FeatureError('retired', ownerId),\n revision: 0,\n });\n let sourceSnapshot: CallAuthoritySourceSnapshot = initialSourceSnapshot;\n const source = Object.freeze({\n getSnapshot: (): CallAuthoritySourceSnapshot => sourceSnapshot,\n subscribe(listener: (event: CallAuthoritySourceEvent) => void): () => void {\n return subscribeAuthority(authorityListeners, listener, () => disposed);\n },\n });\n const ref = Object.freeze({\n [attachmentReadinessRefBrand]: true as const,\n getSnapshot(): AttachmentReadinessSnapshot {\n return publicSnapshot;\n },\n id: ownerId,\n subscribe(listener: () => void): () => void {\n return subscribePublic(listeners, listener, () => disposed);\n },\n });\n const definition: AttachmentDefinition = {\n lifetimeBinding: createCallTargetLifetimeBinding(source, ref),\n source,\n };\n definitions.set(ref, definition);\n\n const retirePendingPermit = (): void => {\n if (pendingPermit === undefined) return;\n\n pendingPermit.state.active = false;\n pendingPermit = undefined;\n };\n\n const clearListeners = (): void => {\n authorityListeners.clear();\n listeners.clear();\n };\n\n const publishSource = (next: CallAuthoritySourceSnapshot): void => {\n const previous = sourceSnapshot;\n sourceSnapshot = next;\n const event = Object.freeze({ current: next, previous });\n pendingSourceEvents.push(event);\n\n if (publishingSource) return;\n\n publishingSource = true;\n\n while (pendingSourceEvents.length > 0) {\n let pendingEventIndex = 0;\n\n while (pendingEventIndex < pendingSourceEvents.length) {\n const pendingEvent = pendingSourceEvents[pendingEventIndex];\n pendingEventIndex += 1;\n\n if (pendingEvent === undefined) continue;\n\n publishAuthorityListeners(authorityListeners, pendingEvent);\n }\n\n pendingSourceEvents.length = 0;\n const publicRevision = sourceSnapshot.revision;\n publishPublicListeners(listeners, () => sourceSnapshot.revision === publicRevision);\n }\n\n publishingSource = false;\n\n if (disposed) clearListeners();\n };\n\n const publishInactive = (reason = new FeatureError('retired', ownerId)): void => {\n retirePendingPermit();\n\n const authority = currentAuthority;\n\n if (authority === undefined) return;\n\n currentAuthority = undefined;\n authority.invalidate(reason);\n publicSnapshot = inactiveSnapshot;\n publishSource(Object.freeze({ kind: 'inactive' as const, reason, revision: sourceSnapshot.revision + 1 }));\n };\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n publishInactive();\n retirePendingPermit();\n\n if (!publishingSource) clearListeners();\n };\n\n return Object.freeze({\n beginOpen(): AttachmentReadinessPermit {\n if (disposed) throw new TypeError(`Attachment readiness ${ownerId} is disposed.`);\n\n if (currentAuthority !== undefined) {\n throw new TypeError(`Attachment readiness ${ownerId} is already ready.`);\n }\n\n retirePendingPermit();\n pendingPermit = makePermit();\n\n return pendingPermit.permit;\n },\n diagnostics(): AttachmentReadinessDiagnostics {\n return Object.freeze({\n authorityListeners: authorityListeners.size,\n disposed,\n listeners: listeners.size,\n openPending: pendingPermit !== undefined,\n status: publicSnapshot.kind,\n });\n },\n dispose,\n publishInactive,\n publishReady(permit: AttachmentReadinessPermit): void {\n if (disposed) throw new TypeError(`Attachment readiness ${ownerId} is disposed.`);\n\n const permitState = permits.get(permit);\n\n if (pendingPermit?.permit !== permit || permitState === undefined || !permitState.active) {\n throw new TypeError(`Attachment readiness ${ownerId} received a stale open permit.`);\n }\n\n permitState.active = false;\n pendingPermit = undefined;\n const authority = makeAuthority();\n currentAuthority = authority;\n publicSnapshot = Object.freeze({ kind: 'ready' as const });\n publishSource(Object.freeze({ authority, kind: 'ready' as const, revision: sourceSnapshot.revision + 1 }));\n },\n ref,\n });\n}\n\nfunction getAttachmentCallAuthoritySource(ref: AttachmentReadinessRef): CallAuthoritySource {\n const definition = definitions.get(ref);\n\n if (definition === undefined) throw new TypeError('AttachmentReadinessRef is not authentic.');\n\n return definition.source;\n}\n\nfunction bindCallTargetToAttachment<Input, Output>(\n target: Call<Input, Output>,\n ref: AttachmentReadinessRef,\n): Call<Input, Output> {\n const definition = definitions.get(ref);\n\n if (definition === undefined) throw new TypeError('AttachmentReadinessRef is not authentic.');\n\n return bindCallTargetLifetime(target, definition.lifetimeBinding);\n}\n\nfunction mintAttachmentCallTarget<Input, Output>(options: {\n readonly id: string;\n readonly owner: CallAuthoritySource;\n readonly run: (input: Input, context: CallContext) => Output | PromiseLike<Output>;\n readonly within: AttachmentReadinessRef;\n}): Call<Input, Output> {\n const within = options.within;\n\n if (!definitions.has(within)) throw new TypeError('AttachmentReadinessRef is not authentic.');\n\n const owner = options.owner;\n let bindings = ownerCallBindings.get(within);\n\n if (bindings === undefined) {\n bindings = new WeakMap();\n ownerCallBindings.set(within, bindings);\n }\n\n let binding = bindings.get(owner);\n\n if (binding === undefined) {\n binding = createCallTargetLifetimeBinding(owner, within);\n bindings.set(owner, binding);\n }\n\n return mintCallTargetWithLifetimeBinding({ id: options.id, run: options.run }, binding);\n}\n\nexport type { AttachmentReadinessRef, AttachmentReadinessSnapshot };\nexport {\n bindCallTargetToAttachment,\n createAttachmentReadinessController,\n getAttachmentCallAuthoritySource,\n mintAttachmentCallTarget,\n reportDetachedError,\n};\nexport type { AttachmentReadinessController, AttachmentReadinessDiagnostics, AttachmentReadinessPermit };\n"],"names":["attachmentReadinessRefBrand","attachmentReadinessPermitBrand","inactiveSnapshot","noop","definitions","ownerCallBindings","permits","reportDetachedError","error","publishPublicListeners","listeners","isCurrentRevision","listener","publishAuthorityListeners","event","makeAuthority","inactiveReason","reason","makePermit","state","permit","subscribePublic","isDisposed","registration","subscribed","subscribeAuthority","createAttachmentReadinessController","options","ownerId","declarationId","authorityListeners","disposed","currentAuthority","publishingSource","publicSnapshot","pendingPermit","pendingSourceEvents","sourceSnapshot","FeatureError","source","ref","definition","createCallTargetLifetimeBinding","retirePendingPermit","clearListeners","publishSource","next","previous","pendingEventIndex","pendingEvent","publicRevision","publishInactive","authority","permitState","bindCallTargetToAttachment","target","bindCallTargetLifetime","mintAttachmentCallTarget","within","owner","bindings","binding","mintCallTargetWithLifetimeBinding"],"mappings":"+NAiBA,MAAMA,EAA8B,OAAO,kCAAkC,EACvEC,EAAiC,OAAO,qCAAqC,EA4C7EC,EAAmB,OAAO,OAAO,CAAE,KAAM,UAAmB,CAAE,EAC9DC,EAAO,IAAA,GACPC,EAAc,IAAI,QAClBC,EAAoB,IAAI,QAIxBC,EAAU,IAAI,QAEdC,EAAuBC,GAAwB,CACnD,GAAI,OAAO,aAAgB,WACzB,GAAI,CACF,YAAYA,CAAK,EAEjB,MACF,MAAQ,CAER,CAGF,WAAW,IAAK,CACd,MAAMA,CACR,CAAC,CACH,EAEA,SAASC,EAAuBC,EAA4CC,EAAgC,CAC1G,SAAW,CAAE,SAAAC,CAAQ,GAAM,CAAC,GAAGF,CAAS,EAAG,CACzC,GAAI,CAACC,EAAiB,EAAI,OAE1B,GAAI,CACFC,EAAQ,CACV,OAASJ,EAAO,CACdD,EAAoBC,CAAK,CAC3B,CACF,CACF,CAEA,SAASK,EACPH,EACAI,EAA+B,CAE/B,SAAW,CAAE,SAAAF,CAAQ,GAAM,CAAC,GAAGF,CAAS,EACtC,GAAI,CACFE,EAASE,CAAK,CAChB,OAASN,EAAO,CACdD,EAAoBC,CAAK,CAC3B,CAEJ,CAEA,SAASO,GAAa,CACpB,IAA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AAM,IAAI,UAAU,0CAA0C,EAE5F,OAAOe,EAAuBD,EAAQd,EAAW,eAAe,CAClE,CAEA,SAASgB,EAAwC9B,EAKhD,CACC,MAAM+B,EAAS/B,EAAQ,OAEvB,GAAI,CAACvB,EAAY,IAAIsD,CAAM,EAAG,MAAM,IAAI,UAAU,0CAA0C,EAE5F,MAAMC,EAAQhC,EAAQ,MACtB,IAAIiC,EAAWvD,EAAkB,IAAIqD,CAAM,EAEvCE,IAAa,SACfA,EAAW,IAAI,QACfvD,EAAkB,IAAIqD,EAAQE,CAAQ,GAGxC,IAAIC,EAAUD,EAAS,IAAID,CAAK,EAEhC,OAAIE,IAAY,SACdA,EAAUnB,EAAgCiB,EAAOD,CAAM,EACvDE,EAAS,IAAID,EAAOE,CAAO,GAGtBC,EAAkC,CAAE,GAAInC,EAAQ,GAAI,IAAKA,EAAQ,GAAG,EAAIkC,CAAO,CACxF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exact physical-generation lease. A source must invalidate its current authority before it can
|
|
3
|
+
* publish another ready authority; consumers use this lease as the post-settlement generation fence.
|
|
4
|
+
*/
|
|
5
|
+
interface CallAuthority {
|
|
6
|
+
assertCurrent(): void;
|
|
7
|
+
isCurrent(): boolean;
|
|
8
|
+
}
|
|
9
|
+
type CallAuthoritySourceSnapshot = {
|
|
10
|
+
readonly authority: CallAuthority;
|
|
11
|
+
readonly kind: 'ready';
|
|
12
|
+
readonly revision: number;
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'inactive';
|
|
15
|
+
readonly reason: unknown;
|
|
16
|
+
readonly revision: number;
|
|
17
|
+
};
|
|
18
|
+
interface CallAuthoritySourceEvent {
|
|
19
|
+
readonly current: CallAuthoritySourceSnapshot;
|
|
20
|
+
readonly previous: CallAuthoritySourceSnapshot;
|
|
21
|
+
}
|
|
22
|
+
interface CallAuthoritySource {
|
|
23
|
+
readonly getSnapshot: () => CallAuthoritySourceSnapshot;
|
|
24
|
+
readonly subscribe: (listener: (event: CallAuthoritySourceEvent) => void) => () => void;
|
|
25
|
+
}
|
|
26
|
+
export type { CallAuthority, CallAuthoritySource, CallAuthoritySourceEvent, CallAuthoritySourceSnapshot };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { CallAuthority, CallAuthoritySourceEvent } from './call-authority.js';
|
|
2
|
+
import type { CallControllerImpl } from './call-controller.js';
|
|
3
|
+
import { CallError } from './errors.js';
|
|
4
|
+
import type { DeclarationId } from './identity.js';
|
|
5
|
+
import type { NoExtraKeys } from './type-helpers.js';
|
|
6
|
+
type CallControllerScheduling = {
|
|
7
|
+
readonly lane?: never;
|
|
8
|
+
readonly policy: 'parallel';
|
|
9
|
+
};
|
|
10
|
+
interface CallDiagnostics {
|
|
11
|
+
readonly closed: boolean;
|
|
12
|
+
readonly pendingCalls: number;
|
|
13
|
+
}
|
|
14
|
+
interface CallRunOptions<Output> {
|
|
15
|
+
readonly onSuccess?: (value: Output) => PromiseLike<void> | void;
|
|
16
|
+
readonly signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A command is invoked, not watched: the controller has no snapshot to read and no listener to register. Shared
|
|
20
|
+
* invocation state a component only observes is a `Readable` field of the model (D71, D162).
|
|
21
|
+
*/
|
|
22
|
+
interface CallController<Input, Output> {
|
|
23
|
+
readonly activate: () => void;
|
|
24
|
+
readonly close: (reason?: unknown) => void;
|
|
25
|
+
readonly diagnostics: () => CallDiagnostics;
|
|
26
|
+
readonly run: (input: Input, options?: CallRunOptions<Output>) => Promise<Output>;
|
|
27
|
+
}
|
|
28
|
+
interface CallControllerOptions {
|
|
29
|
+
readonly captureAuthority?: () => CallAuthority;
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly scheduling: CallControllerScheduling;
|
|
32
|
+
}
|
|
33
|
+
type PendingCall<Input, Output> = {
|
|
34
|
+
abort: AbortController | undefined;
|
|
35
|
+
callId: string;
|
|
36
|
+
externalAbort: (() => void) | undefined;
|
|
37
|
+
externalSignal: AbortSignal | undefined;
|
|
38
|
+
input: Input | undefined;
|
|
39
|
+
onSuccess: ((value: Output) => PromiseLike<void> | void) | undefined;
|
|
40
|
+
ordinal: number;
|
|
41
|
+
owner: CallControllerImpl<Input, Output> | undefined;
|
|
42
|
+
ownerAuthority: CallAuthority | undefined;
|
|
43
|
+
reject: ((reason: unknown) => void) | undefined;
|
|
44
|
+
resolve: ((value: Output) => void) | undefined;
|
|
45
|
+
started: boolean;
|
|
46
|
+
targetAuthority: CallAuthority | undefined;
|
|
47
|
+
};
|
|
48
|
+
type CallOutcome<Output> = {
|
|
49
|
+
readonly error: CallError;
|
|
50
|
+
readonly status: 'cancelled';
|
|
51
|
+
} | {
|
|
52
|
+
readonly error: unknown;
|
|
53
|
+
readonly status: 'failed';
|
|
54
|
+
} | {
|
|
55
|
+
readonly status: 'succeeded';
|
|
56
|
+
readonly value: Output;
|
|
57
|
+
};
|
|
58
|
+
type CapturedCallAuthorities = {
|
|
59
|
+
readonly ownerAuthority: CallAuthority | undefined;
|
|
60
|
+
readonly targetAuthority: CallAuthority | undefined;
|
|
61
|
+
};
|
|
62
|
+
type DetachedCall<Output> = {
|
|
63
|
+
readonly abort: AbortController | undefined;
|
|
64
|
+
readonly reject: ((reason: unknown) => void) | undefined;
|
|
65
|
+
readonly resolve: ((value: Output) => void) | undefined;
|
|
66
|
+
};
|
|
67
|
+
declare const rejectPromise: <Value>(reason: unknown) => Promise<Value>;
|
|
68
|
+
declare function assertAuthenticCallTarget(value: unknown): void;
|
|
69
|
+
declare function assertAuthorityCurrent(authority: CallAuthority | undefined): void;
|
|
70
|
+
declare function isAuthorityCurrent(authority: CallAuthority | undefined): boolean;
|
|
71
|
+
declare function abortAndReject<Output>(detached: DetachedCall<Output>, reason: unknown): void;
|
|
72
|
+
declare function settleDetachedCall<Output>(detached: DetachedCall<Output>, outcome: CallOutcome<Output>): void;
|
|
73
|
+
/** The cancellation reason travels next to the code, so every call cancellation is one `CallError` shape. */
|
|
74
|
+
declare function cancelledCall(reason: unknown): CallError;
|
|
75
|
+
declare function authorityChangeReason(event: CallAuthoritySourceEvent, id: DeclarationId): unknown;
|
|
76
|
+
export { abortAndReject, assertAuthenticCallTarget, assertAuthorityCurrent, authorityChangeReason, cancelledCall, isAuthorityCurrent, rejectPromise, settleDetachedCall, };
|
|
77
|
+
export type { CallController, CallControllerOptions, CallDiagnostics, CallOutcome, CallRunOptions, CapturedCallAuthorities, DetachedCall, NoExtraKeys, PendingCall, };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{abortWithReason as i}from"./abort-compat.js";import{isCallTarget as u}from"./call-target.js";import{CallError as o}from"./errors.js";const l=r=>new Promise((n,e)=>e(r));function s(r){if(!u(r))throw new TypeError("Call adapter source is not authentic.")}function a(r){r!==void 0&&r.assertCurrent()}function f(r){return r===void 0||r.isCurrent()}function c(r,n){r.abort!==void 0&&i(r.abort,n),r.reject!==void 0&&r.reject(n)}function C(r,n){var e,t;if(n.status==="succeeded"){(e=r.resolve)==null||e.call(r,n.value);return}n.status==="cancelled"&&r.abort!==void 0&&i(r.abort,n.error.reason),(t=r.reject)==null||t.call(r,n.error)}function b(r){return new o("cancelled","Call invocation was cancelled.",r)}function p(r,n){return r.current.kind==="inactive"?r.current.reason:new o("publication-rejected",`Call ${n} was rebound to another target.`)}export{c as abortAndReject,s as assertAuthenticCallTarget,a as assertAuthorityCurrent,p as authorityChangeReason,b as cancelledCall,f as isAuthorityCurrent,l as rejectPromise,C as settleDetachedCall};
|
|
2
|
+
//# sourceMappingURL=call-controller-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-controller-support.js","sources":["../src/call-controller-support.ts"],"sourcesContent":["import { abortWithReason } from './abort-compat';\nimport type { CallAuthority, CallAuthoritySourceEvent } from './call-authority';\nimport type { CallControllerImpl } from './call-controller';\nimport { isCallTarget } from './call-target';\nimport { CallError } from './errors';\nimport type { DeclarationId } from './identity';\nimport type { NoExtraKeys } from './type-helpers';\n\ntype CallControllerScheduling = { readonly lane?: never; readonly policy: 'parallel' };\n\ninterface CallDiagnostics {\n readonly closed: boolean;\n readonly pendingCalls: number;\n}\n\ninterface CallRunOptions<Output> {\n readonly onSuccess?: (value: Output) => PromiseLike<void> | void;\n readonly signal?: AbortSignal;\n}\n\n/**\n * A command is invoked, not watched: the controller has no snapshot to read and no listener to register. Shared\n * invocation state a component only observes is a `Readable` field of the model (D71, D162).\n */\ninterface CallController<Input, Output> {\n readonly activate: () => void;\n readonly close: (reason?: unknown) => void;\n readonly diagnostics: () => CallDiagnostics;\n readonly run: (input: Input, options?: CallRunOptions<Output>) => Promise<Output>;\n}\n\ninterface CallControllerOptions {\n readonly captureAuthority?: () => CallAuthority;\n readonly id: string;\n readonly scheduling: CallControllerScheduling;\n}\n\ntype PendingCall<Input, Output> = {\n abort: AbortController | undefined;\n callId: string;\n externalAbort: (() => void) | undefined;\n externalSignal: AbortSignal | undefined;\n input: Input | undefined;\n onSuccess: ((value: Output) => PromiseLike<void> | void) | undefined;\n ordinal: number;\n owner: CallControllerImpl<Input, Output> | undefined;\n ownerAuthority: CallAuthority | undefined;\n reject: ((reason: unknown) => void) | undefined;\n resolve: ((value: Output) => void) | undefined;\n started: boolean;\n targetAuthority: CallAuthority | undefined;\n};\n\ntype CallOutcome<Output> =\n | { readonly error: CallError; readonly status: 'cancelled' }\n | { readonly error: unknown; readonly status: 'failed' }\n | { readonly status: 'succeeded'; readonly value: Output };\n\ntype CapturedCallAuthorities = {\n readonly ownerAuthority: CallAuthority | undefined;\n readonly targetAuthority: CallAuthority | undefined;\n};\n\ntype DetachedCall<Output> = {\n readonly abort: AbortController | undefined;\n readonly reject: ((reason: unknown) => void) | undefined;\n readonly resolve: ((value: Output) => void) | undefined;\n};\n\nconst rejectPromise = <Value>(reason: unknown): Promise<Value> => {\n return new Promise<Value>((_resolve, reject) => reject(reason));\n};\n\nfunction assertAuthenticCallTarget(value: unknown): void {\n if (!isCallTarget(value)) throw new TypeError('Call adapter source is not authentic.');\n}\n\nfunction assertAuthorityCurrent(authority: CallAuthority | undefined): void {\n if (authority !== undefined) authority.assertCurrent();\n}\n\nfunction isAuthorityCurrent(authority: CallAuthority | undefined): boolean {\n return authority === undefined || authority.isCurrent();\n}\n\nfunction abortAndReject<Output>(detached: DetachedCall<Output>, reason: unknown): void {\n if (detached.abort !== undefined) abortWithReason(detached.abort, reason);\n\n if (detached.reject !== undefined) detached.reject(reason);\n}\n\nfunction settleDetachedCall<Output>(detached: DetachedCall<Output>, outcome: CallOutcome<Output>): void {\n if (outcome.status === 'succeeded') {\n detached.resolve?.(outcome.value);\n\n return;\n }\n\n if (outcome.status === 'cancelled' && detached.abort !== undefined) {\n abortWithReason(detached.abort, outcome.error.reason);\n }\n\n detached.reject?.(outcome.error);\n}\n\n/** The cancellation reason travels next to the code, so every call cancellation is one `CallError` shape. */\nfunction cancelledCall(reason: unknown): CallError {\n return new CallError('cancelled', 'Call invocation was cancelled.', reason);\n}\n\nfunction authorityChangeReason(event: CallAuthoritySourceEvent, id: DeclarationId): unknown {\n if (event.current.kind === 'inactive') return event.current.reason;\n\n return new CallError('publication-rejected', `Call ${id} was rebound to another target.`);\n}\n\nexport {\n abortAndReject,\n assertAuthenticCallTarget,\n assertAuthorityCurrent,\n authorityChangeReason,\n cancelledCall,\n isAuthorityCurrent,\n rejectPromise,\n settleDetachedCall,\n};\nexport type {\n CallController,\n CallControllerOptions,\n CallDiagnostics,\n CallOutcome,\n CallRunOptions,\n CapturedCallAuthorities,\n DetachedCall,\n NoExtraKeys,\n PendingCall,\n};\n"],"names":["rejectPromise","reason","_resolve","reject","assertAuthenticCallTarget","value","isCallTarget","assertAuthorityCurrent","authority","isAuthorityCurrent","abortAndReject","detached","abortWithReason","settleDetachedCall","outcome","_a","_b","cancelledCall","CallError","authorityChangeReason","event","id"],"mappings":"4IAqEA,MAAMA,EAAwBC,GACrB,IAAI,QAAe,CAACC,EAAUC,IAAWA,EAAOF,CAAM,CAAC,EAGhE,SAASG,EAA0BC,EAAc,CAC/C,GAAI,CAACC,EAAaD,CAAK,EAAG,MAAM,IAAI,UAAU,uCAAuC,CACvF,CAEA,SAASE,EAAuBC,EAAoC,CAC9DA,IAAc,QAAWA,EAAU,cAAa,CACtD,CAEA,SAASC,EAAmBD,EAAoC,CAC9D,OAAOA,IAAc,QAAaA,EAAU,UAAS,CACvD,CAEA,SAASE,EAAuBC,EAAgCV,EAAe,CACzEU,EAAS,QAAU,QAAWC,EAAgBD,EAAS,MAAOV,CAAM,EAEpEU,EAAS,SAAW,QAAWA,EAAS,OAAOV,CAAM,CAC3D,CAEA,SAASY,EAA2BF,EAAgCG,EAA4B,SAC9F,GAAIA,EAAQ,SAAW,YAAa,EAClCC,EAAAJ,EAAS,UAAT,MAAAI,EAAA,KAAAJ,EAAmBG,EAAQ,OAE3B,MACF,CAEIA,EAAQ,SAAW,aAAeH,EAAS,QAAU,QACvDC,EAAgBD,EAAS,MAAOG,EAAQ,MAAM,MAAM,GAGtDE,EAAAL,EAAS,SAAT,MAAAK,EAAA,KAAAL,EAAkBG,EAAQ,MAC5B,CAGA,SAASG,EAAchB,EAAe,CACpC,OAAO,IAAIiB,EAAU,YAAa,iCAAkCjB,CAAM,CAC5E,CAEA,SAASkB,EAAsBC,EAAiCC,EAAiB,CAC/E,OAAID,EAAM,QAAQ,OAAS,WAAmBA,EAAM,QAAQ,OAErD,IAAIF,EAAU,uBAAwB,QAAQG,CAAE,iCAAiC,CAC1F"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { CallController, CallControllerOptions, CallDiagnostics, CallRunOptions } from './call-controller-support.js';
|
|
2
|
+
import type { Call } from './call-target.js';
|
|
3
|
+
declare class CallControllerImpl<Input, Output> implements CallController<Input, Output> {
|
|
4
|
+
private authoritySource;
|
|
5
|
+
private authoritySourceRelease;
|
|
6
|
+
private captureAuthority;
|
|
7
|
+
private closed;
|
|
8
|
+
private readonly id;
|
|
9
|
+
private nextOrdinal;
|
|
10
|
+
private readonly pending;
|
|
11
|
+
private target;
|
|
12
|
+
constructor(target: Call<Input, Output>, options: CallControllerOptions);
|
|
13
|
+
activate: () => void;
|
|
14
|
+
close(reason?: unknown): void;
|
|
15
|
+
diagnostics(): CallDiagnostics;
|
|
16
|
+
run: (input: Input, options?: CallRunOptions<Output>) => Promise<Output>;
|
|
17
|
+
private areAuthoritiesCurrent;
|
|
18
|
+
private assertCallCanStart;
|
|
19
|
+
private assertOpenForInvocation;
|
|
20
|
+
private assertOpenForRun;
|
|
21
|
+
private assertSignalActive;
|
|
22
|
+
private assertTargetAuthorityCurrent;
|
|
23
|
+
private bindExternalAbort;
|
|
24
|
+
private cancel;
|
|
25
|
+
private canHandleAuthorityChange;
|
|
26
|
+
private canNotifySuccess;
|
|
27
|
+
private captureOwnerAuthority;
|
|
28
|
+
private captureRunAuthorities;
|
|
29
|
+
private captureTargetAuthority;
|
|
30
|
+
private complete;
|
|
31
|
+
private completeFailure;
|
|
32
|
+
private completeTarget;
|
|
33
|
+
private detachCall;
|
|
34
|
+
private detachCallsForAuthority;
|
|
35
|
+
private finish;
|
|
36
|
+
private finishRejected;
|
|
37
|
+
private handleAuthorityChange;
|
|
38
|
+
private isTargetAuthorityCurrent;
|
|
39
|
+
private notifySuccess;
|
|
40
|
+
private publicationAuthorityRejection;
|
|
41
|
+
private publicationRejection;
|
|
42
|
+
private publicationSourceRejection;
|
|
43
|
+
private releaseAuthoritySource;
|
|
44
|
+
private releaseCall;
|
|
45
|
+
private retireAuthority;
|
|
46
|
+
private start;
|
|
47
|
+
private startTarget;
|
|
48
|
+
}
|
|
49
|
+
export { CallControllerImpl };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{compatibleAbortReason as f}from"./abort-compat.js";import{reportDetachedError as a}from"./attachment.js";import{abortAndReject as c,rejectPromise as p,isAuthorityCurrent as h,assertAuthorityCurrent as d,cancelledCall as l,settleDetachedCall as g,authorityChangeReason as A}from"./call-controller-support.js";import{getCallTargetLifetimeBinding as w,invokeCallTarget as C}from"./call-target.js";import{CallError as o}from"./errors.js";import{declarationId as S}from"./identity.js";class b{authoritySource;authoritySourceRelease;captureAuthority;closed=!1;id;nextOrdinal=0;pending=new Map;target;constructor(e,t){var r;if(this.authoritySource=(r=w(e))==null?void 0:r.authoritySource,this.id=S(t.id),this.target=e,this.captureAuthority=t.captureAuthority,t.scheduling.policy!=="parallel"||t.scheduling.lane!==void 0)throw new TypeError("This root-command kernel only supports explicit parallel scheduling.")}activate=()=>{if(this.closed||this.target===void 0)throw new o("closed",`Call ${this.id} cannot be activated after close.`);const e=this.authoritySource;if(e===void 0||this.authoritySourceRelease!==void 0)return;const t=e.subscribe(this.handleAuthorityChange);this.authoritySourceRelease=t;try{e.getSnapshot()}catch(r){this.authoritySourceRelease=void 0;try{t()}catch(i){a(i)}throw r}};close(e=new o("closed",`Call ${this.id} is closed.`)){if(this.closed)return;this.closed=!0,this.target=void 0,this.captureAuthority=void 0,this.authoritySource=void 0;const t=[...this.pending.values()].map(r=>this.detachCall(r));for(const r of t)c(r,e);this.releaseAuthoritySource()}diagnostics(){return Object.freeze({closed:this.closed,pendingCalls:this.pending.size})}run=(e,t={})=>{let r;try{r=this.captureRunAuthorities(t)}catch(s){return p(s)}const i=++this.nextOrdinal,n={abort:new AbortController,callId:`${String(this.id)}#${String(i)}`,externalAbort:void 0,externalSignal:t.signal,input:e,onSuccess:t.onSuccess,ordinal:i,owner:this,ownerAuthority:r.ownerAuthority,reject:void 0,resolve:void 0,started:!1,targetAuthority:r.targetAuthority},u=new Promise((s,y)=>{n.resolve=s,n.reject=y});return this.bindExternalAbort(n),this.pending.set(i,n),this.start(n),u};areAuthoritiesCurrent(e,t){return!h(e)||!h(t)?!1:this.isTargetAuthorityCurrent(t)}assertCallCanStart(e){this.assertOpenForInvocation(),d(e.ownerAuthority),d(e.targetAuthority),this.assertTargetAuthorityCurrent(e.targetAuthority),this.assertSignalActive(e.externalSignal)}assertOpenForInvocation(){if(this.closed||this.target===void 0)throw new o("closed",`Call ${this.id} closed before invocation.`)}assertOpenForRun(){if(this.closed||this.target===void 0)throw new o("closed",`Call ${this.id} is closed.`)}assertSignalActive(e){if((e==null?void 0:e.aborted)===!0)throw l(f(e))}assertTargetAuthorityCurrent(e){if(!this.isTargetAuthorityCurrent(e))throw new o("publication-rejected",`Call ${this.id} was withdrawn before it started.`)}bindExternalAbort(e){const t=e.externalSignal;t!==void 0&&(e.externalAbort=()=>{const r=e.owner;r!==void 0&&r.cancel(e,l(f(t)))},t.addEventListener("abort",e.externalAbort,{once:!0}))}cancel(e,t){e.owner===this&&this.complete(e,{error:t,status:"cancelled"})}canHandleAuthorityChange(){return this.closed||this.authoritySource===void 0?!1:this.authoritySourceRelease!==void 0}canNotifySuccess(e,t){if(this.closed)return!1;try{return this.areAuthoritiesCurrent(e,t)}catch(r){return a(r),!1}}captureOwnerAuthority(){const e=this.captureAuthority;return e===void 0?void 0:e()}captureRunAuthorities(e){this.assertOpenForRun();const t=this.captureOwnerAuthority();d(t);const r=this.captureTargetAuthority();return d(r),this.assertSignalActive(e.signal),{ownerAuthority:t,targetAuthority:r}}captureTargetAuthority(){const e=this.authoritySource;if(e===void 0)return;if(this.authoritySourceRelease===void 0)throw new o("closed",`Call ${this.id} is not active.`);const t=e.getSnapshot();if(t.kind==="ready")return t.authority;throw t.reason}complete(e,t){const r=this.publicationRejection(e);return r!==void 0?(this.finishRejected(e,r.reason),!1):(this.finish(e,t),!0)}completeFailure(e,t){e.owner===this&&this.complete(e,{error:t,status:"failed"})}completeTarget(e,t){if(e.owner!==this)return;const r=e.ownerAuthority,i=e.targetAuthority,n=e.onSuccess;this.complete(e,{status:"succeeded",value:t})&&n!==void 0&&this.canNotifySuccess(r,i)&&this.notifySuccess(n,t)}detachCall(e){this.pending.delete(e.ordinal),this.releaseCall(e);const t={abort:e.abort,reject:e.reject,resolve:e.resolve};return e.abort=void 0,e.owner=void 0,e.ownerAuthority=void 0,e.input=void 0,e.onSuccess=void 0,e.reject=void 0,e.resolve=void 0,e.targetAuthority=void 0,t}detachCallsForAuthority(e){const t=[];for(const r of[...this.pending.values()])r.targetAuthority===e&&t.push(this.detachCall(r));return t}finish(e,t){e.owner===this&&g(this.detachCall(e),t)}finishRejected(e,t){e.owner===this&&c(this.detachCall(e),t)}handleAuthorityChange=e=>{this.canHandleAuthorityChange()&&e.previous.kind==="ready"&&(this.isTargetAuthorityCurrent(e.previous.authority)||this.retireAuthority(e.previous.authority,A(e,this.id)))};isTargetAuthorityCurrent(e){const t=this.authoritySource;if(t===void 0)return e===void 0;const r=t.getSnapshot();return r.kind==="ready"&&r.authority===e}notifySuccess(e,t){let r;try{r=e(t)}catch(i){a(i);return}Promise.resolve(r).catch(a)}publicationAuthorityRejection(e){if(!h(e.ownerAuthority))return{reason:new o("publication-rejected",`Call ${this.id} was withdrawn.`)}}publicationRejection(e){try{return this.publicationAuthorityRejection(e)??this.publicationSourceRejection(e.targetAuthority)}catch(t){return{reason:t}}}publicationSourceRejection(e){const t=this.authoritySource;if(t===void 0)return h(e)?void 0:{reason:new o("publication-rejected",`Call ${this.id} was withdrawn.`)};const r=t.getSnapshot();if(r.kind==="inactive")return{reason:r.reason};if(r.authority!==e||!h(e))return{reason:new o("publication-rejected",`Call ${this.id} was withdrawn.`)}}releaseAuthoritySource(){const e=this.authoritySourceRelease;if(this.authoritySourceRelease=void 0,e!==void 0)try{e()}catch(t){a(t)}}releaseCall(e){e.externalAbort!==void 0&&e.externalSignal!==void 0&&e.externalSignal.removeEventListener("abort",e.externalAbort),e.externalAbort=void 0,e.externalSignal=void 0}retireAuthority(e,t){for(const r of this.detachCallsForAuthority(e))c(r,t)}start(e){if(!(e.started||e.owner!==this)){try{this.assertCallCanStart(e)}catch(t){t instanceof o&&t.code==="cancelled"&&this.publicationRejection(e)===void 0?this.finish(e,{error:t,status:"cancelled"}):this.finishRejected(e,t);return}this.startTarget(e)}}startTarget(e){const t=this.target,r=e.input,i=e.abort;if(t===void 0||i===void 0){this.completeFailure(e,new o("closed",`Call ${this.id} closed before invocation.`));return}e.started=!0;let n;try{n=C(t,r,Object.freeze({signal:i.signal}))}catch(u){this.completeFailure(e,u);return}Promise.resolve(n).then(u=>{const s=e.owner;s!==void 0&&s.completeTarget(e,u)},u=>{const s=e.owner;s!==void 0&&s.completeFailure(e,u)})}}export{b as CallControllerImpl};
|
|
2
|
+
//# sourceMappingURL=call-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-controller.js","sources":["../src/call-controller.ts"],"sourcesContent":["import { compatibleAbortReason } from './abort-compat';\nimport { reportDetachedError } from './attachment';\nimport type { CallAuthority, CallAuthoritySource, CallAuthoritySourceEvent } from './call-authority';\nimport {\n abortAndReject,\n assertAuthorityCurrent,\n authorityChangeReason,\n cancelledCall,\n isAuthorityCurrent,\n rejectPromise,\n settleDetachedCall,\n} from './call-controller-support';\nimport type {\n CallController,\n CallControllerOptions,\n CallDiagnostics,\n CallOutcome,\n CallRunOptions,\n CapturedCallAuthorities,\n DetachedCall,\n PendingCall,\n} from './call-controller-support';\nimport { getCallTargetLifetimeBinding, invokeCallTarget } from './call-target';\nimport type { Call } from './call-target';\nimport { CallError } from './errors';\nimport { declarationId } from './identity';\nimport type { DeclarationId } from './identity';\n\nclass CallControllerImpl<Input, Output> implements CallController<Input, Output> {\n private authoritySource: CallAuthoritySource | undefined;\n private authoritySourceRelease: (() => void) | undefined;\n private captureAuthority: (() => CallAuthority) | undefined;\n private closed = false;\n private readonly id: DeclarationId;\n private nextOrdinal = 0;\n private readonly pending = new Map<number, PendingCall<Input, Output>>();\n private target: Call<Input, Output> | undefined;\n\n constructor(target: Call<Input, Output>, options: CallControllerOptions) {\n this.authoritySource = getCallTargetLifetimeBinding(target as Call<unknown, unknown>)?.authoritySource;\n this.id = declarationId(options.id);\n this.target = target;\n this.captureAuthority = options.captureAuthority;\n\n if (options.scheduling.policy !== 'parallel' || options.scheduling.lane !== undefined) {\n throw new TypeError('This root-command kernel only supports explicit parallel scheduling.');\n }\n }\n\n activate = (): void => {\n if (this.closed || this.target === undefined) {\n throw new CallError('closed', `Call ${this.id} cannot be activated after close.`);\n }\n\n const source = this.authoritySource;\n\n if (source === undefined || this.authoritySourceRelease !== undefined) return;\n\n const release = source.subscribe(this.handleAuthorityChange);\n this.authoritySourceRelease = release;\n\n try {\n source.getSnapshot();\n } catch (error) {\n this.authoritySourceRelease = undefined;\n\n try {\n release();\n } catch (releaseError) {\n reportDetachedError(releaseError);\n }\n\n throw error;\n }\n };\n\n close(reason: unknown = new CallError('closed', `Call ${this.id} is closed.`)): void {\n if (this.closed) return;\n\n this.closed = true;\n this.target = undefined;\n this.captureAuthority = undefined;\n this.authoritySource = undefined;\n\n const detachedCalls = [...this.pending.values()].map(call => this.detachCall(call));\n\n for (const detached of detachedCalls) abortAndReject(detached, reason);\n\n this.releaseAuthoritySource();\n }\n\n diagnostics(): CallDiagnostics {\n return Object.freeze({ closed: this.closed, pendingCalls: this.pending.size });\n }\n\n run = (input: Input, options: CallRunOptions<Output> = {}): Promise<Output> => {\n let authorities: {\n readonly ownerAuthority: CallAuthority | undefined;\n readonly targetAuthority: CallAuthority | undefined;\n };\n\n try {\n authorities = this.captureRunAuthorities(options);\n } catch (error) {\n return rejectPromise(error);\n }\n\n const ordinal = ++this.nextOrdinal;\n const call: PendingCall<Input, Output> = {\n abort: new AbortController(),\n callId: `${String(this.id)}#${String(ordinal)}`,\n externalAbort: undefined,\n externalSignal: options.signal,\n input,\n onSuccess: options.onSuccess,\n ordinal,\n owner: this,\n ownerAuthority: authorities.ownerAuthority,\n reject: undefined,\n resolve: undefined,\n started: false,\n targetAuthority: authorities.targetAuthority,\n };\n const result = new Promise<Output>((resolve, reject) => {\n call.resolve = resolve;\n call.reject = reject;\n });\n this.bindExternalAbort(call);\n\n this.pending.set(ordinal, call);\n this.start(call);\n\n return result;\n };\n\n private areAuthoritiesCurrent(\n ownerAuthority: CallAuthority | undefined,\n targetAuthority: CallAuthority | undefined,\n ): boolean {\n if (!isAuthorityCurrent(ownerAuthority)) return false;\n\n if (!isAuthorityCurrent(targetAuthority)) return false;\n\n return this.isTargetAuthorityCurrent(targetAuthority);\n }\n\n private assertCallCanStart(call: PendingCall<Input, Output>): void {\n this.assertOpenForInvocation();\n assertAuthorityCurrent(call.ownerAuthority);\n assertAuthorityCurrent(call.targetAuthority);\n this.assertTargetAuthorityCurrent(call.targetAuthority);\n this.assertSignalActive(call.externalSignal);\n }\n\n private assertOpenForInvocation(): void {\n if (this.closed || this.target === undefined) {\n throw new CallError('closed', `Call ${this.id} closed before invocation.`);\n }\n }\n\n private assertOpenForRun(): void {\n if (this.closed || this.target === undefined) throw new CallError('closed', `Call ${this.id} is closed.`);\n }\n\n private assertSignalActive(signal: AbortSignal | undefined): void {\n if (signal?.aborted === true) throw cancelledCall(compatibleAbortReason(signal));\n }\n\n private assertTargetAuthorityCurrent(targetAuthority: CallAuthority | undefined): void {\n if (this.isTargetAuthorityCurrent(targetAuthority)) return;\n\n throw new CallError('publication-rejected', `Call ${this.id} was withdrawn before it started.`);\n }\n\n private bindExternalAbort(call: PendingCall<Input, Output>): void {\n const signal = call.externalSignal;\n\n if (signal === undefined) return;\n\n call.externalAbort = (): void => {\n const owner = call.owner;\n\n if (owner !== undefined) owner.cancel(call, cancelledCall(compatibleAbortReason(signal)));\n };\n signal.addEventListener('abort', call.externalAbort, { once: true });\n }\n\n private cancel(call: PendingCall<Input, Output>, error: CallError): void {\n if (call.owner !== this) return;\n\n this.complete(call, { error, status: 'cancelled' });\n }\n\n private canHandleAuthorityChange(): boolean {\n if (this.closed) return false;\n\n if (this.authoritySource === undefined) return false;\n\n return this.authoritySourceRelease !== undefined;\n }\n\n private canNotifySuccess(\n ownerAuthority: CallAuthority | undefined,\n targetAuthority: CallAuthority | undefined,\n ): boolean {\n if (this.closed) return false;\n\n try {\n return this.areAuthoritiesCurrent(ownerAuthority, targetAuthority);\n } catch (error) {\n reportDetachedError(error);\n\n return false;\n }\n }\n\n private captureOwnerAuthority(): CallAuthority | undefined {\n const capture = this.captureAuthority;\n\n return capture === undefined ? undefined : capture();\n }\n\n private captureRunAuthorities(options: CallRunOptions<Output>): CapturedCallAuthorities {\n this.assertOpenForRun();\n\n const ownerAuthority = this.captureOwnerAuthority();\n assertAuthorityCurrent(ownerAuthority);\n const targetAuthority = this.captureTargetAuthority();\n assertAuthorityCurrent(targetAuthority);\n this.assertSignalActive(options.signal);\n\n return { ownerAuthority, targetAuthority };\n }\n\n private captureTargetAuthority(): CallAuthority | undefined {\n const source = this.authoritySource;\n\n if (source === undefined) return undefined;\n\n if (this.authoritySourceRelease === undefined) {\n throw new CallError('closed', `Call ${this.id} is not active.`);\n }\n\n const snapshot = source.getSnapshot();\n\n if (snapshot.kind === 'ready') return snapshot.authority;\n\n throw snapshot.reason;\n }\n\n private complete(call: PendingCall<Input, Output>, outcome: CallOutcome<Output>): boolean {\n const rejection = this.publicationRejection(call);\n\n if (rejection !== undefined) {\n this.finishRejected(call, rejection.reason);\n\n return false;\n }\n\n this.finish(call, outcome);\n\n return true;\n }\n\n private completeFailure(call: PendingCall<Input, Output>, error: unknown): void {\n if (call.owner !== this) return;\n\n this.complete(call, { error, status: 'failed' });\n }\n\n private completeTarget(call: PendingCall<Input, Output>, value: Output): void {\n if (call.owner !== this) return;\n\n const ownerAuthority = call.ownerAuthority;\n const targetAuthority = call.targetAuthority;\n const onSuccess = call.onSuccess;\n\n if (!this.complete(call, { status: 'succeeded', value })) return;\n\n if (onSuccess !== undefined && this.canNotifySuccess(ownerAuthority, targetAuthority)) {\n this.notifySuccess(onSuccess, value);\n }\n }\n\n private detachCall(call: PendingCall<Input, Output>): DetachedCall<Output> {\n this.pending.delete(call.ordinal);\n this.releaseCall(call);\n const detached = { abort: call.abort, reject: call.reject, resolve: call.resolve };\n call.abort = undefined;\n call.owner = undefined;\n call.ownerAuthority = undefined;\n call.input = undefined;\n call.onSuccess = undefined;\n call.reject = undefined;\n call.resolve = undefined;\n call.targetAuthority = undefined;\n\n return detached;\n }\n\n private detachCallsForAuthority(authority: CallAuthority): DetachedCall<Output>[] {\n const detachedCalls: DetachedCall<Output>[] = [];\n\n for (const call of [...this.pending.values()]) {\n if (call.targetAuthority !== authority) continue;\n\n detachedCalls.push(this.detachCall(call));\n }\n\n return detachedCalls;\n }\n\n private finish(call: PendingCall<Input, Output>, outcome: CallOutcome<Output>): void {\n if (call.owner !== this) return;\n\n settleDetachedCall(this.detachCall(call), outcome);\n }\n\n private finishRejected(call: PendingCall<Input, Output>, reason: unknown): void {\n if (call.owner !== this) return;\n\n abortAndReject(this.detachCall(call), reason);\n }\n\n private handleAuthorityChange = (event: CallAuthoritySourceEvent): void => {\n if (!this.canHandleAuthorityChange()) return;\n\n if (event.previous.kind !== 'ready') return;\n\n if (this.isTargetAuthorityCurrent(event.previous.authority)) return;\n\n this.retireAuthority(event.previous.authority, authorityChangeReason(event, this.id));\n };\n\n private isTargetAuthorityCurrent(targetAuthority: CallAuthority | undefined): boolean {\n const source = this.authoritySource;\n\n if (source === undefined) return targetAuthority === undefined;\n\n const snapshot = source.getSnapshot();\n\n return snapshot.kind === 'ready' && snapshot.authority === targetAuthority;\n }\n\n private notifySuccess(onSuccess: (value: Output) => PromiseLike<void> | void, value: Output): void {\n let result: PromiseLike<void> | void;\n\n try {\n result = onSuccess(value);\n } catch (error) {\n reportDetachedError(error);\n\n return;\n }\n\n Promise.resolve(result).catch(reportDetachedError);\n }\n\n private publicationAuthorityRejection(call: PendingCall<Input, Output>): { readonly reason: unknown } | undefined {\n if (!isAuthorityCurrent(call.ownerAuthority)) {\n return { reason: new CallError('publication-rejected', `Call ${this.id} was withdrawn.`) };\n }\n\n return undefined;\n }\n\n private publicationRejection(call: PendingCall<Input, Output>): { readonly reason: unknown } | undefined {\n try {\n const authorityRejection = this.publicationAuthorityRejection(call);\n\n return authorityRejection ?? this.publicationSourceRejection(call.targetAuthority);\n } catch (error) {\n return { reason: error };\n }\n }\n\n private publicationSourceRejection(\n targetAuthority: CallAuthority | undefined,\n ): { readonly reason: unknown } | undefined {\n const source = this.authoritySource;\n\n if (source === undefined) {\n return isAuthorityCurrent(targetAuthority)\n ? undefined\n : { reason: new CallError('publication-rejected', `Call ${this.id} was withdrawn.`) };\n }\n\n const snapshot = source.getSnapshot();\n\n if (snapshot.kind === 'inactive') return { reason: snapshot.reason };\n\n if (snapshot.authority !== targetAuthority || !isAuthorityCurrent(targetAuthority)) {\n return { reason: new CallError('publication-rejected', `Call ${this.id} was withdrawn.`) };\n }\n\n return undefined;\n }\n\n private releaseAuthoritySource(): void {\n const release = this.authoritySourceRelease;\n this.authoritySourceRelease = undefined;\n\n if (release === undefined) return;\n\n try {\n release();\n } catch (error) {\n reportDetachedError(error);\n }\n }\n\n private releaseCall(call: PendingCall<Input, Output>): void {\n if (call.externalAbort !== undefined && call.externalSignal !== undefined) {\n call.externalSignal.removeEventListener('abort', call.externalAbort);\n }\n\n call.externalAbort = undefined;\n call.externalSignal = undefined;\n }\n\n private retireAuthority(retiredAuthority: CallAuthority, reason: unknown): void {\n for (const detached of this.detachCallsForAuthority(retiredAuthority)) abortAndReject(detached, reason);\n }\n\n private start(call: PendingCall<Input, Output>): void {\n if (call.started || call.owner !== this) return;\n\n try {\n this.assertCallCanStart(call);\n } catch (error) {\n if (error instanceof CallError && error.code === 'cancelled' && this.publicationRejection(call) === undefined) {\n this.finish(call, { error, status: 'cancelled' });\n } else {\n this.finishRejected(call, error);\n }\n\n return;\n }\n\n this.startTarget(call);\n }\n\n private startTarget(call: PendingCall<Input, Output>): void {\n const target = this.target;\n const input = call.input;\n const abort = call.abort;\n\n if (target === undefined || abort === undefined) {\n this.completeFailure(call, new CallError('closed', `Call ${this.id} closed before invocation.`));\n\n return;\n }\n\n call.started = true;\n let targetResult: Output | PromiseLike<Output>;\n\n try {\n targetResult = invokeCallTarget(target, input as Input, Object.freeze({ signal: abort.signal }));\n } catch (error) {\n this.completeFailure(call, error);\n\n return;\n }\n\n Promise.resolve(targetResult).then(\n value => {\n const owner = call.owner;\n\n if (owner !== undefined) owner.completeTarget(call, value);\n },\n (error: unknown) => {\n const owner = call.owner;\n\n if (owner !== undefined) owner.completeFailure(call, error);\n },\n );\n }\n}\n\nexport { CallControllerImpl };\n"],"names":["CallControllerImpl","target","options","_a","getCallTargetLifetimeBinding","declarationId","CallError","source","release","error","releaseError","reportDetachedError","reason","detachedCalls","call","detached","abortAndReject","input","authorities","rejectPromise","ordinal","result","resolve","reject","ownerAuthority","targetAuthority","isAuthorityCurrent","assertAuthorityCurrent","signal","cancelledCall","compatibleAbortReason","owner","capture","snapshot","outcome","rejection","value","onSuccess","authority","settleDetachedCall","event","authorityChangeReason","retiredAuthority","abort","targetResult","invokeCallTarget"],"mappings":"ueA4BA,MAAMA,CAAkB,CACd,gBACA,uBACA,iBACA,OAAS,GACA,GACT,YAAc,EACL,QAAU,IAAI,IACvB,OAER,YAAYC,EAA6BC,EAA8B,OAMrE,GALA,KAAK,iBAAkBC,EAAAC,EAA6BH,CAAgC,IAA7D,YAAAE,EAAgE,gBACvF,KAAK,GAAKE,EAAcH,EAAQ,EAAE,EAClC,KAAK,OAASD,EACd,KAAK,iBAAmBC,EAAQ,iBAE5BA,EAAQ,WAAW,SAAW,YAAcA,EAAQ,WAAW,OAAS,OAC1E,MAAM,IAAI,UAAU,sEAAsE,CAE9F,CAEA,SAAW,IAAW,CACpB,GAAI,KAAK,QAAU,KAAK,SAAW,OACjC,MAAM,IAAII,EAAU,SAAU,QAAQ,KAAK,EAAE,mCAAmC,EAGlF,MAAMC,EAAS,KAAK,gBAEpB,GAAIA,IAAW,QAAa,KAAK,yBAA2B,OAAW,OAEvE,MAAMC,EAAUD,EAAO,UAAU,KAAK,qBAAqB,EAC3D,KAAK,uBAAyBC,EAE9B,GAAI,CACFD,EAAO,YAAW,CACpB,OAASE,EAAO,CACd,KAAK,uBAAyB,OAE9B,GAAI,CACFD,EAAO,CACT,OAASE,EAAc,CACrBC,EAAoBD,CAAY,CAClC,CAE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,EAAe,CACtE,UAAWG,KAAY,KAAK,wBAAwB2B,CAAgB,EAAG1B,EAAeD,EAAUH,CAAM,CACxG,CAEQ,MAAME,EAAgC,CAC5C,GAAI,EAAAA,EAAK,SAAWA,EAAK,QAAU,MAEnC,IAAI,CACF,KAAK,mBAAmBA,CAAI,CAC9B,OAASL,EAAO,CACVA,aAAiBH,GAAaG,EAAM,OAAS,aAAe,KAAK,qBAAqBK,CAAI,IAAM,OAClG,KAAK,OAAOA,EAAM,CAAE,MAAAL,EAAO,OAAQ,YAAa,EAEhD,KAAK,eAAeK,EAAML,CAAK,EAGjC,MACF,CAEA,KAAK,YAAYK,CAAI,EACvB,CAEQ,YAAYA,EAAgC,CAClD,MAAMb,EAAS,KAAK,OACdgB,EAAQH,EAAK,MACb6B,EAAQ7B,EAAK,MAEnB,GAAIb,IAAW,QAAa0C,IAAU,OAAW,CAC/C,KAAK,gBAAgB7B,EAAM,IAAIR,EAAU,SAAU,QAAQ,KAAK,EAAE,4BAA4B,CAAC,EAE/F,MACF,CAEAQ,EAAK,QAAU,GACf,IAAI8B,EAEJ,GAAI,CACFA,EAAeC,EAAiB5C,EAAQgB,EAAgB,OAAO,OAAO,CAAE,OAAQ0B,EAAM,MAAM,CAAE,CAAC,CACjG,OAASlC,EAAO,CACd,KAAK,gBAAgBK,EAAML,CAAK,EAEhC,MACF,CAEA,QAAQ,QAAQmC,CAAY,EAAE,KAC5BR,GAAQ,CACN,MAAML,EAAQjB,EAAK,MAEfiB,IAAU,QAAWA,EAAM,eAAejB,EAAMsB,CAAK,CAC3D,EACC3B,GAAkB,CACjB,MAAMsB,EAAQjB,EAAK,MAEfiB,IAAU,QAAWA,EAAM,gBAAgBjB,EAAML,CAAK,CAC5D,CAAC,CAEL,CACD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CallExecutorState } from './call-executor-record.js';
|
|
2
|
+
/** D206: a shared optional slot; inactive observation adds no listener or per-call record. */
|
|
3
|
+
type CallObservationSlot = {
|
|
4
|
+
readonly changed: (() => void) | undefined;
|
|
5
|
+
};
|
|
6
|
+
type CallExecutionFact = Readonly<{
|
|
7
|
+
callId: string;
|
|
8
|
+
declaration: string;
|
|
9
|
+
id: number;
|
|
10
|
+
lane: Readonly<{
|
|
11
|
+
blockedBy: 'unknown' | number | null;
|
|
12
|
+
declaration: string;
|
|
13
|
+
id: number;
|
|
14
|
+
}> | null;
|
|
15
|
+
pendingWaiters: number;
|
|
16
|
+
state: 'draining' | 'queued' | 'running';
|
|
17
|
+
}>;
|
|
18
|
+
type CallExecutionFacts = Readonly<{
|
|
19
|
+
calls: readonly CallExecutionFact[];
|
|
20
|
+
truncated: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
declare function notifyCallObservation(observation: CallObservationSlot | undefined): void;
|
|
23
|
+
/** Pulls only kernel-owned scalar facts; inputs, results, keys and cancellation reasons never leave the executor. */
|
|
24
|
+
declare function inspectCallExecutions<Input, Output>(state: CallExecutorState<Input, Output>, capacity: number): CallExecutionFacts;
|
|
25
|
+
export { inspectCallExecutions, notifyCallObservation };
|
|
26
|
+
export type { CallExecutionFact, CallExecutionFacts, CallObservationSlot };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{inspectCallLane as u}from"./call-lane.js";function d(l){var n;(n=l==null?void 0:l.changed)==null||n.call(l)}function i(l,n){const t=l.options.scheduling,c=t.policy==="parallel"?null:u(t.lane);return{callId:n.bodyCall.callId,declaration:l.options.id,id:n.identity,lane:c===null?null:{...c,blockedBy:n.started?null:c.blockedBy},pendingWaiters:n.waiters.size,state:n.started?n.abort.signal.aborted?"draining":"running":"queued"}}function a(l,n){const t=[];for(const c of l.executionGroups)for(const e of c.executions){if(t.length>=n)return{calls:t,truncated:!0};t.push(i(l,e))}return{calls:t,truncated:!1}}export{a as inspectCallExecutions,d as notifyCallObservation};
|
|
2
|
+
//# sourceMappingURL=call-execution-inspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-execution-inspection.js","sources":["../src/call-execution-inspection.ts"],"sourcesContent":["import type { CallExecution, CallExecutorState } from './call-executor-record';\nimport { inspectCallLane } from './call-lane';\n\n/** D206: a shared optional slot; inactive observation adds no listener or per-call record. */\ntype CallObservationSlot = { readonly changed: (() => void) | undefined };\n\ntype CallExecutionFact = Readonly<{\n callId: string;\n declaration: string;\n id: number;\n lane: Readonly<{ blockedBy: 'unknown' | number | null; declaration: string; id: number }> | null;\n pendingWaiters: number;\n state: 'draining' | 'queued' | 'running';\n}>;\n\ntype CallExecutionFacts = Readonly<{ calls: readonly CallExecutionFact[]; truncated: boolean }>;\n\nfunction notifyCallObservation(observation: CallObservationSlot | undefined): void {\n observation?.changed?.();\n}\n\nfunction inspectExecution<Input, Output>(\n state: CallExecutorState<Input, Output>,\n execution: CallExecution<Input, Output>,\n): CallExecutionFact {\n const scheduling = state.options.scheduling;\n const lane = scheduling.policy === 'parallel' ? null : inspectCallLane(scheduling.lane);\n\n return {\n callId: execution.bodyCall.callId,\n declaration: state.options.id,\n id: execution.identity,\n lane: lane === null ? null : { ...lane, blockedBy: execution.started ? null : lane.blockedBy },\n pendingWaiters: execution.waiters.size,\n state: !execution.started ? 'queued' : execution.abort.signal.aborted ? 'draining' : 'running',\n };\n}\n\n/** Pulls only kernel-owned scalar facts; inputs, results, keys and cancellation reasons never leave the executor. */\nfunction inspectCallExecutions<Input, Output>(\n state: CallExecutorState<Input, Output>,\n capacity: number,\n): CallExecutionFacts {\n const calls: CallExecutionFact[] = [];\n\n for (const group of state.executionGroups) {\n for (const execution of group.executions) {\n if (calls.length >= capacity) return { calls, truncated: true };\n\n calls.push(inspectExecution(state, execution));\n }\n }\n\n return { calls, truncated: false };\n}\n\nexport { inspectCallExecutions, notifyCallObservation };\nexport type { CallExecutionFact, CallExecutionFacts, CallObservationSlot };\n"],"names":["notifyCallObservation","observation","_a","inspectExecution","state","execution","scheduling","lane","inspectCallLane","inspectCallExecutions","capacity","calls","group"],"mappings":"iDAiBA,SAASA,EAAsBC,EAA4C,QACzEC,EAAAD,GAAA,YAAAA,EAAa,UAAb,MAAAC,EAAA,KAAAD,EACF,CAEA,SAASE,EACPC,EACAC,EAAuC,CAEvC,MAAMC,EAAaF,EAAM,QAAQ,WAC3BG,EAAOD,EAAW,SAAW,WAAa,KAAOE,EAAgBF,EAAW,IAAI,EAEtF,MAAO,CACL,OAAQD,EAAU,SAAS,OAC3B,YAAaD,EAAM,QAAQ,GAC3B,GAAIC,EAAU,SACd,KAAME,IAAS,KAAO,KAAO,CAAE,GAAGA,EAAM,UAAWF,EAAU,QAAU,KAAOE,EAAK,SAAS,EAC5F,eAAgBF,EAAU,QAAQ,KAClC,MAAQA,EAAU,QAAqBA,EAAU,MAAM,OAAO,QAAU,WAAa,UAAzD,SAEhC,CAGA,SAASI,EACPL,EACAM,EAAgB,CAEhB,MAAMC,EAA6B,CAAA,EAEnC,UAAWC,KAASR,EAAM,gBACxB,UAAWC,KAAaO,EAAM,WAAY,CACxC,GAAID,EAAM,QAAUD,EAAU,MAAO,CAAE,MAAAC,EAAO,UAAW,EAAI,EAE7DA,EAAM,KAAKR,EAAiBC,EAAOC,CAAS,CAAC,CAC/C,CAGF,MAAO,CAAE,MAAAM,EAAO,UAAW,EAAK,CAClC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CallObservationSlot } from './call-execution-inspection.js';
|
|
2
|
+
import type { CallExecutor, CallExecutorOptions } from './call-executor-types.js';
|
|
3
|
+
import type { NoExtraKeys } from './type-helpers.js';
|
|
4
|
+
declare function createCallExecutor<Input, Output, const Options extends CallExecutorOptions<Input> = CallExecutorOptions<Input>>(options: NoExtraKeys<Options, CallExecutorOptions<Input>> & Options, observation?: CallObservationSlot): CallExecutor<Input, Output>;
|
|
5
|
+
export { createCallExecutor };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{inspectCallExecutions as d}from"./call-execution-inspection.js";import{startCall as m,retireExecutionGroup as c}from"./call-executor.js";import{createCallExecutionGroup as p}from"./call-executor-record.js";import{snapshotCallExecutorOptions as a,CallExecutorClosedError as u}from"./call-executor-support.js";function f(e,o){if(e.closePromise!==void 0)return e.closePromise;e.closed=!0;const t=[...e.executionGroups];for(const r of t)r.retired=!0;const i=Promise.all(t.map(r=>c(e,r,o))).then(()=>{});return e.closePromise=i,i}function x(e,o,t){const i=e.retirements.get(o);if(i!==void 0)return i;e.retiredGenerations.add(o);const r=e.generations.get(o);if(e.generations.delete(o),r===void 0){const s=Promise.resolve();return e.retirements.set(o,s),s}r.retired=!0;const n=c(e,r,t);return e.retirements.set(o,n),n}function G(e,o){const t=a(e),i=p(o),r={closed:!1,closePromise:void 0,defaultExecutionGroup:i,executionGroups:new Set([i]),generations:new WeakMap,nextOrdinal:0,options:t,retiredGenerations:new WeakSet,retirements:new WeakMap};return Object.freeze({close:(n=new u(`Call ${t.id} is closed.`))=>f(r,n),inspect:n=>d(r,n),retireGeneration:(n,s=new u(`Call ${t.id} generation is retired.`))=>x(r,n,s),start:(n,s,l)=>m(r,n,s,l)})}export{G as createCallExecutor};
|
|
2
|
+
//# sourceMappingURL=call-executor-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-executor-factory.js","sources":["../src/call-executor-factory.ts"],"sourcesContent":["import { inspectCallExecutions } from './call-execution-inspection';\nimport type { CallObservationSlot } from './call-execution-inspection';\nimport { retireExecutionGroup, startCall } from './call-executor';\nimport { createCallExecutionGroup } from './call-executor-record';\nimport type { CallExecutorState } from './call-executor-record';\nimport { CallExecutorClosedError, snapshotCallExecutorOptions } from './call-executor-support';\nimport type {\n Awaitable,\n CallExecutionContext,\n CallExecutor,\n CallExecutorOptions,\n CallStartOptions,\n} from './call-executor-types';\nimport type { NoExtraKeys } from './type-helpers';\n\nfunction closeCallExecutor<Input, Output>(state: CallExecutorState<Input, Output>, reason: unknown): Promise<void> {\n if (state.closePromise !== undefined) return state.closePromise;\n\n state.closed = true;\n const executionGroups = [...state.executionGroups];\n\n for (const executionGroup of executionGroups) executionGroup.retired = true;\n\n const closePromise = Promise.all(\n executionGroups.map(executionGroup => retireExecutionGroup(state, executionGroup, reason)),\n ).then(() => undefined);\n state.closePromise = closePromise;\n\n return closePromise;\n}\n\nfunction retireCallGeneration<Input, Output>(\n state: CallExecutorState<Input, Output>,\n generation: object,\n reason: unknown,\n): Promise<void> {\n const existing = state.retirements.get(generation);\n\n if (existing !== undefined) return existing;\n\n state.retiredGenerations.add(generation);\n const executionGroup = state.generations.get(generation);\n state.generations.delete(generation);\n\n if (executionGroup === undefined) {\n const retirement = Promise.resolve();\n state.retirements.set(generation, retirement);\n\n return retirement;\n }\n\n executionGroup.retired = true;\n const retirement = retireExecutionGroup(state, executionGroup, reason);\n state.retirements.set(generation, retirement);\n\n return retirement;\n}\n\nfunction createCallExecutor<\n Input,\n Output,\n const Options extends CallExecutorOptions<Input> = CallExecutorOptions<Input>,\n>(\n options: NoExtraKeys<Options, CallExecutorOptions<Input>> & Options,\n observation?: CallObservationSlot,\n): CallExecutor<Input, Output> {\n const snapshot = snapshotCallExecutorOptions(options);\n const defaultExecutionGroup = createCallExecutionGroup<Input, Output>(observation);\n const state: CallExecutorState<Input, Output> = {\n closed: false,\n closePromise: undefined,\n defaultExecutionGroup,\n executionGroups: new Set([defaultExecutionGroup]),\n generations: new WeakMap(),\n nextOrdinal: 0,\n options: snapshot,\n retiredGenerations: new WeakSet(),\n retirements: new WeakMap(),\n };\n\n return Object.freeze({\n close: (reason: unknown = new CallExecutorClosedError(`Call ${snapshot.id} is closed.`)) =>\n closeCallExecutor(state, reason),\n inspect: (capacity: number) => inspectCallExecutions(state, capacity),\n retireGeneration: (\n generation: object,\n reason: unknown = new CallExecutorClosedError(`Call ${snapshot.id} generation is retired.`),\n ) => retireCallGeneration(state, generation, reason),\n start: (\n input: Input,\n execute: (context: CallExecutionContext) => Awaitable<Output>,\n startOptions?: CallStartOptions,\n ) => startCall(state, input, execute, startOptions),\n });\n}\n\nexport { createCallExecutor };\n"],"names":["closeCallExecutor","state","reason","executionGroups","executionGroup","closePromise","retireExecutionGroup","retireCallGeneration","generation","existing","retirement","createCallExecutor","options","observation","snapshot","snapshotCallExecutorOptions","defaultExecutionGroup","createCallExecutionGroup","CallExecutorClosedError","capacity","inspectCallExecutions","input","execute","startOptions","startCall"],"mappings":"2TAeA,SAASA,EAAiCC,EAAyCC,EAAe,CAChG,GAAID,EAAM,eAAiB,OAAW,OAAOA,EAAM,aAEnDA,EAAM,OAAS,GACf,MAAME,EAAkB,CAAC,GAAGF,EAAM,eAAe,EAEjD,UAAWG,KAAkBD,EAAiBC,EAAe,QAAU,GAEvE,MAAMC,EAAe,QAAQ,IAC3BF,EAAgB,IAAIC,GAAkBE,EAAqBL,EAAOG,EAAgBF,CAAM,CAAC,CAAC,EAC1F,KAAK,IAAA,EAAe,EACtB,OAAAD,EAAM,aAAeI,EAEdA,CACT,CAEA,SAASE,EACPN,EACAO,EACAN,EAAe,CAEf,MAAMO,EAAWR,EAAM,YAAY,IAAIO,CAAU,EAEjD,GAAIC,IAAa,OAAW,OAAOA,EAEnCR,EAAM,mBAAmB,IAAIO,CAAU,EACvC,MAAMJ,EAAiBH,EAAM,YAAY,IAAIO,CAAU,EAGvD,GAFAP,EAAM,YAAY,OAAOO,CAAU,EAE/BJ,IAAmB,OAAW,CAChC,MAAMM,EAAa,QAAQ,QAAO,EAClC,OAAAT,EAAM,YAAY,IAAIO,EAAYE,CAAU,EAErCA,CACT,CAEAN,EAAe,QAAU,GACzB,MAAMM,EAAaJ,EAAqBL,EAAOG,EAAgBF,CAAM,EACrE,OAAAD,EAAM,YAAY,IAAIO,EAAYE,CAAU,EAErCA,CACT,CAEA,SAASC,EAKPC,EACAC,EAAiC,CAEjC,MAAMC,EAAWC,EAA4BH,CAAO,EAC9CI,EAAwBC,EAAwCJ,CAAW,EAC3EZ,EAA0C,CAC9C,OAAQ,GACR,aAAc,OACd,sBAAAe,EACA,gBAAiB,IAAI,IAAI,CAACA,CAAqB,CAAC,EAChD,YAAa,IAAI,QACjB,YAAa,EACb,QAASF,EACT,mBAAoB,IAAI,QACxB,YAAa,IAAI,SAGnB,OAAO,OAAO,OAAO,CACnB,MAAO,CAACZ,EAAkB,IAAIgB,EAAwB,QAAQJ,EAAS,EAAE,aAAa,IACpFd,EAAkBC,EAAOC,CAAM,EACjC,QAAUiB,GAAqBC,EAAsBnB,EAAOkB,CAAQ,EACpE,iBAAkB,CAChBX,EACAN,EAAkB,IAAIgB,EAAwB,QAAQJ,EAAS,EAAE,yBAAyB,IACvFP,EAAqBN,EAAOO,EAAYN,CAAM,EACnD,MAAO,CACLmB,EACAC,EACAC,IACGC,EAAUvB,EAAOoB,EAAOC,EAASC,CAAY,CACnD,CAAA,CACH"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { CallObservationSlot } from './call-execution-inspection.js';
|
|
2
|
+
import type { Awaitable, CallExecutionContext, CallExecutionMetadata, CallExecutorSnapshotOptions, CallKey, CallStartOptions } from './call-executor-types.js';
|
|
3
|
+
import type { CallInvocation, CallInvocationController } from './call-invocation.js';
|
|
4
|
+
import type { CallLaneRequest } from './call-lane.js';
|
|
5
|
+
declare const onceKey: unique symbol;
|
|
6
|
+
type CallCacheKey = typeof onceKey | CallKey;
|
|
7
|
+
type CallWaiter<Output> = {
|
|
8
|
+
readonly abortReleases: (() => void)[];
|
|
9
|
+
active: boolean;
|
|
10
|
+
readonly cacheKey: CallCacheKey | undefined;
|
|
11
|
+
readonly controller: CallInvocationController<Output>;
|
|
12
|
+
};
|
|
13
|
+
type CallExecution<Input, Output> = {
|
|
14
|
+
readonly abort: AbortController;
|
|
15
|
+
readonly bodyCall: CallInvocation<Output>;
|
|
16
|
+
readonly cacheKeys: Set<CallCacheKey>;
|
|
17
|
+
readonly context: CallExecutionContext;
|
|
18
|
+
readonly done: Promise<void>;
|
|
19
|
+
readonly execute: (context: CallExecutionContext) => Awaitable<Output>;
|
|
20
|
+
readonly executionGroup: CallExecutionGroup<Input, Output>;
|
|
21
|
+
readonly flightKey: CallKey | undefined;
|
|
22
|
+
readonly identity: number;
|
|
23
|
+
laneRequest: CallLaneRequest | undefined;
|
|
24
|
+
nextWaiting: CallExecution<Input, Output> | undefined;
|
|
25
|
+
readonly physicalCalls: Set<CallInvocationController<Output>>;
|
|
26
|
+
previousWaiting: CallExecution<Input, Output> | undefined;
|
|
27
|
+
releaseLane: (() => void) | undefined;
|
|
28
|
+
resolveDone: () => void;
|
|
29
|
+
started: boolean;
|
|
30
|
+
stopped: boolean;
|
|
31
|
+
readonly waiters: Set<CallWaiter<Output>>;
|
|
32
|
+
};
|
|
33
|
+
type CallExecutionGroup<Input, Output> = {
|
|
34
|
+
readonly cache: Map<CallCacheKey, Output>;
|
|
35
|
+
readonly executions: Set<CallExecution<Input, Output>>;
|
|
36
|
+
readonly flights: Map<CallKey, CallExecution<Input, Output>>;
|
|
37
|
+
lastWaiting: CallExecution<Input, Output> | undefined;
|
|
38
|
+
readonly observation: CallObservationSlot | undefined;
|
|
39
|
+
retired: boolean;
|
|
40
|
+
retirement: Promise<void> | undefined;
|
|
41
|
+
};
|
|
42
|
+
type CallExecutorState<Input, Output> = {
|
|
43
|
+
closed: boolean;
|
|
44
|
+
closePromise: Promise<void> | undefined;
|
|
45
|
+
readonly defaultExecutionGroup: CallExecutionGroup<Input, Output>;
|
|
46
|
+
readonly executionGroups: Set<CallExecutionGroup<Input, Output>>;
|
|
47
|
+
readonly generations: WeakMap<object, CallExecutionGroup<Input, Output>>;
|
|
48
|
+
nextOrdinal: number;
|
|
49
|
+
readonly options: CallExecutorSnapshotOptions<Input>;
|
|
50
|
+
readonly retiredGenerations: WeakSet<object>;
|
|
51
|
+
readonly retirements: WeakMap<object, Promise<void>>;
|
|
52
|
+
};
|
|
53
|
+
declare function createCallExecutionGroup<Input, Output>(observation?: CallObservationSlot): CallExecutionGroup<Input, Output>;
|
|
54
|
+
/** The per-group waiting list restores an older candidate when a newer lane place is cancelled. */
|
|
55
|
+
declare function trackWaitingExecution<Input, Output>(execution: CallExecution<Input, Output>): void;
|
|
56
|
+
declare function forgetWaitingExecution<Input, Output>(execution: CallExecution<Input, Output>): void;
|
|
57
|
+
declare function prepareExecutionStart<Input, Output>(execution: CallExecution<Input, Output>, releaseLane: (() => void) | undefined): readonly CallWaiter<Output>[] | undefined;
|
|
58
|
+
declare function parentMetadata(options: CallStartOptions | undefined): CallExecutionMetadata | undefined;
|
|
59
|
+
declare function createController<Input, Output>(state: CallExecutorState<Input, Output>, metadata: CallExecutionMetadata | undefined, onCancel: (reason: unknown) => void): CallInvocationController<Output>;
|
|
60
|
+
declare function rejectedCall<Input, Output>(state: CallExecutorState<Input, Output>, metadata: CallExecutionMetadata | undefined, error: unknown): CallInvocation<Output>;
|
|
61
|
+
declare function cancelledCall<Input, Output>(state: CallExecutorState<Input, Output>, metadata: CallExecutionMetadata | undefined, reason: unknown): CallInvocation<Output>;
|
|
62
|
+
declare function readExecutionGroup<Input, Output>(state: CallExecutorState<Input, Output>, generation: object | undefined): CallExecutionGroup<Input, Output> | undefined;
|
|
63
|
+
declare function computeCacheKey<Input>(options: CallExecutorSnapshotOptions<Input>, input: Input): CallCacheKey | undefined;
|
|
64
|
+
declare function computeFlightKey<Input>(options: CallExecutorSnapshotOptions<Input>, input: Input): CallKey | undefined;
|
|
65
|
+
export { cancelledCall, computeCacheKey, computeFlightKey, createCallExecutionGroup, createController, forgetWaitingExecution, parentMetadata, prepareExecutionStart, readExecutionGroup, rejectedCall, trackWaitingExecution, };
|
|
66
|
+
export type { CallCacheKey, CallExecution, CallExecutionGroup, CallExecutorState, CallWaiter };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readCallExecutionMetadata as f,callKey as o}from"./call-executor-support.js";import{createCallInvocation as s}from"./call-invocation.js";import{isCancellation as u}from"./errors.js";import{lastOf as p}from"./platform-compat.js";const g=Symbol("opetope.call.once");function l(n){return{cache:new Map,executions:new Set,flights:new Map,lastWaiting:void 0,observation:n,retired:!1,retirement:void 0}}function W(n){const e=n.executionGroup,t=e.lastWaiting;n.previousWaiting=t,t!==void 0&&(t.nextWaiting=n),e.lastWaiting=n}function c(n){const e=n.previousWaiting,t=n.nextWaiting;e!==void 0&&(e.nextWaiting=t),t!==void 0&&(t.previousWaiting=e),n.executionGroup.lastWaiting===n&&(n.executionGroup.lastWaiting=e),n.previousWaiting=void 0,n.nextWaiting=void 0}function C(n,e){if(n.started||n.stopped||n.executionGroup.retired){e==null||e();return}c(n),n.laneRequest=void 0,n.releaseLane=e,n.started=!0;const t=[...n.waiters];for(const i of t)n.physicalCalls.add(i.controller);return t}function h(n){return f(n==null?void 0:n.parent)}function r(n,e,t){var d;n.nextOrdinal+=1;const i=e===void 0||(d=p(e.callPath))==null?void 0:d.callId,a={callId:`${n.options.id}#${String(n.nextOrdinal)}`,onCancel:t};return s(i===void 0?a:{...a,parentCallId:i})}function m(n,e){u(e)?n.cancelled(e):n.rejected(e),n.stopped(u(e)?{reason:"cancelled-before-start",status:"not-started"}:{reason:"settled",status:"stopped"})}function G(n,e,t){const i=r(n,e,()=>{});return m(i,t),i.call}function v(n,e,t){const i=r(n,e,()=>{});return i.cancelled(t),i.stopped({reason:"cancelled-before-start",status:"not-started"}),i.call}function y(n,e){if(e===void 0)return n.defaultExecutionGroup;if(n.retiredGenerations.has(e))return;const t=n.generations.get(e);if(t!==void 0)return t;const i=l(n.defaultExecutionGroup.observation);return n.generations.set(e,i),n.executionGroups.add(i),i}function E(n,e){const t=n.once;if(t!==void 0)return t===!0?g:o(t(e),"Call once cache key")}function x(n,e){const t=n.singleFlight;return t===void 0?void 0:o(t(e),"Call singleFlight key")}export{v as cancelledCall,E as computeCacheKey,x as computeFlightKey,l as createCallExecutionGroup,r as createController,c as forgetWaitingExecution,h as parentMetadata,C as prepareExecutionStart,y as readExecutionGroup,G as rejectedCall,W as trackWaitingExecution};
|
|
2
|
+
//# sourceMappingURL=call-executor-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-executor-record.js","sources":["../src/call-executor-record.ts"],"sourcesContent":["import type { CallObservationSlot } from './call-execution-inspection';\nimport { callKey, readCallExecutionMetadata } from './call-executor-support';\nimport type {\n Awaitable,\n CallExecutionContext,\n CallExecutionMetadata,\n CallExecutorSnapshotOptions,\n CallKey,\n CallStartOptions,\n} from './call-executor-types';\nimport type { CallInvocation, CallInvocationController } from './call-invocation';\nimport { createCallInvocation } from './call-invocation';\nimport type { CallLaneRequest } from './call-lane';\nimport { isCancellation } from './errors';\nimport { lastOf } from './platform-compat';\n\nconst onceKey = Symbol('opetope.call.once');\n\ntype CallCacheKey = typeof onceKey | CallKey;\n\ntype CallWaiter<Output> = {\n readonly abortReleases: (() => void)[];\n active: boolean;\n readonly cacheKey: CallCacheKey | undefined;\n readonly controller: CallInvocationController<Output>;\n};\n\ntype CallExecution<Input, Output> = {\n readonly abort: AbortController;\n readonly bodyCall: CallInvocation<Output>;\n readonly cacheKeys: Set<CallCacheKey>;\n readonly context: CallExecutionContext;\n readonly done: Promise<void>;\n readonly execute: (context: CallExecutionContext) => Awaitable<Output>;\n readonly executionGroup: CallExecutionGroup<Input, Output>;\n readonly flightKey: CallKey | undefined;\n readonly identity: number;\n laneRequest: CallLaneRequest | undefined;\n nextWaiting: CallExecution<Input, Output> | undefined;\n readonly physicalCalls: Set<CallInvocationController<Output>>;\n previousWaiting: CallExecution<Input, Output> | undefined;\n releaseLane: (() => void) | undefined;\n resolveDone: () => void;\n started: boolean;\n stopped: boolean;\n readonly waiters: Set<CallWaiter<Output>>;\n};\n\ntype CallExecutionGroup<Input, Output> = {\n readonly cache: Map<CallCacheKey, Output>;\n readonly executions: Set<CallExecution<Input, Output>>;\n readonly flights: Map<CallKey, CallExecution<Input, Output>>;\n lastWaiting: CallExecution<Input, Output> | undefined;\n readonly observation: CallObservationSlot | undefined;\n retired: boolean;\n retirement: Promise<void> | undefined;\n};\n\ntype CallExecutorState<Input, Output> = {\n closed: boolean;\n closePromise: Promise<void> | undefined;\n readonly defaultExecutionGroup: CallExecutionGroup<Input, Output>;\n readonly executionGroups: Set<CallExecutionGroup<Input, Output>>;\n readonly generations: WeakMap<object, CallExecutionGroup<Input, Output>>;\n nextOrdinal: number;\n readonly options: CallExecutorSnapshotOptions<Input>;\n readonly retiredGenerations: WeakSet<object>;\n readonly retirements: WeakMap<object, Promise<void>>;\n};\n\nfunction createCallExecutionGroup<Input, Output>(observation?: CallObservationSlot): CallExecutionGroup<Input, Output> {\n return {\n cache: new Map(),\n executions: new Set(),\n flights: new Map(),\n lastWaiting: undefined,\n observation,\n retired: false,\n retirement: undefined,\n };\n}\n\n/** The per-group waiting list restores an older candidate when a newer lane place is cancelled. */\nfunction trackWaitingExecution<Input, Output>(execution: CallExecution<Input, Output>): void {\n const group = execution.executionGroup;\n const previous = group.lastWaiting;\n execution.previousWaiting = previous;\n\n if (previous !== undefined) previous.nextWaiting = execution;\n\n group.lastWaiting = execution;\n}\n\nfunction forgetWaitingExecution<Input, Output>(execution: CallExecution<Input, Output>): void {\n const previous = execution.previousWaiting;\n const next = execution.nextWaiting;\n\n if (previous !== undefined) previous.nextWaiting = next;\n\n if (next !== undefined) next.previousWaiting = previous;\n\n if (execution.executionGroup.lastWaiting === execution) execution.executionGroup.lastWaiting = previous;\n\n execution.previousWaiting = undefined;\n execution.nextWaiting = undefined;\n}\n\nfunction prepareExecutionStart<Input, Output>(\n execution: CallExecution<Input, Output>,\n releaseLane: (() => void) | undefined,\n): readonly CallWaiter<Output>[] | undefined {\n if (execution.started || execution.stopped || execution.executionGroup.retired) {\n releaseLane?.();\n\n return undefined;\n }\n\n forgetWaitingExecution(execution);\n execution.laneRequest = undefined;\n execution.releaseLane = releaseLane;\n execution.started = true;\n const starters = [...execution.waiters];\n\n for (const waiter of starters) execution.physicalCalls.add(waiter.controller);\n\n return starters;\n}\n\nfunction parentMetadata(options: CallStartOptions | undefined): CallExecutionMetadata | undefined {\n return readCallExecutionMetadata(options?.parent);\n}\n\nfunction createController<Input, Output>(\n state: CallExecutorState<Input, Output>,\n metadata: CallExecutionMetadata | undefined,\n onCancel: (reason: unknown) => void,\n): CallInvocationController<Output> {\n state.nextOrdinal += 1;\n const parentCallId = metadata === undefined ? undefined : lastOf(metadata.callPath)?.callId;\n const base = { callId: `${state.options.id}#${String(state.nextOrdinal)}`, onCancel };\n\n return createCallInvocation(parentCallId === undefined ? base : { ...base, parentCallId });\n}\n\nfunction rejectBeforeStart<Output>(controller: CallInvocationController<Output>, error: unknown): void {\n if (isCancellation(error)) controller.cancelled(error);\n else controller.rejected(error);\n\n controller.stopped(\n isCancellation(error)\n ? { reason: 'cancelled-before-start', status: 'not-started' }\n : { reason: 'settled', status: 'stopped' },\n );\n}\n\nfunction rejectedCall<Input, Output>(\n state: CallExecutorState<Input, Output>,\n metadata: CallExecutionMetadata | undefined,\n error: unknown,\n): CallInvocation<Output> {\n const controller = createController<Input, Output>(state, metadata, () => undefined);\n rejectBeforeStart(controller, error);\n\n return controller.call;\n}\n\nfunction cancelledCall<Input, Output>(\n state: CallExecutorState<Input, Output>,\n metadata: CallExecutionMetadata | undefined,\n reason: unknown,\n): CallInvocation<Output> {\n const controller = createController<Input, Output>(state, metadata, () => undefined);\n controller.cancelled(reason);\n controller.stopped({ reason: 'cancelled-before-start', status: 'not-started' });\n\n return controller.call;\n}\n\nfunction readExecutionGroup<Input, Output>(\n state: CallExecutorState<Input, Output>,\n generation: object | undefined,\n): CallExecutionGroup<Input, Output> | undefined {\n if (generation === undefined) return state.defaultExecutionGroup;\n\n if (state.retiredGenerations.has(generation)) return undefined;\n\n const existing = state.generations.get(generation);\n\n if (existing !== undefined) return existing;\n\n const created = createCallExecutionGroup<Input, Output>(state.defaultExecutionGroup.observation);\n state.generations.set(generation, created);\n state.executionGroups.add(created);\n\n return created;\n}\n\nfunction computeCacheKey<Input>(options: CallExecutorSnapshotOptions<Input>, input: Input): CallCacheKey | undefined {\n const once = options.once;\n\n if (once === undefined) return undefined;\n\n return once === true ? onceKey : callKey(once(input), 'Call once cache key');\n}\n\nfunction computeFlightKey<Input>(options: CallExecutorSnapshotOptions<Input>, input: Input): CallKey | undefined {\n const singleFlight = options.singleFlight;\n\n return singleFlight === undefined ? undefined : callKey(singleFlight(input), 'Call singleFlight key');\n}\n\nexport {\n cancelledCall,\n computeCacheKey,\n computeFlightKey,\n createCallExecutionGroup,\n createController,\n forgetWaitingExecution,\n parentMetadata,\n prepareExecutionStart,\n readExecutionGroup,\n rejectedCall,\n trackWaitingExecution,\n};\nexport type { CallCacheKey, CallExecution, CallExecutionGroup, CallExecutorState, CallWaiter };\n"],"names":["onceKey","createCallExecutionGroup","observation","trackWaitingExecution","execution","group","previous","forgetWaitingExecution","next","prepareExecutionStart","releaseLane","starters","waiter","parentMetadata","options","readCallExecutionMetadata","createController","state","metadata","onCancel","parentCallId","_a","lastOf","base","createCallInvocation","rejectBeforeStart","controller","error","isCancellation","rejectedCall","cancelledCall","reason","readExecutionGroup","generation","existing","created","computeCacheKey","input","once","callKey","computeFlightKey","singleFlight"],"mappings":"2OAgBA,MAAMA,EAAU,OAAO,mBAAmB,EAsD1C,SAASC,EAAwCC,EAAiC,CAChF,MAAO,CACL,MAAO,IAAI,IACX,WAAY,IAAI,IAChB,QAAS,IAAI,IACb,YAAa,OACb,YAAAA,EACA,QAAS,GACT,WAAY,OAEhB,CAGA,SAASC,EAAqCC,EAAuC,CACnF,MAAMC,EAAQD,EAAU,eAClBE,EAAWD,EAAM,YACvBD,EAAU,gBAAkBE,EAExBA,IAAa,SAAWA,EAAS,YAAcF,GAEnDC,EAAM,YAAcD,CACtB,CAEA,SAASG,EAAsCH,EAAuC,CACpF,MAAME,EAAWF,EAAU,gBACrBI,EAAOJ,EAAU,YAEnBE,IAAa,SAAWA,EAAS,YAAcE,GAE/CA,IAAS,SAAWA,EAAK,gBAAkBF,GAE3CF,EAAU,eAAe,cAAgBA,IAAWA,EAAU,eAAe,YAAcE,GAE/FF,EAAU,gBAAkB,OAC5BA,EAAU,YAAc,MAC1B,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,EAAW,UAAUK,CAAM,EAC3BL,EAAW,QAAQ,CAAE,OAAQ,yBAA0B,OAAQ,cAAe,EAEvEA,EAAW,IACpB,CAEA,SAASM,EACPf,EACAgB,EAA8B,CAE9B,GAAIA,IAAe,OAAW,OAAOhB,EAAM,sBAE3C,GAAIA,EAAM,mBAAmB,IAAIgB,CAAU,EAAG,OAE9C,MAAMC,EAAWjB,EAAM,YAAY,IAAIgB,CAAU,EAEjD,GAAIC,IAAa,OAAW,OAAOA,EAEnC,MAAMC,EAAUlC,EAAwCgB,EAAM,sBAAsB,WAAW,EAC/F,OAAAA,EAAM,YAAY,IAAIgB,EAAYE,CAAO,EACzClB,EAAM,gBAAgB,IAAIkB,CAAO,EAE1BA,CACT,CAEA,SAASC,EAAuBtB,EAA6CuB,EAAY,CACvF,MAAMC,EAAOxB,EAAQ,KAErB,GAAIwB,IAAS,OAEb,OAAOA,IAAS,GAAOtC,EAAUuC,EAAQD,EAAKD,CAAK,EAAG,qBAAqB,CAC7E,CAEA,SAASG,EAAwB1B,EAA6CuB,EAAY,CACxF,MAAMI,EAAe3B,EAAQ,aAE7B,OAAO2B,IAAiB,OAAY,OAAYF,EAAQE,EAAaJ,CAAK,EAAG,uBAAuB,CACtG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CallExecutionMetadata, CallExecutorOptions, CallExecutorSnapshotOptions, CallKey } from './call-executor-types.js';
|
|
2
|
+
import type { CallInvocation } from './call-invocation.js';
|
|
3
|
+
import type { CallContext } from './call-target.js';
|
|
4
|
+
import { CancellationError } from './errors.js';
|
|
5
|
+
declare class CallExecutorClosedError extends CancellationError {
|
|
6
|
+
readonly name = "CallExecutorClosedError";
|
|
7
|
+
}
|
|
8
|
+
declare class CallContextInactiveError extends CancellationError {
|
|
9
|
+
readonly name = "CallContextInactiveError";
|
|
10
|
+
}
|
|
11
|
+
declare class CallLaneCycleError extends Error {
|
|
12
|
+
readonly name = "CallLaneCycleError";
|
|
13
|
+
}
|
|
14
|
+
declare class CallSingleFlightCycleError extends Error {
|
|
15
|
+
readonly name = "CallSingleFlightCycleError";
|
|
16
|
+
}
|
|
17
|
+
declare const callContextSettledReason: CallContextInactiveError;
|
|
18
|
+
declare function snapshotCallExecutorOptions<Input>(value: CallExecutorOptions<Input>): CallExecutorSnapshotOptions<Input>;
|
|
19
|
+
declare function callKey(value: unknown, label: string): CallKey;
|
|
20
|
+
declare function readCallExecutionMetadata(context: CallContext | undefined): CallExecutionMetadata | undefined;
|
|
21
|
+
declare function bindCallExecutionMetadata(context: CallContext, metadata: CallExecutionMetadata): void;
|
|
22
|
+
declare function inheritCallExecutionMetadata(source: CallContext, target: CallContext): void;
|
|
23
|
+
declare function releaseCallExecutionMetadata(context: CallContext): void;
|
|
24
|
+
declare function hasCallInPath(metadata: CallExecutionMetadata | undefined, call: CallInvocation<unknown>): boolean;
|
|
25
|
+
export { bindCallExecutionMetadata, callContextSettledReason, CallExecutorClosedError, callKey, CallLaneCycleError, CallSingleFlightCycleError, hasCallInPath, inheritCallExecutionMetadata, readCallExecutionMetadata, releaseCallExecutionMetadata, snapshotCallExecutorOptions, };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{defineCallLane as g,isCallLane as h}from"./call-lane.js";import{CancellationError as a}from"./errors.js";import{declarationId as C}from"./identity.js";import{hasOwn as y}from"./platform-compat.js";class w extends a{name="CallExecutorClosedError"}class E extends a{name="CallContextInactiveError"}class b extends Error{name="CallLaneCycleError"}class m extends Error{name="CallSingleFlightCycleError"}const l=new WeakMap,o=new WeakMap,i=new WeakMap,x=new E("Call execution context has settled."),S=new Set(["id","once","scheduling","singleFlight"]),O=new Set(["lane","policy"]);function c(e,n="queue"){return Object.freeze({lane:g({id:`${e}.lane`}),policy:n})}function T(e){if(e!==void 0)throw new TypeError("Parallel call scheduling cannot declare a lane.");return Object.freeze({policy:"parallel"})}function j(e,n,r){if(e===void 0)return c(n,r);if(!h(e))throw new TypeError("Call scheduling lane must be authentic.");return Object.freeze({lane:e,policy:r})}function s(e,n){if(typeof e!="object"||e===null)throw new TypeError(`${n} must be a plain object record.`);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`${n} must be a plain object record.`)}function u(e,n,r){for(const t of Reflect.ownKeys(e))if(!n.has(t))throw new TypeError(`${r} contains unknown field ${String(t)}.`)}function M(e,n){if(e===void 0)return c(n);s(e,"Call scheduling"),u(e,O,"Call scheduling");const r=e.policy??"queue",t=e.lane;if(r==="parallel")return T(t);if(r!=="queue"&&r!=="latest")throw new TypeError("Call scheduling policy must be queue, latest or parallel.");return j(t,n,r)}function d(e,n){if(typeof e!="function")throw new TypeError(`${n} must be a key function.`);return e}function F(e){return e===void 0||e===!0?e:d(e,"Call once")}function $(e){if(s(e,"Call executor options"),u(e,S,"Call executor options"),!y(e,"id"))throw new TypeError("Call executor options require own id.");const n=String(C(e.id));return Object.freeze({id:n,once:F(e.once),scheduling:M(e.scheduling,n),singleFlight:e.singleFlight===void 0?void 0:d(e.singleFlight,"Call singleFlight")})}function k(e,n){if(typeof e!="number"&&typeof e!="string")throw new TypeError(`${n} must return a string or number.`);return e}function f(e){return e===void 0?void 0:l.get(e)??o.get(e.signal)}function p(e,n){if(l.has(e))throw new TypeError("Call execution context is already bound.");l.set(e,n),o.has(e.signal)||(o.set(e.signal,n),i.set(e.signal,e))}function q(e,n){const r=f(e);r!==void 0&&p(n,r)}function K(e){l.delete(e),i.get(e.signal)===e&&(o.delete(e.signal),i.delete(e.signal))}function P(e,n){return(e==null?void 0:e.callPath.includes(n))===!0}export{w as CallExecutorClosedError,b as CallLaneCycleError,m as CallSingleFlightCycleError,p as bindCallExecutionMetadata,x as callContextSettledReason,k as callKey,P as hasCallInPath,q as inheritCallExecutionMetadata,f as readCallExecutionMetadata,K as releaseCallExecutionMetadata,$ as snapshotCallExecutorOptions};
|
|
2
|
+
//# sourceMappingURL=call-executor-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-executor-support.js","sources":["../src/call-executor-support.ts"],"sourcesContent":["import type {\n CallExecutionMetadata,\n CallExecutorOptions,\n CallExecutorScheduling,\n CallExecutorSnapshotOptions,\n CallKey,\n CallKeySelector,\n} from './call-executor-types';\nimport type { CallInvocation } from './call-invocation';\nimport { defineCallLane, isCallLane } from './call-lane';\nimport type { CallContext } from './call-target';\nimport { CancellationError } from './errors';\nimport { declarationId } from './identity';\nimport { hasOwn } from './platform-compat';\n\nclass CallExecutorClosedError extends CancellationError {\n override readonly name = 'CallExecutorClosedError';\n}\n\nclass CallContextInactiveError extends CancellationError {\n override readonly name = 'CallContextInactiveError';\n}\n\nclass CallLaneCycleError extends Error {\n override readonly name = 'CallLaneCycleError';\n}\n\nclass CallSingleFlightCycleError extends Error {\n override readonly name = 'CallSingleFlightCycleError';\n}\n\nconst callExecutionMetadata = new WeakMap<object, CallExecutionMetadata>();\nconst callSignalMetadata = new WeakMap<object, CallExecutionMetadata>();\nconst callSignalOwners = new WeakMap<object, CallContext>();\nconst callContextSettledReason = new CallContextInactiveError('Call execution context has settled.');\nconst executorOptionKeys = new Set<PropertyKey>(['id', 'once', 'scheduling', 'singleFlight']);\nconst schedulingKeys = new Set<PropertyKey>(['lane', 'policy']);\n\nfunction privateQueue(id: string, policy: 'latest' | 'queue' = 'queue'): CallExecutorScheduling {\n return Object.freeze({ lane: defineCallLane({ id: `${id}.lane` }), policy });\n}\n\nfunction parallelScheduling(lane: unknown): CallExecutorScheduling {\n if (lane !== undefined) throw new TypeError('Parallel call scheduling cannot declare a lane.');\n\n return Object.freeze({ policy: 'parallel' as const });\n}\n\nfunction queueScheduling(lane: unknown, id: string, policy: 'latest' | 'queue'): CallExecutorScheduling {\n if (lane === undefined) return privateQueue(id, policy);\n\n if (!isCallLane(lane)) throw new TypeError('Call scheduling lane must be authentic.');\n\n return Object.freeze({ lane, policy });\n}\n\nfunction assertPlainRecord(value: unknown, label: string): asserts value is Readonly<Record<PropertyKey, unknown>> {\n if (typeof value !== 'object' || value === null) throw new TypeError(`${label} must be a plain object record.`);\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n if (prototype !== Object.prototype && prototype !== null) {\n throw new TypeError(`${label} must be a plain object record.`);\n }\n}\n\nfunction assertExactKeys(\n value: Readonly<Record<PropertyKey, unknown>>,\n allowed: ReadonlySet<PropertyKey>,\n label: string,\n): void {\n for (const key of Reflect.ownKeys(value)) {\n if (!allowed.has(key)) throw new TypeError(`${label} contains unknown field ${String(key)}.`);\n }\n}\n\nfunction snapshotScheduling(value: unknown, id: string): CallExecutorScheduling {\n if (value === undefined) return privateQueue(id);\n\n assertPlainRecord(value, 'Call scheduling');\n assertExactKeys(value, schedulingKeys, 'Call scheduling');\n const policy = value['policy'] ?? 'queue';\n const lane = value['lane'];\n\n if (policy === 'parallel') return parallelScheduling(lane);\n\n if (policy !== 'queue' && policy !== 'latest') {\n throw new TypeError('Call scheduling policy must be queue, latest or parallel.');\n }\n\n return queueScheduling(lane, id, policy);\n}\n\nfunction snapshotKeySelector<Input>(value: unknown, label: string): CallKeySelector<Input> {\n if (typeof value !== 'function') throw new TypeError(`${label} must be a key function.`);\n\n return value as CallKeySelector<Input>;\n}\n\nfunction snapshotOnce<Input>(value: unknown): CallKeySelector<Input> | true | undefined {\n if (value === undefined || value === true) return value;\n\n return snapshotKeySelector<Input>(value, 'Call once');\n}\n\nfunction snapshotCallExecutorOptions<Input>(value: CallExecutorOptions<Input>): CallExecutorSnapshotOptions<Input> {\n assertPlainRecord(value, 'Call executor options');\n assertExactKeys(value, executorOptionKeys, 'Call executor options');\n\n if (!hasOwn(value, 'id')) throw new TypeError('Call executor options require own id.');\n\n const id = String(declarationId(value.id));\n\n return Object.freeze({\n id,\n once: snapshotOnce<Input>(value.once),\n scheduling: snapshotScheduling(value.scheduling, id),\n singleFlight:\n value.singleFlight === undefined\n ? undefined\n : snapshotKeySelector<Input>(value.singleFlight, 'Call singleFlight'),\n });\n}\n\nfunction callKey(value: unknown, label: string): CallKey {\n if (typeof value !== 'number' && typeof value !== 'string') {\n throw new TypeError(`${label} must return a string or number.`);\n }\n\n return value;\n}\n\nfunction readCallExecutionMetadata(context: CallContext | undefined): CallExecutionMetadata | undefined {\n return context === undefined\n ? undefined\n : (callExecutionMetadata.get(context) ?? callSignalMetadata.get(context.signal));\n}\n\nfunction bindCallExecutionMetadata(context: CallContext, metadata: CallExecutionMetadata): void {\n if (callExecutionMetadata.has(context)) throw new TypeError('Call execution context is already bound.');\n\n callExecutionMetadata.set(context, metadata);\n\n if (!callSignalMetadata.has(context.signal)) {\n callSignalMetadata.set(context.signal, metadata);\n callSignalOwners.set(context.signal, context);\n }\n}\n\nfunction inheritCallExecutionMetadata(source: CallContext, target: CallContext): void {\n const metadata = readCallExecutionMetadata(source);\n\n if (metadata !== undefined) bindCallExecutionMetadata(target, metadata);\n}\n\nfunction releaseCallExecutionMetadata(context: CallContext): void {\n callExecutionMetadata.delete(context);\n\n if (callSignalOwners.get(context.signal) === context) {\n callSignalMetadata.delete(context.signal);\n callSignalOwners.delete(context.signal);\n }\n}\n\nfunction hasCallInPath(metadata: CallExecutionMetadata | undefined, call: CallInvocation<unknown>): boolean {\n return metadata?.callPath.includes(call) === true;\n}\n\nexport {\n bindCallExecutionMetadata,\n callContextSettledReason,\n CallExecutorClosedError,\n callKey,\n CallLaneCycleError,\n CallSingleFlightCycleError,\n hasCallInPath,\n inheritCallExecutionMetadata,\n readCallExecutionMetadata,\n releaseCallExecutionMetadata,\n snapshotCallExecutorOptions,\n};\n"],"names":["CallExecutorClosedError","CancellationError","CallContextInactiveError","CallLaneCycleError","CallSingleFlightCycleError","callExecutionMetadata","callSignalMetadata","callSignalOwners","callContextSettledReason","executorOptionKeys","schedulingKeys","privateQueue","id","policy","defineCallLane","parallelScheduling","lane","queueScheduling","isCallLane","assertPlainRecord","value","label","prototype","assertExactKeys","allowed","key","snapshotScheduling","snapshotKeySelector","snapshotOnce","snapshotCallExecutorOptions","hasOwn","declarationId","callKey","readCallExecutionMetadata","context","bindCallExecutionMetadata","metadata","inheritCallExecutionMetadata","source","target","releaseCallExecutionMetadata","hasCallInPath","call"],"mappings":"4MAeA,MAAMA,UAAgCC,CAAiB,CACnC,KAAO,yBAC1B,CAED,MAAMC,UAAiCD,CAAiB,CACpC,KAAO,0BAC1B,CAED,MAAME,UAA2B,KAAK,CAClB,KAAO,oBAC1B,CAED,MAAMC,UAAmC,KAAK,CAC1B,KAAO,4BAC1B,CAED,MAAMC,EAAwB,IAAI,QAC5BC,EAAqB,IAAI,QACzBC,EAAmB,IAAI,QACvBC,EAA2B,IAAIN,EAAyB,qCAAqC,EAC7FO,EAAqB,IAAI,IAAiB,CAAC,KAAM,OAAQ,aAAc,cAAc,CAAC,EACtFC,EAAiB,IAAI,IAAiB,CAAC,OAAQ,QAAQ,CAAC,EAE9D,SAASC,EAAaC,EAAYC,EAA6B,QAAO,CACpE,OAAO,OAAO,OAAO,CAAE,KAAMC,EAAe,CAAE,GAAI,GAAGF,CAAE,QAAS,EAAG,OAAAC,CAAM,CAAE,CAC7E,CAEA,SAASE,EAAmBC,EAAa,CACvC,GAAIA,IAAS,OAAW,MAAM,IAAI,UAAU,iDAAiD,EAE7F,OAAO,OAAO,OAAO,CAAE,OAAQ,UAAmB,CAAE,CACtD,CAEA,SAASC,EAAgBD,EAAeJ,EAAYC,EAA0B,CAC5E,GAAIG,IAAS,OAAW,OAAOL,EAAaC,EAAIC,CAAM,EAEtD,GAAI,CAACK,EAAWF,CAAI,EAAG,MAAM,IAAI,UAAU,yCAAyC,EAEpF,OAAO,OAAO,OAAO,CAAE,KAAAA,EAAM,OAAAH,CAAM,CAAE,CACvC,CAEA,SAASM,EAAkBC,EAAgBC,EAAa,CACtD,GAAI,OAAOD,GAAU,UAAYA,IAAU,KAAM,MAAM,IAAI,UAAU,GAAGC,CAAK,iCAAiC,EAE9G,MAAMC,EAAqB,OAAO,eAAeF,CAAK,EAEtD,GAAIE,IAAc,OAAO,WAAaA,IAAc,KAClD,MAAM,IAAI,UAAU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