@requence/service 0.7.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +15 -0
- package/build/{chunk-6w7td62p.js → chunk-8r349zge.js} +46 -3
- package/build/chunk-8r349zge.js.map +11 -0
- package/build/cli.js +17 -7
- package/build/cli.js.map +3 -3
- package/build/index.js +1261 -446
- package/build/index.js.map +28 -14
- package/build/types/helpers/src/index.d.ts +8 -2
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/validate.d.ts +1 -5
- package/build/types/helpers/src/jsonschema/validate.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/zod.d.ts +11 -1
- package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/NodeTree.d.ts +450 -144
- package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/command.d.ts +364 -142
- package/build/types/helpers/src/protocol/command.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/configurationScript.d.ts +10 -0
- package/build/types/helpers/src/protocol/configurationScript.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/helpers.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/index.d.ts +4 -0
- package/build/types/helpers/src/protocol/index.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/logicLanguages.d.ts +19 -0
- package/build/types/helpers/src/protocol/logicLanguages.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/loopDetection.d.ts +23 -0
- package/build/types/helpers/src/protocol/loopDetection.d.ts.map +1 -0
- package/build/types/helpers/src/protocol/nodeType.d.ts +73 -27
- package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/taskOptions.d.ts +4 -1
- package/build/types/helpers/src/protocol/taskOptions.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/templateNodeTypes.d.ts +36 -20
- package/build/types/helpers/src/protocol/templateNodeTypes.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/treeNodes.d.ts +476 -164
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/update.d.ts +22 -22
- package/build/types/helpers/src/protocol/validateTreeStructure.d.ts +22 -0
- package/build/types/helpers/src/protocol/validateTreeStructure.d.ts.map +1 -0
- package/build/types/helpers/src/utils/amqpHeartbeat.d.ts +3 -0
- package/build/types/helpers/src/utils/amqpHeartbeat.d.ts.map +1 -0
- package/build/types/helpers/src/utils/amqpPublishRetry.d.ts +5 -0
- package/build/types/helpers/src/utils/amqpPublishRetry.d.ts.map +1 -0
- package/build/types/helpers/src/utils/claimCheckObject.d.ts +40 -0
- package/build/types/helpers/src/utils/claimCheckObject.d.ts.map +1 -0
- package/build/types/helpers/src/utils/debounce.d.ts.map +1 -1
- package/build/types/helpers/src/{files → utils}/fileObject.d.ts.map +1 -1
- package/build/types/helpers/src/{files → utils}/isValidMimeType.d.ts.map +1 -1
- package/build/types/helpers/src/utils/mapData.d.ts +1 -1
- package/build/types/helpers/src/utils/mapData.d.ts.map +1 -1
- package/build/types/helpers/src/{files → utils}/streamObject.d.ts.map +1 -1
- package/build/types/helpers/src/utils/variableRef.d.ts +19 -0
- package/build/types/helpers/src/utils/variableRef.d.ts.map +1 -0
- package/build/types/helpers/src/utils/variableScriptPatterns.d.ts +125 -0
- package/build/types/helpers/src/utils/variableScriptPatterns.d.ts.map +1 -0
- package/build/types/service/src/boundary.d.ts +75 -0
- package/build/types/service/src/boundary.d.ts.map +1 -0
- package/build/types/service/src/createAmqpConnection.d.ts +21 -4
- package/build/types/service/src/createAmqpConnection.d.ts.map +1 -1
- package/build/types/service/src/errors.d.ts +31 -0
- package/build/types/service/src/errors.d.ts.map +1 -1
- package/build/types/service/src/helpers.d.ts +59 -56
- package/build/types/service/src/helpers.d.ts.map +1 -1
- package/build/types/service/src/index.d.ts +7 -1
- package/build/types/service/src/index.d.ts.map +1 -1
- package/build/types/service/src/transformer.d.ts +16 -0
- package/build/types/service/src/transformer.d.ts.map +1 -0
- package/package.json +6 -3
- package/build/chunk-6w7td62p.js.map +0 -10
- package/build/types/helpers/src/files/RequenceFile.d.ts +0 -40
- package/build/types/helpers/src/files/RequenceFile.d.ts.map +0 -1
- package/build/types/helpers/src/files/RequenceStream.d.ts +0 -32
- package/build/types/helpers/src/files/RequenceStream.d.ts.map +0 -1
- package/build/types/helpers/src/files/index.d.ts +0 -7
- package/build/types/helpers/src/files/index.d.ts.map +0 -1
- package/build/types/helpers/src/files/mapOutput.d.ts +0 -10
- package/build/types/helpers/src/files/mapOutput.d.ts.map +0 -1
- package/build/types/helpers/src/files/types.d.ts +0 -4
- package/build/types/helpers/src/files/types.d.ts.map +0 -1
- package/build/types/helpers/src/utils/createObjectProxy.d.ts +0 -2
- package/build/types/helpers/src/utils/createObjectProxy.d.ts.map +0 -1
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts +0 -8
- package/build/types/helpers/src/utils/resolveRequenceTypes.d.ts.map +0 -1
- package/build/types/service/src/mapInput.d.ts +0 -2
- package/build/types/service/src/mapInput.d.ts.map +0 -1
- /package/build/types/helpers/src/{files → utils}/fileObject.d.ts +0 -0
- /package/build/types/helpers/src/{files → utils}/isValidMimeType.d.ts +0 -0
- /package/build/types/helpers/src/{files → utils}/streamObject.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @requence/service
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c73b646: fixed bun internal typing
|
|
8
|
+
|
|
9
|
+
## 0.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- c68705e: Allow overriding AMQP TLS connection options via environment variables for
|
|
14
|
+
`amqps://` connections: `CA` (inline PEM), `CA_FILE` (PEM file path) and
|
|
15
|
+
`REJECT_UNAUTHORIZED`. These act as a fallback only — options supplied in code
|
|
16
|
+
(`connectionOptions` in TS, `ssl_context` in Python) take precedence.
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 8d86c93: Introduce the TypeScript 7 native compiler (Go) alongside TypeScript 6 for
|
|
21
|
+
parallel use. The `typescript` module now resolves to real v6 (6.0.2) so the full
|
|
22
|
+
JS compiler API that `@requence/typing` consumes at runtime stays available, while
|
|
23
|
+
type-checking and declaration emit run on the native v7 compiler via Microsoft's
|
|
24
|
+
`tsgo` binary (`@typescript/native-preview`) — every package's `check-types` and
|
|
25
|
+
`build-declaration` script now calls `tsgo`, so v6 remains only as the library API
|
|
26
|
+
for `@requence/typing`. Uniform model: `tsc` = v6, `tsgo` = v7. VS Code is pointed
|
|
27
|
+
at the native TS7 language server.
|
|
28
|
+
|
|
29
|
+
Also fixes the `@requence/service` and `@requence/task` declaration builds: add an
|
|
30
|
+
explicit `rootDir` so emitted `.d.ts` land at the path `exports.types` declares
|
|
31
|
+
(previously the types entry pointed at a nonexistent file), and drop a stale
|
|
32
|
+
`files` reference to a removed `helpers/src/files` path.
|
|
33
|
+
|
|
34
|
+
Note: the native compiler is invoked as `tsgo` because Microsoft's `tsc`/`tsc6`
|
|
35
|
+
wrapper packaging fails to resolve under bun.
|
|
36
|
+
|
|
37
|
+
- 37771f8: release
|
|
38
|
+
|
|
3
39
|
## 0.7.1
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -54,6 +54,21 @@ createService(
|
|
|
54
54
|
)
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
### TLS connection options via environment
|
|
58
|
+
|
|
59
|
+
For `amqps://` connections, TLS settings can be overridden with environment
|
|
60
|
+
variables — useful for supplying a private CA or relaxing verification in a
|
|
61
|
+
deployment without changing code:
|
|
62
|
+
|
|
63
|
+
| Variable | Effect |
|
|
64
|
+
| --------------------- | --------------------------------------------------------------------- |
|
|
65
|
+
| `CA` | Inline PEM certificate(s) to trust as the CA. |
|
|
66
|
+
| `CA_FILE` | Path to a PEM file to trust as the CA (`CA` wins when both are set). |
|
|
67
|
+
| `REJECT_UNAUTHORIZED` | Set to `false`/`0`/`no` to disable certificate verification. |
|
|
68
|
+
|
|
69
|
+
These are a **fallback**: any matching value passed in code via
|
|
70
|
+
`connectionOptions` (`ca`, `rejectUnauthorized`) takes precedence.
|
|
71
|
+
|
|
57
72
|
### Return value
|
|
58
73
|
|
|
59
74
|
`createService` returns a `ServiceApi` object immediately (the connection is established in the background):
|
|
@@ -50,7 +50,50 @@ function deobfuscate(str) {
|
|
|
50
50
|
return decodedString.split(separator);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
// src/errors.ts
|
|
54
|
+
class RequenceConnectionError extends Error {
|
|
55
|
+
}
|
|
56
|
+
var UNREACHABLE_STATUS = new Set([502, 503, 504]);
|
|
57
|
+
|
|
58
|
+
class RequenceUnreachableError extends Error {
|
|
59
|
+
status;
|
|
60
|
+
constructor(status, options) {
|
|
61
|
+
super("The requence system is currently not reachable. Please retry later.", options);
|
|
62
|
+
this.status = status;
|
|
63
|
+
this.name = "RequenceUnreachableError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function isUnreachableStatus(status) {
|
|
67
|
+
return UNREACHABLE_STATUS.has(status);
|
|
68
|
+
}
|
|
69
|
+
function assertReachable(response) {
|
|
70
|
+
if (isUnreachableStatus(response.status)) {
|
|
71
|
+
throw new RequenceUnreachableError(response.status);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function reachableFetch(input, init) {
|
|
75
|
+
let response;
|
|
76
|
+
try {
|
|
77
|
+
response = await fetch(input, init);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new RequenceUnreachableError(undefined, { cause: error });
|
|
80
|
+
}
|
|
81
|
+
assertReachable(response);
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
class PayloadTooLargeError extends Error {
|
|
86
|
+
size;
|
|
87
|
+
maxSize;
|
|
88
|
+
constructor(size, maxSize) {
|
|
89
|
+
super(`Message payload is ${size} bytes, which exceeds the maximum message ` + `size of ${maxSize} bytes. Reduce the returned value, or offload large ` + `data (files/streams) so it travels by reference instead of inline.`);
|
|
90
|
+
this.name = "PayloadTooLargeError";
|
|
91
|
+
this.size = size;
|
|
92
|
+
this.maxSize = maxSize;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { obfuscate, deobfuscate, RequenceConnectionError, RequenceUnreachableError, isUnreachableStatus, assertReachable, reachableFetch, PayloadTooLargeError };
|
|
54
97
|
|
|
55
|
-
//# debugId=
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# debugId=24EBA4C8C93E588B64756E2164756E21
|
|
99
|
+
//# sourceMappingURL=chunk-8r349zge.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../helpers/src/utils/obfuscate.ts", "../src/errors.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"const separator = '\\u{f6ee}'\n\nconst base65Chars =\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$'\n\nconst base65CharToIndex: Record<string, number> = {}\nfor (let i = 0; i < base65Chars.length; i++) {\n base65CharToIndex[base65Chars[i]] = i\n}\n\nexport function obfuscate(...parts: Array<string>) {\n const str = parts.join(separator)\n let binaryString = ''\n\n for (let i = 0; i < str.length; i++) {\n const charCode = str.charCodeAt(i)\n binaryString += charCode.toString(2).padStart(16, '0')\n }\n\n let encodedString = ''\n const chunkSize = 6\n let paddingCount = 0\n\n for (let i = 0; i < binaryString.length; i += chunkSize) {\n let chunk = binaryString.substring(i, i + chunkSize)\n\n if (chunk.length < chunkSize) {\n paddingCount = chunkSize - chunk.length\n chunk = chunk.padEnd(chunkSize, '0')\n }\n\n const decimalValue = parseInt(chunk, 2)\n encodedString += base65Chars[decimalValue]\n }\n\n return encodedString + paddingCount.toString()\n}\n\nexport function randomString(length: number) {\n const randomValues = new Uint8Array(length)\n crypto.getRandomValues(randomValues)\n\n let randomString = ''\n for (let i = 0; i < length; i++) {\n randomString += base65Chars[randomValues[i] % base65Chars.length]\n }\n\n return randomString\n}\n\nexport function deobfuscate(str: string) {\n const paddingCount = parseInt(str.slice(-1), 10)\n str = str.slice(0, -1)\n\n let binaryString = ''\n\n for (let i = 0; i < str.length; i++) {\n const decimalValue = base65CharToIndex[str[i]]\n const binaryChunk = decimalValue.toString(2).padStart(6, '0')\n binaryString += binaryChunk\n }\n\n if (paddingCount > 0) {\n binaryString = binaryString.slice(0, -paddingCount)\n }\n\n let decodedString = ''\n const charSize = 16\n\n for (let i = 0; i < binaryString.length; i += charSize) {\n const byte = binaryString.substring(i, i + charSize)\n if (byte.length === 16) {\n const charCode = parseInt(byte, 2)\n decodedString += String.fromCharCode(charCode)\n }\n }\n\n return decodedString.split(separator)\n}\n",
|
|
6
|
+
"export class RequenceConnectionError extends Error {}\n\n// Gateway statuses an ingress/load balancer emits when no healthy backend is\n// available (maintenance window, deploy, cutover). The backend endpoints never\n// return these themselves, so treating them as \"unreachable\" is unambiguous.\nconst UNREACHABLE_STATUS = new Set([502, 503, 504])\n\n/**\n * Signals that the requence system could not be reached — e.g. during a\n * maintenance window or deploy, when the backend is unreachable (connection\n * refused / timeout / DNS failure) or an ingress returns a gateway error\n * (502/503/504). Callers should treat this as transient and retry later.\n */\nexport class RequenceUnreachableError extends Error {\n constructor(\n public readonly status?: number,\n options?: { cause?: unknown },\n ) {\n super(\n 'The requence system is currently not reachable. Please retry later.',\n options,\n )\n this.name = 'RequenceUnreachableError'\n }\n}\n\nexport function isUnreachableStatus(status: number): boolean {\n return UNREACHABLE_STATUS.has(status)\n}\n\n/**\n * Throws a {@link RequenceUnreachableError} when the response carries a gateway\n * status indicating the system is unreachable. Call right after a fetch, before\n * inspecting `response.ok`.\n */\nexport function assertReachable(response: Response): void {\n if (isUnreachableStatus(response.status)) {\n throw new RequenceUnreachableError(response.status)\n }\n}\n\n/**\n * Wraps `fetch` so a transport-level failure (connection refused, DNS failure,\n * timeout) surfaces as a {@link RequenceUnreachableError} instead of a raw\n * TypeError, and gateway statuses (502/503/504) do the same. The returned\n * response is guaranteed not to be a gateway-error response.\n */\nexport async function reachableFetch(\n input: Parameters<typeof fetch>[0],\n init?: Parameters<typeof fetch>[1],\n): Promise<Response> {\n let response: Response\n try {\n response = await fetch(input, init)\n } catch (error) {\n throw new RequenceUnreachableError(undefined, { cause: error })\n }\n assertReachable(response)\n return response\n}\n\nexport class PayloadTooLargeError extends Error {\n readonly size: number\n readonly maxSize: number\n\n constructor(size: number, maxSize: number) {\n super(\n `Message payload is ${size} bytes, which exceeds the maximum message ` +\n `size of ${maxSize} bytes. Reduce the returned value, or offload large ` +\n `data (files/streams) so it travels by reference instead of inline.`,\n )\n this.name = 'PayloadTooLargeError'\n this.size = size\n this.maxSize = maxSize\n }\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";AAAA,IAAM,YAAY;AAElB,IAAM,cACJ;AAEF,IAAM,oBAA4C,CAAC;AACnD,SAAS,IAAI,EAAG,IAAI,YAAY,QAAQ,KAAK;AAAA,EAC3C,kBAAkB,YAAY,MAAM;AACtC;AAEO,SAAS,SAAS,IAAI,OAAsB;AAAA,EACjD,MAAM,MAAM,MAAM,KAAK,SAAS;AAAA,EAChC,IAAI,eAAe;AAAA,EAEnB,SAAS,IAAI,EAAG,IAAI,IAAI,QAAQ,KAAK;AAAA,IACnC,MAAM,WAAW,IAAI,WAAW,CAAC;AAAA,IACjC,gBAAgB,SAAS,SAAS,CAAC,EAAE,SAAS,IAAI,GAAG;AAAA,EACvD;AAAA,EAEA,IAAI,gBAAgB;AAAA,EACpB,MAAM,YAAY;AAAA,EAClB,IAAI,eAAe;AAAA,EAEnB,SAAS,IAAI,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G,CAAC;AAAA;AAQ3C,MAAM,iCAAiC,MAAM;AAAA,EAEhC;AAAA,EADlB,WAAW,CACO,QAChB,SACA;AAAA,IACA,MACE,uEACA,OACF;AAAA,IANgB;AAAA,IAOhB,KAAK,OAAO;AAAA;AAEhB;AAEO,SAAS,mBAAmB,CAAC,QAAyB;AAAA,EAC3D,OAAO,mBAAmB,IAAI,MAAM;AAAA;AAQ/B,SAAS,eAAe,CAAC,UAA0B;AAAA,EACxD,IAAI,oBAAoB,SAAS,MAAM,GAAG;AAAA,IACxC,MAAM,IAAI,yBAAyB,SAAS,MAAM;AAAA,EACpD;AAAA;AASF,eAAsB,cAAc,CAClC,OACA,MACmB;AAAA,EACnB,IAAI;AAAA,EACJ,IAAI;AAAA,IACF,WAAW,MAAM,MAAM,OAAO,IAAI;AAAA,IAClC,OAAO,OAAO;AAAA,IACd,MAAM,IAAI,yBAAyB,WAAW,EAAE,OAAO,MAAM,CAAC;AAAA;AAAA,EAEhE,gBAAgB,QAAQ;AAAA,EACxB,OAAO;AAAA;AAAA;AAGF,MAAM,6BAA6B,MAAM;AAAA,EACrC;AAAA,EACA;AAAA,EAET,WAAW,CAAC,MAAc,SAAiB;AAAA,IACzC,MACE,sBAAsB,mDACpB,WAAW,gEACX,oEACJ;AAAA,IACA,KAAK,OAAO;AAAA,IACZ,KAAK,OAAO;AAAA,IACZ,KAAK,UAAU;AAAA;AAEnB;",
|
|
9
|
+
"debugId": "24EBA4C8C93E588B64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
package/build/cli.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
RequenceUnreachableError,
|
|
4
|
+
deobfuscate,
|
|
5
|
+
reachableFetch
|
|
6
|
+
} from "./chunk-8r349zge.js";
|
|
5
7
|
|
|
6
8
|
// src/cli.ts
|
|
7
9
|
import fs from "node:fs";
|
|
@@ -42,10 +44,18 @@ function loadPkgJson() {
|
|
|
42
44
|
}
|
|
43
45
|
async function fetchTypes(url, headers, targetFile, clear = false, showTimestamp = false) {
|
|
44
46
|
const timestamp = () => colors.zinc(new Date().toLocaleTimeString("en-GB", { hour12: false }));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
let response;
|
|
48
|
+
try {
|
|
49
|
+
response = await reachableFetch(url, {
|
|
50
|
+
method: "GET",
|
|
51
|
+
headers
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error instanceof RequenceUnreachableError) {
|
|
55
|
+
errorExit(error.message);
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
49
59
|
const branchName = response.headers.get("x-branch-name");
|
|
50
60
|
const text = await response.text();
|
|
51
61
|
if (!response.ok) {
|
|
@@ -162,5 +172,5 @@ in your ${chalk.bold("package.json")} in ${chalk.bold("requence.accessToken")} /
|
|
|
162
172
|
});
|
|
163
173
|
}).scriptName("requence-service").help("h").demandCommand(1, 1).strict().parse();
|
|
164
174
|
|
|
165
|
-
//# debugId=
|
|
175
|
+
//# debugId=55A0254889F5B8BD64756E2164756E21
|
|
166
176
|
//# sourceMappingURL=cli.js.map
|
package/build/cli.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/cli.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"#!/usr/bin/env node\n\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { deobfuscate } from '@requence/helpers'\nimport chalk from 'chalk'\nimport { createEventSource } from 'eventsource-client'\nimport yargs from 'yargs'\nimport { hideBin } from 'yargs/helpers'\nimport { z } from 'zod/v4'\n\n// Load .env automatically (Node 20.12+)\nif (typeof process.loadEnvFile === 'function') {\n try {\n process.loadEnvFile()\n } catch {\n // Ignore if .env is missing\n }\n}\n\nconst y = yargs(hideBin(process.argv))\n\nconst colors = {\n red: chalk.hex('#ef4444'),\n green: chalk.hex('#22c55e'),\n yellow: chalk.hex('#eab308'),\n orange: chalk.hex('#f97316'),\n zinc: chalk.hex('#71717a'),\n}\n\nfunction errorExit(title: string, text?: string): never {\n console.error(colors.red.bold(title + '\\n'))\n if (text) {\n console.error(colors.red(text) + '\\n')\n }\n process.exit(1)\n}\n\nlet pkgJson: any | null\nfunction loadPkgJson() {\n if (!pkgJson) {\n pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'))\n }\n return pkgJson\n}\n\nasync function fetchTypes(\n url: string,\n headers: HeadersInit,\n targetFile: string,\n clear = false,\n showTimestamp = false,\n) {\n const timestamp = () =>\n colors.zinc(new Date().toLocaleTimeString('en-GB', { hour12: false }))\n
|
|
5
|
+
"#!/usr/bin/env node\n\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { deobfuscate } from '@requence/helpers'\nimport chalk from 'chalk'\nimport { createEventSource } from 'eventsource-client'\nimport yargs from 'yargs'\nimport { hideBin } from 'yargs/helpers'\nimport { z } from 'zod/v4'\n\nimport { RequenceUnreachableError, reachableFetch } from './errors.ts'\n\n// Load .env automatically (Node 20.12+)\nif (typeof process.loadEnvFile === 'function') {\n try {\n process.loadEnvFile()\n } catch {\n // Ignore if .env is missing\n }\n}\n\nconst y = yargs(hideBin(process.argv))\n\nconst colors = {\n red: chalk.hex('#ef4444'),\n green: chalk.hex('#22c55e'),\n yellow: chalk.hex('#eab308'),\n orange: chalk.hex('#f97316'),\n zinc: chalk.hex('#71717a'),\n}\n\nfunction errorExit(title: string, text?: string): never {\n console.error(colors.red.bold(title + '\\n'))\n if (text) {\n console.error(colors.red(text) + '\\n')\n }\n process.exit(1)\n}\n\nlet pkgJson: any | null\nfunction loadPkgJson() {\n if (!pkgJson) {\n pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'))\n }\n return pkgJson\n}\n\nasync function fetchTypes(\n url: string,\n headers: HeadersInit,\n targetFile: string,\n clear = false,\n showTimestamp = false,\n) {\n const timestamp = () =>\n colors.zinc(new Date().toLocaleTimeString('en-GB', { hour12: false }))\n let response: Response\n try {\n response = await reachableFetch(url, {\n method: 'GET',\n headers,\n })\n } catch (error) {\n if (error instanceof RequenceUnreachableError) {\n errorExit(error.message)\n }\n throw error\n }\n\n const branchName = response.headers.get('x-branch-name')\n const text = await response.text()\n\n if (!response.ok) {\n errorExit(text)\n }\n\n let header =\n '// Generated by requence-service CLI — DO NOT EDIT.\\n// Changes will be overwritten.\\n\\n'\n\n if (branchName) {\n header += `// !!! types for branch \"${branchName}\" !!!\\n\\n`\n }\n const data = `${header}/* eslint-disable */\\n/* oxlint-disable */\\n/* prettier-ignore */\\n\\n${text}`\n\n fs.writeFileSync(targetFile, data)\n\n if (clear) {\n console.clear()\n }\n\n if (branchName) {\n console.info(\n ...(showTimestamp ? [timestamp()] : []),\n colors.yellow(\n 'types for branch',\n chalk.bold(branchName),\n 'saved to',\n chalk.bold(path.relative(process.cwd(), targetFile)),\n ),\n )\n } else {\n console.info(\n ...(showTimestamp ? [timestamp()] : []),\n colors.green(\n 'types saved to',\n chalk.bold(path.relative(process.cwd(), targetFile)),\n ),\n )\n }\n}\n\ny.command(\n 'generate-types',\n 'generates typescript types',\n (yargs) =>\n yargs\n .option('access-token', {\n describe: 'access token',\n type: 'string',\n })\n .option('dev-token', {\n description: 'dev token',\n type: 'string',\n })\n .option('outfile', {\n default: 'requence-env.d.ts',\n })\n .option('outdir', {\n default: '',\n })\n .option('watch', {\n type: 'boolean',\n })\n .option('clear', {\n description:\n 'clear the terminal on watch updates (use --no-clear to disable)',\n type: 'boolean',\n default: true,\n }),\n async (argv) => {\n let token =\n argv.accessToken ??\n process.env.REQUENCE_SERVICE_ACCESS_TOKEN ??\n process.env.REQUENCE_ACCESS_TOKEN\n\n if (!token) {\n const pkgJson = loadPkgJson()\n token =\n pkgJson.requence?.service?.accessToken ?? pkgJson.requence?.accessToken\n }\n\n if (argv.clear) {\n console.info() // newline\n }\n if (!token) {\n errorExit(\n 'No access token found',\n `You can provide the access token as argument to ${chalk.bold('requence-service')},\\nas environment variable ${chalk.bold('REQUENCE_ACCESS_TOKEN')} / ${chalk.bold('REQUENCE_SERVICE_ACCESS_TOKEN')} or\\nin your ${chalk.bold('package.json')} in ${chalk.bold('requence.accessToken')} / ${chalk.bold('requence.service.accessToken')}`,\n )\n }\n\n const parts = deobfuscate(token)\n if (parts.length !== 3 || parts[0] !== 'service') {\n errorExit('Invalid service key')\n }\n\n const [, connectionString, serverUrl] = parts\n const headers: HeadersInit = {\n Authorization: `Bearer ${connectionString}`,\n }\n let devToken =\n argv.devToken ??\n process.env.REQUENCE_SERVICE_DEV_TOKEN ??\n process.env.REQUENCE_DEV_TOKEN\n\n if (!devToken) {\n const pkgJson = loadPkgJson()\n devToken =\n pkgJson.requence?.service?.devToken ?? pkgJson.requence?.devToken\n }\n\n if (devToken) {\n const devParts = deobfuscate(devToken)\n if (devParts[0] !== 'api') {\n throw new Error(\n 'invalid dev token: please provide a personal access token',\n )\n }\n if (devParts[2] !== parts[2]) {\n throw new Error(\n 'invalid dev token: access token and dev token belong to different requence instances',\n )\n }\n\n headers['x-dev-authorization'] = devParts[1]\n }\n\n await fetchTypes(\n serverUrl + '/service/types/typescript',\n headers,\n path.join(argv.outdir || process.cwd(), argv.outfile),\n )\n\n if (!argv.watch) {\n return\n }\n\n if (argv.clear) {\n console.clear()\n }\n console.info(colors.orange.bold('Watching for type changes…'))\n let lastWrite = Date.now()\n const timeSchema = z.coerce.number().int().positive()\n createEventSource({\n method: 'GET',\n url: serverUrl + '/service/watch',\n headers,\n async onMessage({ data }) {\n const timeResult = timeSchema.safeParse(data)\n if (!timeResult.success || timeResult.data < lastWrite) {\n return\n }\n lastWrite = timeResult.data\n if (argv.clear) {\n console.clear()\n }\n console.info(\n colors.zinc.bold(`Regenerating types…${argv.clear ? '\\n\\n' : ''}`),\n )\n\n await fetchTypes(\n serverUrl + '/service/types/typescript',\n headers,\n path.join(argv.outdir || process.cwd(), argv.outfile),\n argv.clear,\n true,\n )\n console.info(\n colors.orange.bold(\n `${argv.clear ? '\\n\\n' : ''}Watching for type changes…`,\n ),\n )\n },\n })\n },\n)\n .scriptName('requence-service')\n .help('h')\n .demandCommand(1, 1)\n .strict()\n .parse()\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AAKA,IAAI,OAAO,QAAQ,gBAAgB,YAAY;AAAA,EAC7C,IAAI;AAAA,IACF,QAAQ,YAAY;AAAA,IACpB,MAAM;AAGV;AAEA,IAAM,IAAI,MAAM,QAAQ,QAAQ,IAAI,CAAC;AAErC,IAAM,SAAS;AAAA,EACb,KAAK,MAAM,IAAI,SAAS;AAAA,EACxB,OAAO,MAAM,IAAI,SAAS;AAAA,EAC1B,QAAQ,MAAM,IAAI,SAAS;AAAA,EAC3B,QAAQ,MAAM,IAAI,SAAS;AAAA,EAC3B,MAAM,MAAM,IAAI,SAAS;AAC3B;AAEA,SAAS,SAAS,CAAC,OAAe,MAAsB;AAAA,EACtD,QAAQ,MAAM,OAAO,IAAI,KAAK,QAAQ;AAAA,CAAI,CAAC;AAAA,EAC3C,IAAI,MAAM;AAAA,IACR,QAAQ,MAAM,OAAO,IAAI,IAAI,IAAI;AAAA,CAAI;AAAA,EACvC;AAAA,EACA,QAAQ,KAAK,CAAC;AAAA;AAGhB,IAAI;AACJ,SAAS,WAAW,GAAG;AAAA,EACrB,IAAI,CAAC,SAAS;AAAA,IACZ,UAAU,KAAK,MAAM,GAAG,aAAa,gBAAgB,OAAO,CAAC;AAAA,EAC/D;AAAA,EACA,OAAO;AAAA;AAGT,eAAe,UAAU,CACvB,KACA,SACA,YACA,QAAQ,OACR,gBAAgB,OAChB;AAAA,EACA,MAAM,YAAY,MAChB,OAAO,KAAK,IAAI,KAAK,EAAE,mBAAmB,SAAS,EAAE,QAAQ,MAAM,CA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