iii-sdk 0.21.8-next.4 → 0.22.0-alpha.1

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 +89 -5
  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 +90 -7
  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-Co4Q4P8p.d.cts} +77 -2
  40. package/dist/types-Co4Q4P8p.d.cts.map +1 -0
  41. package/dist/{types-n-760A15.d.cts → types-DEEbuJE1.d.mts} +77 -2
  42. package/dist/types-DEEbuJE1.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-Co4Q4P8p.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-DEEbuJE1.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-Co4Q4P8p.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-DEEbuJE1.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-Co4Q4P8p.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-DEEbuJE1.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;
@@ -185,7 +202,7 @@ var Sdk = class {
185
202
  };
186
203
  };
187
204
  this.trigger = async (request) => {
188
- const { function_id, payload, action, timeoutMs, metadata } = request;
205
+ const { function_id, payload, action, timeoutMs, metadata, namespace } = request;
189
206
  const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs;
190
207
  if (action?.type === "void") {
191
208
  const traceparent = (0, _iii_dev_helpers_observability.injectTraceparent)();
@@ -196,7 +213,8 @@ var Sdk = class {
196
213
  traceparent,
197
214
  baggage,
198
215
  action,
199
- metadata
216
+ metadata,
217
+ ...namespace !== void 0 ? { namespace } : {}
200
218
  });
201
219
  return;
202
220
  }
@@ -233,7 +251,8 @@ var Sdk = class {
233
251
  traceparent,
234
252
  baggage,
235
253
  action,
236
- metadata
254
+ metadata,
255
+ ...namespace !== void 0 ? { namespace } : {}
237
256
  });
238
257
  });
239
258
  };
@@ -244,6 +263,8 @@ var Sdk = class {
244
263
  this.registerFunction(`stream::list(${streamName})`, stream.list.bind(stream));
245
264
  this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream));
246
265
  };
266
+ this.getConnectionState = () => this.connectionState;
267
+ this.getFatalError = () => this.fatalError;
247
268
  this.shutdown = async () => {
248
269
  this.isShuttingDown = true;
249
270
  this.stopMetricsReporting();
@@ -266,6 +287,7 @@ var Sdk = class {
266
287
  this.setConnectionState("disconnected");
267
288
  };
268
289
  this.workerName = options?.workerName ?? getDefaultWorkerName();
290
+ this.namespace = resolveNamespace(options?.namespace);
269
291
  this.workerDescription = options?.workerDescription;
270
292
  this.metricsReportingEnabled = options?.enableMetricsReporting ?? true;
271
293
  this.invocationTimeoutMs = options?.invocationTimeoutMs ?? 3e4;
@@ -292,6 +314,7 @@ var Sdk = class {
292
314
  os: getOsInfo(),
293
315
  pid: process.pid,
294
316
  isolation: process.env.III_ISOLATION || null,
317
+ ...this.namespace !== void 0 ? { namespace: this.namespace } : {},
295
318
  telemetry: {
296
319
  language,
297
320
  project_name: telemetryOpts?.project_name ?? require_utils.detectProjectName(),
@@ -407,6 +430,7 @@ var Sdk = class {
407
430
  previous_worker_id: this.workerId,
408
431
  reattach_token: this.reattachToken
409
432
  }));
433
+ this.registerWorkerMetadata();
410
434
  this.triggerTypes.forEach(({ message }) => {
411
435
  this.sendMessage(require_iii_types.MessageType.RegisterTriggerType, message, true);
412
436
  });
@@ -422,7 +446,6 @@ var Sdk = class {
422
446
  if (message.type === require_iii_types.MessageType.InvokeFunction && typeof message.invocation_id === "string" && !this.invocations.has(message.invocation_id)) continue;
423
447
  this.sendMessageRaw(JSON.stringify(message));
424
448
  }
425
- this.registerWorkerMetadata();
426
449
  }
