@astrale-os/kernel-server 0.5.0-beta.2 → 0.5.0-beta.21

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 (177) hide show
  1. package/dist/capture.d.ts +0 -1
  2. package/dist/capture.js +0 -1
  3. package/dist/cors/cors.d.ts +0 -1
  4. package/dist/cors/cors.js +0 -1
  5. package/dist/cors/index.d.ts +0 -1
  6. package/dist/cors/index.js +0 -1
  7. package/dist/cors/types.d.ts +0 -1
  8. package/dist/cors/types.js +0 -1
  9. package/dist/errors/availability.d.ts +0 -1
  10. package/dist/errors/availability.js +0 -1
  11. package/dist/errors/classify.d.ts +2 -3
  12. package/dist/errors/classify.js +4 -279
  13. package/dist/errors/index.d.ts +0 -1
  14. package/dist/errors/index.js +0 -1
  15. package/dist/errors/request-body.d.ts +0 -1
  16. package/dist/errors/request-body.js +0 -1
  17. package/dist/errors/response-body.d.ts +0 -1
  18. package/dist/errors/response-body.js +0 -1
  19. package/dist/index.d.ts +1 -2
  20. package/dist/index.js +0 -1
  21. package/dist/invocation/context.d.ts +2 -3
  22. package/dist/invocation/context.js +2 -3
  23. package/dist/invocation/identity.d.ts +9 -0
  24. package/dist/invocation/identity.js +11 -0
  25. package/dist/invocation/index.d.ts +2 -2
  26. package/dist/invocation/index.js +1 -1
  27. package/dist/invocation/publication-route.d.ts +5 -4
  28. package/dist/invocation/publication-route.js +8 -7
  29. package/dist/invocation/types.d.ts +33 -9
  30. package/dist/invocation/types.js +0 -1
  31. package/dist/issuer/exchange.d.ts +2 -3
  32. package/dist/issuer/exchange.js +13 -12
  33. package/dist/issuer/index.d.ts +0 -1
  34. package/dist/issuer/index.js +0 -1
  35. package/dist/issuer/routes.d.ts +0 -1
  36. package/dist/issuer/routes.js +14 -12
  37. package/dist/issuer/types.d.ts +2 -2
  38. package/dist/issuer/types.js +0 -1
  39. package/dist/lifecycle/active.d.ts +2 -1
  40. package/dist/lifecycle/active.js +5 -3
  41. package/dist/lifecycle/index.d.ts +0 -1
  42. package/dist/lifecycle/index.js +0 -1
  43. package/dist/publication/delivery/handler.d.ts +0 -1
  44. package/dist/publication/delivery/handler.js +2 -2
  45. package/dist/publication/delivery/index.d.ts +0 -1
  46. package/dist/publication/delivery/index.js +0 -1
  47. package/dist/publication/delivery/types.d.ts +1 -2
  48. package/dist/publication/delivery/types.js +0 -1
  49. package/dist/publication/index.d.ts +0 -1
  50. package/dist/publication/index.js +0 -1
  51. package/dist/publication/snapshot.d.ts +5 -3
  52. package/dist/publication/snapshot.js +14 -7
  53. package/dist/publication/table.d.ts +4 -0
  54. package/dist/publication/table.js +16 -0
  55. package/dist/publication/types.d.ts +5 -2
  56. package/dist/publication/types.js +0 -1
  57. package/dist/routes/index.d.ts +0 -1
  58. package/dist/routes/index.js +0 -1
  59. package/dist/routes/routes.d.ts +3 -3
  60. package/dist/routes/routes.js +91 -26
  61. package/dist/server.d.ts +0 -1
  62. package/dist/server.js +13 -7
  63. package/dist/transport/body.d.ts +0 -1
  64. package/dist/transport/body.js +0 -1
  65. package/dist/transport/codecs.d.ts +1 -2
  66. package/dist/transport/codecs.js +1 -2
  67. package/dist/transport/credential.d.ts +1 -2
  68. package/dist/transport/credential.js +1 -2
  69. package/dist/transport/http/handler.d.ts +2 -1
  70. package/dist/transport/http/handler.js +36 -33
  71. package/dist/transport/http/index.d.ts +0 -1
  72. package/dist/transport/http/index.js +0 -1
  73. package/dist/transport/http/render.d.ts +17 -13
  74. package/dist/transport/http/render.js +120 -41
  75. package/dist/transport/index.d.ts +0 -1
  76. package/dist/transport/index.js +0 -1
  77. package/dist/transport/router.d.ts +0 -1
  78. package/dist/transport/router.js +0 -1
  79. package/dist/transport/stream-error.d.ts +2 -3
  80. package/dist/transport/stream-error.js +3 -4
  81. package/dist/transport/types.d.ts +1 -2
  82. package/dist/transport/types.js +0 -1
  83. package/dist/transport/websocket/index.d.ts +0 -1
  84. package/dist/transport/websocket/index.js +0 -1
  85. package/dist/transport/websocket/session.d.ts +4 -3
  86. package/dist/transport/websocket/session.js +56 -39
  87. package/dist/transport/websocket/upgrade.d.ts +2 -1
  88. package/dist/transport/websocket/upgrade.js +2 -2
  89. package/dist/types.d.ts +6 -4
  90. package/dist/types.js +0 -1
  91. package/package.json +23 -13
  92. package/dist/capture.d.ts.map +0 -1
  93. package/dist/capture.js.map +0 -1
  94. package/dist/cors/cors.d.ts.map +0 -1
  95. package/dist/cors/cors.js.map +0 -1
  96. package/dist/cors/index.d.ts.map +0 -1
  97. package/dist/cors/index.js.map +0 -1
  98. package/dist/cors/types.d.ts.map +0 -1
  99. package/dist/cors/types.js.map +0 -1
  100. package/dist/errors/availability.d.ts.map +0 -1
  101. package/dist/errors/availability.js.map +0 -1
  102. package/dist/errors/classify.d.ts.map +0 -1
  103. package/dist/errors/classify.js.map +0 -1
  104. package/dist/errors/index.d.ts.map +0 -1
  105. package/dist/errors/index.js.map +0 -1
  106. package/dist/errors/request-body.d.ts.map +0 -1
  107. package/dist/errors/request-body.js.map +0 -1
  108. package/dist/errors/response-body.d.ts.map +0 -1
  109. package/dist/errors/response-body.js.map +0 -1
  110. package/dist/index.d.ts.map +0 -1
  111. package/dist/index.js.map +0 -1
  112. package/dist/invocation/context.d.ts.map +0 -1
  113. package/dist/invocation/context.js.map +0 -1
  114. package/dist/invocation/index.d.ts.map +0 -1
  115. package/dist/invocation/index.js.map +0 -1
  116. package/dist/invocation/publication-route.d.ts.map +0 -1
  117. package/dist/invocation/publication-route.js.map +0 -1
  118. package/dist/invocation/types.d.ts.map +0 -1
  119. package/dist/invocation/types.js.map +0 -1
  120. package/dist/issuer/exchange.d.ts.map +0 -1
  121. package/dist/issuer/exchange.js.map +0 -1
  122. package/dist/issuer/index.d.ts.map +0 -1
  123. package/dist/issuer/index.js.map +0 -1
  124. package/dist/issuer/routes.d.ts.map +0 -1
  125. package/dist/issuer/routes.js.map +0 -1
  126. package/dist/issuer/types.d.ts.map +0 -1
  127. package/dist/issuer/types.js.map +0 -1
  128. package/dist/lifecycle/active.d.ts.map +0 -1
  129. package/dist/lifecycle/active.js.map +0 -1
  130. package/dist/lifecycle/index.d.ts.map +0 -1
  131. package/dist/lifecycle/index.js.map +0 -1
  132. package/dist/publication/delivery/handler.d.ts.map +0 -1
  133. package/dist/publication/delivery/handler.js.map +0 -1
  134. package/dist/publication/delivery/index.d.ts.map +0 -1
  135. package/dist/publication/delivery/index.js.map +0 -1
  136. package/dist/publication/delivery/types.d.ts.map +0 -1
  137. package/dist/publication/delivery/types.js.map +0 -1
  138. package/dist/publication/index.d.ts.map +0 -1
  139. package/dist/publication/index.js.map +0 -1
  140. package/dist/publication/snapshot.d.ts.map +0 -1
  141. package/dist/publication/snapshot.js.map +0 -1
  142. package/dist/publication/types.d.ts.map +0 -1
  143. package/dist/publication/types.js.map +0 -1
  144. package/dist/routes/index.d.ts.map +0 -1
  145. package/dist/routes/index.js.map +0 -1
  146. package/dist/routes/routes.d.ts.map +0 -1
  147. package/dist/routes/routes.js.map +0 -1
  148. package/dist/server.d.ts.map +0 -1
  149. package/dist/server.js.map +0 -1
  150. package/dist/transport/body.d.ts.map +0 -1
  151. package/dist/transport/body.js.map +0 -1
  152. package/dist/transport/codecs.d.ts.map +0 -1
  153. package/dist/transport/codecs.js.map +0 -1
  154. package/dist/transport/credential.d.ts.map +0 -1
  155. package/dist/transport/credential.js.map +0 -1
  156. package/dist/transport/http/handler.d.ts.map +0 -1
  157. package/dist/transport/http/handler.js.map +0 -1
  158. package/dist/transport/http/index.d.ts.map +0 -1
  159. package/dist/transport/http/index.js.map +0 -1
  160. package/dist/transport/http/render.d.ts.map +0 -1
  161. package/dist/transport/http/render.js.map +0 -1
  162. package/dist/transport/index.d.ts.map +0 -1
  163. package/dist/transport/index.js.map +0 -1
  164. package/dist/transport/router.d.ts.map +0 -1
  165. package/dist/transport/router.js.map +0 -1
  166. package/dist/transport/stream-error.d.ts.map +0 -1
  167. package/dist/transport/stream-error.js.map +0 -1
  168. package/dist/transport/types.d.ts.map +0 -1
  169. package/dist/transport/types.js.map +0 -1
  170. package/dist/transport/websocket/index.d.ts.map +0 -1
  171. package/dist/transport/websocket/index.js.map +0 -1
  172. package/dist/transport/websocket/session.d.ts.map +0 -1
  173. package/dist/transport/websocket/session.js.map +0 -1
  174. package/dist/transport/websocket/upgrade.d.ts.map +0 -1
  175. package/dist/transport/websocket/upgrade.js.map +0 -1
  176. package/dist/types.d.ts.map +0 -1
  177. package/dist/types.js.map +0 -1
