iii-sdk 0.21.8 → 0.22.0-alpha.2

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 (53) hide show
  1. package/dist/channel.d.cts +1 -1
  2. package/dist/channel.d.mts +1 -1
  3. package/dist/engine.d.cts +1 -2
  4. package/dist/engine.d.mts +1 -2
  5. package/dist/errors-CKW836UA.d.cts +62 -0
  6. package/dist/errors-CKW836UA.d.cts.map +1 -0
  7. package/dist/errors-DQVZBqCr.d.mts +62 -0
  8. package/dist/errors-DQVZBqCr.d.mts.map +1 -0
  9. package/dist/errors.cjs +11 -0
  10. package/dist/errors.cjs.map +1 -1
  11. package/dist/errors.d.cts +2 -40
  12. package/dist/errors.d.mts +2 -40
  13. package/dist/errors.mjs +11 -1
  14. package/dist/errors.mjs.map +1 -1
  15. package/dist/helpers.d.cts +1 -1
  16. package/dist/helpers.d.mts +1 -1
  17. package/dist/{iii-types-BvaIabiX.cjs → iii-types-BHasLgj1.cjs} +2 -1
  18. package/dist/iii-types-BHasLgj1.cjs.map +1 -0
  19. package/dist/{iii-types-wPYrg7hX.mjs → iii-types-Btz-0RpP.mjs} +2 -1
  20. package/dist/iii-types-Btz-0RpP.mjs.map +1 -0
  21. package/dist/index.cjs +96 -9
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +11 -4
  24. package/dist/index.d.cts.map +1 -1
  25. package/dist/index.d.mts +11 -4
  26. package/dist/index.d.mts.map +1 -1
  27. package/dist/index.mjs +97 -11
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/internal.d.cts +1 -1
  30. package/dist/internal.d.mts +1 -1
  31. package/dist/protocol.cjs +1 -1
  32. package/dist/protocol.d.cts +1 -1
  33. package/dist/protocol.d.mts +1 -1
  34. package/dist/protocol.mjs +1 -1
  35. package/dist/runtime.d.cts +1 -2
  36. package/dist/runtime.d.mts +1 -2
  37. package/dist/trigger.d.cts +1 -1
  38. package/dist/trigger.d.mts +1 -1
  39. package/dist/{types-BD2fp4Py.d.mts → types-DEiuZFsp.d.cts} +83 -2
  40. package/dist/types-DEiuZFsp.d.cts.map +1 -0
  41. package/dist/{types-n-760A15.d.cts → types-LJLev920.d.mts} +83 -2
  42. package/dist/types-LJLev920.d.mts.map +1 -0
  43. package/package.json +2 -2
  44. package/dist/errors.d.cts.map +0 -1
  45. package/dist/errors.d.mts.map +0 -1
  46. package/dist/iii-constants-Baptl8nm.d.mts +0 -47
  47. package/dist/iii-constants-Baptl8nm.d.mts.map +0 -1
  48. package/dist/iii-constants-BqXp8xSN.d.cts +0 -47
  49. package/dist/iii-constants-BqXp8xSN.d.cts.map +0 -1
  50. package/dist/iii-types-BvaIabiX.cjs.map +0 -1
  51. package/dist/iii-types-wPYrg7hX.mjs.map +0 -1
  52. package/dist/types-BD2fp4Py.d.mts.map +0 -1
  53. package/dist/types-n-760A15.d.cts.map +0 -1
@@ -1,2 +1,2 @@
1
- import { O as StreamChannelRef, t as Channel, v as ChannelReader, y as ChannelWriter } from "./types-n-760A15.cjs";
1
+ import { C as ChannelWriter, M as StreamChannelRef, S as ChannelReader, t as Channel } from "./types-DEiuZFsp.cjs";
2
2
  export { type Channel, ChannelReader, ChannelWriter, type StreamChannelRef };
@@ -1,2 +1,2 @@
1
- import { O as StreamChannelRef, t as Channel, v as ChannelReader, y as ChannelWriter } from "./types-BD2fp4Py.mjs";
1
+ import { C as ChannelWriter, M as StreamChannelRef, S as ChannelReader, t as Channel } from "./types-LJLev920.mjs";
2
2
  export { type Channel, ChannelReader, ChannelWriter, type StreamChannelRef };
package/dist/engine.d.cts CHANGED
@@ -1,3 +1,2 @@
1
- import { l as RemoteFunctionHandler } from "./types-n-760A15.cjs";
2
- import { n as EngineTriggers, t as EngineFunctions } from "./iii-constants-BqXp8xSN.cjs";
1
+ import { _ as EngineTriggers, g as EngineFunctions, l as RemoteFunctionHandler } from "./types-DEiuZFsp.cjs";
3
2
  export { EngineFunctions, EngineTriggers, type RemoteFunctionHandler };
package/dist/engine.d.mts CHANGED
@@ -1,3 +1,2 @@
1
- import { l as RemoteFunctionHandler } from "./types-BD2fp4Py.mjs";
2
- import { n as EngineTriggers, t as EngineFunctions } from "./iii-constants-Baptl8nm.mjs";
1
+ import { _ as EngineTriggers, g as EngineFunctions, l as RemoteFunctionHandler } from "./types-LJLev920.mjs";
3
2
  export { EngineFunctions, EngineTriggers, type RemoteFunctionHandler };
