@sanoma-ai/workflows 0.1.0 → 0.2.0
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/README.md +72 -21
- package/dist/apply-steps.d.ts +6 -0
- package/dist/apply-steps.js +93 -0
- package/dist/apply-steps.js.map +1 -0
- package/dist/apply.d.ts +197 -0
- package/dist/apply.js +470 -0
- package/dist/apply.js.map +1 -0
- package/dist/call.d.ts +4 -0
- package/dist/call.js +19 -4
- package/dist/call.js.map +1 -1
- package/dist/client.d.ts +38 -2
- package/dist/client.js +67 -10
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +33 -16
- package/dist/config.js.map +1 -1
- package/dist/credentials.d.ts +25 -0
- package/dist/credentials.js +73 -5
- package/dist/credentials.js.map +1 -1
- package/dist/datafile.d.ts +11 -2
- package/dist/datafile.js +56 -2
- package/dist/datafile.js.map +1 -1
- package/dist/describe.d.ts +11 -5
- package/dist/describe.js +13 -5
- package/dist/describe.js.map +1 -1
- package/dist/drift.d.ts +64 -12
- package/dist/drift.js +118 -41
- package/dist/drift.js.map +1 -1
- package/dist/expectations.d.ts +2 -2
- package/dist/expectations.js +28 -3
- package/dist/expectations.js.map +1 -1
- package/dist/host.d.ts +56 -0
- package/dist/host.js +45 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/lockfile.d.ts +36 -0
- package/dist/lockfile.js +69 -0
- package/dist/lockfile.js.map +1 -0
- package/dist/op.d.ts +3 -0
- package/dist/op.js.map +1 -1
- package/dist/resource.d.ts +188 -22
- package/dist/resource.js +173 -28
- package/dist/resource.js.map +1 -1
- package/dist/resources.d.ts +18 -3
- package/dist/resources.js +53 -6
- package/dist/resources.js.map +1 -1
- package/dist/run.d.ts +14 -0
- package/dist/run.js +6 -1
- package/dist/run.js.map +1 -1
- package/dist/sandbox.js +5 -1
- package/dist/sandbox.js.map +1 -1
- package/dist/scenario.d.ts +12 -3
- package/dist/scenario.js +33 -8
- package/dist/scenario.js.map +1 -1
- package/dist/secret.d.ts +42 -0
- package/dist/secret.js +58 -0
- package/dist/secret.js.map +1 -0
- package/dist/shared.d.ts +8 -0
- package/dist/shared.js +7 -0
- package/dist/shared.js.map +1 -1
- package/dist/source.d.ts +58 -0
- package/dist/source.js +54 -0
- package/dist/source.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worker.d.ts +3 -0
- package/dist/worker.js +13 -4
- package/dist/worker.js.map +1 -1
- package/dist/writer.d.ts +35 -0
- package/dist/writer.js +201 -0
- package/dist/writer.js.map +1 -0
- package/package.json +6 -1
- package/src/apply-steps.ts +110 -0
- package/src/apply.ts +626 -0
- package/src/call.ts +19 -4
- package/src/client.ts +83 -13
- package/src/config.ts +48 -25
- package/src/credentials.ts +90 -5
- package/src/datafile.ts +76 -4
- package/src/describe.ts +36 -16
- package/src/drift.ts +155 -45
- package/src/expectations.ts +30 -4
- package/src/host.ts +96 -0
- package/src/index.ts +24 -1
- package/src/lockfile.ts +95 -0
- package/src/op.ts +3 -0
- package/src/resource.ts +270 -47
- package/src/resources.ts +63 -8
- package/src/run.ts +15 -0
- package/src/sandbox.ts +5 -1
- package/src/scenario.ts +50 -13
- package/src/secret.ts +92 -0
- package/src/shared.ts +10 -0
- package/src/source.ts +82 -0
- package/src/version.ts +1 -1
- package/src/worker.ts +16 -5
- package/src/writer.ts +225 -0
package/dist/shared.js
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
export const DEFAULT_SLEEP_NAME = "Sleep";
|
|
9
9
|
/** The built-in drift workflow's name, which a config's own workflows may not take; a UI and the scenarios name its runs by it. */
|
|
10
10
|
export const DRIFT_WORKFLOW = "drift";
|
|
11
|
+
/**
|
|
12
|
+
* The built-in apply workflow's name: the only workflow that may call a writable resource type's
|
|
13
|
+
* change operations (`create`, `update`, `delete`).
|
|
14
|
+
*/
|
|
15
|
+
export const APPLY_WORKFLOW = "apply";
|
|
16
|
+
/** The workflows the runtime adds itself, which a config's own may not be named: drift and apply. */
|
|
17
|
+
export const BUILT_IN_WORKFLOWS = new Set([DRIFT_WORKFLOW, APPLY_WORKFLOW]);
|
|
11
18
|
/**
|
|
12
19
|
* Every run status, in the order a run may pass through them: waiting on the queue, running,
|
|
13
20
|
* waiting for an approval, or ended. `waiting` is `running` with an approval pending.
|
package/dist/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAoBA,mGAAmG;AACnG,iGAAiG;AACjG,wEAAwE;AAExE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AAE1C,mIAAmI;AACnI,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,qGAAqG;AACrG,MAAM,CAAC,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;AAEjG;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAU,CAAC;AAKzG,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAyC,CAAC;AAE1G,gEAAgE;AAChE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAiB,EAAW,EAAE,CAAE,cAAuC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEjH;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,QAAyC,E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EAAE,EAAE,CACzC,CAAC,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEpF,uFAAuF;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAoB,EAAW,EAAE,CACjF,MAAM,KAAK,KAAK,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,QAAQ,CAAC,CAAC"}
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** A company's repository, as the runtime writes to it. */
|
|
3
|
+
export interface Source {
|
|
4
|
+
/** The repository's root directory. */
|
|
5
|
+
root: string;
|
|
6
|
+
/**
|
|
7
|
+
* Records the files at `paths`, relative to `root`, as one change by `author` (who made it, as
|
|
8
|
+
* the app names them: a login or a typed name). Its revision; undefined when nothing changed.
|
|
9
|
+
*/
|
|
10
|
+
commit(change: {
|
|
11
|
+
paths: string[];
|
|
12
|
+
message: string;
|
|
13
|
+
author: string;
|
|
14
|
+
}): {
|
|
15
|
+
revision: string;
|
|
16
|
+
} | undefined | Promise<{
|
|
17
|
+
revision: string;
|
|
18
|
+
} | undefined>;
|
|
19
|
+
/** The revision `ref` names, the checked-out one by default. */
|
|
20
|
+
head(ref?: string): string | Promise<string>;
|
|
21
|
+
/** Pushes `ref` to the repository at `url`, signed in with `token`. */
|
|
22
|
+
push?(target: {
|
|
23
|
+
url: string;
|
|
24
|
+
token: string;
|
|
25
|
+
ref: string;
|
|
26
|
+
}): void | Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The built-in operation `sanoma.source.resolve`: the commit `ref` names in the repository at
|
|
30
|
+
* `url` now, by `git ls-remote` (a branch first, then a tag, peeled; a full commit id is itself).
|
|
31
|
+
* Apply calls it to fill a host's revision before it plans, and drift to see a merge. `resolveConfig`
|
|
32
|
+
* registers it when a connector declares a host type.
|
|
33
|
+
*/
|
|
34
|
+
export declare const sourceOps: import("./op.ts").Connector<"sanoma", {
|
|
35
|
+
readonly source: {
|
|
36
|
+
readonly resolve: {
|
|
37
|
+
readonly effect: "read";
|
|
38
|
+
readonly idempotent: true;
|
|
39
|
+
readonly description: "Resolve a branch or tag of a git repository to the commit it names now";
|
|
40
|
+
readonly input: z.ZodObject<{
|
|
41
|
+
url: z.ZodString;
|
|
42
|
+
ref: z.ZodString;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
readonly output: z.ZodObject<{
|
|
45
|
+
revision: z.ZodString;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
readonly target: ({ url, ref }: {
|
|
48
|
+
url: string;
|
|
49
|
+
ref: string;
|
|
50
|
+
}) => string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
export declare const SOURCE_RESOLVE = "sanoma.source.resolve";
|
|
55
|
+
/** The driver of `sanoma.source.resolve`: git on this machine, with its own credential helpers. */
|
|
56
|
+
export declare const sourceDriver: import("./op.ts").Driver;
|
|
57
|
+
/** The commit `ref` (a branch, a tag, `HEAD`, a full ref or a commit id) names in the repository at `url`. */
|
|
58
|
+
export declare function resolveRevision(url: string, ref: string): Promise<string>;
|
package/dist/source.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { defineConnector, defineDriver, DriverError } from "./op.js";
|
|
5
|
+
/**
|
|
6
|
+
* The built-in operation `sanoma.source.resolve`: the commit `ref` names in the repository at
|
|
7
|
+
* `url` now, by `git ls-remote` (a branch first, then a tag, peeled; a full commit id is itself).
|
|
8
|
+
* Apply calls it to fill a host's revision before it plans, and drift to see a merge. `resolveConfig`
|
|
9
|
+
* registers it when a connector declares a host type.
|
|
10
|
+
*/
|
|
11
|
+
export const sourceOps = defineConnector("sanoma", {
|
|
12
|
+
source: {
|
|
13
|
+
resolve: {
|
|
14
|
+
effect: "read",
|
|
15
|
+
idempotent: true,
|
|
16
|
+
description: "Resolve a branch or tag of a git repository to the commit it names now",
|
|
17
|
+
input: z.object({ url: z.string().min(1), ref: z.string().min(1) }),
|
|
18
|
+
output: z.object({ revision: z.string() }),
|
|
19
|
+
target: ({ url, ref }) => `${url}#${ref}`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
export const SOURCE_RESOLVE = "sanoma.source.resolve";
|
|
24
|
+
/** The driver of `sanoma.source.resolve`: git on this machine, with its own credential helpers. */
|
|
25
|
+
export const sourceDriver = defineDriver(sourceOps, {
|
|
26
|
+
source: { resolve: async ({ url, ref }) => ({ revision: await resolveRevision(url, ref) }) },
|
|
27
|
+
});
|
|
28
|
+
const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
29
|
+
/** The commit `ref` (a branch, a tag, `HEAD`, a full ref or a commit id) names in the repository at `url`. */
|
|
30
|
+
export async function resolveRevision(url, ref) {
|
|
31
|
+
if (COMMIT.test(ref))
|
|
32
|
+
return ref;
|
|
33
|
+
const { stdout } = await promisify(execFile)("git", ["ls-remote", "--", url, ref, `${ref}^{}`], {
|
|
34
|
+
// Never a prompt for credentials: a repository that needs them and has none fails.
|
|
35
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
36
|
+
timeout: 30_000,
|
|
37
|
+
}).catch((err) => {
|
|
38
|
+
throw new DriverError(`git ls-remote ${url} failed: ${err.stderr?.trim() || err.message}`, {
|
|
39
|
+
retryable: true,
|
|
40
|
+
cause: err,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
const refs = new Map(stdout.split("\n").flatMap((line) => {
|
|
44
|
+
const [sha, name] = line.split("\t");
|
|
45
|
+
return sha && name ? [[name, sha]] : [];
|
|
46
|
+
}));
|
|
47
|
+
for (const name of [`refs/heads/${ref}`, `refs/tags/${ref}^{}`, `refs/tags/${ref}`, ref]) {
|
|
48
|
+
const sha = refs.get(name);
|
|
49
|
+
if (sha)
|
|
50
|
+
return sha;
|
|
51
|
+
}
|
|
52
|
+
throw new DriverError(`${url} has no branch or tag ${ref}`, { retryable: false, vendorCode: "no_such_ref" });
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA0BrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,EAAE;IACjD,MAAM,EAAE;QACN,OAAO,EAAE;YACP,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,wEAAwE;YACrF,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACnE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAgC,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE;SACxE;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAoE,CAAC;AAEnG,mGAAmG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,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnD,CAAC,CAAC,CACH,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,CAAC,cAAc,GAAG,EAAE,EAAE,aAAa,GAAG,KAAK,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;QACzF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;IACtB,CAAC;IACD,MAAM,IAAI,WAAW,CAAC,GAAG,GAAG,yBAAyB,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAC;AAC/G,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type WorkflowDefinition } from "./define.ts";
|
|
2
2
|
/** This package's version. A unit test keeps it equal to package.json. */
|
|
3
|
-
export declare const RUNTIME_VERSION = "0.
|
|
3
|
+
export declare const RUNTIME_VERSION = "0.2.0";
|
|
4
4
|
/**
|
|
5
5
|
* The sequence of DBOS calls the runtime makes around each `ctx` call: policy step, approval
|
|
6
6
|
* events and messages, the driver step. Bump it whenever that sequence changes, even without a
|
package/dist/version.js
CHANGED
|
@@ -5,7 +5,7 @@ import { dirname, join } from "node:path";
|
|
|
5
5
|
import { jsonSchemaOf, opIdsOf } from "./define.js";
|
|
6
6
|
import { upFrom } from "./paths.js";
|
|
7
7
|
/** This package's version. A unit test keeps it equal to package.json. */
|
|
8
|
-
export const RUNTIME_VERSION = "0.
|
|
8
|
+
export const RUNTIME_VERSION = "0.2.0";
|
|
9
9
|
/**
|
|
10
10
|
* The sequence of DBOS calls the runtime makes around each `ctx` call: policy step, approval
|
|
11
11
|
* events and messages, the driver step. Bump it whenever that sequence changes, even without a
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SanomaConfig } from "./config.ts";
|
|
2
|
+
import type { Source } from "./source.ts";
|
|
2
3
|
export interface Worker {
|
|
3
4
|
/**
|
|
4
5
|
* The vendors whose drivers could not run when the worker started, in the config's order: a
|
|
@@ -23,6 +24,8 @@ export interface WorkerOptions {
|
|
|
23
24
|
* restarting during a rolling deploy would otherwise take the new workers' runs.
|
|
24
25
|
*/
|
|
25
26
|
promote?: boolean;
|
|
27
|
+
/** The company's repository, which apply commits the lockfile to; the launcher passes its checkout. */
|
|
28
|
+
source?: Source;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Registers the workflows, connects to Postgres and recovers any runs that were interrupted.
|
package/dist/worker.js
CHANGED
|
@@ -2,14 +2,15 @@ import { DBOS } from "@dbos-inc/dbos-sdk";
|
|
|
2
2
|
import { buildCtx, isInfrastructureError } from "./call.js";
|
|
3
3
|
import { dbosStatusesOf } from "./client.js";
|
|
4
4
|
import { resolveConfig } from "./config.js";
|
|
5
|
-
import { watchCredentials } from "./credentials.js";
|
|
6
|
-
import { DBOS_DATABASE_OPTIONS, prepareDatabase } from "./db.js";
|
|
5
|
+
import { storedSecrets, watchCredentials } from "./credentials.js";
|
|
6
|
+
import { DBOS_DATABASE_OPTIONS, lazyPool, prepareDatabase } from "./db.js";
|
|
7
7
|
import { credentialsOf, unconfigured, unconfiguredSummary } from "./env.js";
|
|
8
8
|
import { errorInfo, parseOrThrow } from "./errors.js";
|
|
9
9
|
import { entry, ownedLedger, skipped, write, writeFailure } from "./ledger.js";
|
|
10
10
|
import { dbosLogger, quietIfSandbox, setLogLevel, warn } from "./log.js";
|
|
11
11
|
import { lineStartsOf, readSource } from "./ast.js";
|
|
12
12
|
import { callsOf, outlineWithSource } from "./outline.js";
|
|
13
|
+
import { currentRun } from "./run.js";
|
|
13
14
|
import { errorMessage } from "./shared.js";
|
|
14
15
|
// DBOS registrations are process-wide and survive shutdown, so a name is registered once, and
|
|
15
16
|
// its function reads the state of the worker running when a run starts, definition and all; the
|
|
@@ -29,16 +30,19 @@ export async function startWorker(config, options = {}) {
|
|
|
29
30
|
setLogLevel(options.logLevel);
|
|
30
31
|
// The config's own, or a Postgres store made for this worker, which `stop` then closes.
|
|
31
32
|
const ledger = ownedLedger(resolved);
|
|
33
|
+
const secrets = lazyPool(resolved.databaseUrl, "secrets");
|
|
32
34
|
const state = {
|
|
33
35
|
app: resolved.appName,
|
|
34
36
|
ops: resolved.ops,
|
|
35
37
|
drivers: resolved.drivers,
|
|
36
38
|
fakes: resolved.fakes,
|
|
37
39
|
...(resolved.scenarios && { scenarios: resolved.scenarios }),
|
|
40
|
+
...(options.source && { source: options.source }),
|
|
38
41
|
types: resolved.types,
|
|
39
42
|
steps: resolved.steps,
|
|
40
43
|
policy: resolved.policy,
|
|
41
44
|
ledger: ledger.store,
|
|
45
|
+
secrets: storedSecrets(() => secrets.db(), "sanoma"),
|
|
42
46
|
workflows: resolved.workflows,
|
|
43
47
|
outlines: new Map([...resolved.workflows].map(([name, wf]) => [name, outlineOf(wf)])),
|
|
44
48
|
stopped: false,
|
|
@@ -52,7 +56,12 @@ export async function startWorker(config, options = {}) {
|
|
|
52
56
|
state.stopped = true;
|
|
53
57
|
// Each is closed whatever the one before did; the first failure is what stop throws.
|
|
54
58
|
let failed;
|
|
55
|
-
for (const close of [
|
|
59
|
+
for (const close of [
|
|
60
|
+
() => DBOS.shutdown(),
|
|
61
|
+
() => credentials.close(),
|
|
62
|
+
() => secrets.close(),
|
|
63
|
+
() => ledger.close(),
|
|
64
|
+
]) {
|
|
56
65
|
await close().catch((error) => (failed ??= { error }));
|
|
57
66
|
}
|
|
58
67
|
if (failed)
|
|
@@ -198,7 +207,7 @@ async function runWorkflow(name, { input, startedBy, sandbox }) {
|
|
|
198
207
|
const { seedSandbox } = await import("./sandbox.js");
|
|
199
208
|
await seedSandbox(run, sandbox);
|
|
200
209
|
}
|
|
201
|
-
output = await wf.run(buildCtx(wf, run), parsed);
|
|
210
|
+
output = await currentRun.run(run, () => wf.run(buildCtx(wf, run), parsed));
|
|
202
211
|
}
|
|
203
212
|
finally {
|
|
204
213
|
// Before the outcome is written: a call still queued must find the run ended.
|
package/dist/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAuB,aAAa,EAAqB,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAuB,aAAa,EAAqB,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE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G,EAAE,OAAO,CAAC,CAAC;YAClC,CAAC;YACD,MAAM,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9E,CAAC;gBAAS,CAAC;YACT,8EAA8E;YAC9E,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC;QACnB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACzE,IAAI,qBAAqB,CAAC,GAAG,EAAE,KAAK,CAAC;YAAE,OAAO,CAAC,MAAM,EAAE,4BAA4B,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;;YACpG,MAAM,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1C,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,MAAM,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/writer.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { FormatConfig } from "oxfmt";
|
|
2
|
+
import { type DataFileExport, type DataFileImport, type DataValue } from "./datafile.ts";
|
|
3
|
+
/** A whole data file to render: its imports and its resources, in order. */
|
|
4
|
+
export interface DataFileContent {
|
|
5
|
+
imports: readonly Pick<DataFileImport, "source" | "imported" | "local">[];
|
|
6
|
+
exports: readonly Pick<DataFileExport, "name" | "vendor" | "type" | "desired">[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* oxfmt's options from `<root>/.oxfmtrc.json`, what `oxfmt` itself reads there, less what only
|
|
10
|
+
* its CLI uses (`ignorePatterns`, `overrides`); none, oxfmt's defaults, without the file.
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatOptions(root: string): FormatConfig;
|
|
13
|
+
/**
|
|
14
|
+
* `source`, a data file's text, with fields of its resource `exportName` set to new values:
|
|
15
|
+
* `fields` by dotted path, a list item's with its index, as a drift report names them
|
|
16
|
+
* (`required_pull_request_reviews.0.dismiss_stale_reviews`). A field the declaration does not
|
|
17
|
+
* have is added at the end of the object that should hold it. Only that `export const` changes:
|
|
18
|
+
* it is formatted with oxfmt under `options` (`formatOptions`), and every other byte of the file
|
|
19
|
+
* stays as it was.
|
|
20
|
+
*
|
|
21
|
+
* A value naming a secret adds `import { secret } from "sanoma/resources"` after the file's
|
|
22
|
+
* imports when it has none.
|
|
23
|
+
*
|
|
24
|
+
* Throws when the file does not parse, declares no such resource, or a path cannot be set: it
|
|
25
|
+
* runs through a value that is not an object or a list, or ends at a reference to another
|
|
26
|
+
* resource (a person changes a reference; a vendor's value never replaces one).
|
|
27
|
+
*/
|
|
28
|
+
export declare function setFields(source: string, exportName: string, fields: Readonly<Record<string, DataValue>>, options?: FormatConfig): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* A whole data file: the imports, one per source, then each resource as `export const`, then
|
|
31
|
+
* `export default` naming them all, formatted with oxfmt under `options`. `readDataFile` reads it
|
|
32
|
+
* back as it was given: what `readDataFile` returns renders the file again. A file whose values
|
|
33
|
+
* name a secret also imports `secret` from "sanoma/resources".
|
|
34
|
+
*/
|
|
35
|
+
export declare function renderDataFile({ imports, exports }: DataFileContent, options?: FormatConfig): Promise<string>;
|
package/dist/writer.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse } from "./ast.js";
|
|
4
|
+
import { isReference, keyName, readDataFile, SECRET_ENTRIES, } from "./datafile.js";
|
|
5
|
+
import { isSecret } from "./secret.js";
|
|
6
|
+
/**
|
|
7
|
+
* oxfmt's options from `<root>/.oxfmtrc.json`, what `oxfmt` itself reads there, less what only
|
|
8
|
+
* its CLI uses (`ignorePatterns`, `overrides`); none, oxfmt's defaults, without the file.
|
|
9
|
+
*/
|
|
10
|
+
export function formatOptions(root) {
|
|
11
|
+
let text;
|
|
12
|
+
try {
|
|
13
|
+
text = readFileSync(join(root, ".oxfmtrc.json"), "utf8");
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
if (err.code === "ENOENT")
|
|
17
|
+
return {};
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
const { $schema: _, ignorePatterns: __, overrides: ___, ...options } = JSON.parse(text);
|
|
21
|
+
return options;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `source`, a data file's text, with fields of its resource `exportName` set to new values:
|
|
25
|
+
* `fields` by dotted path, a list item's with its index, as a drift report names them
|
|
26
|
+
* (`required_pull_request_reviews.0.dismiss_stale_reviews`). A field the declaration does not
|
|
27
|
+
* have is added at the end of the object that should hold it. Only that `export const` changes:
|
|
28
|
+
* it is formatted with oxfmt under `options` (`formatOptions`), and every other byte of the file
|
|
29
|
+
* stays as it was.
|
|
30
|
+
*
|
|
31
|
+
* A value naming a secret adds `import { secret } from "sanoma/resources"` after the file's
|
|
32
|
+
* imports when it has none.
|
|
33
|
+
*
|
|
34
|
+
* Throws when the file does not parse, declares no such resource, or a path cannot be set: it
|
|
35
|
+
* runs through a value that is not an object or a list, or ends at a reference to another
|
|
36
|
+
* resource (a person changes a reference; a vendor's value never replaces one).
|
|
37
|
+
*/
|
|
38
|
+
export async function setFields(source, exportName, fields, options = {}) {
|
|
39
|
+
let text = source;
|
|
40
|
+
// One field at a time, each against the file as the last left it: no offset goes stale.
|
|
41
|
+
for (const [path, value] of Object.entries(fields)) {
|
|
42
|
+
const { start, end, replacement } = editAt(declarationOf(text, exportName).object, path, value);
|
|
43
|
+
text = text.slice(0, start) + replacement + text.slice(end);
|
|
44
|
+
}
|
|
45
|
+
if (Object.values(fields).some(holdsSecret))
|
|
46
|
+
text = withSecretImport(text);
|
|
47
|
+
// The declaration on its own: a top-level statement formats the same in its file as alone.
|
|
48
|
+
const { start, end } = declarationOf(text, exportName).statement;
|
|
49
|
+
const formatted = await format(text.slice(start, end), options);
|
|
50
|
+
return text.slice(0, start) + formatted.trimEnd() + text.slice(end);
|
|
51
|
+
}
|
|
52
|
+
/** What a data file imports `secret` from when it names one (`readDataFile` lists no such import). */
|
|
53
|
+
const SECRET_IMPORT = { source: "sanoma/resources", imported: "secret", local: "secret" };
|
|
54
|
+
/**
|
|
55
|
+
* A whole data file: the imports, one per source, then each resource as `export const`, then
|
|
56
|
+
* `export default` naming them all, formatted with oxfmt under `options`. `readDataFile` reads it
|
|
57
|
+
* back as it was given: what `readDataFile` returns renders the file again. A file whose values
|
|
58
|
+
* name a secret also imports `secret` from "sanoma/resources".
|
|
59
|
+
*/
|
|
60
|
+
export async function renderDataFile({ imports, exports }, options = {}) {
|
|
61
|
+
const names = new Map();
|
|
62
|
+
const hasSecret = imports.some((i) => i.local === SECRET_IMPORT.local);
|
|
63
|
+
const all = !hasSecret && exports.some((e) => holdsSecret(e.desired)) ? [...imports, SECRET_IMPORT] : imports;
|
|
64
|
+
for (const { source, imported, local } of all) {
|
|
65
|
+
const list = names.get(source) ?? [];
|
|
66
|
+
list.push(imported === local ? local : `${imported} as ${local}`);
|
|
67
|
+
names.set(source, list);
|
|
68
|
+
}
|
|
69
|
+
const parts = [
|
|
70
|
+
[...names].map(([source, list]) => `import { ${list.join(", ")} } from ${JSON.stringify(source)};`).join("\n"),
|
|
71
|
+
// The top-level object on lines of its own, so oxfmt keeps it expanded as people write it.
|
|
72
|
+
...exports.map(({ name, vendor, type, desired }) => {
|
|
73
|
+
const body = Object.entries(desired).map(([key, value]) => `${keyOf(key)}: ${literal(value)},\n`);
|
|
74
|
+
return `export const ${name} = ${vendor}.${type}({${body.length ? `\n${body.join("")}` : ""}});`;
|
|
75
|
+
}),
|
|
76
|
+
`export default [${exports.map((e) => e.name).join(", ")}];`,
|
|
77
|
+
];
|
|
78
|
+
return format(`${parts.filter(Boolean).join("\n\n")}\n`, options);
|
|
79
|
+
}
|
|
80
|
+
/** `text` with `secret` imported after its imports, unless it imports it already. */
|
|
81
|
+
function withSecretImport(text) {
|
|
82
|
+
const imports = parse("/data-file.ts", text).program.body.filter((s) => s.type === "ImportDeclaration");
|
|
83
|
+
const has = imports.some((s) => SECRET_ENTRIES.has(s.source.value) &&
|
|
84
|
+
s.specifiers.some((sp) => (sp.imported?.name ?? sp.imported?.value) === "secret"));
|
|
85
|
+
if (has)
|
|
86
|
+
return text;
|
|
87
|
+
const at = imports.at(-1)?.end ?? 0;
|
|
88
|
+
const line = `import { ${SECRET_IMPORT.local} } from ${JSON.stringify(SECRET_IMPORT.source)};`;
|
|
89
|
+
return at ? `${text.slice(0, at)}\n${line}${text.slice(at)}` : `${line}\n${text}`;
|
|
90
|
+
}
|
|
91
|
+
/** The `export const` of the resource `name` in `text`, and the object literal its constructor takes. */
|
|
92
|
+
function declarationOf(text, name) {
|
|
93
|
+
// The name is never resolved, and a relative import is checked against the file's own directory.
|
|
94
|
+
const filename = "/data-file.ts";
|
|
95
|
+
const { program, errors } = parse(filename, text);
|
|
96
|
+
if (errors.length)
|
|
97
|
+
throw new Error(`The data file does not parse: ${errors[0].message}`);
|
|
98
|
+
const found = readDataFile(program, filename).exports.find((e) => e.name === name);
|
|
99
|
+
if (!found)
|
|
100
|
+
throw new Error(`The data file declares no resource ${name}`);
|
|
101
|
+
const statement = program.body.find((s) => s.start === found.start);
|
|
102
|
+
return { statement, object: statement.declaration.declarations[0].init.arguments[0] };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* What setting `path` to `value` in `object` replaces, and with what. A key may hold a dot
|
|
106
|
+
* (`metadata: { "app.owner": … }`), and a drift report's path does not say so: at each object,
|
|
107
|
+
* the longest run of the path's segments that names a field is that field.
|
|
108
|
+
*/
|
|
109
|
+
function editAt(object, path, value) {
|
|
110
|
+
const keys = path.split(".");
|
|
111
|
+
let node = object;
|
|
112
|
+
for (let i = 0; i < keys.length;) {
|
|
113
|
+
if (node.type === "ObjectExpression") {
|
|
114
|
+
const names = new Map(node.properties.map((p) => [fieldName(p), p]));
|
|
115
|
+
let j = keys.length;
|
|
116
|
+
while (j > i && !names.has(keys.slice(i, j).join(".")))
|
|
117
|
+
j--;
|
|
118
|
+
if (j === i)
|
|
119
|
+
return added(node, keys.slice(i), path, value);
|
|
120
|
+
node = names.get(keys.slice(i, j).join(".")).value;
|
|
121
|
+
i = j;
|
|
122
|
+
}
|
|
123
|
+
else if (node.type === "ArrayExpression" && /^\d+$/.test(keys[i]) && node.elements[Number(keys[i])]) {
|
|
124
|
+
node = node.elements[Number(keys[i])];
|
|
125
|
+
i++;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const at = keys.slice(0, i).join(".");
|
|
129
|
+
throw new Error(`Cannot set ${path}: ${at} is not an object or a list with item ${keys[i]}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const named = referenceIn(node);
|
|
133
|
+
if (named) {
|
|
134
|
+
throw new Error(`Cannot set ${path}: it names the resource ${named}; change a reference in the file itself`);
|
|
135
|
+
}
|
|
136
|
+
return { start: node.start, end: node.end, replacement: literal(value) };
|
|
137
|
+
}
|
|
138
|
+
/** The first resource a value names, itself or anywhere inside it: a vendor's value never replaces one. */
|
|
139
|
+
function referenceIn(node) {
|
|
140
|
+
if (node.type === "Identifier")
|
|
141
|
+
return node.name;
|
|
142
|
+
const items = node.type === "ArrayExpression" ? node.elements : node.type === "ObjectExpression" ? node.properties : [];
|
|
143
|
+
for (const item of items) {
|
|
144
|
+
const named = item && referenceIn(item.type === "Property" ? item.value : item);
|
|
145
|
+
if (named)
|
|
146
|
+
return named;
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The edit that adds `keys` (the first missing, then any under it) with `value` at the end of
|
|
152
|
+
* `object`. Only objects are made under it: a list item's index there is refused.
|
|
153
|
+
*/
|
|
154
|
+
function added(object, [key, ...under], path, value) {
|
|
155
|
+
const index = under.find((k) => /^\d+$/.test(k));
|
|
156
|
+
if (index !== undefined)
|
|
157
|
+
throw new Error(`Cannot set ${path}: the file has no list to hold item ${index}`);
|
|
158
|
+
const nested = under.reduceRight((v, k) => Object.fromEntries([[k, v]]), value);
|
|
159
|
+
const field = `${keyOf(key)}: ${literal(nested)}`;
|
|
160
|
+
const last = object.properties.at(-1);
|
|
161
|
+
return last
|
|
162
|
+
? { start: last.end, end: last.end, replacement: `, ${field}` }
|
|
163
|
+
: { start: object.start, end: object.end, replacement: `{ ${field} }` };
|
|
164
|
+
}
|
|
165
|
+
/** A property's name, as `readDataFile` reads it. */
|
|
166
|
+
const fieldName = (p) => (p.type === "Property" && !p.computed ? keyName(p.key) : undefined);
|
|
167
|
+
/** A field's name in source: bare when it can be, else a string. */
|
|
168
|
+
const keyOf = (key) => (/^[A-Za-z_$][\w$]*$/.test(key) ? key : JSON.stringify(key));
|
|
169
|
+
/** True when a value names a secret, itself or anywhere inside it. */
|
|
170
|
+
const holdsSecret = (value) => isSecret(value) ||
|
|
171
|
+
(typeof value === "object" && value !== null && !isReference(value) && Object.values(value).some(holdsSecret));
|
|
172
|
+
/** A value in the data-file subset, as source, on one line: oxfmt lays it out. */
|
|
173
|
+
function literal(value) {
|
|
174
|
+
if (isReference(value))
|
|
175
|
+
return value.name;
|
|
176
|
+
if (isSecret(value))
|
|
177
|
+
return `secret(${JSON.stringify(value.$secret)}${value.generate ? ", { generate: true }" : ""})`;
|
|
178
|
+
if (value === null || typeof value === "boolean" || typeof value === "string")
|
|
179
|
+
return JSON.stringify(value);
|
|
180
|
+
if (typeof value === "number") {
|
|
181
|
+
if (!Number.isFinite(value))
|
|
182
|
+
throw new Error(`${value} cannot be written in a data file: write a finite number`);
|
|
183
|
+
return Object.is(value, -0) ? "0" : String(value);
|
|
184
|
+
}
|
|
185
|
+
if (Array.isArray(value))
|
|
186
|
+
return `[${value.map(literal).join(", ")}]`;
|
|
187
|
+
if (typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
188
|
+
const fields = Object.entries(value).map(([key, v]) => `${keyOf(key)}: ${literal(v)}`);
|
|
189
|
+
return fields.length ? `{ ${fields.join(", ")} }` : "{}";
|
|
190
|
+
}
|
|
191
|
+
throw new Error(`${String(value)} cannot be written in a data file: ${typeof value} is not a data value`);
|
|
192
|
+
}
|
|
193
|
+
/** `text` formatted by oxfmt, loaded only when a file is written. */
|
|
194
|
+
async function format(text, options) {
|
|
195
|
+
const oxfmt = await import("oxfmt");
|
|
196
|
+
const { code, errors } = await oxfmt.format("data-file.ts", text, options);
|
|
197
|
+
if (errors.length)
|
|
198
|
+
throw new Error(`oxfmt could not format the data file: ${errors[0].message}`);
|
|
199
|
+
return code;
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAa,KAAK,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAIL,WAAW,EACX,OAAO,EACP,YAAY,EACZ,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAavC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,CAAC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I,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,sCAAsC,OAAO,KAAK,sBAAsB,CAAC,CAAC;AAC5G,CAAC;AAED,qEAAqE;AACrE,KAAK,UAAU,MAAM,CAAC,IAAY,EAAE,OAAqB;IACvD,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3E,IAAI,MAAM,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,CAAC,CAAC,CAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAClG,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanoma-ai/workflows",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Business processes as TypeScript functions, run durably on DBOS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"approvals",
|
|
@@ -47,6 +47,10 @@
|
|
|
47
47
|
"types": "./dist/plugin.d.ts",
|
|
48
48
|
"default": "./dist/plugin.js"
|
|
49
49
|
},
|
|
50
|
+
"./resources": {
|
|
51
|
+
"types": "./dist/secret.d.ts",
|
|
52
|
+
"default": "./dist/secret.js"
|
|
53
|
+
},
|
|
50
54
|
"./scenario": {
|
|
51
55
|
"types": "./dist/scenario.d.ts",
|
|
52
56
|
"default": "./dist/scenario.js"
|
|
@@ -71,6 +75,7 @@
|
|
|
71
75
|
"@dbos-inc/dbos-sdk": "^5.2.11",
|
|
72
76
|
"@faker-js/faker": "^10.6.0",
|
|
73
77
|
"oxc-parser": "^0.153.0",
|
|
78
|
+
"oxfmt": "^0.72.0",
|
|
74
79
|
"pg": "^8.23.1",
|
|
75
80
|
"randexp": "^0.5.3",
|
|
76
81
|
"zod-schema-faker": "^2.1.2"
|