package/dist/capture.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  /** Capture one receiver-bound method while preserving the capability's exact method type. */
2
2
  export declare function captureMethod<Receiver extends object, Name extends keyof Receiver>(input: Receiver, name: Name, invalidMessage: string): Receiver[Name];
3
- //# sourceMappingURL=capture.d.ts.map
package/dist/capture.js CHANGED
@@ -7,4 +7,3 @@ export function captureMethod(input, name, invalidMessage) {
7
7
  throw new TypeError(invalidMessage);
8
8
  return method.bind(input);
9
9
  }
10
- //# sourceMappingURL=capture.js.map
@@ -19,4 +19,3 @@ export interface CorsPolicy {
19
19
  }
20
20
  /** Admit one immutable policy. `false` delegates the complete concern to an outer application. */
21
21
  export declare function prepareCors(input: CorsConfig | false | undefined): CorsPolicy;
22
- //# sourceMappingURL=cors.d.ts.map
package/dist/cors/cors.js CHANGED
@@ -133,4 +133,3 @@ function appendVary(headers, value) {
133
133
  names.add(value);
134
134
  headers.set('vary', [...names].join(', '));
135
135
  }
136
- //# sourceMappingURL=cors.js.map
@@ -1,3 +1,2 @@
1
1
  export { prepareCors, type CorsPolicy, type CorsRoute } from './cors.js';