@@ -0,0 +1,62 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC
4
+ * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the
5
+ * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`
6
+ * that was targeted, so callers get a single error type across all failure
7
+ * modes and can disambiguate via `err.code`.
8
+ *
9
+ * Before this existed, rejection values were plain `ErrorBody`-shaped objects,
10
+ * which printed as `[object Object]` when stringified, leaving developers to
11
+ * grep through SDK source to figure out what tripped. The class name, `code`
12
+ * prefix in the message, and `function_id` field together make a rejection
13
+ * self-describing.
14
+ */
15
+ type InvocationErrorInit = {
16
+ code: string;
17
+ message: string;
18
+ function_id?: string;
19
+ stacktrace?: string;
20
+ };
21
+ declare class InvocationError extends Error {
22
+ readonly code: string;
23
+ readonly function_id?: string;
24
+ readonly stacktrace?: string;
25
+ constructor(init: InvocationErrorInit);
26
+ }
27
+ /**
28
+ * Fatal error surfaced when the engine rejects this worker's registration with
29
+ * a `registrationrejected` message: another live worker already owns this
30
+ * `worker_name` (or an exported function id) in the target `namespace`. The
31
+ * engine closes the connection on rejection, so this is terminal -- the SDK
32
+ * stops the worker and does not reconnect. Carries the wire fields
33
+ * (`code`, `namespace`, `worker_name`, `owner_worker_id`) so callers can tell
34
+ * exactly which identity collided and with whom.
35
+ */
36
+ type RegistrationRejectedInit = {
37
+ code: string;
38
+ namespace: string;
39
+ worker_name: string;
40
+ owner_worker_id: string;
41
+ };
42
+ declare class RegistrationRejectedError extends Error {
43
+ readonly code: string;
44
+ readonly namespace: string;
45
+ readonly worker_name: string;
46
+ readonly owner_worker_id: string;
47
+ constructor(init: RegistrationRejectedInit);
48
+ }
49
+ /**
50
+ * True when `value` looks like the wire `ErrorBody` the engine sends in
51
+ * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
52
+ * Used to distinguish an engine rejection (which we wrap in
53
+ * {@link InvocationError}) from a JS `Error` thrown elsewhere.
54
+ */
55
+ declare function isErrorBody(value: unknown): value is {
56
+ code: string;
57
+ message: string;
58
+ stacktrace?: string;
59
+ };
60
+ //#endregion
61
+ export { isErrorBody as a, RegistrationRejectedInit as i, InvocationErrorInit as n, RegistrationRejectedError as r, InvocationError as t };
62
+ //# sourceMappingURL=errors-CKW836UA.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-CKW836UA.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";;AAaA;;;;;;;;;;AAOA;;KAPY,mBAAA;EACV,IAAA;EACA,OAAA;EACA,WAAA;EACA,UAAA;AAAA;AAAA,cAGW,eAAA,SAAwB,KAAA;EAAA,SACnB,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;cAEJ,IAAA,EAAM,mBAAA;AAAA;;;;;;;;;;KAkBR,wBAAA;EACV,IAAA;EACA,SAAA;EACA,WAAA;EACA,eAAA;AAAA;AAAA,cAGW,yBAAA,SAAkC,KAAA;EAAA,SAC7B,IAAA;EAAA,SACA,SAAA;EAAA,SACA,WAAA;EAAA,SACA,eAAA;cAEJ,IAAA,EAAM,wBAAA;AAAA;;AAkBpB;;;;;iBAAgB,WAAA,CAAY,KAAA,YAAiB,KAAA;EAC3C,IAAA;EACA,OAAA;EACA,UAAA;AAAA"}
@@ -0,0 +1,62 @@
1
+ //#region src/errors.d.ts
2
+ /**
3
+ * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC
4
+ * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the
5
+ * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`
6
+ * that was targeted, so callers get a single error type across all failure
7
+ * modes and can disambiguate via `err.code`.
8
+ *
9
+ * Before this existed, rejection values were plain `ErrorBody`-shaped objects,
10
+ * which printed as `[object Object]` when stringified, leaving developers to
11
+ * grep through SDK source to figure out what tripped. The class name, `code`
12
+ * prefix in the message, and `function_id` field together make a rejection
13
+ * self-describing.
14
+ */
15
+ type InvocationErrorInit = {
16
+ code: string;
17
+ message: string;
18
+ function_id?: string;
19
+ stacktrace?: string;
20
+ };
21
+ declare class InvocationError extends Error {
22
+ readonly code: string;
23
+ readonly function_id?: string;
24
+ readonly stacktrace?: string;
25
+ constructor(init: InvocationErrorInit);
26
+ }
27
+ /**
28
+ * Fatal error surfaced when the engine rejects this worker's registration with
29
+ * a `registrationrejected` message: another live worker already owns this
30
+ * `worker_name` (or an exported function id) in the target `namespace`. The
31
+ * engine closes the connection on rejection, so this is terminal -- the SDK
32
+ * stops the worker and does not reconnect. Carries the wire fields
33
+ * (`code`, `namespace`, `worker_name`, `owner_worker_id`) so callers can tell
34
+ * exactly which identity collided and with whom.
35
+ */
36
+ type RegistrationRejectedInit = {
37
+ code: string;
38
+ namespace: string;
39
+ worker_name: string;
40
+ owner_worker_id: string;
41
+ };
42
+ declare class RegistrationRejectedError extends Error {
43
+ readonly code: string;
44
+ readonly namespace: string;
45
+ readonly worker_name: string;
46
+ readonly owner_worker_id: string;
47
+ constructor(init: RegistrationRejectedInit);
48
+ }
49
+ /**
50
+ * True when `value` looks like the wire `ErrorBody` the engine sends in
51
+ * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
52
+ * Used to distinguish an engine rejection (which we wrap in
53
+ * {@link InvocationError}) from a JS `Error` thrown elsewhere.
54
+ */
55
+ declare function isErrorBody(value: unknown): value is {
56
+ code: string;
57
+ message: string;
58
+ stacktrace?: string;
59
+ };
60
+ //#endregion
61
+ export { isErrorBody as a, RegistrationRejectedInit as i, InvocationErrorInit as n, RegistrationRejectedError as r, InvocationError as t };
62
+ //# sourceMappingURL=errors-DQVZBqCr.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-DQVZBqCr.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;AAaA;;;;;;;;;;AAOA;;KAPY,mBAAA;EACV,IAAA;EACA,OAAA;EACA,WAAA;EACA,UAAA;AAAA;AAAA,cAGW,eAAA,SAAwB,KAAA;EAAA,SACnB,IAAA;EAAA,SACA,WAAA;EAAA,SACA,UAAA;cAEJ,IAAA,EAAM,mBAAA;AAAA;;;;;;;;;;KAkBR,wBAAA;EACV,IAAA;EACA,SAAA;EACA,WAAA;EACA,eAAA;AAAA;AAAA,cAGW,yBAAA,SAAkC,KAAA;EAAA,SAC7B,IAAA;EAAA,SACA,SAAA;EAAA,SACA,WAAA;EAAA,SACA,eAAA;cAEJ,IAAA,EAAM,wBAAA;AAAA;;AAkBpB;;;;;iBAAgB,WAAA,CAAY,KAAA,YAAiB,KAAA;EAC3C,IAAA;EACA,OAAA;EACA,UAAA;AAAA"}
package/dist/errors.cjs CHANGED
@@ -10,6 +10,16 @@ var InvocationError = class extends Error {
10
10
  this.stacktrace = init.stacktrace;
11
11
  }
12
12
  };
