little-durable-objects 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.
Files changed (71) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +49 -0
  3. package/dist/host/actorModule.d.ts +4 -0
  4. package/dist/host/actorModule.d.ts.map +1 -0
  5. package/dist/host/actorModule.js +54 -0
  6. package/dist/host/actorModule.js.map +1 -0
  7. package/dist/host/session.d.ts +20 -0
  8. package/dist/host/session.d.ts.map +1 -0
  9. package/dist/host/session.js +220 -0
  10. package/dist/host/session.js.map +1 -0
  11. package/dist/host/worker/entrypoint.d.ts +2 -0
  12. package/dist/host/worker/entrypoint.d.ts.map +1 -0
  13. package/dist/host/worker/entrypoint.js +26 -0
  14. package/dist/host/worker/entrypoint.js.map +1 -0
  15. package/dist/host/worker/runtime.d.ts +14 -0
  16. package/dist/host/worker/runtime.d.ts.map +1 -0
  17. package/dist/host/worker/runtime.js +77 -0
  18. package/dist/host/worker/runtime.js.map +1 -0
  19. package/dist/host/worker/supervisor.d.ts +21 -0
  20. package/dist/host/worker/supervisor.d.ts.map +1 -0
  21. package/dist/host/worker/supervisor.js +190 -0
  22. package/dist/host/worker/supervisor.js.map +1 -0
  23. package/dist/host.d.ts +2 -0
  24. package/dist/host.d.ts.map +1 -0
  25. package/dist/host.js +2 -0
  26. package/dist/host.js.map +1 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/providers/modal.d.ts +29 -0
  32. package/dist/providers/modal.d.ts.map +1 -0
  33. package/dist/providers/modal.js +193 -0
  34. package/dist/providers/modal.js.map +1 -0
  35. package/dist/providers/modalCli.d.ts +3 -0
  36. package/dist/providers/modalCli.d.ts.map +1 -0
  37. package/dist/providers/modalCli.js +18 -0
  38. package/dist/providers/modalCli.js.map +1 -0
  39. package/dist/providers/types.d.ts +31 -0
  40. package/dist/providers/types.d.ts.map +1 -0
  41. package/dist/providers/types.js +2 -0
  42. package/dist/providers/types.js.map +1 -0
  43. package/dist/regions.d.ts +59 -0
  44. package/dist/regions.d.ts.map +1 -0
  45. package/dist/regions.js +46 -0
  46. package/dist/regions.js.map +1 -0
  47. package/dist/shared/actor.d.ts +28 -0
  48. package/dist/shared/actor.d.ts.map +1 -0
  49. package/dist/shared/actor.js +105 -0
  50. package/dist/shared/actor.js.map +1 -0
  51. package/dist/shared/errors.d.ts +25 -0
  52. package/dist/shared/errors.d.ts.map +1 -0
  53. package/dist/shared/errors.js +48 -0
  54. package/dist/shared/errors.js.map +1 -0
  55. package/dist/shared/invocationContext.d.ts +4 -0
  56. package/dist/shared/invocationContext.d.ts.map +1 -0
  57. package/dist/shared/invocationContext.js +10 -0
  58. package/dist/shared/invocationContext.js.map +1 -0
  59. package/dist/shared/types.d.ts +123 -0
  60. package/dist/shared/types.d.ts.map +1 -0
  61. package/dist/shared/types.js +111 -0
  62. package/dist/shared/types.js.map +1 -0
  63. package/dist/workflow/client.d.ts +23 -0
  64. package/dist/workflow/client.d.ts.map +1 -0
  65. package/dist/workflow/client.js +49 -0
  66. package/dist/workflow/client.js.map +1 -0
  67. package/dist/workflow/remoteClient.d.ts +26 -0
  68. package/dist/workflow/remoteClient.d.ts.map +1 -0
  69. package/dist/workflow/remoteClient.js +136 -0
  70. package/dist/workflow/remoteClient.js.map +1 -0
  71. package/package.json +82 -0
