@vscode/component-explorer-cli 0.2.1-163 → 0.2.1-165

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 (89) hide show
  1. package/README.md +90 -0
  2. package/dist/_virtual/_build-info.js +1 -1
  3. package/dist/commands/mcpCommand.js +6 -1
  4. package/dist/commands/mcpCommand.js.map +1 -1
  5. package/dist/commands/serveCommand.d.ts +4 -1
  6. package/dist/commands/serveCommand.d.ts.map +1 -1
  7. package/dist/commands/serveCommand.js +91 -25
  8. package/dist/commands/serveCommand.js.map +1 -1
  9. package/dist/daemon/DaemonService.d.ts +5 -208
  10. package/dist/daemon/DaemonService.d.ts.map +1 -1
  11. package/dist/daemon/DaemonService.js +228 -304
  12. package/dist/daemon/DaemonService.js.map +1 -1
  13. package/dist/daemon/client.d.ts +76 -5
  14. package/dist/daemon/client.d.ts.map +1 -1
  15. package/dist/daemon/daemonRpc.test.d.ts +2 -0
  16. package/dist/daemon/daemonRpc.test.d.ts.map +1 -0
  17. package/dist/daemon/endpointServer.d.ts +4 -0
  18. package/dist/daemon/endpointServer.d.ts.map +1 -0
  19. package/dist/daemon/endpointServer.js +24 -0
  20. package/dist/daemon/endpointServer.js.map +1 -0
  21. package/dist/daemon/inProcessClient.d.ts +3 -9
  22. package/dist/daemon/inProcessClient.d.ts.map +1 -1
  23. package/dist/daemon/inProcessClient.js +29 -30
  24. package/dist/daemon/inProcessClient.js.map +1 -1
  25. package/dist/daemon/lifecycle.d.ts +4 -5
  26. package/dist/daemon/lifecycle.d.ts.map +1 -1
  27. package/dist/daemon/lifecycle.js +3 -2
  28. package/dist/daemon/lifecycle.js.map +1 -1
  29. package/dist/daemon/pipeClient.d.ts +2 -3
  30. package/dist/daemon/pipeClient.d.ts.map +1 -1
  31. package/dist/daemon/pipeClient.js +93 -195
  32. package/dist/daemon/pipeClient.js.map +1 -1
  33. package/dist/daemon/pipeName.d.ts +2 -2
  34. package/dist/daemon/pipeName.d.ts.map +1 -1
  35. package/dist/daemon/pipeName.js +6 -4
  36. package/dist/daemon/pipeName.js.map +1 -1
  37. package/dist/daemon/pipeServer.d.ts +2 -2
  38. package/dist/daemon/pipeServer.d.ts.map +1 -1
  39. package/dist/daemon/pipeServer.js +79 -70
  40. package/dist/daemon/pipeServer.js.map +1 -1
  41. package/dist/daemon/registerDaemonConnection.d.ts +7 -0
  42. package/dist/daemon/registerDaemonConnection.d.ts.map +1 -0
  43. package/dist/daemon/registerDaemonConnection.js +37 -0
  44. package/dist/daemon/registerDaemonConnection.js.map +1 -0
  45. package/dist/daemon/transports.test.d.ts +2 -0
  46. package/dist/daemon/transports.test.d.ts.map +1 -0
  47. package/dist/daemon/types.d.ts +1655 -8
  48. package/dist/daemon/types.d.ts.map +1 -1
  49. package/dist/daemon/types.js +4 -0
  50. package/dist/daemon/types.js.map +1 -0
  51. package/dist/daemon/version.d.ts +1 -5
  52. package/dist/daemon/version.d.ts.map +1 -1
  53. package/dist/daemon/version.js +2 -6
  54. package/dist/daemon/version.js.map +1 -1
  55. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/chunks/inspectionHost-BA6ZmC_P.js +2523 -0
  56. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/chunks/inspectionHost-BA6ZmC_P.js.map +1 -0
  57. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/chunks/src-DYVSK_tz.js +1871 -0
  58. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/chunks/src-DYVSK_tz.js.map +1 -0
  59. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/chunks/webSocketTransport-Ct4OIdG9.js +220 -0
  60. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/chunks/webSocketTransport-Ct4OIdG9.js.map +1 -0
  61. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/node.js +721 -0
  62. package/dist/external/linkrpc/typescript/packages/linkrpc/dist/node.js.map +1 -0
  63. package/dist/index.d.ts +0 -2
  64. package/dist/js-component-explorer/packages/common/dist/daemonRpc.js +165 -0
  65. package/dist/js-component-explorer/packages/common/dist/daemonRpc.js.map +1 -0
  66. package/dist/mcp/DaemonAccessor.d.ts +2 -3
  67. package/dist/mcp/DaemonAccessor.d.ts.map +1 -1
  68. package/dist/mcp/McpServer.d.ts +1 -1
  69. package/dist/mcp/McpServer.d.ts.map +1 -1
  70. package/dist/mcp/McpServer.js +69 -58
  71. package/dist/mcp/McpServer.js.map +1 -1
  72. package/dist/renderManifest.d.ts +70 -5
  73. package/dist/server/serverConfig.d.ts +0 -2
  74. package/dist/server/serverConfig.d.ts.map +1 -1
  75. package/dist/server/serverConfig.js.map +1 -1
  76. package/dist/server/viteServer.d.ts +0 -2
  77. package/dist/server/viteServer.d.ts.map +1 -1
  78. package/dist/server/viteServer.js.map +1 -1
  79. package/package.json +9 -8
  80. package/dist/formatValue.js +0 -96
  81. package/dist/formatValue.js.map +0 -1
  82. package/dist/js-component-explorer/packages/simple-api/dist/chunk-FJ7AVNQE.js +0 -138
  83. package/dist/js-component-explorer/packages/simple-api/dist/chunk-FJ7AVNQE.js.map +0 -1
  84. package/dist/js-component-explorer/packages/simple-api/dist/chunk-TTRCY65Z.js +0 -27
  85. package/dist/js-component-explorer/packages/simple-api/dist/chunk-TTRCY65Z.js.map +0 -1
  86. package/dist/js-component-explorer/packages/simple-api/dist/chunk-WNXMRXWV.js +0 -28
  87. package/dist/js-component-explorer/packages/simple-api/dist/chunk-WNXMRXWV.js.map +0 -1
  88. package/dist/js-component-explorer/packages/simple-api/dist/express.js +0 -104
  89. package/dist/js-component-explorer/packages/simple-api/dist/express.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vscode/component-explorer-cli",