13
+ var RegistrationRejectedError = class extends Error {
14
+ constructor(init) {
15
+ super(`${init.code}: registration rejected for worker "${init.worker_name}" in namespace "${init.namespace}" (already owned by worker ${init.owner_worker_id})`);
16
+ this.name = "RegistrationRejectedError";
17
+ this.code = init.code;
18
+ this.namespace = init.namespace;
19
+ this.worker_name = init.worker_name;
20
+ this.owner_worker_id = init.owner_worker_id;
21
+ }
22
+ };
13
23
  /**
14
24
  * True when `value` looks like the wire `ErrorBody` the engine sends in
15
25
  * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
@@ -24,5 +34,6 @@ function isErrorBody(value) {
24
34
 
25
35
  //#endregion
26
36
  exports.InvocationError = InvocationError;
37
+ exports.RegistrationRejectedError = RegistrationRejectedError;
27
38
  exports.isErrorBody = isErrorBody;
28
39
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC\n * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the\n * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`\n * that was targeted, so callers get a single error type across all failure\n * modes and can disambiguate via `err.code`.\n *\n * Before this existed, rejection values were plain `ErrorBody`-shaped objects,\n * which printed as `[object Object]` when stringified, leaving developers to\n * grep through SDK source to figure out what tripped. The class name, `code`\n * prefix in the message, and `function_id` field together make a rejection\n * self-describing.\n */\nexport type InvocationErrorInit = {\n code: string\n message: string\n function_id?: string\n stacktrace?: string\n}\n\nexport class InvocationError extends Error {\n public readonly code: string\n public readonly function_id?: string\n public readonly stacktrace?: string\n\n constructor(init: InvocationErrorInit) {\n super(`${init.code}: ${init.message}`)\n this.name = 'InvocationError'\n this.code = init.code\n this.function_id = init.function_id\n this.stacktrace = init.stacktrace\n }\n}\n\n/**\n * True when `value` looks like the wire `ErrorBody` the engine sends in\n * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.\n * Used to distinguish an engine rejection (which we wrap in\n * {@link InvocationError}) from a JS `Error` thrown elsewhere.\n */\nexport function isErrorBody(value: unknown): value is {\n code: string\n message: string\n stacktrace?: string\n} {\n if (typeof value !== 'object' || value === null) return false\n const v = value as { code?: unknown; message?: unknown; stacktrace?: unknown }\n return (\n typeof v.code === 'string' &&\n typeof v.message === 'string' &&\n (v.stacktrace === undefined || typeof v.stacktrace === 'string')\n )\n}\n"],"mappings":";;;AAoBA,IAAa,kBAAb,cAAqC,MAAM;CAKzC,YAAY,MAA2B;AACrC,QAAM,GAAG,KAAK,KAAK,IAAI,KAAK,UAAU;AACtC,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,cAAc,KAAK;AACxB,OAAK,aAAa,KAAK;;;;;;;;;AAU3B,SAAgB,YAAY,OAI1B;AACA,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,YAAY,aACpB,EAAE,eAAe,UAAa,OAAO,EAAE,eAAe"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC\n * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the\n * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`\n * that was targeted, so callers get a single error type across all failure\n * modes and can disambiguate via `err.code`.\n *\n * Before this existed, rejection values were plain `ErrorBody`-shaped objects,\n * which printed as `[object Object]` when stringified, leaving developers to\n * grep through SDK source to figure out what tripped. The class name, `code`\n * prefix in the message, and `function_id` field together make a rejection\n * self-describing.\n */\nexport type InvocationErrorInit = {\n code: string\n message: string\n function_id?: string\n stacktrace?: string\n}\n\nexport class InvocationError extends Error {\n public readonly code: string\n public readonly function_id?: string\n public readonly stacktrace?: string\n\n constructor(init: InvocationErrorInit) {\n super(`${init.code}: ${init.message}`)\n this.name = 'InvocationError'\n this.code = init.code\n this.function_id = init.function_id\n this.stacktrace = init.stacktrace\n }\n}\n\n/**\n * Fatal error surfaced when the engine rejects this worker's registration with\n * a `registrationrejected` message: another live worker already owns this\n * `worker_name` (or an exported function id) in the target `namespace`. The\n * engine closes the connection on rejection, so this is terminal -- the SDK\n * stops the worker and does not reconnect. Carries the wire fields\n * (`code`, `namespace`, `worker_name`, `owner_worker_id`) so callers can tell\n * exactly which identity collided and with whom.\n */\nexport type RegistrationRejectedInit = {\n code: string\n namespace: string\n worker_name: string\n owner_worker_id: string\n}\n\nexport class RegistrationRejectedError extends Error {\n public readonly code: string\n public readonly namespace: string\n public readonly worker_name: string\n public readonly owner_worker_id: string\n\n constructor(init: RegistrationRejectedInit) {\n super(\n `${init.code}: registration rejected for worker \"${init.worker_name}\" in namespace \"${init.namespace}\" (already owned by worker ${init.owner_worker_id})`,\n )\n this.name = 'RegistrationRejectedError'\n this.code = init.code\n this.namespace = init.namespace\n this.worker_name = init.worker_name\n this.owner_worker_id = init.owner_worker_id\n }\n}\n\n/**\n * True when `value` looks like the wire `ErrorBody` the engine sends in\n * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.\n * Used to distinguish an engine rejection (which we wrap in\n * {@link InvocationError}) from a JS `Error` thrown elsewhere.\n */\nexport function isErrorBody(value: unknown): value is {\n code: string\n message: string\n stacktrace?: string\n} {\n if (typeof value !== 'object' || value === null) return false\n const v = value as { code?: unknown; message?: unknown; stacktrace?: unknown }\n return (\n typeof v.code === 'string' &&\n typeof v.message === 'string' &&\n (v.stacktrace === undefined || typeof v.stacktrace === 'string')\n )\n}\n"],"mappings":";;;AAoBA,IAAa,kBAAb,cAAqC,MAAM;CAKzC,YAAY,MAA2B;AACrC,QAAM,GAAG,KAAK,KAAK,IAAI,KAAK,UAAU;AACtC,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,cAAc,KAAK;AACxB,OAAK,aAAa,KAAK;;;AAoB3B,IAAa,4BAAb,cAA+C,MAAM;CAMnD,YAAY,MAAgC;AAC1C,QACE,GAAG,KAAK,KAAK,sCAAsC,KAAK,YAAY,kBAAkB,KAAK,UAAU,6BAA6B,KAAK,gBAAgB,GACxJ;AACD,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,YAAY,KAAK;AACtB,OAAK,cAAc,KAAK;AACxB,OAAK,kBAAkB,KAAK;;;;;;;;;AAUhC,SAAgB,YAAY,OAI1B;AACA,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,YAAY,aACpB,EAAE,eAAe,UAAa,OAAO,EAAE,eAAe"}
package/dist/errors.d.cts CHANGED
@@ -1,40 +1,2 @@
1
- //#region src/errors.d.ts
2
- /**
3
- * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC
4
- * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the
5
- * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`
6
- * that was targeted, so callers get a single error type across all failure
7
- * modes and can disambiguate via `err.code`.
8
- *
9
- * Before this existed, rejection values were plain `ErrorBody`-shaped objects,
10
- * which printed as `[object Object]` when stringified, leaving developers to
11
- * grep through SDK source to figure out what tripped. The class name, `code`
12
- * prefix in the message, and `function_id` field together make a rejection
13
- * self-describing.
14
- */
15
- type InvocationErrorInit = {
16
- code: string;
17
- message: string;
18
- function_id?: string;
19
- stacktrace?: string;
20
- };
21
- declare class InvocationError extends Error {
22
- readonly code: string;
23
- readonly function_id?: string;
24
- readonly stacktrace?: string;
25
- constructor(init: InvocationErrorInit);
26
- }
27
- /**
28
- * True when `value` looks like the wire `ErrorBody` the engine sends in
29
- * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
30
- * Used to distinguish an engine rejection (which we wrap in
31
- * {@link InvocationError}) from a JS `Error` thrown elsewhere.
32
- */
33
- declare function isErrorBody(value: unknown): value is {
34
- code: string;
35
- message: string;
36
- stacktrace?: string;
37
- };
38
- //#endregion
39
- export { InvocationError, InvocationErrorInit, isErrorBody };
40
- //# sourceMappingURL=errors.d.cts.map
1
+ import { a as isErrorBody, i as RegistrationRejectedInit, n as InvocationErrorInit, r as RegistrationRejectedError, t as InvocationError } from "./errors-CKW836UA.cjs";
2
+ export { InvocationError, InvocationErrorInit, RegistrationRejectedError, RegistrationRejectedInit, isErrorBody };
package/dist/errors.d.mts CHANGED
@@ -1,40 +1,2 @@
1
- //#region src/errors.d.ts
2
- /**
3
- * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC
4
- * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the
5
- * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`
6
- * that was targeted, so callers get a single error type across all failure
7
- * modes and can disambiguate via `err.code`.
8
- *
9
- * Before this existed, rejection values were plain `ErrorBody`-shaped objects,
10
- * which printed as `[object Object]` when stringified, leaving developers to
11
- * grep through SDK source to figure out what tripped. The class name, `code`
12
- * prefix in the message, and `function_id` field together make a rejection
13
- * self-describing.
14
- */
15
- type InvocationErrorInit = {
16
- code: string;
17
- message: string;
18
- function_id?: string;
19
- stacktrace?: string;
20
- };
21
- declare class InvocationError extends Error {
22
- readonly code: string;
23
- readonly function_id?: string;
24
- readonly stacktrace?: string;
25
- constructor(init: InvocationErrorInit);
26
- }
27
- /**
28
- * True when `value` looks like the wire `ErrorBody` the engine sends in
29
- * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
30
- * Used to distinguish an engine rejection (which we wrap in
31
- * {@link InvocationError}) from a JS `Error` thrown elsewhere.
32
- */
33
- declare function isErrorBody(value: unknown): value is {
34
- code: string;
35
- message: string;
36
- stacktrace?: string;
37
- };
38
- //#endregion
39
- export { InvocationError, InvocationErrorInit, isErrorBody };
40
- //# sourceMappingURL=errors.d.mts.map
1
+ import { a as isErrorBody, i as RegistrationRejectedInit, n as InvocationErrorInit, r as RegistrationRejectedError, t as InvocationError } from "./errors-DQVZBqCr.mjs";
2
+ export { InvocationError, InvocationErrorInit, RegistrationRejectedError, RegistrationRejectedInit, isErrorBody };
package/dist/errors.mjs CHANGED
@@ -8,6 +8,16 @@ var InvocationError = class extends Error {
8
8
  this.stacktrace = init.stacktrace;
9
9
  }
