@ultrst-armada/kloks 1.4.3 → 1.4.5

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 (79) hide show
  1. package/package.json +8 -20
  2. package/packages/audio-midi/dist/index.d.ts +23 -14
  3. package/packages/audio-midi/dist/index.js +170 -45
  4. package/packages/audio-midi/kloks.manifest.json +8 -8
  5. package/packages/audio-midi/package.json +1 -1
  6. package/packages/backend/dist/{WebSocketTransport-CxUzUfwl.d.ts → WebSocketTransport-CHmkJ0tj.d.ts} +109 -2
  7. package/packages/backend/dist/auth/index.js +6 -6
  8. package/packages/backend/dist/{chunk-T3NYNBDC.js → chunk-5E6JRFUH.js} +201 -3
  9. package/packages/backend/dist/{chunk-XTWHEZWS.js → chunk-7B24ZWB3.js} +16 -1
  10. package/packages/backend/dist/chunk-DULUHQ5S.js +597 -0
  11. package/packages/backend/dist/{chunk-4ZFXEFOE.js → chunk-MPYASJ5A.js} +2 -87
  12. package/packages/backend/dist/{chunk-KX3OTBQ3.js → chunk-OZDYAEH4.js} +0 -114
  13. package/packages/backend/dist/{chunk-FO6WYLW4.js → chunk-TQMLJ7NY.js} +131 -44
  14. package/packages/backend/dist/chunk-TY32TUNI.js +376 -0
  15. package/packages/backend/dist/chunk-VDROUXFT.js +116 -0
  16. package/packages/backend/dist/chunk-ZDH4XI7W.js +140 -0
  17. package/packages/backend/dist/{chunk-DZ4ZGIZM.js → chunk-ZO3PZGNQ.js} +96 -655
  18. package/packages/backend/dist/client/index.d.ts +2 -3
  19. package/packages/backend/dist/connectivity/index.d.ts +18 -6
  20. package/packages/backend/dist/connectivity/index.js +3 -7
  21. package/packages/backend/dist/index.d.ts +3 -6
  22. package/packages/backend/dist/index.js +98 -88
  23. package/packages/backend/dist/krnl-services.d.ts +84 -7
  24. package/packages/backend/dist/krnl-services.js +40 -12
  25. package/packages/backend/dist/services/index.d.ts +4 -6
  26. package/packages/backend/dist/services/index.js +2 -2
  27. package/packages/backend/dist/srkl/index.js +6 -4
  28. package/packages/backend/dist/storage/index.js +7 -7
  29. package/packages/backend/dist/workspace/index.js +2 -2
  30. package/packages/backend/kloks.manifest.json +47 -45
  31. package/packages/backend/package.json +3 -8
  32. package/packages/client/package.json +1 -1
  33. package/packages/contracts/dist/index.js +5 -10
  34. package/packages/contracts/package.json +1 -1
  35. package/packages/functions/dist/index.d.ts +12 -1
  36. package/packages/functions/dist/index.js +132 -24
  37. package/packages/functions/package.json +1 -1
  38. package/packages/orchestrations/dist/index.d.ts +33 -31
  39. package/packages/orchestrations/dist/index.js +81 -203
  40. package/packages/orchestrations/kloks.manifest.json +10 -2
  41. package/packages/orchestrations/package.json +2 -2
  42. package/packages/services/dist/index.d.ts +51 -1
  43. package/packages/services/dist/index.js +234 -36
  44. package/packages/services/kloks.manifest.json +69 -33
  45. package/packages/services/package.json +1 -1
  46. package/packages/state-graph/dist/{BaseGraph-BvkSYOTw.d.ts → BaseGraph-Bd5F1NMP.d.ts} +1 -1
  47. package/packages/state-graph/dist/{BaseNode-DTcd3K1B.d.ts → BaseNode-DKpGXMy8.d.ts} +6 -0
  48. package/packages/state-graph/dist/{CompatibilityMatrix-Dj-tCWUA.d.ts → CompatibilityMatrix-TiEJ3j3_.d.ts} +1 -1
  49. package/packages/state-graph/dist/domain/index.d.ts +3 -3
  50. package/packages/state-graph/dist/domain/index.js +0 -1
  51. package/packages/state-graph/dist/index.d.ts +40 -8
  52. package/packages/state-graph/dist/index.js +214 -65
  53. package/packages/state-graph/dist/rules/index.d.ts +3 -3
  54. package/packages/state-graph/dist/rules/index.js +0 -1
  55. package/packages/state-graph/dist/spatial/index.d.ts +4 -4
  56. package/packages/state-graph/dist/spatial/index.js +0 -1
  57. package/packages/state-graph/dist/state/index.js +1 -3
  58. package/packages/state-graph/dist/store/index.d.ts +4 -4
  59. package/packages/state-graph/dist/store/index.js +0 -1
  60. package/packages/state-graph/dist/{types-VDoc4FIc.d.ts → types-D5kQSa65.d.ts} +2 -2
  61. package/packages/state-graph/kloks.manifest.json +26 -10
  62. package/packages/state-graph/package.json +2 -8
  63. package/packages/backend/dist/IdempotencyManager-B5MjK871.d.ts +0 -16
  64. package/packages/backend/dist/chunk-25Y7AVTP.js +0 -55
  65. package/packages/backend/dist/chunk-3EPY34R6.js +0 -67
  66. package/packages/backend/dist/chunk-7KNGX522.js +0 -220
  67. package/packages/backend/dist/chunk-FZKBTF34.js +0 -15
  68. package/packages/backend/dist/chunk-QGHDJGYS.js +0 -92
  69. package/packages/backend/dist/chunk-UPFKBBQI.js +0 -138
  70. package/packages/backend/dist/chunk-VQEFULWT.js +0 -88
  71. package/packages/backend/dist/execution/index.d.ts +0 -124
  72. package/packages/backend/dist/execution/index.js +0 -20
  73. package/packages/backend/dist/types-BERZJ93O.d.ts +0 -110
  74. package/packages/state-graph/dist/chunk-3RG5ZIWI.js +0 -10
  75. package/packages/state-graph/dist/chunk-Q5I42UX7.js +0 -0
  76. package/packages/state-graph/dist/chunk-ZTHBPV24.js +0 -267
  77. package/packages/state-graph/dist/execution/index.d.ts +0 -152
  78. package/packages/state-graph/dist/execution/index.js +0 -16
  79. /package/packages/state-graph/dist/{chunk-SHIBCPGQ.js → chunk-EW4ACSZB.js} +0 -0