@@ -0,0 +1,46 @@
1
+ const canonicalRegionPattern = /^[a-z0-9](?:[a-z0-9._-]{0,62}[a-z0-9])?$/u;
2
+ const recommendedRegionCatalog = {
3
+ "north-america-east": {
4
+ modal: { regions: ["us-east"], cloud: "gcp", observedPlacements: ["gcp:us-east*"] }
5
+ },
6
+ "north-america-central": {
7
+ modal: { regions: ["us-central"], cloud: "gcp", observedPlacements: ["gcp:us-central*"] }
8
+ },
9
+ "north-america-south": {
10
+ modal: { regions: ["us-south"], cloud: "gcp", observedPlacements: ["gcp:us-south*"] }
11
+ },
12
+ "north-america-west": {
13
+ modal: { regions: ["us-west"], cloud: "gcp", observedPlacements: ["gcp:us-west*"] }
14
+ },
15
+ "europe-west": {
16
+ modal: { regions: ["eu-west"], cloud: "gcp", observedPlacements: ["gcp:europe-west*"] }
17
+ },
18
+ "asia-southeast": {
19
+ modal: { regions: ["ap-southeast"], cloud: "gcp", observedPlacements: ["gcp:asia-southeast*"] }
20
+ }
21
+ };
22
+ function modalPlacement(region, catalog = recommendedRegionCatalog) {
23
+ const placement = catalog[validateCanonicalRegion(region)]?.modal;
24
+ if (!placement)
25
+ throw new Error(`canonical region ${JSON.stringify(region)} has no Modal placement`);
26
+ return placement;
27
+ }
28
+ function canonicalRegionForModal(cloud, region, catalog = recommendedRegionCatalog) {
29
+ if (!region)
30
+ return undefined;
31
+ const normalizedRegion = region.toLowerCase();
32
+ const normalizedCloud = cloud?.toLowerCase().replace(/^cloud_provider_/u, "");
33
+ const candidates = [normalizedCloud ? `${normalizedCloud}:${normalizedRegion}` : undefined, normalizedRegion].filter((candidate) => candidate !== undefined);
34
+ return Object.entries(catalog).find(([, definition]) => definition.modal.observedPlacements.some(pattern => candidates.some(candidate => matchesPlacement(pattern, candidate))))?.[0];
35
+ }
36
+ function validateCanonicalRegion(value) {
37
+ if (!canonicalRegionPattern.test(value))
38
+ throw new Error(`invalid canonical region ${JSON.stringify(value)}`);
39
+ return value;
40
+ }
41
+ function matchesPlacement(pattern, candidate) {
42
+ const normalized = pattern.toLowerCase();
43
+ return normalized.endsWith("*") ? candidate.startsWith(normalized.slice(0, -1)) : candidate === normalized;
44
+ }
45
+ export { canonicalRegionForModal, modalPlacement, recommendedRegionCatalog, validateCanonicalRegion };
46
+ //# sourceMappingURL=regions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.js","sourceRoot":"","sources":["../regions.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,2CAA2C,CAAA;AAc1E,MAAM,wBAAwB,GAAG;IAC7B,oB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C,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,UAAU,CAAA;AAC9G,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,CAAA"}
@@ -0,0 +1,28 @@
1
+ declare abstract class Actor {
2
+ protected constructor();
3
+ static get<TActorClass extends ActorClass>(this: ValidActorClass<TActorClass>, actorId: string): ActorReference<TActorClass["prototype"]>;
4
+ protected get id(): string;
5
+ }
6
+ declare function registerActorClass<Instance extends Actor>(actorClass: ActorClass<Instance>): ActorDefinition;
7
+ declare function findActorDefinition(actorType: string): ActorDefinition | undefined;
8
+ declare function bindActorIdentity(instance: Actor, actorId: string): void;
9
+ interface ActorDefinition {
10
+ readonly actorType: string;
11
+ readonly actorClass: ActorClass;
12
+ readonly methods: ReadonlySet<string>;
13
+ }
14
+ type ActorClass<Instance extends Actor = Actor> = Function & {
15
+ readonly prototype: Instance;
16
+ };
17
+ type AsyncMethod = (...args: never[]) => Promise<unknown>;
18
+ type PubliclyConstructibleActorClass = abstract new (...args: never[]) => Actor;
19
+ type InvalidActorMethod<Instance extends Actor> = {
20
+ [Key in keyof Instance]: Instance[Key] extends (...args: never[]) => unknown ? (Instance[Key] extends AsyncMethod ? never : Key) : never;
21
+ }[keyof Instance];
22
+ type ValidActorClass<TActorClass extends ActorClass> = TActorClass extends PubliclyConstructibleActorClass ? never : InvalidActorMethod<TActorClass["prototype"]> extends never ? TActorClass : never;
23
+ type ActorReference<Instance extends Actor> = {
24
+ [Key in keyof Instance as Instance[Key] extends AsyncMethod ? Key : never]: Instance[Key];
25
+ };
26
+ export { Actor, bindActorIdentity, findActorDefinition, registerActorClass };
27
+ export type { ActorClass, ActorDefinition, ActorReference };
28
+ //# sourceMappingURL=actor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../../shared/actor.ts"],"names":[],"mappings":"AAUA,uBAAe,KAAK;IAChB,SAA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AAG,KAAK;CAC3I,CAAC,MAAM,QAAQ,CAAC,CAAA;AACjB,KAAK,eAAe,CAAC,WAAW,SAAS,UAAU,IAAI,WAAW,SAAS,+BAA+B,GAAG,KAAK,GAAG,kBAAkB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,SAAS,KAAK,GAAG,WAAW,GAAG,KAAK,CAAA;AACrM,KAAK,cAAc,CAAC,QAAQ,SAAS,KAAK,IAAI;KACzC,GAAG,IAAI,MAAM,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,SAAS,WAAW,GAAG,GAAG,GAAG,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC;CAC5F,CAAA;AAED,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAA;AAC5E,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,CAAA"}
@@ -0,0 +1,105 @@
1
+ import { actorClient } from "../workflow/client.js";
2
+ import { ActorDefinitionError } from "./errors.js";
3
+ import { validateActorComponent } from "./types.js";
4
+ const actorMetadata = new WeakMap();
5
+ const actorDefinitions = new Map();
6
+ const asyncFunction = Object.getPrototypeOf(async () => { }).constructor;
7
+ const referenceClasses = new WeakMap();
8
+ class Actor {
9
+ constructor() { }
10
+ static get(actorId) {
11
+ return getActorReference(this, validateActorComponent("actor ID", actorId));
12
+ }
13
+ get id() {
14
+ return metadataFor(this).actorId;
15
+ }
16
+ }
17
+ function registerActorClass(actorClass) {
18
+ const actorType = actorName(actorClass);
19
+ const existing = actorDefinitions.get(actorType);
20
+ if (existing !== undefined) {
21
+ if (existing.actorClass !== actorClass)
22
+ throw new ActorDefinitionError(`duplicate actor type ${actorType}`);
23
+ return existing;
24
+ }
25
+ validateActorClass(actorClass, actorType);
26
+ const definition = {
27
+ actorType: validateActorComponent("actor type", actorType),
28
+ actorClass,
29
+ methods: new Set(discoverMethods(actorClass, actorType))
30
+ };
31
+ actorDefinitions.set(actorType, definition);
32
+ return definition;
33
+ }
34
+ function findActorDefinition(actorType) {
35
+ return actorDefinitions.get(actorType);
36
+ }
37
+ function getActorReference(actorClass, actorId) {
38
+ const definition = registerActorClass(actorClass);
39
+ const Reference = referenceClass(definition);
40
+ return new Reference(actorId);
41
+ }
42
+ function bindActorIdentity(instance, actorId) {
43
+ actorMetadata.set(instance, { actorId: validateActorComponent("actor ID", actorId) });
44
+ }
45
+ function referenceClass(definition) {
46
+ const existing = referenceClasses.get(definition.actorClass);
47
+ if (existing !== undefined)
48
+ return existing;
49
+ class ActorReference extends Actor {
50
+ constructor(actorId) {
51
+ super();
52
+ bindActorIdentity(this, actorId);
53
+ }
54
+ }
55
+ definition.methods.forEach(method => {
56
+ Object.defineProperty(ActorReference.prototype, method, {
57
+ configurable: false,
58
+ enumerable: false,
59
+ writable: false,
60
+ value: function forwardActorMethod(...args) {
61
+ const metadata = metadataFor(this);
62
+ return actorClient().invoke(definition.actorType, metadata.actorId, method, args);
63
+ }
64
+ });
65
+ });
66
+ referenceClasses.set(definition.actorClass, ActorReference);
67
+ return ActorReference;
68
+ }
69
+ function metadataFor(instance) {
70
+ const metadata = actorMetadata.get(instance);
71
+ if (metadata === undefined)
72
+ throw new ActorDefinitionError("actor identity is unavailable outside an actor invocation");
73
+ return metadata;
74
+ }
75
+ function discoverMethods(actorClass, actorType) {
76
+ if (Object.getOwnPropertySymbols(actorClass.prototype).length > 0)
77
+ throw new ActorDefinitionError(`actor class ${actorType} cannot define symbol methods`);
78
+ return Object.entries(Object.getOwnPropertyDescriptors(actorClass.prototype)).flatMap(([name, descriptor]) => {
79
+ if (name === "constructor")
80
+ return [];
81
+ if (descriptor.get !== undefined || descriptor.set !== undefined)
82
+ throw new ActorDefinitionError(`actor class ${actorType} cannot define accessor ${name}`);
83
+ if (typeof descriptor.value !== "function")
84
+ return [];
85
+ validateActorComponent("actor method", name);
86
+ if (name === "then")
87
+ throw new ActorDefinitionError(`actor class ${actorType} cannot define method then`);
88
+ if (!(descriptor.value instanceof asyncFunction))
89
+ throw new ActorDefinitionError(`actor method ${actorType}.${name} must be async`);
90
+ return [name];
91
+ });
92
+ }
93
+ function validateActorClass(actorClass, actorType) {
94
+ if (Object.getPrototypeOf(actorClass.prototype) !== Actor.prototype)
95
+ throw new ActorDefinitionError(`actor class ${actorType} must extend Actor directly`);
96
+ if (actorClass.length !== 0)
97
+ throw new ActorDefinitionError(`actor class ${actorType} cannot require constructor arguments`);
98
+ }
99
+ function actorName(actorClass) {
100
+ if (actorClass.name.length === 0)
101
+ throw new ActorDefinitionError("actor classes must be named");
102
+ return actorClass.name;
103
+ }
104
+ export { Actor, bindActorIdentity, findActorDefinition, registerActorClass };
105
+ //# sourceMappingURL=actor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actor.js","sourceRoot":"","sources":["../../shared/actor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEnD,MAAM,aAAa,GAAG,IAAI,OAAO,EAAyB,CAAA;AAC1D,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA2B,CAAA;AAC3D,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC,WAAW,CAAA;AACvE,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAiC,CAAA;AAErE,MAAe,KAAK;IAChB,gBAAyB,CAAC;IAE1B,MAAM,CAAC,GAAG,CAAqE,OAAe;QAC1F,OAAO,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;IAC/E,CAAC;IAED,IAAc,EAAE;QACZ,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,CAAA;IACpC,CAAC;CACJ;AAED,SAAS,kBAAkB,CAAyB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B,CAAC,6BAA6B,CAAC,CAAA;IAC/F,OAAO,UAAU,CAAC,IAAI,CAAA;AAC1B,CAAC;AA0BD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ declare class ActorConfigurationError extends Error {
2
+ constructor(message: string, options?: ErrorOptions);
3
+ }
4
+ declare class ActorDefinitionError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ declare class ActorInvocationError extends Error {
8
+ readonly code: string;
9
+ readonly requestId: string;
10
+ constructor(code: string, requestId: string, message: string);
11
+ }
12
+ declare class ActorSessionError extends Error {
13
+ constructor(message: string, options?: ErrorOptions);
14
+ }
15
+ declare class ActorProtocolError extends Error {
16
+ constructor(message: string, options?: ErrorOptions);
17
+ }
18
+ declare class ActorSerializationError extends Error {
19
+ constructor(message: string, options?: ErrorOptions);
20
+ }
21
+ declare class ActorValidationError extends Error {
22
+ constructor(message: string);
23
+ }
24
+ export { ActorConfigurationError, ActorDefinitionError, ActorInvocationError, ActorProtocolError, ActorSerializationError, ActorSessionError, ActorValidationError };
25
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../shared/errors.ts"],"names":[],"mappings":"AAAA,cAAM,uBAAwB,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAItD;AAED,cAAM,oBAAqB,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI9B;AAED,cAAM,oBAAqB,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;gBAEd,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAM/D;AAED,cAAM,iBAAkB,SAAQ,KAAK;gBACrB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAItD;AAED,cAAM,kBAAmB,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAItD;AAED,cAAM,uBAAwB,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAItD;AAED,cAAM,oBAAqB,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI9B;AAED,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAA"}
@@ -0,0 +1,48 @@
1
+ class ActorConfigurationError extends Error {
2
+ constructor(message, options) {
3
+ super(message, options);
4
+ this.name = "ActorConfigurationError";
5
+ }
6
+ }
7
+ class ActorDefinitionError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "ActorDefinitionError";
11
+ }
12
+ }
13
+ class ActorInvocationError extends Error {
14
+ code;
15
+ requestId;
16
+ constructor(code, requestId, message) {
17
+ super(message);
18
+ this.name = "ActorInvocationError";
19
+ this.code = code;
20
+ this.requestId = requestId;
21
+ }
22
+ }
23
+ class ActorSessionError extends Error {
24
+ constructor(message, options) {
25
+ super(message, options);
26
+ this.name = "ActorSessionError";
27
+ }
28
+ }
29
+ class ActorProtocolError extends Error {
30
+ constructor(message, options) {
31
+ super(message, options);
32
+ this.name = "ActorProtocolError";
33
+ }
34
+ }
35
+ class ActorSerializationError extends Error {
36
+ constructor(message, options) {
37
+ super(message, options);
38
+ this.name = "ActorSerializationError";
39
+ }
40
+ }
41
+ class ActorValidationError extends Error {
42
+ constructor(message) {
43
+ super(message);
44
+ this.name = "ActorValidationError";
45
+ }
46
+ }
47
+ export { ActorConfigurationError, ActorDefinitionError, ActorInvocationError, ActorProtocolError, ActorSerializationError, ActorSessionError, ActorValidationError };
48
+ //# sourceMappingURL=errors.js.map
@@ -0,0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AAM,oBAAqB,SAAQ,KAAK;IACpC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACtC,CAAC;CACJ;AAED,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ declare function runInActorInvocation<T>(operation: () => T): T;
2
+ declare function currentActorInvocation(): true | undefined;
3
+ export { currentActorInvocation, runInActorInvocation };
4
+ //# sourceMappingURL=invocationContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocationContext.d.ts","sourceRoot":"","sources":["../../shared/invocationContext.ts"],"names":[],"mappings":"AAIA,iBAAS,oBAAoB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,CAEtD;AAED,iBAAS,sBAAsB,IAAI,IAAI,GAAG,SAAS,CAElD;AAED,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const invocationStorage = new AsyncLocalStorage();
3
+ function runInActorInvocation(operation) {
4
+ return invocationStorage.run(true, operation);
5
+ }
6
+ function currentActorInvocation() {
7
+ return invocationStorage.getStore();
8
+ }
9
+ export { currentActorInvocation, runInActorInvocation };
10
+ //# sourceMappingURL=invocationContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocationContext.js","sourceRoot":"","sources":["../../shared/invocationContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAQ,CAAA;AAEvD,SAAS,oBAAoB,CAAI,SAAkB;IAC/C,OAAO,iBAAiB,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,sBAAsB;IAC3B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAA;AACvC,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,CAAA"}
@@ -0,0 +1,123 @@
1
+ import { z } from "zod";
2
+ type JsonPrimitive = string | number | boolean | null;
3
+ type JsonObject = {
4
+ readonly [key: string]: JsonValue;
5
+ };
6
+ type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
7
+ declare const invokeCommandSchema: z.ZodObject<{
8
+ type: z.ZodLiteral<"invoke">;
9
+ request_id: z.ZodString;
10
+ actor: z.ZodObject<{
11
+ namespace_id: z.ZodString;
12
+ actor_type: z.ZodString;
13
+ actor_id: z.ZodString;
14
+ }, z.core.$strip>;
15
+ method: z.ZodString;
16
+ args: z.ZodArray<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
17
+ state: z.ZodNullable<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
18
+ }, z.core.$strip>;
19
+ declare const evictCommandSchema: z.ZodObject<{
20
+ type: z.ZodLiteral<"evict">;
21
+ actor: z.ZodObject<{
22
+ namespace_id: z.ZodString;
23
+ actor_type: z.ZodString;
24
+ actor_id: z.ZodString;
25
+ }, z.core.$strip>;
26
+ }, z.core.$strip>;
27
+ declare const executorCommandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
28
+ type: z.ZodLiteral<"invoke">;
29
+ request_id: z.ZodString;
30
+ actor: z.ZodObject<{
31
+ namespace_id: z.ZodString;
32
+ actor_type: z.ZodString;
33
+ actor_id: z.ZodString;
34
+ }, z.core.$strip>;
35
+ method: z.ZodString;
36
+ args: z.ZodArray<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
37
+ state: z.ZodNullable<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
38
+ }, z.core.$strip>, z.ZodObject<{
39
+ type: z.ZodLiteral<"evict">;
40
+ actor: z.ZodObject<{
41
+ namespace_id: z.ZodString;
42
+ actor_type: z.ZodString;
43
+ actor_id: z.ZodString;
44
+ }, z.core.$strip>;
45
+ }, z.core.$strip>], "type">;
46
+ declare const actorSessionServerMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
47
+ type: z.ZodLiteral<"attached">;
48
+ protocol: z.ZodLiteral<11>;
49
+ }, z.core.$strip>, z.ZodObject<{
50
+ type: z.ZodLiteral<"command">;
51
+ message_id: z.ZodNumber;
52
+ command: z.ZodDiscriminatedUnion<[z.ZodObject<{
53
+ type: z.ZodLiteral<"invoke">;
54
+ request_id: z.ZodString;
55
+ actor: z.ZodObject<{
56
+ namespace_id: z.ZodString;
57
+ actor_type: z.ZodString;
58
+ actor_id: z.ZodString;
59
+ }, z.core.$strip>;
60
+ method: z.ZodString;
61
+ args: z.ZodArray<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
62
+ state: z.ZodNullable<z.ZodType<JsonValue, unknown, z.core.$ZodTypeInternals<JsonValue, unknown>>>;
63
+ }, z.core.$strip>, z.ZodObject<{
64
+ type: z.ZodLiteral<"evict">;
65
+ actor: z.ZodObject<{
66
+ namespace_id: z.ZodString;
67
+ actor_type: z.ZodString;
68
+ actor_id: z.ZodString;
69
+ }, z.core.$strip>;
70
+ }, z.core.$strip>], "type">;
71
+ }, z.core.$strip>], "type">;
72
+ declare class JsonActorStateSerializer {
73
+ clone(value: unknown, label: string): JsonValue;
74
+ snapshot(instance: object): JsonObject;
75
+ hydrate(instance: object, state: JsonObject): void;
76
+ private cloneObject;
77
+ private cloneValue;
78
+ private encode;
79
+ }
80
+ declare function validateActorComponent(name: string, value: string): string;
81
+ declare function parseActorSessionServerMessage(document: string): ActorSessionServerMessage;
82
+ declare function failedReply(code: string, message: string): FailedReply;
83
+ declare function errorMessage(error: unknown): string;
84
+ type InvokeCommand = z.infer<typeof invokeCommandSchema>;
85
+ type EvictCommand = z.infer<typeof evictCommandSchema>;
86
+ type ActorExecutorCommand = z.infer<typeof executorCommandSchema>;
87
+ type ActorSessionServerMessage = z.infer<typeof actorSessionServerMessageSchema>;
88
+ type ActorExecutorReply = InvokedReply | FailedReply | EvictedReply;
89
+ type ActorSessionClientMessage = AttachMessage | ReplyMessage;
90
+ interface AttachMessage {
91
+ readonly type: "attach";
92
+ readonly protocol: 11;
93
+ readonly actor_types: readonly string[];
94
+ }
95
+ interface ReplyMessage {
96
+ readonly type: "reply";
97
+ readonly message_id: number;
98
+ readonly reply: ActorExecutorReply;
99
+ }
100
+ interface InvokedReply {
101
+ readonly type: "invoked";
102
+ readonly result: JsonValue;
103
+ readonly state: JsonObject;
104
+ }
105
+ interface FailedReply {
106
+ readonly type: "failed";
107
+ readonly code: string;
108
+ readonly message: string;
109
+ }
110
+ interface EvictedReply {
111
+ readonly type: "evicted";
112
+ }
113
+ interface ActorWorkerData {
114
+ readonly actorType: string;
115
+ readonly moduleUrl: string;
116
+ }
117
+ type ActorWorkerRequest = {
118
+ readonly type: "invoke";
119
+ readonly command: InvokeCommand;
120
+ };
121
+ export { JsonActorStateSerializer, errorMessage, failedReply, parseActorSessionServerMessage, validateActorComponent };
122
+ export type { ActorExecutorCommand, ActorExecutorReply, ActorSessionClientMessage, ActorSessionServerMessage, ActorWorkerData, ActorWorkerRequest, EvictCommand, InvokeCommand, JsonObject, JsonPrimitive, JsonValue };
123
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../shared/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AACrD,KAAK,UAAU,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAA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AY,EACZ,aAAa,EACb,UAAU,EACV,aAAa,EACb,SAAS,EACZ,CAAA"}
@@ -0,0 +1,111 @@
1
+ import { z } from "zod";
2
+ import { ActorProtocolError, ActorSerializationError, ActorValidationError } from "./errors.js";
3
+ const actorComponentSchema = z.string().regex(/^[A-Za-z0-9._-]+$/u);
4
+ const jsonValueSchema = z.lazy(() => z.union([z.string(), z.number(), z.boolean(), z.null(), z.array(jsonValueSchema), z.record(z.string(), jsonValueSchema)]));
5
+ const actorIdentitySchema = z.object({
6
+ namespace_id: actorComponentSchema,
7
+ actor_type: actorComponentSchema,
8
+ actor_id: actorComponentSchema
9
+ });
10
+ const invokeCommandSchema = z.object({
11
+ type: z.literal("invoke"),
12
+ request_id: actorComponentSchema,
13
+ actor: actorIdentitySchema,
14
+ method: actorComponentSchema,
15
+ args: z.array(jsonValueSchema),
16
+ state: jsonValueSchema.nullable()
17
+ });
18
+ const evictCommandSchema = z.object({
19
+ type: z.literal("evict"),
20
+ actor: actorIdentitySchema
21
+ });
22
+ const executorCommandSchema = z.discriminatedUnion("type", [invokeCommandSchema, evictCommandSchema]);
23
+ const actorSessionServerMessageSchema = z.discriminatedUnion("type", [
24
+ z.object({ type: z.literal("attached"), protocol: z.literal(11) }),
25
+ z.object({
26
+ type: z.literal("command"),
27
+ message_id: z.number().int().nonnegative(),
28
+ command: executorCommandSchema
29
+ })
30
+ ]);
31
+ class JsonActorStateSerializer {
32
+ clone(value, label) {
33
+ return this.cloneValue(value, label);
34
+ }
35
+ snapshot(instance) {
36
+ const state = Object.fromEntries(Object.keys(instance).map(key => [key, Reflect.get(instance, key)]));
37
+ return this.cloneObject(state, "actor state");
38
+ }
39
+ hydrate(instance, state) {
40
+ const restored = this.cloneObject(state, "actor state");
41
+ Object.keys(instance).forEach(key => {
42
+ if (!Reflect.deleteProperty(instance, key))
43
+ throw new ActorSerializationError(`actor field ${key} cannot be restored`);
44
+ });
45
+ Object.entries(restored).forEach(([key, value]) => {
46
+ Object.defineProperty(instance, key, {
47
+ configurable: true,
48
+ enumerable: true,
49
+ writable: true,
50
+ value
51
+ });
52
+ });
53
+ }
54
+ cloneObject(value, label) {
55
+ const cloned = this.cloneValue(value, label);
56
+ if (!isJsonObject(cloned))
57
+ throw new ActorSerializationError(`${label} must be a JSON object`);
58
+ return cloned;
59
+ }
60
+ cloneValue(value, label) {
61
+ const encoded = this.encode(value, label);
62
+ const decoded = JSON.parse(encoded);
63
+ const result = jsonValueSchema.safeParse(decoded);
64
+ if (!result.success)
65
+ throw new ActorSerializationError(`${label} must be JSON serializable`);
66
+ return result.data;
67
+ }
68
+ encode(value, label) {
69
+ try {
70
+ const encoded = JSON.stringify(value);
71
+ if (encoded === undefined)
72
+ throw new ActorSerializationError(`${label} must be JSON serializable`);
73
+ return encoded;
74
+ }
75
+ catch (error) {
76
+ if (error instanceof ActorSerializationError)
77
+ throw error;
78
+ throw new ActorSerializationError(`${label} must be JSON serializable`, { cause: error });
79
+ }
80
+ }
81
+ }
82
+ function validateActorComponent(name, value) {
83
+ const result = actorComponentSchema.safeParse(value);
84
+ if (!result.success)
85
+ throw new ActorValidationError(`${name} may contain only ASCII letters, digits, '.', '-', and '_'`);
86
+ return result.data;
87
+ }
88
+ function parseActorSessionServerMessage(document) {
89
+ let value;
90
+ try {
91
+ value = JSON.parse(document);
92
+ }
93
+ catch (error) {
94
+ throw new ActorProtocolError("actor session message is not valid JSON", { cause: error });
95
+ }
96
+ const result = actorSessionServerMessageSchema.safeParse(value);
97
+ if (!result.success)
98
+ throw new ActorProtocolError(`actor session message is invalid: ${result.error.message}`);
99
+ return result.data;
100
+ }
101
+ function failedReply(code, message) {
102
+ return { type: "failed", code, message };
103
+ }
104
+ function errorMessage(error) {
105
+ return error instanceof Error ? error.message : String(error);
106
+ }
107
+ function isJsonObject(value) {
108
+ return typeof value === "object" && value !== null && !Array.isArray(value);
109
+ }
110
+ export { JsonActorStateSerializer, errorMessage, failedReply, parseActorSessionServerMessage, validateActorComponent };
111
+ //# sourceMapping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IAAI,EAAE,OAAO,EAAE,CAAA;AAC5C,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACjE,CAAC;AAED,SAAS,YAAY,CAAC,KAAgB;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC/E,CAAC;AA4CD,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,WAAW,EAAE,8BAA8B,EAAE,sBAAsB,EAAE,CAAA"}
@@ -0,0 +1,23 @@
1
+ import type { JsonValue } from "../shared/types.js";
2
+ import type { DurableObjectsClientOptions } from "./remoteClient.js";
3
+ interface ActorClientTransport {
4
+ invoke(actorType: string, actorId: string, method: string, args: readonly unknown[]): Promise<unknown>;
5
+ }
6
+ declare function actorClient(): ActorClientTransport;
7
+ declare function configureDurableObjects(options: DurableObjectsClientOptions): void;
8
+ declare function runWithActorClientForTests<T>(options: ActorTestClientOptions, operation: () => T): T;
9
+ interface ActorInvocationRequest {
10
+ readonly requestId: string;
11
+ readonly actorType: string;
12
+ readonly actorId: string;
13
+ readonly method: string;
14
+ readonly args: readonly JsonValue[];
15
+ }
16
+ interface ActorTestClientOptions {
17
+ readonly requestId?: () => string;
18
+ readonly invoke: ActorTestInvoker;
19
+ }
20
+ type ActorTestInvoker = (request: ActorInvocationRequest) => Promise<unknown>;
21
+ export { actorClient, configureDurableObjects, runWithActorClientForTests };
22
+ export type { ActorInvocationRequest, ActorTestClientOptions, DurableObjectsClientOptions };
23
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../workflow/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAGnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAA;AAEpE,UAAU,oBAAoB;IAC1B,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACzG;AAID,iBAAS,WAAW,IAAI,oBAAoB,CAE3C;AAED,iBAAS,uBAAuB,CAAC,OAAO,EAAE,2BAA2B,GAAG,IAAI,CAE3E;AAED,iBAAS,0BAA0B,CAAC,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,CAE7F;AAyCD,UAAU,sBAAsB;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,CAAA;CACtC;AAED,UAAU,sBAAsB;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,MAAM,CAAA;IACjC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;CACpC;AAED,KAAK,gBAAgB,GAAG,CAAC,OAAO,EAAE,sBAAsB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7E,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,CAAA;AAC3E,YAAY,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { ActorProtocolError } from "../shared/errors.js";
3
+ import { JsonActorStateSerializer, validateActorComponent } from "../shared/types.js";
4
+ import { RemoteActorClient } from "./remoteClient.js";
5
+ const scopedClients = new AsyncLocalStorage();
6
+ function actorClient() {
7
+ return scopedClients.getStore() ?? defaultClients.get();
8
+ }
9
+ function configureDurableObjects(options) {
10
+ defaultClients.configure(options);
11
+ }
12
+ function runWithActorClientForTests(options, operation) {
13
+ return scopedClients.run(new TestActorClient(options), operation);
14
+ }
15
+ class DefaultActorClientProvider {
16
+ client = new RemoteActorClient();
17
+ get() {
18
+ return this.client;
19
+ }
20
+ configure(options) {
21
+ this.client = new RemoteActorClient(options);
22
+ }
23
+ }
24
+ const defaultClients = new DefaultActorClientProvider();
25
+ class TestActorClient {
26
+ serializer = new JsonActorStateSerializer();
27
+ requestId;
28
+ invokeTest;
29
+ constructor(options) {
30
+ this.requestId = options.requestId ?? (() => globalThis.crypto.randomUUID());
31
+ this.invokeTest = options.invoke;
32
+ }
33
+ async invoke(actorType, actorId, method, args) {
34
+ const requestId = validateActorComponent("request ID", this.requestId());
35
+ const serializedArgs = this.serializer.clone(args, "actor arguments");
36
+ if (!Array.isArray(serializedArgs))
37
+ throw new ActorProtocolError("actor arguments must be a JSON array");
38
+ const request = {
39
+ requestId,
40
+ actorType: validateActorComponent("actor type", actorType),
41
+ actorId: validateActorComponent("actor ID", actorId),
42
+ method: validateActorComponent("actor method", method),
43
+ args: serializedArgs
44
+ };
45
+ return this.invokeTest(request);
46
+ }
47
+ }
48
+ export { actorClient, configureDurableObjects, runWithActorClientForTests };
49
+ //# sourceMappingURL=client.js.map