10
10
  };
11
+ var RegistrationRejectedError = class extends Error {
12
+ constructor(init) {
13
+ super(`${init.code}: registration rejected for worker "${init.worker_name}" in namespace "${init.namespace}" (already owned by worker ${init.owner_worker_id})`);
14
+ this.name = "RegistrationRejectedError";
15
+ this.code = init.code;
16
+ this.namespace = init.namespace;
17
+ this.worker_name = init.worker_name;
18
+ this.owner_worker_id = init.owner_worker_id;
19
+ }
20
+ };
11
21
  /**
12
22
  * True when `value` looks like the wire `ErrorBody` the engine sends in
13
23
  * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.
@@ -21,5 +31,5 @@ function isErrorBody(value) {
21
31
  }
22
32
 
23
33
  //#endregion
24
- export { InvocationError, isErrorBody };
34
+ export { InvocationError, RegistrationRejectedError, isErrorBody };
25
35
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC\n * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the\n * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`\n * that was targeted, so callers get a single error type across all failure\n * modes and can disambiguate via `err.code`.\n *\n * Before this existed, rejection values were plain `ErrorBody`-shaped objects,\n * which printed as `[object Object]` when stringified, leaving developers to\n * grep through SDK source to figure out what tripped. The class name, `code`\n * prefix in the message, and `function_id` field together make a rejection\n * self-describing.\n */\nexport type InvocationErrorInit = {\n code: string\n message: string\n function_id?: string\n stacktrace?: string\n}\n\nexport class InvocationError extends Error {\n public readonly code: string\n public readonly function_id?: string\n public readonly stacktrace?: string\n\n constructor(init: InvocationErrorInit) {\n super(`${init.code}: ${init.message}`)\n this.name = 'InvocationError'\n this.code = init.code\n this.function_id = init.function_id\n this.stacktrace = init.stacktrace\n }\n}\n\n/**\n * True when `value` looks like the wire `ErrorBody` the engine sends in\n * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.\n * Used to distinguish an engine rejection (which we wrap in\n * {@link InvocationError}) from a JS `Error` thrown elsewhere.\n */\nexport function isErrorBody(value: unknown): value is {\n code: string\n message: string\n stacktrace?: string\n} {\n if (typeof value !== 'object' || value === null) return false\n const v = value as { code?: unknown; message?: unknown; stacktrace?: unknown }\n return (\n typeof v.code === 'string' &&\n typeof v.message === 'string' &&\n (v.stacktrace === undefined || typeof v.stacktrace === 'string')\n )\n}\n"],"mappings":";AAoBA,IAAa,kBAAb,cAAqC,MAAM;CAKzC,YAAY,MAA2B;AACrC,QAAM,GAAG,KAAK,KAAK,IAAI,KAAK,UAAU;AACtC,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,cAAc,KAAK;AACxB,OAAK,aAAa,KAAK;;;;;;;;;AAU3B,SAAgB,YAAY,OAI1B;AACA,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,YAAY,aACpB,EAAE,eAAe,UAAa,OAAO,EAAE,eAAe"}
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Typed error surfaced when an invocation dispatched over the SDK fails, RBAC\n * rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the\n * engine to respond. Wraps the wire `ErrorBody` shape plus the `function_id`\n * that was targeted, so callers get a single error type across all failure\n * modes and can disambiguate via `err.code`.\n *\n * Before this existed, rejection values were plain `ErrorBody`-shaped objects,\n * which printed as `[object Object]` when stringified, leaving developers to\n * grep through SDK source to figure out what tripped. The class name, `code`\n * prefix in the message, and `function_id` field together make a rejection\n * self-describing.\n */\nexport type InvocationErrorInit = {\n code: string\n message: string\n function_id?: string\n stacktrace?: string\n}\n\nexport class InvocationError extends Error {\n public readonly code: string\n public readonly function_id?: string\n public readonly stacktrace?: string\n\n constructor(init: InvocationErrorInit) {\n super(`${init.code}: ${init.message}`)\n this.name = 'InvocationError'\n this.code = init.code\n this.function_id = init.function_id\n this.stacktrace = init.stacktrace\n }\n}\n\n/**\n * Fatal error surfaced when the engine rejects this worker's registration with\n * a `registrationrejected` message: another live worker already owns this\n * `worker_name` (or an exported function id) in the target `namespace`. The\n * engine closes the connection on rejection, so this is terminal -- the SDK\n * stops the worker and does not reconnect. Carries the wire fields\n * (`code`, `namespace`, `worker_name`, `owner_worker_id`) so callers can tell\n * exactly which identity collided and with whom.\n */\nexport type RegistrationRejectedInit = {\n code: string\n namespace: string\n worker_name: string\n owner_worker_id: string\n}\n\nexport class RegistrationRejectedError extends Error {\n public readonly code: string\n public readonly namespace: string\n public readonly worker_name: string\n public readonly owner_worker_id: string\n\n constructor(init: RegistrationRejectedInit) {\n super(\n `${init.code}: registration rejected for worker \"${init.worker_name}\" in namespace \"${init.namespace}\" (already owned by worker ${init.owner_worker_id})`,\n )\n this.name = 'RegistrationRejectedError'\n this.code = init.code\n this.namespace = init.namespace\n this.worker_name = init.worker_name\n this.owner_worker_id = init.owner_worker_id\n }\n}\n\n/**\n * True when `value` looks like the wire `ErrorBody` the engine sends in\n * `InvocationResult.error`: `{ code: string, message: string, stacktrace?: string }`.\n * Used to distinguish an engine rejection (which we wrap in\n * {@link InvocationError}) from a JS `Error` thrown elsewhere.\n */\nexport function isErrorBody(value: unknown): value is {\n code: string\n message: string\n stacktrace?: string\n} {\n if (typeof value !== 'object' || value === null) return false\n const v = value as { code?: unknown; message?: unknown; stacktrace?: unknown }\n return (\n typeof v.code === 'string' &&\n typeof v.message === 'string' &&\n (v.stacktrace === undefined || typeof v.stacktrace === 'string')\n )\n}\n"],"mappings":";AAoBA,IAAa,kBAAb,cAAqC,MAAM;CAKzC,YAAY,MAA2B;AACrC,QAAM,GAAG,KAAK,KAAK,IAAI,KAAK,UAAU;AACtC,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,cAAc,KAAK;AACxB,OAAK,aAAa,KAAK;;;AAoB3B,IAAa,4BAAb,cAA+C,MAAM;CAMnD,YAAY,MAAgC;AAC1C,QACE,GAAG,KAAK,KAAK,sCAAsC,KAAK,YAAY,kBAAkB,KAAK,UAAU,6BAA6B,KAAK,gBAAgB,GACxJ;AACD,OAAK,OAAO;AACZ,OAAK,OAAO,KAAK;AACjB,OAAK,YAAY,KAAK;AACtB,OAAK,cAAc,KAAK;AACxB,OAAK,kBAAkB,KAAK;;;;;;;;;AAUhC,SAAgB,YAAY,OAI1B;AACA,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,OAAO,EAAE,SAAS,YAClB,OAAO,EAAE,YAAY,aACpB,EAAE,eAAe,UAAa,OAAO,EAAE,eAAe"}
@@ -1,4 +1,4 @@
1
- import { O as StreamChannelRef, _ as ChannelItem, g as ChannelDirection, r as IIIClient, t as Channel } from "./types-n-760A15.cjs";
1
+ import { M as StreamChannelRef, b as ChannelDirection, r as IIIClient, t as Channel, x as ChannelItem } from "./types-DEiuZFsp.cjs";
2
2
  import { IStream } from "./stream.cjs";