@@ -1,11 +1,4 @@
1
1
  import "../chunk-LS3HWJBX.js";
2
- import {
3
- authorizeB2,
4
- b2DownloadFile,
5
- b2ListBuckets,
6
- b2ListFileNames,
7
- b2UploadFile
8
- } from "../chunk-4QEMALXF.js";
9
2
  import {
10
3
  BackblazeB2Adapter,
11
4
  BaseStorageAdapter,
@@ -21,6 +14,13 @@ import {
21
14
  renameS3Folder,
22
15
  resolveBackblazeEndpoint
23
16
  } from "../chunk-J2J24JVC.js";
17
+ import {
18
+ authorizeB2,
19
+ b2DownloadFile,
20
+ b2ListBuckets,
21
+ b2ListFileNames,
22
+ b2UploadFile
23
+ } from "../chunk-4QEMALXF.js";
24
24
  export {
25
25
  BackblazeB2Adapter,
26
26
  BaseStorageAdapter,
@@ -6,11 +6,11 @@ import {
6
6
  WorkspaceFS,
7
7
  remoteWorkspaceService,
8
8
  workingWorkspaceService
9
- } from "../chunk-DZ4ZGIZM.js";
9
+ } from "../chunk-DULUHQ5S.js";
10
10
  import {
11
11
  formatCanonicalWorkspaceFolderName,
12
12
  sanitizeWorkspaceName
13
- } from "../chunk-FZKBTF34.js";
13
+ } from "../chunk-ZO3PZGNQ.js";
14
14
  export {
15
15
  RemoteWorkspaceService,
16
16
  SyncEngine,
@@ -14,13 +14,6 @@
14
14
  "export": "AuthServiceFacade",
15
15
  "facade": "AuthServiceFacade"
16
16
  },
17
- "ui": {
18
- "package": "@floks/ui",
19
- "components": [
20
- "LoginModal",
21
- "CredentialField"
22
- ]
23
- },
24
17
  "modes": [
25
18
  "backend",
26
19
  "fullstack"
@@ -33,7 +26,12 @@
33
26
  "App.main-content"
34
27
  ]
35
28
  },
36
- "dependencies": []
29
+ "dependencies": [],
30
+ "defaultFrontend": {
31
+ "component": "AuthPage",
32
+ "package": "@ultrst-armada/floks/ui",
33
+ "relationship": "recommended"
34
+ }
37
35
  },