2
2
  export type { CorsConfig } from './types.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1 @@
1
1
  export { prepareCors } from './cors.js';
2
- //# sourceMappingURL=index.js.map
@@ -9,4 +9,3 @@ export interface CorsConfig {
9
9
  /** Emit Access-Control-Allow-Credentials; requires one explicit origin rather than `*`. */
10
10
  readonly credentials?: boolean;
11
11
  }
12
- //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -8,4 +8,3 @@ export declare class IssuerKeysUnavailableError extends Error {
8
8
  readonly name = "IssuerKeysUnavailableError";
9
9
  constructor(message?: string, options?: ErrorOptions);
10
10
  }
11
- //# sourceMappingURL=availability.d.ts.map
@@ -12,4 +12,3 @@ export class IssuerKeysUnavailableError extends Error {
12
12
  super(message, options);
13
13
  }
14
14
  }
15
- //# sourceMappingURL=availability.js.map
@@ -1,4 +1,3 @@
1
- import { errors } from '@astrale-os/kernel-protocol';
2
- /** Convert only errors owned by an admitted protocol boundary into safe public data. */
1
+ import * as errors from '@astrale-os/kernel-protocol/errors';
2
+ /** Convert only errors owned by an admitted Server or Protocol boundary into safe public data. */
3
3
  export declare function classifyError(input: unknown): errors.ErrorPayload;
4
- //# sourceMappingURL=classify.d.ts.map
@@ -1,15 +1,8 @@
1
1
  import { PathError } from '@astrale-os/kernel-core/path';
2
- import { AuthenticationError } from '@astrale-os/kernel-ports/authentication';
3
- import { AuthorizationError } from '@astrale-os/kernel-ports/authorization';
4
- import { EventError } from '@astrale-os/kernel-ports/events';
5
- import { FunctionError } from '@astrale-os/kernel-ports/functions';
6
- import { NetworkError } from '@astrale-os/kernel-ports/network';
7
- import { ObservabilityError } from '@astrale-os/kernel-ports/observability';
8
- import { SchemaError } from '@astrale-os/kernel-ports/schema';
9
- import { errors } from '@astrale-os/kernel-protocol';
2
+ import * as errors from '@astrale-os/kernel-protocol/errors';
10
3
  import { RequestBodyTooLargeError } from './request-body.js';
11
4
  import { ResponseBodyTooLargeError } from './response-body.js';