3
3
 
4
4
  //#region src/utils.d.ts
@@ -1,4 +1,4 @@
1
- import { O as StreamChannelRef, _ as ChannelItem, g as ChannelDirection, r as IIIClient, t as Channel } from "./types-BD2fp4Py.mjs";
1
+ import { M as StreamChannelRef, b as ChannelDirection, r as IIIClient, t as Channel, x as ChannelItem } from "./types-LJLev920.mjs";
2
2
  import { IStream } from "./stream.mjs";
3
3
 
4
4
  //#region src/utils.d.ts
@@ -11,6 +11,7 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
11
11
  MessageType["UnregisterTriggerType"] = "unregistertriggertype";
12
12
  MessageType["TriggerRegistrationResult"] = "triggerregistrationresult";
13
13
  MessageType["WorkerRegistered"] = "workerregistered";
14
+ MessageType["RegistrationRejected"] = "registrationrejected";
14
15
  MessageType["Reattach"] = "reattach";
15
16
  return MessageType;
16
17
  }({});
@@ -22,4 +23,4 @@ Object.defineProperty(exports, 'MessageType', {
22
23
  return MessageType;
23
24
  }
24
25
  });
25
- //# sourceMappingURL=iii-types-BvaIabiX.cjs.map
26
+ //# sourceMappingURL=iii-types-BHasLgj1.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iii-types-BHasLgj1.cjs","names":[],"sources":["../src/iii-types.ts"],"sourcesContent":["import type { HttpInvocationConfig } from '@iii-dev/helpers/http'\n\n/**\n * Any JSON value: the TypeScript equivalent of the engine's arbitrary-JSON\n * wire values (Rust `serde_json::Value`). Used where the wire contract is\n * \"any JSON\", e.g. per-invocation `metadata`.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\nexport enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n RegistrationRejected = 'registrationrejected',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type ErrorBody = {\n code: string\n message: string\n stacktrace?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n error?: ErrorBody\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: Record<string, unknown>\n /**\n * Namespace the trigger's target function resolves in. Omit for the engine's\n * default namespace, independent of this connection's namespace.\n */\n namespace?: string\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter.\n */\n name?: string\n /**\n * The description of the parameter.\n */\n description?: string\n /**\n * The type of the parameter.\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects).\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays).\n */\n items?: unknown\n /**\n * Whether the parameter is required.\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda).\n */\n id: string\n /**\n * The description of the function.\n */\n description?: string\n /**\n * The request format of the function.\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function.\n */\n response_format?: RegisterFunctionFormat\n /**\n * Arbitrary metadata attached to the function.\n */\n metadata?: Record<string, unknown>\n /**\n * HTTP invocation config for external HTTP functions (Lambda, Cloudflare Workers, etc.).\n */\n invocation?: HttpInvocationConfig\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Request object passed to {@link IIIClient.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: unknown\n /**\n * Target namespace for routing. Omit to route within the engine's default\n * namespace. Serialized into the {@link InvokeFunctionMessage} `namespace`\n * field; omitted from the wire when undefined.\n */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function.\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Optional per-invocation metadata (arbitrary JSON). Travels as a separate\n * channel from `data`. Omitted from the JSON when undefined; absence on\n * inbound means \"no metadata\" (backward compatible with older engines).\n */\n metadata?: JsonValue\n /**\n * Target namespace for routing. Optional and additive: omitted from the JSON\n * when undefined, and absence on inbound means the engine's default\n * namespace (backward compatible with older engines).\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function.\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type WorkerRegisteredMessage = {\n message_type: MessageType.WorkerRegistered\n worker_id: string\n /** Secret to present in a reattach frame on reconnect; absent on older engines. */\n reattach_token?: string\n}\n\n/**\n * Sent by the engine when this worker's registration collides with a live\n * worker in `namespace`. The `code` decides severity:\n *\n * - `WORKER_NAMESPACE_CONFLICT`: another worker already holds this\n * `(namespace, worker_name)`. The engine closes the connection -- fatal: the\n * SDK stops the worker and does not reconnect.\n * - `FUNCTION_NAMESPACE_CONFLICT`: another worker already exports this one\n * function id (carried in `worker_name`). The engine keeps the connection\n * open -- non-fatal: only that registration is refused and the worker keeps\n * serving its other functions.\n */\nexport type RegistrationRejectedMessage = {\n message_type: MessageType.RegistrationRejected\n /** Machine-readable rejection code (`WORKER_NAMESPACE_CONFLICT` | `FUNCTION_NAMESPACE_CONFLICT`). */\n code: string\n /** Namespace in which the collision occurred. */\n namespace: string\n /** The contested identity: the worker name, or (FUNCTION conflict) the function id. */\n worker_name: string\n /** ID of the live worker that already owns the contested identity. */\n owner_worker_id: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n | WorkerRegisteredMessage\n | RegistrationRejectedMessage\n"],"mappings":";;AAeA,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD"}
@@ -10,10 +10,11 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
10
10
  MessageType["UnregisterTriggerType"] = "unregistertriggertype";