427
450
  isOpen() {
428
451
  return this.ws?.readyState === ws.WebSocket.OPEN;
@@ -481,6 +504,58 @@ var Sdk = class {
481
504
  });
482
505
  else console.error(`[iii] ${message}`, error ?? "");
483
506
  }
507
+ logWarn(message) {
508
+ const otelLogger = (0, _iii_dev_helpers_observability.getLogger)();
509
+ if (otelLogger) otelLogger.emit({
510
+ severityNumber: _iii_dev_helpers_observability.SeverityNumber.WARN,
511
+ body: `[iii] ${message}`
512
+ });
513
+ else console.warn(`[iii] ${message}`);
514
+ }
515
+ /**
516
+ * Handle a `registrationrejected` from the engine. The `code` decides the
517
+ * severity:
518
+ *
519
+ * - {@link WORKER_NAMESPACE_CONFLICT}: another live worker already holds this
520
+ * `(namespace, worker_name)`. The engine closes the connection, so this is
521
+ * fatal -- stop the worker, do not reconnect, and surface a
522
+ * {@link RegistrationRejectedError} to every pending invocation.
523
+ * - {@link FUNCTION_NAMESPACE_CONFLICT}: another live worker in this namespace
524
+ * already exports this one function id. Only that registration is refused;
525
+ * the engine keeps the connection open and the worker keeps serving its
526
+ * other functions. Non-fatal -- log a warning and continue. Here
527
+ * `worker_name` carries the contested function id (the engine reuses the
528
+ * struct).
529
+ * - Any other code: treated as fatal (safe default).
530
+ */
531
+ onRegistrationRejected(init) {
532
+ if (init.code === FUNCTION_NAMESPACE_CONFLICT) {
533
+ 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.`);
534
+ return;
535
+ }
536
+ const error = new require_errors.RegistrationRejectedError(init);
537
+ this.fatalError = error;
538
+ if (init.code === WORKER_NAMESPACE_CONFLICT) this.logError("Registration rejected by engine", error);
539
+ else this.logError(`Registration rejected by engine with unknown code "${init.code}"; treating as fatal`, error);
540
+ this.isShuttingDown = true;
541
+ this.clearReconnectTimeout();
542
+ this.stopHeartbeat();
543
+ for (const [, invocation] of this.invocations) {
544
+ if (invocation.timeout) clearTimeout(invocation.timeout);
545
+ invocation.reject(error);
546
+ }
547
+ this.invocations.clear();
548
+ if (this.ws) {
549
+ this.ws.removeAllListeners();
550
+ this.ws.on("error", () => {});
551
+ try {
552
+ this.ws.terminate();
553
+ } catch {}
554
+ this.ws = void 0;
555
+ }
556
+ this.stopMetricsReporting();
557
+ this.setConnectionState("failed");
558
+ }
484
559
  onInvocationResult(invocation_id, result, error) {
485
560
  const invocation = this.invocations.get(invocation_id);
486
561
  if (invocation) {
@@ -661,6 +736,14 @@ var Sdk = class {
661
736
  this.reattachToken = reattach_token;
662
737
  console.debug("[iii] Worker registered with ID:", worker_id);
663
738
  this.startMetricsReporting();
739
+ } else if (msgType === require_iii_types.MessageType.RegistrationRejected) {
740
+ const { code, namespace, worker_name, owner_worker_id } = message;
741
+ this.onRegistrationRejected({
742
+ code,
743
+ namespace,
744
+ worker_name,
745
+ owner_worker_id
746
+ });
664
747
  }
665
748
  }
666
749
  };
@@ -714,6 +797,7 @@ const registerWorker = (address, options) => new Sdk(address, options);
714
797
 
715
798
  //#endregion
716
799
  exports.InvocationError = require_errors.InvocationError;
800
+ exports.RegistrationRejectedError = require_errors.RegistrationRejectedError;
717
801
  exports.TriggerAction = TriggerAction;
718
802
  exports.registerWorker = registerWorker;
719
803
  //# sourceMappingURL=index.cjs.map