3
- "version": "0.2.1-163",
3
+ "version": "0.2.1-165",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,8 +23,8 @@
23
23
  "types": "./dist/index.d.ts"
24
24
  },
25
25
  "./daemon-types": {
26
- "import": "./dist/daemon/DaemonService.js",
27
- "types": "./dist/daemon/DaemonService.d.ts"
26
+ "import": "./dist/daemon/types.js",
27
+ "types": "./dist/daemon/types.d.ts"
28
28
  },
29
29
  "./daemon-client": {
30
30
  "import": "./dist/daemon/client.js",
@@ -52,21 +52,21 @@
52
52
  "dependencies": {
53
53
  "@modelcontextprotocol/sdk": "^1.29.0",
54
54
  "clipanion": "4.0.0-rc.4",
55
- "express": "^5.2.1",
56
55
  "istanbul-lib-coverage": "^3.2.2",
57
56
  "v8-to-istanbul": "^9.3.0",
58
57
  "vite-plugin-istanbul": "^7.2.0",
59
- "zod": "^4.3.6"
58
+ "ws": "^8.18.0",
59
+ "zod": "^4.4.3"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "playwright": ">=1.40.0",
63
63
  "vite": ">=5.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@hediet/simple-api": "workspace:*",
66
+ "@hediet/linkrpc": "link:../../../external/linkrpc/typescript/packages/linkrpc",
67
+ "@hediet/linkrpc-cli": "link:../../../external/linkrpc/typescript/packages/linkrpc-cli",
67
68
  "@rollup/plugin-node-resolve": "^16.0.3",
68
69
  "@rollup/plugin-typescript": "^12.3.0",
69
- "@types/express": "^5.0.6",
70
70
  "@types/istanbul-lib-coverage": "^2.0.6",
71
71
  "@types/node": "^20.19.39",
72
72
  "@vitejs/plugin-react": "^4.7.0",
@@ -78,11 +78,12 @@
78
78
  "react": "^18.3.1",
79
79
  "react-dom": "^18.3.1",
80
80
  "rollup": "^4.60.1",
81
+ "rollup-plugin-dts": "^6.4.1",
81
82
  "semver": "workspace:*",
82
83
  "tsx": "4.22.4",
83
84
  "typescript": "^5.9.3",
84
85
  "vite": "^6.4.3",
85
86
  "vitest": "^4.1.0"
86
87
  },
87
- "gitHead": "4445737237dc9e9f9e6a5ef7f28ed84c049478cf"
88
+ "gitHead": "3398cd4a37a0c24ace23ae3bf06d3924d4ea5068"
88
89
  }