11
11
  MessageType["TriggerRegistrationResult"] = "triggerregistrationresult";
12
12
  MessageType["WorkerRegistered"] = "workerregistered";
13
+ MessageType["RegistrationRejected"] = "registrationrejected";
13
14
  MessageType["Reattach"] = "reattach";
14
15
  return MessageType;
15
16
  }({});
16
17
 
17
18
  //#endregion
18
19
  export { MessageType as t };
19
- //# sourceMappingURL=iii-types-wPYrg7hX.mjs.map
20
+ //# sourceMappingURL=iii-types-Btz-0RpP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iii-types-Btz-0RpP.mjs","names":[],"sources":["../src/iii-types.ts"],"sourcesContent":["import type { HttpInvocationConfig } from '@iii-dev/helpers/http'\n\n/**\n * Any JSON value: the TypeScript equivalent of the engine's arbitrary-JSON\n * wire values (Rust `serde_json::Value`). Used where the wire contract is\n * \"any JSON\", e.g. per-invocation `metadata`.\n */\nexport type JsonValue =\n | string\n | number\n | boolean\n | null\n | JsonValue[]\n | { [key: string]: JsonValue }\n\nexport enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n RegistrationRejected = 'registrationrejected',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type ErrorBody = {\n code: string\n message: string\n stacktrace?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n error?: ErrorBody\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: Record<string, unknown>\n /**\n * Namespace the trigger's target function resolves in. Omit for the engine's\n * default namespace, independent of this connection's namespace.\n */\n namespace?: string\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter.\n */\n name?: string\n /**\n * The description of the parameter.\n */\n description?: string\n /**\n * The type of the parameter.\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects).\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays).\n */\n items?: unknown\n /**\n * Whether the parameter is required.\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda).\n */\n id: string\n /**\n * The description of the function.\n */\n description?: string\n /**\n * The request format of the function.\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function.\n */\n response_format?: RegisterFunctionFormat\n /**\n * Arbitrary metadata attached to the function.\n */\n metadata?: Record<string, unknown>\n /**\n * HTTP invocation config for external HTTP functions (Lambda, Cloudflare Workers, etc.).\n */\n invocation?: HttpInvocationConfig\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Request object passed to {@link IIIClient.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Arbitrary user-specifiable metadata supplied to the triggered handler function on every invocation. */\n metadata?: unknown\n /**\n * Target namespace for routing. Omit to route within the engine's default\n * namespace. Serialized into the {@link InvokeFunctionMessage} `namespace`\n * field; omitted from the wire when undefined.\n */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function.\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Optional per-invocation metadata (arbitrary JSON). Travels as a separate\n * channel from `data`. Omitted from the JSON when undefined; absence on\n * inbound means \"no metadata\" (backward compatible with older engines).\n */\n metadata?: JsonValue\n /**\n * Target namespace for routing. Optional and additive: omitted from the JSON\n * when undefined, and absence on inbound means the engine's default\n * namespace (backward compatible with older engines).\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function.\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type WorkerRegisteredMessage = {\n message_type: MessageType.WorkerRegistered\n worker_id: string\n /** Secret to present in a reattach frame on reconnect; absent on older engines. */\n reattach_token?: string\n}\n\n/**\n * Sent by the engine when this worker's registration collides with a live\n * worker in `namespace`. The `code` decides severity:\n *\n * - `WORKER_NAMESPACE_CONFLICT`: another worker already holds this\n * `(namespace, worker_name)`. The engine closes the connection -- fatal: the\n * SDK stops the worker and does not reconnect.\n * - `FUNCTION_NAMESPACE_CONFLICT`: another worker already exports this one\n * function id (carried in `worker_name`). The engine keeps the connection\n * open -- non-fatal: only that registration is refused and the worker keeps\n * serving its other functions.\n */\nexport type RegistrationRejectedMessage = {\n message_type: MessageType.RegistrationRejected\n /** Machine-readable rejection code (`WORKER_NAMESPACE_CONFLICT` | `FUNCTION_NAMESPACE_CONFLICT`). */\n code: string\n /** Namespace in which the collision occurred. */\n namespace: string\n /** The contested identity: the worker name, or (FUNCTION conflict) the function id. */\n worker_name: string\n /** ID of the live worker that already owns the contested identity. */\n owner_worker_id: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n | WorkerRegisteredMessage\n | RegistrationRejectedMessage\n"],"mappings":";AAeA,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD"}
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@ const require_utils = require('./utils-63wxBJg-.cjs');
3
3
  const require_errors = require('./errors.cjs');