12
- /** Convert only errors owned by an admitted protocol boundary into safe public data. */
5
+ /** Convert only errors owned by an admitted Server or Protocol boundary into safe public data. */
13
6
  export function classifyError(input) {
14
7
  if (input instanceof errors.ProtocolError)
15
8
  return input.payload;
@@ -22,282 +15,15 @@ export function classifyError(input) {
22
15
  if (input instanceof PathError) {
23
16
  return publicError('VALIDATION_ERROR', 'Target Path is invalid.');
24
17
  }
25
- if (input instanceof FunctionError)
26
- return classifyFunction(input);
27
- if (input instanceof AuthenticationError)
28
- return classifyAuthentication(input);
29
- if (input instanceof AuthorizationError)
30
- return classifyAuthorization(input);
31
- if (input instanceof SchemaError)
32
- return classifySchema(input);
33
- if (input instanceof EventError)
34
- return classifyEvent(input);
35
- if (input instanceof ObservabilityError)
36
- return classifyObservability(input);
37
- if (input instanceof NetworkError)
38
- return classifyNetwork(input);
39
18
  return internal(input);
40
19
  }
41
- function classifyFunction(input) {
42
- const reason = errors.reasonOf(input.reason);
43
- switch (input.code) {
44
- case 'FUNCTION_INVOCATION_INVALID':
45
- return publicError('VALIDATION_ERROR', 'Function invocation is invalid.', input.code);
46
- case 'FUNCTION_INPUT_INVALID':
47
- return publicError('VALIDATION_ERROR', reasonMessage(reason, 'Function input is invalid.'), reason);
48
- case 'FUNCTION_CONFLICT':
49
- return publicError('CONFLICT', reasonMessage(reason, 'Function execution conflicts with current state.'), reason ?? input.code);
50
- case 'FUNCTION_UNAVAILABLE':
51
- return publicError('METHOD_NOT_FOUND', 'Callable was not found.');
52
- case 'FUNCTION_DENIED':
53
- return publicError('ACCESS_DENIED', 'Access denied.', reason);
54
- case 'FUNCTION_MISS':
55
- return publicError('METHOD_NOT_FOUND', 'Callable is not served by this application.', input.code);
56
- case 'FUNCTION_BINDING_UNAVAILABLE':
57
- return publicError('BACKEND_UNAVAILABLE', 'Callable execution is unavailable.');
58
- case 'FUNCTION_EXECUTION_LIMIT':
59
- return publicError('LIMIT_EXCEEDED', 'Function execution limit exceeded.', reason);
60
- case 'FUNCTION_CANCELLED':
61
- return publicError('CANCELLED', 'Function invocation was cancelled.', reason ?? input.code);
62
- case 'FUNCTION_DEADLINE_EXCEEDED':
63
- return publicError('DEADLINE_EXCEEDED', 'Function invocation deadline exceeded.', reason ?? input.code);
64
- case 'FUNCTION_OUTCOME_UNKNOWN':
65
- reportUnknownFunction(input);
66
- return publicError('OUTCOME_UNKNOWN', 'Function outcome is unknown; do not retry automatically.', reason ?? input.code);
67
- case 'FUNCTION_OUTPUT_INVALID':
68
- case 'FUNCTION_BINDING_INVALID':
69
- case 'FUNCTION_REDIRECT_INVALID':
70
- case 'FUNCTION_RESULT_MISMATCH':
71
- case 'RESULT_CONTRACT_VIOLATION':
72
- return internal(input);
73
- case 'FUNCTION_EXECUTION_FAILED':
74
- return reason === undefined
75
- ? internal(input)
76
- : publicError('BACKEND_UNAVAILABLE', reasonMessage(reason, 'Function execution is unavailable.'), reason);
77
- }
78
- }
79
- function classifyAuthentication(input) {
80
- switch (input.code) {
81
- case 'NO_AUTH':
82
- return publicError('AUTH_MISSING', 'Authentication is required.');
83
- case 'INVALID_CREDENTIAL':
84
- case 'INVALID_GRANT':
85
- case 'IDENTITY_NOT_FOUND':
86
- case 'ISSUER_INVALID':
87
- case 'ISSUER_NOT_FOUND':
88
- return publicError('AUTH_INVALID', 'Credential is invalid.');
89
- case 'GRANT_BROADENING':
90
- case 'PROVISION_DENIED':
91
- return publicError('ACCESS_DENIED', 'Access denied.');
92
- case 'PROVISION_INVALID':
93
- return publicError('VALIDATION_ERROR', 'Identity provision request is invalid.', input.code);
94
- case 'IDENTITY_CONFLICT':
95
- case 'PROVISION_CONFLICT':
96
- case 'TRUST_REVISION_CONFLICT':
97
- return publicError('CONFLICT', 'Authentication state changed.', input.code);
98
- case 'PROVISION_OUTCOME_UNKNOWN':
99
- return publicError('OUTCOME_UNKNOWN', 'Identity provision outcome is unknown; do not retry automatically.', input.code);
100
- case 'TRUST_UPDATE_OUTCOME_UNKNOWN':
101
- return publicError('OUTCOME_UNKNOWN', 'Authentication Trust outcome is unknown; do not retry automatically.', input.code);
102
- case 'TRUST_INVALID':
103
- return internal(input);
104
- case 'MINT_FAILED':
105
- case 'AUTHENTICATION_BACKEND_FAILED':
106
- return publicError('BACKEND_UNAVAILABLE', 'Authentication is unavailable.');
107
- }
108
- }
109
- function classifyAuthorization(input) {
110
- switch (input.code) {
111
- case 'POLICY_NOT_FOUND':
112
- case 'CAPABILITY_TARGET_INVALID':
113
- return publicError('NOT_FOUND', 'Requested resource was not found.');
114
- case 'POLICY_COMPILATION_FAILED':
115
- return internal(input);
116
- case 'POLICY_SNAPSHOT_MISMATCH':
117
- return publicError('CONFLICT', 'Authorization basis changed.', input.code);
118
- case 'POLICY_PLAN_TOO_COMPLEX':
119
- return publicError('LIMIT_EXCEEDED', 'Authorization plan limit exceeded.', input.code);
120
- case 'POLICY_EVALUATION_TIMEOUT':
121
- return publicError('DEADLINE_EXCEEDED', 'Authorization evaluation deadline exceeded.', input.code);
122
- case 'POLICY_BACKEND_ERROR':
123
- return publicError('BACKEND_UNAVAILABLE', 'Authorization is unavailable.');
124
- case 'AUTHORITY_DENIED':
125
- return publicError('ACCESS_DENIED', 'Access denied.');
126
- case 'RESULT_CONTRACT_VIOLATION':
127
- return internal(input);
128
- }
129
- }
130
- function classifySchema(input) {
131
- if (input.outcome === 'unknown') {
132
- return publicError('OUTCOME_UNKNOWN', 'Schema activation outcome is unknown; do not retry automatically.', input.code);
133
- }
134
- switch (input.code) {
135
- case 'SCHEMA_INPUT_INVALID':
136
- return publicError('VALIDATION_ERROR', 'Schema request is invalid.');
137
- case 'SCHEMA_NOT_FOUND':
138
- return publicError('NOT_FOUND', 'Domain was not found.');
139
- case 'SCHEMA_ARTIFACT_INVALID':
140
- case 'SCHEMA_DEPENDENCY_MISSING':
141
- return publicError('VALIDATION_ERROR', 'Domain schema is invalid.');
142
- case 'SCHEMA_ARTIFACT_UNAVAILABLE':
143
- return publicError('NOT_FOUND', 'Domain Runtime artifact is unavailable.');
144
- case 'SCHEMA_REVISION_CONFLICT':
145
- return publicError('CONFLICT', 'Domain revision conflicts with current state.');
146
- case 'SCHEMA_OPERATION_CONFLICT':
147
- return publicError('CONFLICT', 'Schema operation identity conflicts with retained state.');
148
- case 'SCHEMA_REQUIREMENTS_UNSATISFIED':
149
- return publicError('ACCESS_DENIED', 'Domain installation requirements are not satisfied.');
150
- case 'SCHEMA_DEPENDENTS_PRESENT':
151
- return publicError('CONFLICT', 'Domain has active dependents.');
152
- case 'DATA_MIGRATION_REQUIRED':
153
- return publicError('CONFLICT', 'Schema change requires an explicit data migration.');
154
- case 'SCHEMA_UPGRADE_INCOMPATIBLE':
155
- return publicError('UNSUPPORTED', 'Schema operation is not supported.');
156
- case 'BACKEND_FEATURE_UNSUPPORTED':
157
- return publicError('UNSUPPORTED', 'Schema operation is not supported.', input.code);
158
- case 'SCHEMA_BACKEND_FAILED':
159
- case 'SCHEMA_ACTIVATION_FAILED':
160
- return publicError('BACKEND_UNAVAILABLE', 'Schema backend is unavailable.', input.code);
161
- case 'SCHEMA_INTEGRITY_ERROR':
162
- return internal(input);
163
- }
164
- }
165
- function classifyEvent(input) {
166
- switch (input.code) {
167
- case 'EVENT_INVALID':
168
- return publicError('VALIDATION_ERROR', 'Event request is invalid.', input.code);
169
- case 'EVENT_RETENTION_GAP':
170
- return publicError('CONFLICT', 'Event retention frontier is no longer available.', input.code);
171
- case 'SUBSCRIPTION_UNAVAILABLE':
172
- return publicError('CONFLICT', 'Event subscription is unavailable.', input.code);
173
- case 'EVENT_BACKEND_FAILED':
174
- return publicError('BACKEND_UNAVAILABLE', 'Event transport is unavailable.');
175
- }
176
- }
177
- function classifyObservability(input) {
178
- switch (input.code) {
179
- case 'OBSERVABILITY_INVALID':
180
- return publicError('VALIDATION_ERROR', 'Journal request is invalid.', input.code);
181
- case 'OBSERVABILITY_RETENTION_GAP':
182
- return publicError('CONFLICT', 'Journal retention frontier is no longer available.', input.code);
183
- case 'OBSERVABILITY_DURABILITY_FAILED':
184
- case 'OBSERVABILITY_BACKEND_FAILED':
185
- return publicError('BACKEND_UNAVAILABLE', 'Journal is unavailable.');
186
- }
187
- }
188
- function classifyNetwork(input) {
189
- switch (input.code) {
190
- case 'NETWORK_INVALID':
191
- case 'INVALID_URL':
192
- return publicError('VALIDATION_ERROR', 'Network request is invalid.', input.code);
193
- case 'UNSUPPORTED_PROTOCOL':
194
- case 'UNSUPPORTED_FEATURE':
195
- return publicError('UNSUPPORTED', 'Network operation is not supported.', input.code);
196
- case 'HOST_POLICY_DENIED':
197
- return publicError('ACCESS_DENIED', 'Network target is denied.');
198
- case 'TIMEOUT':
199
- return publicError('DEADLINE_EXCEEDED', 'Network operation deadline exceeded.', input.code);
200
- case 'ABORTED':
201
- return publicError('CANCELLED', 'Network operation was cancelled.', input.code);
202
- case 'TOO_MANY_REDIRECTS':
203
- case 'REQUEST_TOO_LARGE':
204
- case 'RESPONSE_BODY_TOO_LARGE':
205
- return publicError('LIMIT_EXCEEDED', 'Network operation limit exceeded.', input.code);
206
- case 'NETWORK_BACKEND_CONTRACT':
207
- return internal(input);
208
- case 'DNS_ERROR':
209
- case 'CONNECT_ERROR':
210
- case 'TLS_ERROR':
211
- case 'NETWORK_ERROR':
212
- return publicError('BACKEND_UNAVAILABLE', 'Network transport is unavailable.');
213
- }
214
- }
215
- function publicError(name, message, reason) {
216
- const candidate = typeof reason === 'string'
217
- ? Object.freeze({ code: reason, details: Object.freeze({}) })
218
- : reason;
219
- const admitted = errors.reasonOf(candidate);
220
- return {
221
- code: errors.CODES[name],
222
- message,
223
- ...(admitted === undefined ? {} : { data: admitted }),
224
- };
225
- }
226
- function reasonMessage(reason, fallback) {
227
- switch (reason?.code) {
228
- case 'SCHEMA_NOT_FOUND':
229
- return 'Domain was not found.';
230
- case 'SCHEMA_ARTIFACT_INVALID':
231
- case 'SCHEMA_DEPENDENCY_MISSING':
232
- return 'Domain schema is invalid.';
233
- case 'SCHEMA_REVISION_CONFLICT':
234
- return 'Domain revision conflicts with current state.';
235
- case 'SCHEMA_OPERATION_CONFLICT':
236
- return 'Schema operation identity conflicts with retained state.';
237
- case 'SCHEMA_DEPENDENTS_PRESENT':
238
- return 'Domain has active dependents.';
239
- case 'DATA_MIGRATION_REQUIRED':
240
- return 'Schema change requires an explicit data migration.';
241
- case 'BACKEND_FEATURE_UNSUPPORTED':
242
- case 'SCHEMA_UPGRADE_INCOMPATIBLE':
243
- return 'Schema operation is not supported.';
244
- case 'SCHEMA_BACKEND_FAILED':
245
- case 'SCHEMA_ACTIVATION_FAILED':
246
- return 'Schema backend is unavailable.';
247
- default:
248
- return fallback;
249
- }
20
+ function publicError(name, message) {
21
+ return { code: errors.CODES[name], message };
250
22
  }
251
23
  function internal(input) {
252
24
  reportInternal(input);
253
25
  return publicError('INTERNAL_ERROR', 'Internal application error.');
254
26
  }
255
- function reportUnknownFunction(input) {
256
- const cause = input.cause;
257
- const error = cause instanceof Error ? cause : undefined;
258
- const failureCode = typeof input.details.failureCode === 'string' ? input.details.failureCode : undefined;
259
- if (cause === undefined && failureCode === undefined)
260
- return;
261
- // Never print the message, stack, cause, input, credentials, or backend command.
262
- // oxlint-disable-next-line no-console
263
- console.error('[server] Function outcome is unknown', {
264
- type: error?.constructor.name ?? typeof cause,
265
- code: stableCode(cause),
266
- failureCode,
267
- ...(hostDebugErrors() ? { trail: stableErrorTrail(input.cause) } : {}),
268
- });
269
- }
270
- function hostDebugErrors() {
271
- const runtime = Reflect.get(globalThis, 'process');
272
- if (runtime === null || typeof runtime !== 'object')
273
- return false;
274
- const environment = Reflect.get(runtime, 'env');
275
- return (environment !== null &&
276
- typeof environment === 'object' &&
277
- Reflect.get(environment, 'KERNEL_HOST_DEBUG_ERRORS') === '1');
278
- }
279
- function stableErrorTrail(input) {
280
- if (!(input instanceof Error))
281
- return Object.freeze([]);
282
- const current = Object.freeze({
283
- type: input.constructor.name,
284
- code: stableCode(input),
285
- ...('phase' in input && typeof input.phase === 'string' ? { phase: input.phase } : {}),
286
- ...(stableSchemaCoordinate(input) === undefined
287
- ? {}
288
- : { coordinate: stableSchemaCoordinate(input) }),
289
- });
290
- if (input instanceof AggregateError) {
291
- return Object.freeze([current, ...input.errors.flatMap((cause) => stableErrorTrail(cause))]);
292
- }
293
- return Object.freeze([current, ...stableErrorTrail(input.cause)]);
294
- }
295
- function stableSchemaCoordinate(input) {
296
- if (stableCode(input) !== 'DOMAIN_DEFINITION_NOT_FOUND')
297
- return undefined;
298
- const match = /^Definition ([a-z0-9.-]+:[a-z]+\.[A-Za-z][A-Za-z0-9_]*) does not exist\.$/u.exec(input.message);
299
- return match?.[1];
300
- }
301
27
  function stableCode(input) {
302
28
  if (input !== null && typeof input === 'object' && 'code' in input) {
303
29
  return typeof input.code === 'string' ? input.code : undefined;
@@ -313,4 +39,3 @@ function reportInternal(input) {
313
39
  code: stableCode(input),
314
40
  });
315
41
  }
316
- //# sourceMappingURL=classify.js.map
@@ -2,4 +2,3 @@ export { DeliveryUnavailableError, IssuerKeysUnavailableError } from './availabi
2
2
  export { classifyError } from './classify.js';
3
3
  export { RequestBodyInvalidError, RequestBodyTooLargeError } from './request-body.js';
4
4
  export { ResponseBodyTooLargeError } from './response-body.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,3 @@ export { DeliveryUnavailableError, IssuerKeysUnavailableError } from './availabi
2
2
  export { classifyError } from './classify.js';
3
3
  export { RequestBodyInvalidError, RequestBodyTooLargeError } from './request-body.js';
4
4
  export { ResponseBodyTooLargeError } from './response-body.js';
5
- //# sourceMappingURL=index.js.map
@@ -5,4 +5,3 @@ export declare class RequestBodyTooLargeError extends Error {
5
5
  export declare class RequestBodyInvalidError extends Error {
6
6
  constructor(message: string);
7
7
  }
8
- //# sourceMappingURL=request-body.d.ts.map
@@ -12,4 +12,3 @@ export class RequestBodyInvalidError extends Error {
12
12
  this.name = 'RequestBodyInvalidError';
13
13
  }
14
14
  }
15
- //# sourceMappingURL=request-body.js.map
@@ -2,4 +2,3 @@ export declare class ResponseBodyTooLargeError extends Error {
2
2
  readonly maximumBytes: number;
3
3
  constructor(maximumBytes: number);
4
4
  }
5
- //# sourceMappingURL=response-body.d.ts.map
@@ -6,4 +6,3 @@ export class ResponseBodyTooLargeError extends Error {
6
6
  this.name = 'ResponseBodyTooLargeError';
7
7
  }
8
8
  }
9
- //# sourceMappingURL=response-body.js.map
package/dist/index.d.ts CHANGED
@@ -2,5 +2,4 @@ export { createServer, prepareServer } from './server.js';
2
2
  export { DeliveryUnavailableError, IssuerKeysUnavailableError } from './errors/index.js';
3
3
  export { preparePublicationSnapshot } from './publication/index.js';
4
4
  export * as publication from './publication/index.js';
5
- export type { Application, ApplicationHost, CorsConfig, Handler, HandlerRequest, HealthProbe, InvocationContext, Issuer, exchange, PreparedServer, PublicationSnapshot, PublicationSnapshotInput, PublicationSource, Server, ServerCloseOptions, ServerConfig, ServerLimits, ServerOptions, WebSocketAdapter, WebSocketHandlers, WebSocketLike, WebSocketUpgradeOptions, } from './types.js';
6
- //# sourceMappingURL=index.d.ts.map
5
+ export type { Application, ApplicationHost, CorsConfig, ExecutionControl, Handler, HandlerRequest, HandlerResult, HandlerStream, HealthProbe, InvocationContext, InvocationSource, RequestBackground, RequestEvidence, RequestSleep, Issuer, exchange, PreparedServer, PublicationSnapshot, PublicationSnapshotInput, PublicationSource, Server, ServerCloseOptions, ServerConfig, ServerLimits, ServerOptions, WebSocketAdapter, WebSocketHandlers, WebSocketLike, WebSocketUpgradeOptions, } from './types.js';
package/dist/index.js CHANGED
@@ -2,4 +2,3 @@ export { createServer, prepareServer } from './server.js';
2
2
  export { DeliveryUnavailableError, IssuerKeysUnavailableError } from './errors/index.js';
3
3
  export { preparePublicationSnapshot } from './publication/index.js';
4
4
  export * as publication from './publication/index.js';
5
- //# sourceMappingURL=index.js.map
@@ -1,7 +1,6 @@
1
- import type { invocation as protocol } from '@astrale-os/kernel-protocol';
1
+ import type * as protocol from '@astrale-os/kernel-protocol/invocation';
2
2
  import type { ActiveOperation, ActiveOperations } from '../lifecycle/index.js';
3
3
  import type { ApplicationHost, InvocationContext } from './types.js';
4
- export declare function invocationContext(operation: ActiveOperation, active: ActiveOperations, host?: ApplicationHost, requestBody?: Uint8Array, idempotencyKey?: protocol.IdempotencyKey, delegate?: InvocationContext['delegate']): InvocationContext;
4
+ export declare function invocationContext(assigned: protocol.InvocationId, operation: ActiveOperation, active: ActiveOperations, host?: ApplicationHost, requestBody?: Uint8Array, idempotencyKey?: protocol.IdempotencyKey): InvocationContext;
5
5
  /** Default non-durable timer used when the application host supplies no timer capability. */
6
6
  export declare function defaultSleep(durationMs: number): Promise<void>;
7
- //# sourceMappingURL=context.d.ts.map
@@ -1,13 +1,13 @@
1
- export function invocationContext(operation, active, host, requestBody, idempotencyKey, delegate) {
1
+ export function invocationContext(assigned, operation, active, host, requestBody, idempotencyKey) {
2
2
  const body = requestBody?.slice();
3
3
  return Object.freeze({
4
+ invocation: assigned,
4
5
  execution: Object.freeze({ deadline: operation.deadline, signal: operation.signal }),
5
6
  background: (task) => active.background(task, host?.waitUntil),
6
7
  sleep: async (durationMs) => {
7
8
  await interruptibleSleep(sleepDuration(durationMs), operation.signal, host?.sleep);
8
9
  },
9
10
  ...(idempotencyKey === undefined ? {} : { idempotencyKey }),
10
- ...(delegate === undefined ? {} : { delegate }),
11
11
  ...(body === undefined ? {} : { request: Object.freeze({ body: () => body.slice() }) }),
12
12
  });
13
13
  }
@@ -58,4 +58,3 @@ function sleepDuration(input) {
58
58
  }
59
59
  return input;
60
60
  }
61
- //# sourceMappingURL=context.js.map
@@ -0,0 +1,9 @@
1
+ import type { IssuerId } from '@astrale-os/kernel-core/auth';
2
+ import type * as protocol from '@astrale-os/kernel-protocol/invocation';
3
+ /** Injected source-owned identity allocator captured before Server readiness. */
4
+ export interface InvocationSource {
5
+ readonly source: IssuerId;
6
+ next(): string;
7
+ }
8
+ export type NextInvocationId = () => protocol.InvocationId;
9
+ export declare function captureInvocationSource(input: InvocationSource): NextInvocationId;
@@ -0,0 +1,11 @@
1
+ import { issuer } from '@astrale-os/kernel-core/auth';
2
+ import * as protocolInvocation from '@astrale-os/kernel-protocol/invocation';
3
+ import { captureMethod } from '../capture.js';
4
+ export function captureInvocationSource(input) {
5
+ if (input === null || typeof input !== 'object') {
6
+ throw new TypeError('Server Invocation source is invalid.');
7
+ }
8
+ const source = issuer.accept(input.source);
9
+ const next = captureMethod(input, 'next', 'Server Invocation source is invalid.');
10
+ return () => protocolInvocation.acceptInvocationId({ source, id: next() });
11
+ }
@@ -1,4 +1,4 @@
1
1
  export { defaultSleep, invocationContext } from './context.js';
2
+ export { captureInvocationSource, type InvocationSource, type NextInvocationId, } from './identity.js';
2
3
  export { publicationRouteDecision, type PublicationRouteDecision } from './publication-route.js';
3
- export type { ApplicationHost, Handler, HandlerRequest, InvocationContext } from './types.js';
4
- //# sourceMappingURL=index.d.ts.map
4
+ export type { ApplicationHost, ExecutionControl, Handler, HandlerRequest, HandlerResult, HandlerStream, InvocationContext, RequestBackground, RequestEvidence, RequestSleep, } from './types.js';
@@ -1,3 +1,3 @@
1
1
  export { defaultSleep, invocationContext } from './context.js';
2
+ export { captureInvocationSource, } from './identity.js';
2
3
  export { publicationRouteDecision } from './publication-route.js';
3
- //# sourceMappingURL=index.js.map
@@ -1,12 +1,13 @@
1
- import type { errors, publication } from '@astrale-os/kernel-protocol';
1
+ import type { ErrorPayload } from '@astrale-os/kernel-protocol/errors';
2
+ import type { Publication } from '@astrale-os/kernel-protocol/publication/publication';
3
+ import type { PublicationRef } from '@astrale-os/kernel-protocol/publication/reference';
2
4
  export type PublicationRouteDecision = {
3
5
  readonly kind: 'exact';
4
6
  } | {
5
7
  readonly kind: 'same-schema';
6
8
  } | {
7
9
  readonly kind: 'rejected';
8
- readonly error: errors.ErrorPayload;
10
+ readonly error: ErrorPayload;
9
11
  };
10
12
  /** Compare untrusted installed routing evidence with the one captured serving Publication. */
11
- export declare function publicationRouteDecision(current: publication.Publication, installed: publication.PublicationRef): PublicationRouteDecision;
12
- //# sourceMappingURL=publication-route.d.ts.map
13
+ export declare function publicationRouteDecision(current: Publication, installed: PublicationRef): PublicationRouteDecision;
@@ -1,14 +1,16 @@
1
- import { errors as protocolErrors, invocation, publication as publications, } from '@astrale-os/kernel-protocol';
1
+ import { CODES } from '@astrale-os/kernel-protocol/errors';
2
+ import { SCHEMA_UPGRADE_REQUIRED, SERVICE_TRUST_REQUIRED, } from '@astrale-os/kernel-protocol/invocation/service-reason';
3
+ import { compareReference } from '@astrale-os/kernel-protocol/publication/reference';
2
4
  /** Compare untrusted installed routing evidence with the one captured serving Publication. */
3
5
  export function publicationRouteDecision(current, installed) {
4
- switch (publications.compareReference(current, installed)) {
6
+ switch (compareReference(current, installed)) {
5
7
  case 'exact':
6
8
  return Object.freeze({ kind: 'exact' });
7
9
  case 'same-schema':
8
10
  return Object.freeze({ kind: 'same-schema' });
9
11
  case 'schema-drift':
10
12
  return rejected('Installed Domain schema requires an explicit upgrade.', Object.freeze({
11
- code: invocation.SCHEMA_UPGRADE_REQUIRED,
13
+ code: SCHEMA_UPGRADE_REQUIRED,
12
14
  details: Object.freeze({
13
15
  origin: installed.origin,
14
16
  installedRevision: installed.revision,
@@ -17,7 +19,7 @@ export function publicationRouteDecision(current, installed) {
17
19
  }));
18
20
  case 'identity-drift':
19
21
  return rejected('Installed Domain Service identity requires explicit trust.', Object.freeze({
20
- code: invocation.SERVICE_TRUST_REQUIRED,
22
+ code: SERVICE_TRUST_REQUIRED,
21
23
  details: Object.freeze({
22
24
  origin: installed.origin,
23
25
  installedIssuer: installed.identity.issuer,
@@ -28,7 +30,7 @@ export function publicationRouteDecision(current, installed) {
28
30
  return Object.freeze({
29
31
  kind: 'rejected',
30
32
  error: Object.freeze({
31
- code: protocolErrors.CODES.INVALID_REQUEST,
33
+ code: CODES.INVALID_REQUEST,
32
34
  message: 'Routed Publication origin differs from the served Domain.',
33
35
  }),
34
36
  });
@@ -37,7 +39,6 @@ export function publicationRouteDecision(current, installed) {
37
39
  function rejected(message, data) {
38
40
  return Object.freeze({
39
41
  kind: 'rejected',
40
- error: Object.freeze({ code: protocolErrors.CODES.CONFLICT, message, data }),
42
+ error: Object.freeze({ code: CODES.CONFLICT, message, data }),
41
43
  });
42
44
  }
43
- //# sourceMappingURL=publication-route.js.map
@@ -1,22 +1,49 @@
1
1
  import type { CredentialInput } from '@astrale-os/kernel-core/auth';
2
- import type { InboundRequestOptions, RequestBackground, RequestSleep } from '@astrale-os/kernel-ports';
3
- import type { Call, Result } from '@astrale-os/kernel-ports/functions';
4
- import type { invocation as protocol } from '@astrale-os/kernel-protocol';
2
+ import type { CallableResult } from '@astrale-os/kernel-core/callable';
3
+ import type { Value } from '@astrale-os/kernel-dsl/value';
4
+ import type * as protocol from '@astrale-os/kernel-protocol/invocation';
5
5
  import type { PublicationSnapshot } from '../publication/index.js';
6
6
  /** Optional platform retention and timer adaptation for one Fetch invocation. */
7
7
  export interface ApplicationHost {
8
8
  waitUntil(promise: Promise<unknown>): void;
9
9
  readonly sleep?: (durationMs: number) => Promise<void>;
10
10
  }
11
+ /** Ephemeral execution lifetime for one admitted request. */
12
+ export interface ExecutionControl {
13
+ readonly deadline: number;
14
+ readonly signal: AbortSignal;
15
+ }
16
+ /** Register non-durable work with the request owner. */
17
+ export type RequestBackground = (task: () => void | PromiseLike<unknown>) => void;
18
+ /** Request-owner timer bounded by the same cancellation and deadline. */
19
+ export type RequestSleep = (durationMs: number) => Promise<void>;
20
+ /** Exact bounded ingress evidence retained outside portable Function input. */
21
+ export interface RequestEvidence {
22
+ body(): Uint8Array;
23
+ }
11
24
  /** Immutable lifetime and execution conveniences for one admitted dispatch. */
12
- export interface InvocationContext extends InboundRequestOptions {
25
+ export interface InvocationContext {
26
+ readonly invocation: protocol.InvocationId;
27
+ readonly execution: ExecutionControl;
28
+ readonly idempotencyKey?: protocol.IdempotencyKey;
29
+ readonly request?: RequestEvidence;
13
30
  readonly background: RequestBackground;
14
31
  /** Rejects promptly when execution is cancelled or reaches its deadline. */
15
32
  readonly sleep: RequestSleep;
16
33
  }
34
+ export interface HandlerStream extends AsyncIterable<Value> {
35
+ cancel(reason?: string): Promise<void>;
36
+ }
37
+ /** Complete semantic result accepted from one ready application Handler. */
38
+ export type HandlerResult = CallableResult<Value, HandlerStream> | {
39
+ readonly kind: 'redirect';
40
+ readonly redirect: protocol.Redirection;
41
+ } | {
42
+ readonly kind: 'miss';
43
+ };
17
44
  /** Ready semantic capability invoked by canonical and advertised transport routes. */
18
45
  export interface HandlerRequest {
19
- readonly call: Call;
46
+ readonly call: protocol.Call;
20
47
  /** Admitted transport correlation syntax, separate from semantic execution options. */
21
48
  readonly trace?: protocol.Trace;
22
49
  readonly credential?: CredentialInput;
@@ -31,8 +58,5 @@ export interface HandlerRequest {
31
58
  readonly context: InvocationContext;
32
59
  }
33
60
  export interface Handler {
34
- dispatch(request: HandlerRequest): Promise<Result | {
35
- readonly kind: 'miss';
36
- }>;
61
+ dispatch(request: HandlerRequest): Promise<HandlerResult>;
37
62
  }
38
- //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map