38
36
  {
39
37
  "id": "storage",
@@ -46,12 +44,6 @@
46
44
  "export": "StorageServiceFacade",
47
45
  "facade": "StorageServiceFacade"
48
46
  },
49
- "ui": {
50
- "package": "@floks/ui",
51
- "components": [
52
- "BaseCard"
53
- ]
54
- },
55
47
  "modes": [
56
48
  "backend",
57
49
  "fullstack"
@@ -64,7 +56,14 @@
64
56
  "App.main-content"
65
57
  ]
66
58
  },
67
- "dependencies": []
59
+ "dependencies": [
60
+ "srkl"
61
+ ],
62
+ "defaultFrontend": {
63
+ "component": "WorkspaceTilesMenu",
64
+ "package": "@ultrst-armada/floks/ui",
65
+ "relationship": "recommended"
66
+ }
68
67
  },
69
68
  {
70
69
  "id": "workspace",
@@ -77,12 +76,6 @@
77
76
  "export": "WorkspaceServiceFacade",
78
77
  "facade": "WorkspaceServiceFacade"
79
78
  },
80
- "ui": {
81
- "package": "@floks/ui",
82
- "components": [
83
- "WorkspaceTilesMenu"
84
- ]
85
- },
86
79
  "modes": [
87
80
  "backend",
88
81
  "fullstack"
@@ -95,7 +88,16 @@
95
88
  "App.main-content"
96
89
  ]
97
90
  },
98
- "dependencies": []
91
+ "dependencies": [
92
+ "auth",
93
+ "storage",
94
+ "srkl"
95
+ ],
96
+ "defaultFrontend": {
97
+ "component": "WorkspaceTilesMenu",
98
+ "package": "@ultrst-armada/floks/ui",
99
+ "relationship": "recommended"
100
+ }
99
101
  },
100
102
  {
101
103
  "id": "control-plane",
@@ -108,12 +110,6 @@
108
110
  "export": "ControlPlaneServiceFacade",
109
111
  "facade": "ControlPlaneServiceFacade"
110
112
  },
111
- "ui": {
112
- "package": "@floks/ui",
113
- "components": [
114
- "StatusIndicator"
115
- ]
116
- },
117
113
  "modes": [
118
114
  "backend",
119
115
  "fullstack"
@@ -126,18 +122,23 @@
126
122
  "App.footer"
127
123
  ]
128
124
  },
129
- "dependencies": []
125
+ "dependencies": [],
126
+ "defaultFrontend": {
127
+ "component": "StatusIndicator",
128
+ "package": "@ultrst-armada/floks/ui",
129
+ "relationship": "recommended"
130
+ }
130
131
  },