4
4
  const require_iii_constants = require('./iii-constants-M_BGfxGD.cjs');
5
5
  const require_channels = require('./channels-C2ezAJ_g.cjs');
6
- const require_iii_types = require('./iii-types-BvaIabiX.cjs');
6
+ const require_iii_types = require('./iii-types-BHasLgj1.cjs');
7
7
  let _opentelemetry_api = require("@opentelemetry/api");
8
8
  let node_module = require("node:module");
9
9
  let node_os = require("node:os");
@@ -14,6 +14,18 @@ let _iii_dev_helpers_observability_internal = require("@iii-dev/helpers/observab
14
14
 
15
15
  //#region src/iii.ts
16
16
  const { version: SDK_VERSION } = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
17
+ /**
18
+ * `registrationrejected` code (engine `protocol.rs`): another live worker
19
+ * already holds this `(namespace, worker_name)`. The engine closes the
20
+ * connection -- fatal.
21
+ */
22
+ const WORKER_NAMESPACE_CONFLICT = "WORKER_NAMESPACE_CONFLICT";
23
+ /**
24
+ * `registrationrejected` code (engine `protocol.rs`): another live worker in
25
+ * this namespace already exports this one function id. The connection stays
26
+ * open -- non-fatal.
27
+ */
28
+ const FUNCTION_NAMESPACE_CONFLICT = "FUNCTION_NAMESPACE_CONFLICT";
17
29
  function getOsInfo() {
18
30
  return `${node_os.platform()} ${node_os.release()} (${node_os.arch()})`;
19
31
  }
@@ -22,6 +34,11 @@ function getDefaultWorkerName() {
22
34
  if (managedName) return managedName;
23
35
  return `${node_os.hostname()}:${process.pid}`;
24
36
  }
37
+ function resolveNamespace(optionNamespace) {
38
+ if (optionNamespace) return optionNamespace;
39
+ const managedNamespace = process.env.III_NAMESPACE;
40
+ if (managedNamespace) return managedNamespace;
41
+ }
25
42
  var Sdk = class {
26
43
  constructor(address, options) {
27
44
  this.address = address;
@@ -50,7 +67,8 @@ var Sdk = class {
50
67
  type: triggerType.id,
51
68
  function_id: functionId,
52
69
  config,
53
- metadata
70
+ metadata,
71
+ namespace: this.namespace
54
72
  });
55
73
  },
56
74
  registerFunction: (functionId, handler, config, metadata) => {
@@ -59,7 +77,8 @@ var Sdk = class {
59
77
  type: triggerType.id,
60
78
  function_id: functionId,
61
79
  config,
62
- metadata
80
+ metadata,
81
+ namespace: this.namespace
63
82
  });
64
83
  return ref;
65
84
  },
@@ -185,7 +204,7 @@ var Sdk = class {
185
204
  };
186
205
  };
187
206
  this.trigger = async (request) => {
188
- const { function_id, payload, action, timeoutMs, metadata } = request;
207
+ const { function_id, payload, action, timeoutMs, metadata, namespace } = request;
189
208
  const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs;
190
209
  if (action?.type === "void") {
191
210
  const traceparent = (0, _iii_dev_helpers_observability.injectTraceparent)();
@@ -196,7 +215,8 @@ var Sdk = class {
196
215
  traceparent,
197
216
  baggage,
198
217
  action,
199
- metadata
218
+ metadata,
219
+ ...namespace !== void 0 ? { namespace } : {}
200
220
  });
201
221
  return;
202
222
  }
@@ -233,7 +253,8 @@ var Sdk = class {
233
253
  traceparent,
234
254
  baggage,
235
255
  action,
236
- metadata
256
+ metadata,
257
+ ...namespace !== void 0 ? { namespace } : {}
237
258
  });
238
259
  });
239
260
  };
@@ -244,6 +265,8 @@ var Sdk = class {
244
265
  this.registerFunction(`stream::list(${streamName})`, stream.list.bind(stream));
245
266
  this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream));
246
267
  };