@@ -1,96 +0,0 @@
1
- function formatValue(value, maxLength = 100) {
2
- return truncate(formatInner(value), maxLength);
3
- }
4
- function formatInner(value) {
5
- if (value === null) {
6
- return 'null';
7
- }
8
- if (value === undefined) {
9
- return 'undefined';
10
- }
11
- switch (typeof value) {
12
- case 'string':
13
- return JSON.stringify(value);
14
- case 'number':
15
- case 'boolean':
16
- return String(value);
17
- }
18
- if (Array.isArray(value)) {
19
- if (value.length === 0) {
20
- return '[]';
21
- }
22
- const items = value.map(formatInner);
23
- const joined = `[${items.join(', ')}]`;
24
- return joined;
25
- }
26
- if (typeof value === 'object') {
27
- const entries = Object.entries(value);
28
- if (entries.length === 0) {
29
- return '{}';
30
- }
31
- const parts = entries.map(([k, v]) => `${k}: ${formatInner(v)}`);
32
- return `{${parts.join(', ')}}`;
33
- }
34
- return String(value);
35
- }
36
- function truncate(str, maxLength) {
37
- if (str.length <= maxLength) {
38
- return str;
39
- }
40
- // Try to find the outermost container type for a smart summary suffix
41
- const suffix = summarySuffix(str);
42
- const available = maxLength - suffix.length - 1; // 1 for ellipsis char
43
- if (available <= 0) {
44
- return str.slice(0, maxLength - 1) + '…';
45
- }
46
- return str.slice(0, available) + '…' + suffix;
47
- }
48
- function summarySuffix(str) {
49
- if (str.startsWith('[')) {
50
- const count = countTopLevelCommas(str, '[', ']') + 1;
51
- return ` (${count} items)`;
52
- }
53
- if (str.startsWith('{')) {
54
- const count = countTopLevelCommas(str, '{', '}') + 1;
55
- return ` (${count} keys)`;
56
- }
57
- if (str.startsWith('"')) {
58
- return ` (${str.length - 2} chars)`;
59
- }
60
- return '';
61
- }
62
- function countTopLevelCommas(str, open, close) {
63
- let depth = 0;
64
- let count = 0;
65
- let inString = false;
66
- for (let i = 0; i < str.length; i++) {
67
- const ch = str[i];
68
- if (inString) {
69
- if (ch === '\\') {
70
- i++;
71
- continue;
72
- }
73
- if (ch === '"') {
74
- inString = false;
75
- }
76
- continue;
77
- }
78
- if (ch === '"') {
79
- inString = true;
80
- continue;
81
- }
82
- if (ch === open || ch === '[' || ch === '{') {
83
- depth++;
84
- }
85
- else if (ch === close || ch === ']' || ch === '}') {
86
- depth--;
87
- }
88
- else if (ch === ',' && depth === 1) {
89
- count++;
90
- }
91
- }
92
- return count;
93
- }
94
-
95
- export { formatValue };
96
- //# sourceMappingURL=formatValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatValue.js","sources":["../src/formatValue.ts"],"sourcesContent":[null],"names":[],"mappings":"SAAgB,WAAW,CAAC,KAAc,EAAE,SAAS,GAAG,GAAG,EAAA;IAC1D,OAAO,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;AAC/C;AAEA,SAAS,WAAW,CAAC,KAAc,EAAA;AAClC,IAAA,IAAI,KAAK,KAAK,IAAI,EAAE;AAAE,QAAA,OAAO,MAAM;IAAE;AACrC,IAAA,IAAI,KAAK,KAAK,SAAS,EAAE;AAAE,QAAA,OAAO,WAAW;IAAE;IAE/C,QAAQ,OAAO,KAAK;AACnB,QAAA,KAAK,QAAQ;AACZ,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;AAC7B,QAAA,KAAK,QAAQ;AACb,QAAA,KAAK,SAAS;AACb,YAAA,OAAO,MAAM,CAAC,KAAK,CAAC;;AAKtB,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACzB,QAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AAAE,YAAA,OAAO,IAAI;QAAE;QACvC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC;QACpC,MAAM,MAAM,GAAG,CAAA,CAAA,EAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAA,CAAG;AACtC,QAAA,OAAO,MAAM;IACd;AAEA,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC9B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC;AAChE,QAAA,IAAI,OAAO,CAAC,M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server.ts
4
- function createApiFactory() {
5
- const factoryToken = /* @__PURE__ */ Symbol("apiFactory");
6
- return createFactoryImpl(factoryToken, void 0);
7
- }
8
- function createFactoryImpl(factoryToken, middleware) {
9
- const factory = {
10
- _factoryToken: factoryToken,
11
- _middleware: middleware,
12
- withMiddleware(mwOrFn) {
13
- const mw = typeof mwOrFn === "function" ? { _dependencies: void 0, _provides: void 0, run: mwOrFn } : mwOrFn;
14
- const composed = middleware ? {
15
- _dependencies: void 0,
16
- _provides: void 0,
17
- run: async (ctx) => {
18
- const intermediate = await middleware.run(ctx);
19
- return await mw.run(intermediate);
20
- }
21
- } : mw;
22
- return createFactoryImpl(factoryToken, composed);
23
- },
24
- createMiddleware(fn) {
25
- return {
26
- _dependencies: void 0,
27
- _provides: void 0,
28
- run: fn
29
- };
30
- },
31
- createMethod(options, run) {
32
- const obj = z.object(options.args);
33
- const resultValidator = options.result;
34
- return {
35
- _factoryToken: factoryToken,
36
- _contextRequirement: void 0,
37
- get TArg() {
38
- throw new Error("Type-only property");
39
- },
40
- get TResult() {
41
- throw new Error("Type-only property");
42
- },
43
- argType: obj,
44
- resultType: resultValidator ?? z.unknown(),
45
- run: async (args, rawContext) => {
46
- const parsedArgs = obj.parse(args ?? {});
47
- let ctx;
48
- const baseCtx = middleware ? await middleware.run(rawContext) : rawContext;
49
- if (options.middleware) {
50
- ctx = await options.middleware.run(baseCtx);
51
- } else {
52
- ctx = baseCtx;
53
- }
54
- const result = await run(parsedArgs, ctx);
55
- if (resultValidator) {
56
- return resultValidator.parse(result);
57
- }
58
- return result;
59
- }
60
- };
61
- },
62
- createApi(methods) {
63
- for (const [name, method] of Object.entries(methods)) {
64
- if (method instanceof ApiImplementation) {
65
- if (method._factoryToken !== factoryToken) {
66
- throw new Error(
67
- `Method "${name}" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`
68
- );
69
- }
70
- } else {
71
- const m = method;
72
- if (m._factoryToken !== factoryToken) {
73
- throw new Error(
74
- `Method "${name}" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`
75
- );
76
- }
77
- }
78
- }
79
- return new ApiImplementation(factoryToken, methods);
80
- }
81
- };
82
- return factory;
83
- }
84
- var ApiImplementation = class _ApiImplementation {
85
- constructor(factoryToken, _methods) {
86
- this._methods = _methods;
87
- this._factoryToken = factoryToken;
88
- }
89
- _methods;
90
- _factoryToken;
91
- get TMethods() {
92
- throw new Error("Type-only property");
93
- }
94
- getMethods() {
95
- const methods = [];
96
- for (const [name, method] of Object.entries(this._methods)) {
97
- if (method instanceof _ApiImplementation) {
98
- const subMethods = method.getMethods();
99
- for (const subMethod of subMethods) {
100
- methods.push({
101
- ...subMethod,
102
- path: `${name}/${subMethod.path}`
103
- });
104
- }
105
- } else {
106
- methods.push({
107
- path: name,
108
- argType: method.argType,
109
- resultType: method.resultType
110
- });
111
- }
112
- }
113
- return methods;
114
- }
115
- async run(method, arg, context) {
116
- const parts = method.split("/", 2);
117
- const firstPart = parts[0];
118
- if (!(firstPart in this._methods)) {
119
- return Promise.reject(new Error(`Method not found: ${method}`));
120
- }
121
- const impl = this._methods[firstPart];
122
- if (parts.length > 1) {
123
- if (!(impl instanceof _ApiImplementation)) {
124
- throw new Error(`Method not found: ${method}`);
125
- }
126
- return impl.run(parts[1], arg, context);
127
- } else {
128
- if (impl instanceof _ApiImplementation) {
129
- throw new Error(`Method not found: ${method}`);
130
- }
131
- const result = await impl.run(arg, context);
132
- return result ?? null;
133
- }
134
- }
135
- };
136
-
137
- export { ApiImplementation, createApiFactory };
138
- //# sourceMappingURL=chunk-FJ7AVNQE.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunk-FJ7AVNQE.js","sources":["../../../../../../simple-api/dist/chunk-FJ7AVNQE.mjs"],"sourcesContent":["// src/server.ts\nimport { z } from \"zod\";\nfunction createApiFactory() {\n const factoryToken = /* @__PURE__ */ Symbol(\"apiFactory\");\n return createFactoryImpl(factoryToken, void 0);\n}\nfunction createFactoryImpl(factoryToken, middleware) {\n const factory = {\n _factoryToken: factoryToken,\n _middleware: middleware,\n withMiddleware(mwOrFn) {\n const mw = typeof mwOrFn === \"function\" ? { _dependencies: void 0, _provides: void 0, run: mwOrFn } : mwOrFn;\n const composed = middleware ? {\n _dependencies: void 0,\n _provides: void 0,\n run: async (ctx) => {\n const intermediate = await middleware.run(ctx);\n return await mw.run(intermediate);\n }\n } : mw;\n return createFactoryImpl(factoryToken, composed);\n },\n createMiddleware(fn) {\n return {\n _dependencies: void 0,\n _provides: void 0,\n run: fn\n };\n },\n createMethod(options, run) {\n const obj = z.object(options.args);\n const resultValidator = options.result;\n return {\n _factoryToken: factoryToken,\n _contextRequirement: void 0,\n get TArg() {\n throw new Error(\"Type-only property\");\n },\n get TResult() {\n throw new Error(\"Type-only property\");\n },\n argType: obj,\n resultType: resultValidator ?? z.unknown(),\n run: async (args, rawContext) => {\n const parsedArgs = obj.parse(args ?? {});\n let ctx;\n const baseCtx = middleware ? await middleware.run(rawContext) : rawContext;\n if (options.middleware) {\n ctx = await options.middleware.run(baseCtx);\n } else {\n ctx = baseCtx;\n }\n const result = await run(parsedArgs, ctx);\n if (resultValidator) {\n return resultValidator.parse(result);\n }\n return result;\n }\n };\n },\n createApi(methods) {\n for (const [name, method] of Object.entries(methods)) {\n if (method instanceof ApiImplementation) {\n if (method._factoryToken !== factoryToken) {\n throw new Error(\n `Method \"${name}\" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`\n );\n }\n } else {\n const m = method;\n if (m._factoryToken !== factoryToken) {\n throw new Error(\n `Method \"${name}\" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`\n );\n }\n }\n }\n return new ApiImplementation(factoryToken, methods);\n }\n };\n return factory;\n}\nvar ApiImplementation = class _ApiImplementation {\n constructor(factoryToken, _methods) {\n this._methods = _methods;\n this._factoryToken = factoryToken;\n }\n _methods;\n _factoryToken;\n get TMethods() {\n throw new Error(\"Type-only property\");\n }\n getMethods() {\n const methods = [];\n for (const [name, method] of Object.entries(this._methods)) {\n if (method instanceof _ApiImplementation) {\n const subMethods = method.getMethods();\n for (const subMethod of subMethods) {\n methods.push({\n ...subMethod,\n path: `${name}/${subMethod.path}`\n });\n }\n } else {\n methods.push({\n path: name,\n argType: method.argType,\n resultType: method.resultType\n });\n }\n }\n return methods;\n }\n async run(method, arg, context) {\n const parts = method.split(\"/\", 2);\n const firstPart = parts[0];\n if (!(firstPart in this._methods)) {\n return Promise.reject(new Error(`Method not found: ${method}`));\n }\n const impl = this._methods[firstPart];\n if (parts.length > 1) {\n if (!(impl instanceof _ApiImplementation)) {\n throw new Error(`Method not found: ${method}`);\n }\n return impl.run(parts[1], arg, context);\n } else {\n if (impl instanceof _ApiImplementation) {\n throw new Error(`Method not found: ${method}`);\n }\n const result = await impl.run(arg, context);\n return result ?? null;\n }\n }\n};\n\nexport {\n createApiFactory,\n ApiImplementation\n};\n//# sourceMappingURL=chunk-FJ7AVNQE.mjs.map"],"names":[],"mappings":";;AAAA;AAEA,SAAS,gBAAgB,GAAG;AAC5B,EAAE,MAAM,YAAY,mBAAmB,MAAM,CAAC,YAAY,CAAC;AAC3D,EAAE,OAAO,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC;AAChD;AACA,SAAS,iBAAiB,CAAC,YAAY,EAAE,UAAU,EAAE;AACrD,EAAE,MAAM,OAAO,GAAG;AAClB,IAAI,aAAa,EAAE,YAAY;AAC/B,IAAI,WAAW,EAAE,UAAU;AAC3B,IAAI,cAAc,CAAC,MAAM,EAAE;AAC3B,MAAM,MAAM,EAAE,GAAG,OAAO,MAAM,KAAK,UAAU,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM;AAClH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG;AACpC,QAAQ,aAAa,EAAE,MAAM;AAC7B,QAAQ,SAAS,EAAE,MAAM;AACzB,QAAQ,GAAG,EAAE,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E;AACvC,MAAM,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AACrE,IAAI;AACJ,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;AACzC,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;AAC1B,MAAM,IAAI,EAAE,IAAI,YAAY,kBAAkB,CAAC,EAAE;AACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC;AACtD,MAAM;AACN,MAAM,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC;AAC7C,IAAI,CAAC,MAAM;AACX,MAAM,IAAI,IAAI,YAAY,kBAAkB,EAAE;AAC9C,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC;AACtD,MAAM;AACN,MAAM,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC;AACjD,MAAM,OAAO,MAAM,IAAI,IAAI;AAC3B,IAAI;AACJ,EAAE;AACF;;;;"}
@@ -1,27 +0,0 @@
1
- // src/AsyncStream.ts
2
- var AsyncStream = class _AsyncStream {
3
- constructor(iterator) {
4
- this.iterator = iterator;
5
- }
6
- iterator;
7
- static fromIterable(fn) {
8
- return new _AsyncStream(fn[Symbol.asyncIterator]());
9
- }
10
- static fromFn(fn) {
11
- return new _AsyncStream(fn());
12
- }
13
- [Symbol.asyncIterator]() {
14
- return this.iterator;
15
- }
16
- };
17
- var MediaResponse = class {
18
- constructor(mimeType, data) {
19
- this.mimeType = mimeType;
20
- this.data = data;
21
- }
22
- mimeType;
23
- data;
24
- };
25
-
26
- export { AsyncStream, MediaResponse };
27
- //# sourceMappingURL=chunk-TTRCY65Z.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunk-TTRCY65Z.js","sources":["../../../../../../simple-api/dist/chunk-TTRCY65Z.mjs"],"sourcesContent":["// src/AsyncStream.ts\nvar AsyncStream = class _AsyncStream {\n constructor(iterator) {\n this.iterator = iterator;\n }\n iterator;\n static fromIterable(fn) {\n return new _AsyncStream(fn[Symbol.asyncIterator]());\n }\n static fromFn(fn) {\n return new _AsyncStream(fn());\n }\n [Symbol.asyncIterator]() {\n return this.iterator;\n }\n};\nvar MediaResponse = class {\n constructor(mimeType, data) {\n this.mimeType = mimeType;\n this.data = data;\n }\n mimeType;\n data;\n};\n\nexport {\n AsyncStream,\n MediaResponse\n};\n//# sourceMappingURL=chunk-TTRCY65Z.mjs.map"],"names":[],"mappings":"AAAA;AACG,IAAC,WAAW,GAAG,MAAM,YAAY,CAAC;AACrC,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ;AAC5B,EAAE;AACF,EAAE,QAAQ;AACV,EAAE,OAAO,YAAY,CAAC,EAAE,EAAE;AAC1B,IAAI,OAAO,IAAI,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;AACvD,EAAE;AACF,EAAE,OAAO,MAAM,CAAC,EAAE,EAAE;AACpB,IAAI,OAAO,IAAI,YAAY,CAAC,EAAE,EAAE,CAAC;AACjC,EAAE;AACF,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG;AAC3B,IAAI,OAAO,IAAI,CAAC,QAAQ;AACxB,EAAE;AACF;AACG,IAAC,aAAa,GAAG,MAAM;AAC1B,EAAE,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE;AAC9B,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ;AAC5B,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI;AACpB,EAAE;AACF,EAAE,QAAQ;AACV,EAAE,IAAI;AACN;;;;"}
@@ -1,28 +0,0 @@
1
- var ProxyApiClient = class {
2
- constructor(_request) {
3
- this._request = _request;
4
- }
5
- _request;
6
- _createProxy(prefix) {
7
- return new Proxy(() => {
8
- }, {
9
- apply: async (_target, _self, args) => {
10
- const result = await this._request(prefix, args[0]);
11
- return result;
12
- },
13
- get: (_target, prop) => {
14
- if (typeof prop === "symbol") {
15
- return void 0;
16
- }
17
- if (prop === "then" || prop === "catch" || prop === "finally" || prop === "toString" || prop === "valueOf" || prop === "toJSON" || prop === "name" || prop === "length" || prop === "prototype" || prop === "constructor" || prop === "caller" || prop === "arguments") {
18
- return void 0;
19
- }
20
- return this._createProxy(`${prefix}${prefix ? "/" : ""}${prop}`);
21
- }
22
- });
23
- }
24
- methods = this._createProxy("");
25
- };
26
-
27
- export { ProxyApiClient };
28
- //# sourceMappingURL=chunk-WNXMRXWV.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunk-WNXMRXWV.js","sources":["../../../../../../simple-api/dist/chunk-WNXMRXWV.mjs"],"sourcesContent":["import {\n AsyncStream\n} from \"./chunk-TTRCY65Z.mjs\";\n\n// src/client.ts\nvar ApiError = class extends Error {\n constructor(statusCode, method, message) {\n super(message);\n this.statusCode = statusCode;\n this.method = method;\n this.name = \"ApiError\";\n }\n statusCode;\n method;\n};\nvar ProxyApiClient = class {\n constructor(_request) {\n this._request = _request;\n }\n _request;\n _createProxy(prefix) {\n return new Proxy(() => {\n }, {\n apply: async (_target, _self, args) => {\n const result = await this._request(prefix, args[0]);\n return result;\n },\n get: (_target, prop) => {\n if (typeof prop === \"symbol\") {\n return void 0;\n }\n if (prop === \"then\" || prop === \"catch\" || prop === \"finally\" || prop === \"toString\" || prop === \"valueOf\" || prop === \"toJSON\" || prop === \"name\" || prop === \"length\" || prop === \"prototype\" || prop === \"constructor\" || prop === \"caller\" || prop === \"arguments\") {\n return void 0;\n }\n return this._createProxy(`${prefix}${prefix ? \"/\" : \"\"}${prop}`);\n }\n });\n }\n methods = this._createProxy(\"\");\n};\nfunction createFetchClient(baseUrl, options) {\n return new ProxyApiClient(async (method, arg) => {\n const result = await fetch(`${baseUrl}/${method}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...options?.getHeaders?.()\n },\n body: JSON.stringify(arg)\n });\n if (result.status !== 200) {\n const data2 = await result.json().catch(() => null);\n let message;\n if (data2 && typeof data2 === \"object\" && (\"errorMessage\" in data2 || \"error\" in data2)) {\n const msg = data2.errorMessage ?? data2.error;\n const stack = data2.stack;\n message = `${msg}${stack ? `\n${stack}` : \"\"}`;\n } else {\n message = `Error calling API method \"${method}\" (${result.status}): ${JSON.stringify(data2)}`;\n }\n const error = new ApiError(result.status, method, message);\n options?.onError?.(error);\n throw error;\n }\n const contentType = result.headers.get(\"Content-Type\");\n if (contentType?.startsWith(\"application/jsonl\")) {\n return AsyncStream.fromFn(async function* () {\n const reader = result.body?.getReader();\n if (!reader) {\n return;\n }\n let buffer = \"\";\n const decoder = new TextDecoder(\"utf-8\");\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n buffer += decoder.decode(value, { stream: true });\n let eolIndex;\n while ((eolIndex = buffer.indexOf(\"\\n\")) >= 0) {\n const line = buffer.slice(0, eolIndex).trim();\n buffer = buffer.slice(eolIndex + 1);\n if (line.length > 0) {\n yield JSON.parse(line);\n }\n }\n }\n const finalLine = buffer.trim();\n if (finalLine.length > 0) {\n yield JSON.parse(finalLine);\n }\n });\n }\n const data = await result.json();\n return data;\n });\n}\nfunction createLocalClient(api, context) {\n return new ProxyApiClient(async (method, args) => {\n return await api.run(method, args, context);\n });\n}\n\nexport {\n ApiError,\n ProxyApiClient,\n createFetchClient,\n createLocalClient\n};\n//# sourceMappingURL=chunk-WNXMRXWV.mjs.map"],"names":[],"mappings":"AAeG,IAAC,cAAc,GAAG,MAAM;AAC3B,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ;AAC5B,EAAE;AACF,EAAE,QAAQ;AACV,EAAE,YAAY,CAAC,MAAM,EAAE;AACvB,IAAI,OAAO,IAAI,KAAK,CAAC,MAAM;AAC3B,IAAI,CAAC,EAAE;AACP,MAAM,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,EAAE,IAAI,KAAK;AAC7C,QAAQ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3D,QAAQ,OAAO,MAAM;AACrB,MAAM,CAAC;AACP,MAAM,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK;AAC9B,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AACtC,UAAU,OAAO,MAAM;AACvB,QAAQ;AACR,QAAQ,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,WAAW,EAAE;AAChR,UAAU,OAAO,MAAM;AACvB,QAAQ;AACR,QAAQ,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACxE,MAAM;AACN,KAAK,CAAC;AACN,EAAE;AACF,EAAE,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;AACjC;;;;"}
@@ -1,104 +0,0 @@
1
- import 'zod';
2
- import { MediaResponse, AsyncStream } from './chunk-TTRCY65Z.js';
3
- import { Router, json } from 'express';
4
-
5
- function createApiRouter(api, options) {
6
- const router = Router();
7
- router.use((req, res, next) => {
8
- res.header("Access-Control-Allow-Origin", "*");
9
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
10
- res.header("Access-Control-Allow-Methods", "POST, OPTIONS");
11
- if (req.method === "OPTIONS") {
12
- res.sendStatus(200);
13
- } else {
14
- next();
15
- }
16
- });
17
- router.use(json());
18
- async function invokeApi(api2, method, args, req, res) {
19
- const context = options?.contextFactory ? options.contextFactory(req) : { request: req };
20
- try {
21
- const result = await api2.run(method, args, context);
22
- if (result instanceof MediaResponse) {
23
- if (result.mimeType.startsWith("audio/") || result.mimeType.startsWith("video/")) {
24
- const range = req.headers.range;
25
- const fileSize = result.data.byteLength;
26
- if (range) {
27
- const parts = range.replace(/bytes=/, "").split("-");
28
- const start = parseInt(parts[0], 10);
29
- const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;
30
- if (start >= fileSize || end >= fileSize || start > end) {
31
- res.status(416).send("Requested range not satisfiable");
32
- return;
33
- }
34
- const chunkSize = end - start + 1;
35
- const chunk = result.data.slice(start, end + 1);
36
- res.writeHead(206, {
37
- "Content-Range": `bytes ${start}-${end}/${fileSize}`,
38
- "Accept-Ranges": "bytes",
39
- "Content-Length": chunkSize,
40
- "Content-Type": result.mimeType
41
- });
42
- res.end(chunk);
43
- } else {
44
- res.writeHead(200, {
45
- "Content-Type": result.mimeType,
46
- "Content-Length": fileSize,
47
- "Accept-Ranges": "bytes"
48
- });
49
- res.end(result.data);
50
- }
51
- } else {
52
- res.writeHead(200, {
53
- "Content-Type": result.mimeType,
54
- "Content-Length": result.data.byteLength
55
- });
56
- res.end(result.data);
57
- }
58
- } else if (result instanceof AsyncStream) {
59
- res.writeHead(200, {
60
- "Content-Type": "application/jsonl; charset=utf-8",
61
- "Transfer-Encoding": "chunked",
62
- Connection: "keep-alive"
63
- });
64
- const iterator = result[Symbol.asyncIterator]();
65
- res.on("close", () => {
66
- iterator.return?.();
67
- });
68
- try {
69
- while (true) {
70
- const { value, done } = await iterator.next();
71
- if (done) {
72
- break;
73
- }
74
- res.write(JSON.stringify(value) + "\n");
75
- }
76
- } catch (e) {
77
- console.error("Error while streaming response:", e);
78
- res.write(JSON.stringify({ error: e.message }) + "\n");
79
- }
80
- res.end();
81
- } else {
82
- res.json(result);
83
- }
84
- } catch (e) {
85
- res.status(500).json({ error: e.message, stack: e.stack, method });
86
- }
87
- }
88
- router.post("/{*method}", async (req, res) => {
89
- const method = req.params.method.join("/");
90
- const arg = req.body;
91
- await invokeApi(api, method, arg, req, res);
92
- });
93
- router.get("/{*method}", async (req, res) => {
94
- const m = req.params.method;
95
- m[m.length - 1] = "get" + m[m.length - 1];
96
- const method = m.join("/");
97
- const arg = req.query ?? {};
98
- await invokeApi(api, method, arg, req, res);
99
- });
100
- return router;
101
- }
102
-
103
- export { AsyncStream, MediaResponse, createApiRouter };
104
- //# sourceMappingURL=express.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"express.js","sources":["../../../../../../simple-api/dist/express.mjs"],"sourcesContent":["import {\n ApiImplementation\n} from \"./chunk-FJ7AVNQE.mjs\";\nimport {\n AsyncStream,\n MediaResponse\n} from \"./chunk-TTRCY65Z.mjs\";\n\n// src/express.ts\nimport { json, Router } from \"express\";\nfunction createApiRouter(api, options) {\n const router = Router();\n router.use((req, res, next) => {\n res.header(\"Access-Control-Allow-Origin\", \"*\");\n res.header(\"Access-Control-Allow-Headers\", \"Origin, X-Requested-With, Content-Type, Accept, Authorization\");\n res.header(\"Access-Control-Allow-Methods\", \"POST, OPTIONS\");\n if (req.method === \"OPTIONS\") {\n res.sendStatus(200);\n } else {\n next();\n }\n });\n router.use(json());\n async function invokeApi(api2, method, args, req, res) {\n const context = options?.contextFactory ? options.contextFactory(req) : { request: req };\n try {\n const result = await api2.run(method, args, context);\n if (result instanceof MediaResponse) {\n if (result.mimeType.startsWith(\"audio/\") || result.mimeType.startsWith(\"video/\")) {\n const range = req.headers.range;\n const fileSize = result.data.byteLength;\n if (range) {\n const parts = range.replace(/bytes=/, \"\").split(\"-\");\n const start = parseInt(parts[0], 10);\n const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1;\n if (start >= fileSize || end >= fileSize || start > end) {\n res.status(416).send(\"Requested range not satisfiable\");\n return;\n }\n const chunkSize = end - start + 1;\n const chunk = result.data.slice(start, end + 1);\n res.writeHead(206, {\n \"Content-Range\": `bytes ${start}-${end}/${fileSize}`,\n \"Accept-Ranges\": \"bytes\",\n \"Content-Length\": chunkSize,\n \"Content-Type\": result.mimeType\n });\n res.end(chunk);\n } else {\n res.writeHead(200, {\n \"Content-Type\": result.mimeType,\n \"Content-Length\": fileSize,\n \"Accept-Ranges\": \"bytes\"\n });\n res.end(result.data);\n }\n } else {\n res.writeHead(200, {\n \"Content-Type\": result.mimeType,\n \"Content-Length\": result.data.byteLength\n });\n res.end(result.data);\n }\n } else if (result instanceof AsyncStream) {\n res.writeHead(200, {\n \"Content-Type\": \"application/jsonl; charset=utf-8\",\n \"Transfer-Encoding\": \"chunked\",\n Connection: \"keep-alive\"\n });\n const iterator = result[Symbol.asyncIterator]();\n res.on(\"close\", () => {\n iterator.return?.();\n });\n try {\n while (true) {\n const { value, done } = await iterator.next();\n if (done) {\n break;\n }\n res.write(JSON.stringify(value) + \"\\n\");\n }\n } catch (e) {\n console.error(\"Error while streaming response:\", e);\n res.write(JSON.stringify({ error: e.message }) + \"\\n\");\n }\n res.end();\n } else {\n res.json(result);\n }\n } catch (e) {\n res.status(500).json({ error: e.message, stack: e.stack, method });\n }\n }\n router.post(\"/{*method}\", async (req, res) => {\n const method = req.params.method.join(\"/\");\n const arg = req.body;\n await invokeApi(api, method, arg, req, res);\n });\n router.get(\"/{*method}\", async (req, res) => {\n const m = req.params.method;\n m[m.length - 1] = \"get\" + m[m.length - 1];\n const method = m.join(\"/\");\n const arg = req.query ?? {};\n await invokeApi(api, method, arg, req, res);\n });\n return router;\n}\nexport {\n ApiImplementation,\n AsyncStream,\n MediaResponse,\n createApiRouter\n};\n//# sourceMappingURL=express.mjs.map"],"names":[],"mappings":";;;;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