131
132
  {
132
- "id": "execution",
133
- "name": "Execution & Worker Boundary",
133
+ "id": "database",
134
+ "name": "Database Service",
134
135
  "version": "1.0.0",
135
- "description": "Executable backend facade with isolated background worker boundary.",
136
+ "description": "SQL and transaction execution driver service.",
136
137
  "backend": {
137
138
  "package": "@kloks/backend",
138
139
  "subpath": "krnl-services",
139
- "export": "ExecutionServiceFacade",
140
- "facade": "ExecutionServiceFacade"
140
+ "export": "DatabaseServiceFacade",
141
+ "facade": "DatabaseServiceFacade"
141
142
  },
142
143
  "modes": [
143
144
  "backend"
@@ -150,15 +151,15 @@
150
151
  "dependencies": []
151
152
  },
152
153
  {
153
- "id": "database",
154
- "name": "Database Service",
154
+ "id": "gemini",
155
+ "name": "Google Gemini AI Service",
155
156
  "version": "1.0.0",
156
- "description": "SQL and transaction execution driver service.",
157
+ "description": "Gemini text and multimodal generation service.",
157
158
  "backend": {
158
159
  "package": "@kloks/backend",
159
160
  "subpath": "krnl-services",
160
- "export": "DatabaseServiceFacade",
161
- "facade": "DatabaseServiceFacade"
161
+ "export": "GeminiServiceFacade",
162
+ "facade": "GeminiServiceFacade"
162
163
  },
163
164
  "modes": [
164
165
  "backend"
@@ -171,18 +172,19 @@
171
172
  "dependencies": []
172
173
  },
173
174
  {
174
- "id": "gemini",
175
- "name": "Google Gemini AI Service",
175
+ "id": "srkl",
176
+ "name": "SRKL Credential Federation",
176
177
  "version": "1.0.0",
177
- "description": "Gemini text and multimodal generation service.",
178
+ "description": "Service-account discovery and Backblaze B2 bucket federation for reusable application modules.",
178
179
  "backend": {
179
180
  "package": "@kloks/backend",
180
181
  "subpath": "krnl-services",
181
- "export": "GeminiServiceFacade",
182
- "facade": "GeminiServiceFacade"
182
+ "export": "SrklServiceFacade",
183
+ "facade": "SrklServiceFacade"
183
184
  },
184
185
  "modes": [
185
- "backend"
186
+ "backend",
187
+ "fullstack"
186
188
  ],
187
189
  "targets": {
188
190
  "backend": [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kloks/backend",
3
3
  "version": "1.0.0",
4
- "description": "Kloks Backend Services — Auth, Storage, Workspace, Control Plane, API, Connectivity & Execution built on KrnlTS",
4
+ "description": "Kloks Backend Services \u2014 Auth, Storage, Workspace, Control Plane, API, Connectivity & Execution built on KrnlTS",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "publishConfig": {
@@ -58,11 +58,6 @@
58
58
  "types": "./dist/srkl/index.d.ts",
59
59
  "default": "./dist/srkl/index.js"
60
60
  },
61
- "./execution": {
62
- "import": "./dist/execution/index.js",
63
- "types": "./dist/execution/index.d.ts",
64
- "default": "./dist/execution/index.js"
65
- },
66
61
  "./services": {
67
62
  "import": "./dist/services/index.js",
68
63
  "types": "./dist/services/index.d.ts",
@@ -75,7 +70,7 @@
75
70
  }
76
71
  },
77
72
  "scripts": {
78
- "build": "tsup src/index.ts src/krnl-services.ts src/services/index.ts src/auth/index.ts src/storage/index.ts src/workspace/index.ts src/control-plane/index.ts src/api/index.ts src/connectivity/index.ts src/client/index.ts src/srkl/index.ts src/execution/index.ts --format esm --dts --clean --external @kloks/functions --external react --external @kloks/state-graph --external @neondatabase/serverless --external @supabase/supabase-js --external @aws-sdk/client-s3 --external @aws-sdk/lib-storage --external bcryptjs --external better-sqlite3 --external zod --external ws",
73
+ "build": "tsup src/index.ts src/krnl-services.ts src/services/index.ts src/auth/index.ts src/storage/index.ts src/workspace/index.ts src/control-plane/index.ts src/api/index.ts src/connectivity/index.ts src/client/index.ts src/srkl/index.ts --format esm --dts --clean --external @kloks/functions --external react --external @kloks/state-graph --external @neondatabase/serverless --external @supabase/supabase-js --external @aws-sdk/client-s3 --external @aws-sdk/lib-storage --external bcryptjs --external better-sqlite3 --external zod --external ws",
79
74
  "typecheck": "tsc --noEmit",
80
75
  "clean": "rm -rf dist"
81
76
  },
@@ -120,6 +115,6 @@
120
115
  }
121
116
  },
122
117
  "devDependencies": {
123
- "@ultrst-armada/krnl": "^1.0.2"
118
+ "@ultrst-armada/krnl": "^1.0.3"
124
119
  }
125
120
  }
@@ -36,6 +36,6 @@
36
36
  }
37
37
  },
38
38
  "devDependencies": {
39
- "@ultrst-armada/krnl": "^1.0.2"
39
+ "@ultrst-armada/krnl": "^1.0.3"
40
40
  }
41
41
  }