268
+ this.getConnectionState = () => this.connectionState;
269
+ this.getFatalError = () => this.fatalError;
247
270
  this.shutdown = async () => {
248
271
  this.isShuttingDown = true;
249
272
  this.stopMetricsReporting();
@@ -266,6 +289,7 @@ var Sdk = class {
266
289
  this.setConnectionState("disconnected");
267
290
  };
268
291
  this.workerName = options?.workerName ?? getDefaultWorkerName();
292
+ this.namespace = resolveNamespace(options?.namespace);
269
293
  this.workerDescription = options?.workerDescription;
270
294
  this.metricsReportingEnabled = options?.enableMetricsReporting ?? true;
271
295
  this.invocationTimeoutMs = options?.invocationTimeoutMs ?? 3e4;
@@ -292,6 +316,7 @@ var Sdk = class {
292
316
  os: getOsInfo(),
293
317
  pid: process.pid,
294
318
  isolation: process.env.III_ISOLATION || null,
319
+ ...this.namespace !== void 0 ? { namespace: this.namespace } : {},
295
320
  telemetry: {
296
321
  language,
297
322
  project_name: telemetryOpts?.project_name ?? require_utils.detectProjectName(),
@@ -407,6 +432,7 @@ var Sdk = class {
407
432
  previous_worker_id: this.workerId,
408
433
  reattach_token: this.reattachToken
409
434
  }));
435
+ this.registerWorkerMetadata();
410
436
  this.triggerTypes.forEach(({ message }) => {
411
437
  this.sendMessage(require_iii_types.MessageType.RegisterTriggerType, message, true);
412
438
  });
@@ -422,7 +448,6 @@ var Sdk = class {
422
448
  if (message.type === require_iii_types.MessageType.InvokeFunction && typeof message.invocation_id === "string" && !this.invocations.has(message.invocation_id)) continue;
423
449
  this.sendMessageRaw(JSON.stringify(message));
424
450
  }
425
- this.registerWorkerMetadata();
426
451
  }
427
452
  isOpen() {
428
453
  return this.ws?.readyState === ws.WebSocket.OPEN;
@@ -481,6 +506,58 @@ var Sdk = class {
481
506
  });
482
507
  else console.error(`[iii] ${message}`, error ?? "");
483
508
  }
509
+ logWarn(message) {
510
+ const otelLogger = (0, _iii_dev_helpers_observability.getLogger)();
511
+ if (otelLogger) otelLogger.emit({
512
+ severityNumber: _iii_dev_helpers_observability.SeverityNumber.WARN,
513
+ body: `[iii] ${message}`
514
+ });
515
+ else console.warn(`[iii] ${message}`);
516
+ }
517
+ /**
518
+ * Handle a `registrationrejected` from the engine. The `code` decides the
519
+ * severity:
520
+ *
521
+ * - {@link WORKER_NAMESPACE_CONFLICT}: another live worker already holds this
522
+ * `(namespace, worker_name)`. The engine closes the connection, so this is
523
+ * fatal -- stop the worker, do not reconnect, and surface a
524
+ * {@link RegistrationRejectedError} to every pending invocation.
525
+ * - {@link FUNCTION_NAMESPACE_CONFLICT}: another live worker in this namespace
526
+ * already exports this one function id. Only that registration is refused;
527
+ * the engine keeps the connection open and the worker keeps serving its
528
+ * other functions. Non-fatal -- log a warning and continue. Here
529
+ * `worker_name` carries the contested function id (the engine reuses the
530
+ * struct).
531
+ * - Any other code: treated as fatal (safe default).
532
+ */
533
+ onRegistrationRejected(init) {
534
+ if (init.code === FUNCTION_NAMESPACE_CONFLICT) {
535
+ this.logWarn(`Function registration rejected: function "${init.worker_name}" in namespace "${init.namespace}" is already exported by worker ${init.owner_worker_id}. The worker stays connected and keeps serving its other functions.`);
536
+ return;
537
+ }
538
+ const error = new require_errors.RegistrationRejectedError(init);
539
+ this.fatalError = error;
540
+ if (init.code === WORKER_NAMESPACE_CONFLICT) this.logError("Registration rejected by engine", error);
541
+ else this.logError(`Registration rejected by engine with unknown code "${init.code}"; treating as fatal`, error);
542
+ this.isShuttingDown = true;
543
+ this.clearReconnectTimeout();
544
+ this.stopHeartbeat();
545
+ for (const [, invocation] of this.invocations) {
546
+ if (invocation.timeout) clearTimeout(invocation.timeout);
547
+ invocation.reject(error);
548
+ }
549
+ this.invocations.clear();
550
+ if (this.ws) {
551
+ this.ws.removeAllListeners();
552
+ this.ws.on("error", () => {});
553
+ try {
554
+ this.ws.terminate();
555
+ } catch {}
556
+ this.ws = void 0;
557
+ }
558
+ this.stopMetricsReporting();
559
+ this.setConnectionState("failed");
560
+ }
484
561
  onInvocationResult(invocation_id, result, error) {
485
562
  const invocation = this.invocations.get(invocation_id);
486
563
  if (invocation) {
@@ -574,14 +651,15 @@ var Sdk = class {
574
651
  }
575
652
  }
576
653
  async onRegisterTrigger(message) {
577
- const { trigger_type, id, function_id, config, metadata } = message;
654
+ const { trigger_type, id, function_id, config, metadata, namespace } = message;
578
655
  const triggerTypeData = this.triggerTypes.get(trigger_type);
579
656
  if (triggerTypeData) try {
580
657
  await triggerTypeData.handler.registerTrigger({
581
658
  id,
582
659
  function_id,
583
660
  config,
584
- metadata
661
+ metadata,
662
+ namespace
585
663
  });
586
664
  this.sendMessage(require_iii_types.MessageType.TriggerRegistrationResult, {
587
665
  id,
@@ -661,6 +739,14 @@ var Sdk = class {
661
739
  this.reattachToken = reattach_token;
662
740
  console.debug("[iii] Worker registered with ID:", worker_id);
663
741
  this.startMetricsReporting();
742
+ } else if (msgType === require_iii_types.MessageType.RegistrationRejected) {
743
+ const { code, namespace, worker_name, owner_worker_id } = message;
744
+ this.onRegistrationRejected({
745
+ code,
746
+ namespace,
747
+ worker_name,
748
+ owner_worker_id
749
+ });
664
750
  }
665
751
  }
666
752
  };
@@ -714,6 +800,7 @@ const registerWorker = (address, options) => new Sdk(address, options);
714
800
 
715
801
  //#endregion
716
802
  exports.InvocationError = require_errors.InvocationError;
803
+ exports.RegistrationRejectedError = require_errors.RegistrationRejectedError;
717
804
  exports.TriggerAction = TriggerAction;
718
805
  exports.registerWorker = registerWorker;
719
806
  //# sourceMappingURL=index.cjs.map