@@ -224,24 +224,20 @@ var KLOKS_PUBLIC_SURFACE = [
224
224
  { name: "MidiManager", subpath: "audio-midi", category: "audio-midi", hasZodSchema: false },
225
225
  { name: "AudioHardwareServiceFacade", subpath: "audio-midi", category: "audio-midi", hasZodSchema: false },
226
226
  { name: "MidiServiceFacade", subpath: "audio-midi", category: "audio-midi", hasZodSchema: false },
227
- { name: "AudioMidiOrchestratorFacade", subpath: "audio-midi", category: "audio-midi", hasZodSchema: false },
227
+ { name: "AudioMidiOrchestratorDefinition", subpath: "audio-midi", category: "audio-midi", hasZodSchema: false },
228
228
  { name: "AudioBusConfig", subpath: "audio-midi", category: "audio-midi", hasZodSchema: true },
229
229
  { name: "AudioHardwareState", subpath: "audio-midi", category: "audio-midi", hasZodSchema: true },
230
230
  { name: "MidiCommandType", subpath: "audio-midi", category: "audio-midi", hasZodSchema: true },
231
231
  { name: "MidiEventPayload", subpath: "audio-midi", category: "audio-midi", hasZodSchema: true },
232
232
  // ── orchestrations ──
233
- { name: "OrchestratorAFacade", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
234
- { name: "OrchestratorBFacade", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
235
- { name: "WorkspaceBackendFacade", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
236
- { name: "backendFacade", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
237
- { name: "workerExecutionBoundary", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
233
+ { name: "OrchestratorADefinition", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
234
+ { name: "OrchestratorBDefinition", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
235
+ { name: "AudioMidiOrchestratorDefinition", subpath: "orchestrations", category: "orchestrations", hasZodSchema: false },
238
236
  // ── backend ──
239
237
  { name: "AuthServiceFacade", subpath: "backend", category: "backend", hasZodSchema: false },
240
238
  { name: "StorageServiceFacade", subpath: "backend", category: "backend", hasZodSchema: false },
241
239
  { name: "WorkspaceServiceFacade", subpath: "backend", category: "backend", hasZodSchema: false },
242
240
  { name: "ControlPlaneServiceFacade", subpath: "backend", category: "backend", hasZodSchema: false },
243
- { name: "ExecutionServiceFacade", subpath: "backend", category: "backend", hasZodSchema: false },
244
- { name: "ExecutableBackendFacade", subpath: "backend", category: "backend", hasZodSchema: false },
245
241
  // ── services ──
246
242
  { name: "ServiceAFacade", subpath: "services", category: "services", hasZodSchema: false },
247
243
  { name: "ServiceBFacade", subpath: "services", category: "services", hasZodSchema: false },
@@ -276,10 +272,9 @@ var QWNSR_REQUIRED_SURFACE = [
276
272
  "createNodeInstance",
277
273
  "StateLifecycleServiceFacade",
278
274
  "NodeGraphEngineServiceFacade",
279
- "WorkspaceBackendFacade",
280
275
  "AudioHardwareServiceFacade",
281
276
  "MidiServiceFacade",
282
- "AudioMidiOrchestratorFacade"
277
+ "AudioMidiOrchestratorDefinition"
283
278
  ];
284
279
  function validateConsumerSurfaceCompatibility(requiredSymbols = QWNSR_REQUIRED_SURFACE, publicSurface = KLOKS_PUBLIC_SURFACE) {
285
280
  const publicNames = new Set(publicSurface.map((s) => s.name));
@@ -28,6 +28,6 @@
28
28
  "zod": "^3.24.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@ultrst-armada/krnl": "^1.0.2"
31
+ "@ultrst-armada/krnl": "^1.0.3"
32
32
  }
33
33
  }
@@ -384,5 +384,16 @@ declare const FunctionsServiceFacade: {
384
384
  createInstance: () => _ultrst_armada_krnl.ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
385
385
  execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
386
386
  };
387
+ declare const krnlFunctionsServiceDefinition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
388
+ declare const krnlFunctionsServiceFacade: {
389
+ id: string;
390
+ name: string;
391
+ version: string;
392
+ runtime: "server";
393
+ deployment: "local";
394
+ definition: ServiceDefinition<Record<string, unknown>, Record<string, unknown>>;
395
+ createInstance: () => _ultrst_armada_krnl.ServiceInstance<Record<string, unknown>, Record<string, unknown>>;
396
+ execute: <TIn = unknown, TOut = unknown>(op: string, input?: TIn) => Promise<TOut>;
397
+ };
387
398
 
388
- export { type Disposable, type EventListener, FileCache, FileLock, FunctionsServiceDefinition, FunctionsServiceFacade, LRUCache, type Logger, type Provider, type RealtimeWorkspaceEvent, type ReleaseFn, type Result, SkipoBase, type SkipoConfig, type SkipoHTTPOptions, type SkipoHTTPResult, type SpawnHandle, TTLCache, appendFile, copyDir, createClient, createTempDir, createTempFile, debounce, deepClone, deepEqual, deepMerge, del, deleteDir, deleteFile, dirExists, ensureDir, execCmd, fileExists, firstExisting, get, getEnv, getFileStat, getPath, getRecentEvents, interpolate, isPlaceholderConnection, listDir, loadEnv, memoize, objectDiff, once, pLimit, platform, post, prefixedId, publishRealtimeEvent, put, readFile, readJSON, request, requestRaw, requireEnv, retry, sanitizeDatabaseUrl, setPath, shortId, sleep, spawnCmd, streamResponse, subscribeRealtimeEvents, swr, throttle, toCamelCase, toKebabCase, toPascalCase, toScreamingSnake, toSlug, toSnakeCase, updateJSON, uuid, validateEnvSchema, walkDir, watchDir, watchFile, which, withTempDir, withTimeout, writeFile, writeFileAtomic, writeJSON };
399
+ export { type Disposable, type EventListener, FileCache, FileLock, FunctionsServiceDefinition, FunctionsServiceFacade, LRUCache, type Logger, type Provider, type RealtimeWorkspaceEvent, type ReleaseFn, type Result, SkipoBase, type SkipoConfig, type SkipoHTTPOptions, type SkipoHTTPResult, type SpawnHandle, TTLCache, appendFile, copyDir, createClient, createTempDir, createTempFile, debounce, deepClone, deepEqual, deepMerge, del, deleteDir, deleteFile, dirExists, ensureDir, execCmd, fileExists, firstExisting, get, getEnv, getFileStat, getPath, getRecentEvents, interpolate, isPlaceholderConnection, krnlFunctionsServiceDefinition, krnlFunctionsServiceFacade, listDir, loadEnv, memoize, objectDiff, once, pLimit, platform, post, prefixedId, publishRealtimeEvent, put, readFile, readJSON, request, requestRaw, requireEnv, retry, sanitizeDatabaseUrl, setPath, shortId, sleep, spawnCmd, streamResponse, subscribeRealtimeEvents, swr, throttle, toCamelCase, toKebabCase, toPascalCase, toScreamingSnake, toSlug, toSnakeCase, updateJSON, uuid, validateEnvSchema, walkDir, watchDir, watchFile, which, withTempDir, withTimeout, writeFile, writeFileAtomic, writeJSON };
@@ -1,4 +1,4 @@
1
- // ../../node_modules/.pnpm/@ultrst-armada+krnl@1.0.2/node_modules/@ultrst-armada/krnl/packages/core/dist/index.js
1
+ // ../../node_modules/.pnpm/@ultrst-armada+krnl@1.0.3/node_modules/@ultrst-armada/krnl/packages/core/dist/index.js
2
2
  var ServiceStateStore = class {
3
3
  state;
4
4
  listeners = /* @__PURE__ */ new Set();
@@ -52,17 +52,37 @@ var ServiceEventBus = class {
52
52
  this.handlers.clear();
53
53
  }
54
54
  };
55
+ var TRANSITIONS = {
56
+ uninitialized: ["initializing"],
57
+ initializing: ["ready", "uninitialized"],
58
+ ready: ["starting"],
59
+ starting: ["running", "ready"],
60
+ running: ["stopping"],
61
+ stopping: ["stopped", "running"],
62
+ stopped: ["starting"]
63
+ };
55
64
  var LifecycleManager = class {
56
65
  status = "uninitialized";
57
66
  getStatus() {
58
67
  return this.status;
59
68
  }
60
- setStatus(next) {
69
+ canTransitionTo(next) {
70
+ return TRANSITIONS[this.status].includes(next);
71
+ }
72
+ transitionTo(next) {
73
+ if (!this.canTransitionTo(next)) {
74
+ throw new Error("[Lifecycle] Invalid transition '" + this.status + "' -> '" + next + "'.");
75
+ }
61
76
  this.status = next;
62
77
  }
78
+ setStatus(next) {
79
+ this.transitionTo(next);
80
+ }
63
81
  assertRunning(serviceName) {
64
82
  if (this.status !== "running") {
65
- throw new Error(`[Service:${serviceName}] Cannot invoke operation while status is '${this.status}' (expected 'running').`);
83
+ throw new Error(
84
+ "[Service:" + serviceName + "] Cannot invoke operation while status is '" + this.status + "' (expected 'running')."
85
+ );
66
86
  }
67
87
  }
68
88
  };
@@ -74,7 +94,7 @@ var ServiceInstance = class {
74
94
  this.version = definition.version;
75
95
  this.lifecycle = new LifecycleManager();
76
96
  this.eventBus = new ServiceEventBus();
77
- if (definition.state?.initial) {
97
+ if (definition.state) {
78
98
  this.stateStore = new ServiceStateStore(definition.state.initial);
79
99
  }
80
100
  }
@@ -85,46 +105,76 @@ var ServiceInstance = class {
85
105
  stateStore;
86
106
  eventBus;
87
107
  lifecycle;
108
+ initialized = false;
109
+ disposed = false;
88
110
  getDefinition() {
89
111
  return this.definition;
90
112
  }
113
+ getStatus() {
114
+ return this.lifecycle.getStatus();
115
+ }
91
116
  async start() {
92
- this.lifecycle.setStatus("starting");
93
- if (this.definition.lifecycle?.onInit) {
94
- await this.definition.lifecycle.onInit();
117
+ if (this.disposed) throw new Error("[Service:" + this.name + "] Cannot start a disposed service.");
118
+ const current = this.lifecycle.getStatus();
119
+ if (current === "running") return;
120
+ if (current === "initializing" || current === "starting" || current === "stopping") {
121
+ throw new Error("[Service:" + this.name + "] Cannot start while status is '" + current + "'.");
95
122
  }
96
- if (this.definition.lifecycle?.onStart) {
97
- await this.definition.lifecycle.onStart();
123
+ if (!this.initialized) {
124
+ this.lifecycle.transitionTo("initializing");
125
+ try {
126
+ await this.definition.lifecycle?.onInit?.();
127
+ this.initialized = true;
128
+ this.lifecycle.transitionTo("ready");
129
+ } catch (error) {
130
+ this.lifecycle.transitionTo("uninitialized");
131
+ throw error;
132
+ }
133
+ }
134
+ this.lifecycle.transitionTo("starting");
135
+ try {
136
+ await this.definition.lifecycle?.onStart?.();
137
+ this.lifecycle.transitionTo("running");
138
+ } catch (error) {
139
+ this.lifecycle.transitionTo("ready");
140
+ throw error;
98
141
  }
99
- this.lifecycle.setStatus("running");
100
142
  }
101
143
  async stop() {
102
- this.lifecycle.setStatus("stopping");
103
- if (this.definition.lifecycle?.onStop) {
104
- await this.definition.lifecycle.onStop();
144
+ const current = this.lifecycle.getStatus();
145
+ if (current === "stopped") return;
146
+ if (current !== "running") {
147
+ throw new Error("[Service:" + this.name + "] Cannot stop while status is '" + current + "'.");
105
148
  }
106
- if (this.definition.lifecycle?.onDispose) {
107
- await this.definition.lifecycle.onDispose();
149
+ this.lifecycle.transitionTo("stopping");
150
+ try {
151
+ await this.definition.lifecycle?.onStop?.();
152
+ this.lifecycle.transitionTo("stopped");
153
+ } catch (error) {
154
+ this.lifecycle.transitionTo("running");
155
+ throw error;
108
156
  }
109
- this.lifecycle.setStatus("stopped");
157
+ }
158
+ async dispose() {
159
+ if (this.disposed) return;
160
+ if (this.lifecycle.getStatus() === "running") await this.stop();
161
+ await this.definition.lifecycle?.onDispose?.();
162
+ this.disposed = true;
110
163
  }
111
164
  async call(op, input, ctx = {}) {
112
165
  this.lifecycle.assertRunning(this.name);
113
166
  const operation = this.definition.operations[op];
114
167
  if (!operation) {
115
- throw new Error(`[Service:${this.name}] Operation '${op}' not found.`);
168
+ throw new Error("[Service:" + this.name + "] Operation '" + op + "' not found.");
116
169
  }
117
170
  return await operation.handler(input, ctx);
118
171
  }
119
172
  getState() {
120
- if (!this.stateStore) {
121
- return Object.freeze({});
122
- }
123
- return this.stateStore.getState();
173
+ return this.stateStore?.getState() ?? Object.freeze({});
124
174
  }
125
175
  setState(mutation) {
126
176
  if (!this.stateStore) {
127
- this.stateStore = new ServiceStateStore(mutation);
177
+ this.stateStore = new ServiceStateStore({ ...mutation });
128
178
  return;
129
179
  }
130
180
  this.stateStore.setState(mutation);
@@ -136,12 +186,66 @@ var ServiceInstance = class {
136
186
  this.eventBus.emit(event, payload);
137
187
  }
138
188
  };
139
- function createServiceDefinition(definition) {
189
+ function assertRecord(value, field) {
190
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
191
+ throw new Error("[KrnlTS] Invalid service definition: '" + field + "' must be an object.");
192
+ }
193
+ }
194
+ function assertNonEmptyString(value, field) {
195
+ if (typeof value !== "string" || value.trim().length === 0) {
196
+ throw new Error("[KrnlTS] Invalid service definition: '" + field + "' must be a non-empty string.");
197
+ }
198
+ }
199
+ function validateServiceDefinition(definition) {
200
+ if (!definition || typeof definition !== "object") {
201
+ throw new Error("[KrnlTS] Invalid service definition: expected an object.");
202
+ }
203
+ assertNonEmptyString(definition.id, "id");
204
+ assertNonEmptyString(definition.name, "name");
205
+ assertNonEmptyString(definition.version, "version");
206
+ if (!definition.operations || typeof definition.operations !== "object") {
207
+ throw new Error("[Service:" + definition.name + "] Invalid operations: expected an object.");
208
+ }
209
+ for (const [key, operation] of Object.entries(definition.operations)) {
210
+ if (!operation || typeof operation !== "object") {
211
+ throw new Error("[Service:" + definition.name + "] Invalid operation '" + key + "'.");
212
+ }
213
+ assertNonEmptyString(operation.id, "operations." + key + ".id");
214
+ assertNonEmptyString(operation.name, "operations." + key + ".name");
215
+ if (operation.inputSchema !== void 0) assertRecord(operation.inputSchema, "operations." + key + ".inputSchema");
216
+ if (operation.outputSchema !== void 0) assertRecord(operation.outputSchema, "operations." + key + ".outputSchema");
217
+ if (typeof operation.handler !== "function") {
218
+ throw new Error("[Service:" + definition.name + "] Operation '" + key + "' must define a handler.");
219
+ }
220
+ }
221
+ for (const [key, event] of Object.entries(definition.events ?? {})) {
222
+ if (!event || typeof event !== "object") {
223
+ throw new Error("[Service:" + definition.name + "] Invalid event '" + key + "'.");
224
+ }
225
+ assertNonEmptyString(event.name, "events." + key + ".name");
226
+ }
227
+ for (const [key, schema] of Object.entries(definition.inputs ?? {})) assertRecord(schema, "inputs." + key);
228
+ for (const [key, schema] of Object.entries(definition.outputs ?? {})) assertRecord(schema, "outputs." + key);
229
+ if (definition.state?.schema !== void 0) assertRecord(definition.state.schema, "state.schema");
230
+ for (const capability of definition.capabilities ?? []) {
231
+ assertNonEmptyString(capability.id, "capability.id");
232
+ assertNonEmptyString(capability.name, "capability.name");
233
+ if (!Array.isArray(capability.protocols)) {
234
+ throw new Error("[Service:" + definition.name + "] Capability '" + capability.name + "' protocols must be an array.");
235
+ }
236
+ }
237
+ for (const dependency of definition.dependencies ?? []) {
238
+ assertNonEmptyString(dependency.serviceId, "dependency.serviceId");
239
+ }
140
240
  return definition;
141
241
  }
242
+ function createServiceDefinition(definition) {
243
+ return validateServiceDefinition(definition);
244
+ }
142
245
  function createService(definition) {
143
- return new ServiceInstance(definition);
246
+ return new ServiceInstance(validateServiceDefinition(definition));
144
247
  }
248
+ var asyncHooks = globalThis.process?.getBuiltinModule?.("node:async_hooks");
145
249
 
146
250
  // src/string.ts
147
251
  function toCamelCase(str) {
@@ -1121,6 +1225,8 @@ var FunctionsServiceFacade = {
1121
1225
  return defaultFunctionsService.call(op, input);
1122
1226
  }
1123
1227
  };
1228
+ var krnlFunctionsServiceDefinition = FunctionsServiceDefinition;
1229
+ var krnlFunctionsServiceFacade = FunctionsServiceFacade;
1124
1230
  export {
1125
1231
  FileCache,
1126
1232
  FileLock,
@@ -1153,6 +1259,8 @@ export {
1153
1259
  getRecentEvents,
1154
1260
  interpolate,
1155
1261
  isPlaceholderConnection,
1262
+ krnlFunctionsServiceDefinition,
1263
+ krnlFunctionsServiceFacade,
1156
1264
  listDir,
1157
1265
  loadEnv,
1158
1266
  memoize,
@@ -28,6 +28,6 @@
28
28
  "zod": "^3.24.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@ultrst-armada/krnl": "^1.0.2"
31
+ "@ultrst-armada/krnl": "^1.0.3"
32
32
  }
33
33
  }