rivetkit 2.3.5 → 2.3.7
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/dist/browser/client.d.ts +19 -5
- package/dist/browser/client.js +32 -9
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +12 -2
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +115 -5
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +19 -5
- package/dist/tsup/agent-os/index.d.ts +19 -5
- package/dist/tsup/agent-os/index.js +115 -5
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-ID7DMKXR.cjs → chunk-2SGPZEAJ.cjs} +13 -3
- package/dist/tsup/chunk-2SGPZEAJ.cjs.map +1 -0
- package/dist/tsup/{chunk-2GZPBFZV.cjs → chunk-46AE7JOI.cjs} +262 -252
- package/dist/tsup/chunk-46AE7JOI.cjs.map +1 -0
- package/dist/tsup/{chunk-FJQ36P7Q.js → chunk-6D2WRHJV.js} +2 -2
- package/dist/tsup/{chunk-WGRSAJSX.js → chunk-7YQJXWBW.js} +3 -3
- package/dist/tsup/{chunk-NYEGEML6.js → chunk-CH25U5NO.js} +3 -3
- package/dist/tsup/{chunk-7IIAJQTF.cjs → chunk-DOPH7DT2.cjs} +7 -7
- package/dist/tsup/{chunk-7IIAJQTF.cjs.map → chunk-DOPH7DT2.cjs.map} +1 -1
- package/dist/tsup/{chunk-G3CCRCTK.cjs → chunk-HNHLBM3Y.cjs} +108 -6
- package/dist/tsup/chunk-HNHLBM3Y.cjs.map +1 -0
- package/dist/tsup/{chunk-TKPQNJQ2.cjs → chunk-MNZFNIVI.cjs} +3 -3
- package/dist/tsup/{chunk-TKPQNJQ2.cjs.map → chunk-MNZFNIVI.cjs.map} +1 -1
- package/dist/tsup/{chunk-YOP6FRYG.js → chunk-OG4OR2CM.js} +13 -3
- package/dist/tsup/chunk-OG4OR2CM.js.map +1 -0
- package/dist/tsup/{chunk-SHBE77IT.js → chunk-QWLJCP3X.js} +106 -4
- package/dist/tsup/chunk-QWLJCP3X.js.map +1 -0
- package/dist/tsup/{chunk-PG5P2IDC.cjs → chunk-TQHMPWL6.cjs} +9 -9
- package/dist/tsup/{chunk-PG5P2IDC.cjs.map → chunk-TQHMPWL6.cjs.map} +1 -1
- package/dist/tsup/{chunk-7HDG7FY3.cjs → chunk-UIZZCJ5W.cjs} +4 -4
- package/dist/tsup/{chunk-7HDG7FY3.cjs.map → chunk-UIZZCJ5W.cjs.map} +1 -1
- package/dist/tsup/{chunk-ENPXVDGZ.js → chunk-YHPFCYL3.js} +2 -2
- package/dist/tsup/{chunk-PMIEL4PM.js → chunk-YU3C5OCU.js} +130 -120
- package/dist/tsup/chunk-YU3C5OCU.js.map +1 -0
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +4 -4
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-BzdqbLAP.d.ts → config-BRpVbJCD.d.ts} +20 -6
- package/dist/tsup/{config-CPPEwn_e.d.cts → config-BobvQpex.d.cts} +20 -6
- package/dist/tsup/{context-wWv-K2K_.d.ts → context-Cj-DFyiy.d.ts} +1 -1
- package/dist/tsup/{context-DSA9gFXB.d.cts → context-YEBNJrws.d.cts} +1 -1
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +2 -2
- package/dist/tsup/db/mod.js +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +1 -1
- package/dist/tsup/dynamic/mod.d.ts +1 -1
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +4 -4
- package/dist/tsup/inspector/mod.js +3 -3
- package/dist/tsup/inspector-tab/mod.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.d.cts +2 -2
- package/dist/tsup/inspector-tab/mod.d.ts +2 -2
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/mod.cjs +175 -85
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +3 -3
- package/dist/tsup/mod.d.ts +3 -3
- package/dist/tsup/mod.js +107 -17
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +16 -13
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +15 -12
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +9 -9
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +19 -9
- package/src/actor/actions.ts +119 -0
- package/src/actor/config.ts +61 -18
- package/src/actor/definition.ts +3 -0
- package/src/client/actor-common.ts +3 -1
- package/src/client/client.ts +24 -11
- package/src/registry/config/index.ts +2 -4
- package/src/registry/index.ts +86 -5
- package/src/registry/napi-runtime.ts +4 -0
- package/src/registry/native.ts +17 -16
- package/src/registry/runtime.ts +1 -0
- package/src/registry/wasm-runtime.ts +6 -0
- package/src/test/mod.ts +1 -19
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.test.ts +170 -0
- package/src/unstable/migrations.ts +141 -0
- package/dist/tsup/chunk-2GZPBFZV.cjs.map +0 -1
- package/dist/tsup/chunk-G3CCRCTK.cjs.map +0 -1
- package/dist/tsup/chunk-ID7DMKXR.cjs.map +0 -1
- package/dist/tsup/chunk-PMIEL4PM.js.map +0 -1
- package/dist/tsup/chunk-SHBE77IT.js.map +0 -1
- package/dist/tsup/chunk-YOP6FRYG.js.map +0 -1
- /package/dist/tsup/{chunk-FJQ36P7Q.js.map → chunk-6D2WRHJV.js.map} +0 -0
- /package/dist/tsup/{chunk-WGRSAJSX.js.map → chunk-7YQJXWBW.js.map} +0 -0
- /package/dist/tsup/{chunk-NYEGEML6.js.map → chunk-CH25U5NO.js.map} +0 -0
- /package/dist/tsup/{chunk-ENPXVDGZ.js.map → chunk-YHPFCYL3.js.map} +0 -0
package/dist/tsup/test/mod.cjs
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkDOPH7DT2cjs = require('../chunk-DOPH7DT2.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
var _chunk2GZPBFZVcjs = require('../chunk-2GZPBFZV.cjs');
|
|
6
|
+
var _chunk46AE7JOIcjs = require('../chunk-46AE7JOI.cjs');
|
|
8
7
|
require('../chunk-MYWZCDML.cjs');
|
|
8
|
+
require('../chunk-MNZFNIVI.cjs');
|
|
9
9
|
require('../chunk-UEULFXUI.cjs');
|
|
10
|
-
require('../chunk-
|
|
11
|
-
require('../chunk-ID7DMKXR.cjs');
|
|
10
|
+
require('../chunk-2SGPZEAJ.cjs');
|
|
12
11
|
require('../chunk-4FC7TVS6.cjs');
|
|
13
12
|
|
|
14
|
-
// src/test/
|
|
13
|
+
// src/test/ready.ts
|
|
15
14
|
var _pretry = require('p-retry'); var _pretry2 = _interopRequireDefault(_pretry);
|
|
16
15
|
async function waitForRegistryReady(registry) {
|
|
17
|
-
const clientConfig = _chunk2GZPBFZVcjs.convertRegistryConfigToClientConfig.call(void 0,
|
|
18
|
-
registry.parseConfig()
|
|
19
|
-
);
|
|
20
16
|
await _pretry2.default.call(void 0,
|
|
21
17
|
async () => {
|
|
22
|
-
await
|
|
18
|
+
const response = await registry.routes.health();
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`RivetKit registry is not ready: ${response.status} ${await response.text()}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
|
-
retries:
|
|
26
|
+
retries: 120,
|
|
26
27
|
minTimeout: 50,
|
|
27
28
|
maxTimeout: 250
|
|
28
29
|
}
|
|
29
30
|
);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
// src/test/mod.ts
|
|
31
34
|
async function setupTest(c, registry) {
|
|
32
35
|
registry.config.test = { ...registry.config.test, enabled: true };
|
|
33
36
|
registry.config.noWelcome = true;
|
|
34
37
|
registry.start();
|
|
35
38
|
await waitForRegistryReady(registry);
|
|
36
|
-
const client =
|
|
37
|
-
...
|
|
39
|
+
const client = _chunkDOPH7DT2cjs.createClient.call(void 0, {
|
|
40
|
+
..._chunk46AE7JOIcjs.convertRegistryConfigToClientConfig.call(void 0, registry.parseConfig()),
|
|
38
41
|
disableMetadataLookup: false
|
|
39
42
|
});
|
|
40
43
|
c.onTestFinished(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/test/mod.cjs","../../../src/test/mod.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/test/mod.cjs","../../../src/test/ready.ts","../../../src/test/mod.ts"],"names":[],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B;AACE;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACA;ACZA,iFAAmB;AAGnB,MAAA,SAAsB,oBAAA,CACrB,QAAA,EACgB;AAChB,EAAA,MAAM,8BAAA;AAAA,IACL,MAAA,CAAA,EAAA,GAAY;AACX,MAAA,MAAM,SAAA,EAAW,MAAM,QAAA,CAAS,MAAA,CAAO,MAAA,CAAO,CAAA;AAC9C,MAAA,GAAA,CAAI,CAAC,QAAA,CAAS,EAAA,EAAI;AACjB,QAAA,MAAM,IAAI,KAAA;AAAA,UACT,CAAA,gCAAA,EAAmC,QAAA,CAAS,MAAM,CAAA,CAAA,EAAI,MAAM,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA;AAAA,QAAA;AAC5E,MAAA;AACD,IAAA;AACD,IAAA;AACA,MAAA;AACU,MAAA;AACG,MAAA;AACA,IAAA;AACb,EAAA;AAEF;ADUA;AACA;AEtBA;AAIC,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AAEA,EAAA;AAA+B,IAAA;AAC+B,IAAA;AACtC,EAAA;AAGxB,EAAA;AACC,IAAA;AAAqB,EAAA;AAGtB,EAAA;AACD;AFiBA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/test/mod.cjs","sourcesContent":[null,"import pRetry from \"p-retry\";\nimport type { Registry } from \"@/registry\";\n\nexport async function waitForRegistryReady(\n\tregistry: Registry<any>,\n): Promise<void> {\n\tawait pRetry(\n\t\tasync () => {\n\t\t\tconst response = await registry.routes.health();\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`RivetKit registry is not ready: ${response.status} ${await response.text()}`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tretries: 120,\n\t\t\tminTimeout: 50,\n\t\t\tmaxTimeout: 250,\n\t\t},\n\t);\n}\n","import type { TestContext } from \"vitest\";\nimport { convertRegistryConfigToClientConfig } from \"@/client/config\";\nimport { type Client, createClient } from \"@/client/mod\";\nimport type { Registry } from \"@/registry\";\nimport { waitForRegistryReady } from \"./ready\";\n\nexport interface SetupTestResult<A extends Registry<any>> {\n\tclient: Client<A>;\n}\n\nexport async function setupTest<A extends Registry<any>>(\n\tc: TestContext,\n\tregistry: A,\n): Promise<SetupTestResult<A>> {\n\tregistry.config.test = { ...registry.config.test, enabled: true };\n\tregistry.config.noWelcome = true;\n\n\tregistry.start();\n\tawait waitForRegistryReady(registry);\n\n\tconst client = createClient<A>({\n\t\t...convertRegistryConfigToClientConfig(registry.parseConfig()),\n\t\tdisableMetadataLookup: false,\n\t});\n\n\tc.onTestFinished(async () => {\n\t\tawait client.dispose();\n\t});\n\n\treturn { client };\n}\n"]}
|
package/dist/tsup/test/mod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { aC as Registry, a2 as Client } from '../config-BobvQpex.cjs';
|
|
3
3
|
import 'zod/v4';
|
|
4
4
|
import '../config-BxOimoGX.cjs';
|
|
5
5
|
import '@rivetkit/rivetkit-wasm';
|
package/dist/tsup/test/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestContext } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { aC as Registry, a2 as Client } from '../config-BRpVbJCD.js';
|
|
3
3
|
import 'zod/v4';
|
|
4
4
|
import '../config-BxOimoGX.js';
|
|
5
5
|
import '@rivetkit/rivetkit-wasm';
|
package/dist/tsup/test/mod.js
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-CH25U5NO.js";
|
|
4
4
|
import {
|
|
5
|
-
convertRegistryConfigToClientConfig
|
|
6
|
-
|
|
7
|
-
} from "../chunk-PMIEL4PM.js";
|
|
5
|
+
convertRegistryConfigToClientConfig
|
|
6
|
+
} from "../chunk-YU3C5OCU.js";
|
|
8
7
|
import "../chunk-JI6GZ2C2.js";
|
|
8
|
+
import "../chunk-YHPFCYL3.js";
|
|
9
9
|
import "../chunk-7AFZMFPQ.js";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-YOP6FRYG.js";
|
|
10
|
+
import "../chunk-OG4OR2CM.js";
|
|
12
11
|
import "../chunk-ZZ3WBRPD.js";
|
|
13
12
|
|
|
14
|
-
// src/test/
|
|
13
|
+
// src/test/ready.ts
|
|
15
14
|
import pRetry from "p-retry";
|
|
16
15
|
async function waitForRegistryReady(registry) {
|
|
17
|
-
const clientConfig = convertRegistryConfigToClientConfig(
|
|
18
|
-
registry.parseConfig()
|
|
19
|
-
);
|
|
20
16
|
await pRetry(
|
|
21
17
|
async () => {
|
|
22
|
-
await
|
|
18
|
+
const response = await registry.routes.health();
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`RivetKit registry is not ready: ${response.status} ${await response.text()}`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
23
24
|
},
|
|
24
25
|
{
|
|
25
|
-
retries:
|
|
26
|
+
retries: 120,
|
|
26
27
|
minTimeout: 50,
|
|
27
28
|
maxTimeout: 250
|
|
28
29
|
}
|
|
29
30
|
);
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
// src/test/mod.ts
|
|
31
34
|
async function setupTest(c, registry) {
|
|
32
35
|
registry.config.test = { ...registry.config.test, enabled: true };
|
|
33
36
|
registry.config.noWelcome = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/test/mod.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/test/ready.ts","../../../src/test/mod.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport type { Registry } from \"@/registry\";\n\nexport async function waitForRegistryReady(\n\tregistry: Registry<any>,\n): Promise<void> {\n\tawait pRetry(\n\t\tasync () => {\n\t\t\tconst response = await registry.routes.health();\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`RivetKit registry is not ready: ${response.status} ${await response.text()}`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tretries: 120,\n\t\t\tminTimeout: 50,\n\t\t\tmaxTimeout: 250,\n\t\t},\n\t);\n}\n","import type { TestContext } from \"vitest\";\nimport { convertRegistryConfigToClientConfig } from \"@/client/config\";\nimport { type Client, createClient } from \"@/client/mod\";\nimport type { Registry } from \"@/registry\";\nimport { waitForRegistryReady } from \"./ready\";\n\nexport interface SetupTestResult<A extends Registry<any>> {\n\tclient: Client<A>;\n}\n\nexport async function setupTest<A extends Registry<any>>(\n\tc: TestContext,\n\tregistry: A,\n): Promise<SetupTestResult<A>> {\n\tregistry.config.test = { ...registry.config.test, enabled: true };\n\tregistry.config.noWelcome = true;\n\n\tregistry.start();\n\tawait waitForRegistryReady(registry);\n\n\tconst client = createClient<A>({\n\t\t...convertRegistryConfigToClientConfig(registry.parseConfig()),\n\t\tdisableMetadataLookup: false,\n\t});\n\n\tc.onTestFinished(async () => {\n\t\tawait client.dispose();\n\t});\n\n\treturn { client };\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,OAAO,YAAY;AAGnB,eAAsB,qBACrB,UACgB;AAChB,QAAM;AAAA,IACL,YAAY;AACX,YAAM,WAAW,MAAM,SAAS,OAAO,OAAO;AAC9C,UAAI,CAAC,SAAS,IAAI;AACjB,cAAM,IAAI;AAAA,UACT,mCAAmC,SAAS,MAAM,IAAI,MAAM,SAAS,KAAK,CAAC;AAAA,QAC5E;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,YAAY;AAAA,IACb;AAAA,EACD;AACD;;;ACXA,eAAsB,UACrB,GACA,UAC8B;AAC9B,WAAS,OAAO,OAAO,EAAE,GAAG,SAAS,OAAO,MAAM,SAAS,KAAK;AAChE,WAAS,OAAO,YAAY;AAE5B,WAAS,MAAM;AACf,QAAM,qBAAqB,QAAQ;AAEnC,QAAM,SAAS,aAAgB;AAAA,IAC9B,GAAG,oCAAoC,SAAS,YAAY,CAAC;AAAA,IAC7D,uBAAuB;AAAA,EACxB,CAAC;AAED,IAAE,eAAe,YAAY;AAC5B,UAAM,OAAO,QAAQ;AAAA,EACtB,CAAC;AAED,SAAO,EAAE,OAAO;AACjB;","names":[]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/unstable/migrations.ts
|
|
2
|
+
var DEFAULT_MIGRATION_TABLE_NAME = "rivetkit_schema_version";
|
|
3
|
+
function migrations({
|
|
4
|
+
tableName = DEFAULT_MIGRATION_TABLE_NAME,
|
|
5
|
+
adopt,
|
|
6
|
+
migrations: ladder
|
|
7
|
+
}) {
|
|
8
|
+
validateTableName(tableName);
|
|
9
|
+
validateLadder(ladder);
|
|
10
|
+
return async (database) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const quotedTableName = `"${tableName}"`;
|
|
13
|
+
await database.execute(`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS ${quotedTableName} (
|
|
15
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
16
|
+
schema_version INTEGER NOT NULL CHECK (
|
|
17
|
+
schema_version BETWEEN 0 AND ${Number.MAX_SAFE_INTEGER}
|
|
18
|
+
)
|
|
19
|
+
) STRICT
|
|
20
|
+
`);
|
|
21
|
+
const rows = await database.execute(
|
|
22
|
+
`SELECT schema_version FROM ${quotedTableName} WHERE singleton = 1`
|
|
23
|
+
);
|
|
24
|
+
if (rows.length > 1) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`invalid migration table "${tableName}": expected at most one version row, received ${rows.length}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const rawCurrent = (_a = rows[0]) == null ? void 0 : _a.schema_version;
|
|
30
|
+
let current = rows.length === 0 ? 0 : rawCurrent;
|
|
31
|
+
if (rows.length === 0 && adopt) {
|
|
32
|
+
current = await adopt(database);
|
|
33
|
+
}
|
|
34
|
+
if (typeof current !== "number" || !Number.isSafeInteger(current) || current < 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`invalid schema version ${String(current)} in migration table "${tableName}"`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (current > ladder.length) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`migration version ${current} in "${tableName}" is newer than supported version ${ladder.length}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (rows.length === 0 && current > 0) {
|
|
45
|
+
await writeVersion(database, quotedTableName, current);
|
|
46
|
+
}
|
|
47
|
+
for (const migration of ladder.slice(current)) {
|
|
48
|
+
if (migration.sql !== void 0) {
|
|
49
|
+
await database.execute(migration.sql);
|
|
50
|
+
} else {
|
|
51
|
+
await migration.up(database);
|
|
52
|
+
}
|
|
53
|
+
await writeVersion(database, quotedTableName, migration.version);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function writeVersion(database, quotedTableName, version) {
|
|
58
|
+
await database.execute(
|
|
59
|
+
`INSERT INTO ${quotedTableName} (singleton, schema_version)
|
|
60
|
+
VALUES (1, ?)
|
|
61
|
+
ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,
|
|
62
|
+
version
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function validateTableName(tableName) {
|
|
66
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`invalid migration table name "${tableName}": expected a SQLite identifier`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function validateLadder(ladder) {
|
|
73
|
+
if (ladder.length === 0) {
|
|
74
|
+
throw new Error("migration ladder must not be empty");
|
|
75
|
+
}
|
|
76
|
+
for (const [index, migration] of ladder.entries()) {
|
|
77
|
+
const expectedVersion = index + 1;
|
|
78
|
+
if (migration.version !== expectedVersion) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`invalid migration ladder: expected version ${expectedVersion}, received ${migration.version}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const hasSql = typeof migration.sql === "string";
|
|
84
|
+
const hasUp = typeof migration.up === "function";
|
|
85
|
+
if (hasSql === hasUp) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`invalid migration ${migration.version}: expected exactly one of sql or up`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (hasSql && migration.sql.trim().length === 0) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`invalid migration ${migration.version}: SQL is empty`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
exports.DEFAULT_MIGRATION_TABLE_NAME = DEFAULT_MIGRATION_TABLE_NAME; exports.migrations = migrations;
|
|
101
|
+
//# sourceMappingURL=migrations.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/unstable/migrations.cjs","../../../src/unstable/migrations.ts"],"names":[],"mappings":"AAAA;ACEO,IAAM,6BAAA,EAA+B,yBAAA;AA8BrC,SAAS,UAAA,CAAW;AAAA,EAC1B,UAAA,EAAY,4BAAA;AAAA,EACZ,KAAA;AAAA,EACA,UAAA,EAAY;AACb,CAAA,EAAgE;AAC/D,EAAA,iBAAA,CAAkB,SAAS,CAAA;AAC3B,EAAA,cAAA,CAAe,MAAM,CAAA;AAErB,EAAA,OAAO,MAAA,CAAO,QAAA,EAAA,GAAa;AAxC5B,IAAA,IAAA,EAAA;AAyCE,IAAA,MAAM,gBAAA,EAAkB,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA,CAAA;AACrC,IAAA,MAAM,QAAA,CAAS,OAAA,CAAQ,CAAA;AAAA,8BAAA,EACO,eAAe,CAAA;AAAA;AAAA;AAAA,kCAAA,EAGX,MAAA,CAAO,gBAAgB,CAAA;AAAA;AAAA;AAAA,EAAA,CAGxD,CAAA;AAED,IAAA,MAAM,KAAA,EAAO,MAAM,QAAA,CAAS,OAAA;AAAA,MAC3B,CAAA,2BAAA,EAA8B,eAAe,CAAA,oBAAA;AAAA,IAC9C,CAAA;AACA,IAAA,GAAA,CAAI,IAAA,CAAK,OAAA,EAAS,CAAA,EAAG;AACpB,MAAA,MAAM,IAAI,KAAA;AAAA,QACT,CAAA,yBAAA,EAA4B,SAAS,CAAA,8CAAA,EAAiD,IAAA,CAAK,MAAM,CAAA;AAAA,MAAA;AAClG,IAAA;AAGD,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AAA8B,IAAA;AAE/B,IAAA;AAKC,MAAA;AAAU,QAAA;AACiE,MAAA;AAC3E,IAAA;AAED,IAAA;AACC,MAAA;AAAU,QAAA;AACsF,MAAA;AAChG,IAAA;AAED,IAAA;AACC,MAAA;AAAqD,IAAA;AAGtD,IAAA;AACC,MAAA;AACC,QAAA;AAAoC,MAAA;AAEpC,QAAA;AAA2B,MAAA;AAE5B,MAAA;AAA+D,IAAA;AAChE,EAAA;AAEF;AAEA;AAKC,EAAA;AAAe,IAAA;AACgB;AAAA,gFAAA;AAAA,IAAA;AAG9B,EAAA;AAEF;AAEA;AACC,EAAA;AACC,IAAA;AAAU,MAAA;AACiC,IAAA;AAC3C,EAAA;AAEF;AAEA;AACC,EAAA;AACC,IAAA;AAAoD,EAAA;AAGrD,EAAA;AACC,IAAA;AACA,IAAA;AACC,MAAA;AAAU,QAAA;AACmF,MAAA;AAC7F,IAAA;AAED,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AAAU,QAAA;AAC6B,MAAA;AACvC,IAAA;AAED,IAAA;AACC,MAAA;AAAU,QAAA;AAC6B,MAAA;AACvC,IAAA;AACD,EAAA;AAEF;AD5CA;AACA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/unstable/migrations.cjs","sourcesContent":[null,"import type { RawAccess } from \"@/common/database/config\";\n\nexport const DEFAULT_MIGRATION_TABLE_NAME = \"rivetkit_schema_version\";\n\nexport type MigrationDatabase = Pick<RawAccess, \"execute\">;\n\nexport type Migration =\n\t| {\n\t\t\tversion: number;\n\t\t\tsql: string;\n\t\t\tup?: never;\n\t }\n\t| {\n\t\t\tversion: number;\n\t\t\tsql?: never;\n\t\t\tup: (db: MigrationDatabase) => Promise<void> | void;\n\t };\n\nexport interface MigrationsOptions {\n\t/** A table owned by this schema. Override this when multiple schemas share a database. */\n\ttableName?: string;\n\t/** Detect the version of a schema that predates its migration table. */\n\tadopt?: (db: MigrationDatabase) => Promise<number> | number;\n\t/** Contiguous migrations numbered from 1. */\n\tmigrations: readonly Migration[];\n}\n\n/**\n * Creates an `onMigrate` callback that applies each unapplied migration in order.\n * RivetKit runs the callback inside its migration savepoint, making the complete\n * ladder atomic when used with `db({ onMigrate })`.\n */\nexport function migrations({\n\ttableName = DEFAULT_MIGRATION_TABLE_NAME,\n\tadopt,\n\tmigrations: ladder,\n}: MigrationsOptions): (db: MigrationDatabase) => Promise<void> {\n\tvalidateTableName(tableName);\n\tvalidateLadder(ladder);\n\n\treturn async (database) => {\n\t\tconst quotedTableName = `\"${tableName}\"`;\n\t\tawait database.execute(`\n\t\t\tCREATE TABLE IF NOT EXISTS ${quotedTableName} (\n\t\t\t\tsingleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n\t\t\t\tschema_version INTEGER NOT NULL CHECK (\n\t\t\t\t\tschema_version BETWEEN 0 AND ${Number.MAX_SAFE_INTEGER}\n\t\t\t\t)\n\t\t\t) STRICT\n\t\t`);\n\n\t\tconst rows = await database.execute<{ schema_version: unknown }>(\n\t\t\t`SELECT schema_version FROM ${quotedTableName} WHERE singleton = 1`,\n\t\t);\n\t\tif (rows.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration table \"${tableName}\": expected at most one version row, received ${rows.length}`,\n\t\t\t);\n\t\t}\n\n\t\tconst rawCurrent = rows[0]?.schema_version;\n\t\tlet current = rows.length === 0 ? 0 : rawCurrent;\n\t\tif (rows.length === 0 && adopt) {\n\t\t\tcurrent = await adopt(database);\n\t\t}\n\t\tif (\n\t\t\ttypeof current !== \"number\" ||\n\t\t\t!Number.isSafeInteger(current) ||\n\t\t\tcurrent < 0\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid schema version ${String(current)} in migration table \"${tableName}\"`,\n\t\t\t);\n\t\t}\n\t\tif (current > ladder.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`migration version ${current} in \"${tableName}\" is newer than supported version ${ladder.length}`,\n\t\t\t);\n\t\t}\n\t\tif (rows.length === 0 && current > 0) {\n\t\t\tawait writeVersion(database, quotedTableName, current);\n\t\t}\n\n\t\tfor (const migration of ladder.slice(current)) {\n\t\t\tif (migration.sql !== undefined) {\n\t\t\t\tawait database.execute(migration.sql);\n\t\t\t} else {\n\t\t\t\tawait migration.up(database);\n\t\t\t}\n\t\t\tawait writeVersion(database, quotedTableName, migration.version);\n\t\t}\n\t};\n}\n\nasync function writeVersion(\n\tdatabase: MigrationDatabase,\n\tquotedTableName: string,\n\tversion: number,\n): Promise<void> {\n\tawait database.execute(\n\t\t`INSERT INTO ${quotedTableName} (singleton, schema_version)\n\t\t VALUES (1, ?)\n\t\t ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,\n\t\tversion,\n\t);\n}\n\nfunction validateTableName(tableName: string): void {\n\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {\n\t\tthrow new Error(\n\t\t\t`invalid migration table name \"${tableName}\": expected a SQLite identifier`,\n\t\t);\n\t}\n}\n\nfunction validateLadder(ladder: readonly Migration[]): void {\n\tif (ladder.length === 0) {\n\t\tthrow new Error(\"migration ladder must not be empty\");\n\t}\n\n\tfor (const [index, migration] of ladder.entries()) {\n\t\tconst expectedVersion = index + 1;\n\t\tif (migration.version !== expectedVersion) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration ladder: expected version ${expectedVersion}, received ${migration.version}`,\n\t\t\t);\n\t\t}\n\t\tconst hasSql = typeof migration.sql === \"string\";\n\t\tconst hasUp = typeof migration.up === \"function\";\n\t\tif (hasSql === hasUp) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration ${migration.version}: expected exactly one of sql or up`,\n\t\t\t);\n\t\t}\n\t\tif (hasSql && migration.sql.trim().length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration ${migration.version}: SQL is empty`,\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { R as RawAccess } from '../config-BxOimoGX.cjs';
|
|
2
|
+
|
|
3
|
+
declare const DEFAULT_MIGRATION_TABLE_NAME = "rivetkit_schema_version";
|
|
4
|
+
type MigrationDatabase = Pick<RawAccess, "execute">;
|
|
5
|
+
type Migration = {
|
|
6
|
+
version: number;
|
|
7
|
+
sql: string;
|
|
8
|
+
up?: never;
|
|
9
|
+
} | {
|
|
10
|
+
version: number;
|
|
11
|
+
sql?: never;
|
|
12
|
+
up: (db: MigrationDatabase) => Promise<void> | void;
|
|
13
|
+
};
|
|
14
|
+
interface MigrationsOptions {
|
|
15
|
+
/** A table owned by this schema. Override this when multiple schemas share a database. */
|
|
16
|
+
tableName?: string;
|
|
17
|
+
/** Detect the version of a schema that predates its migration table. */
|
|
18
|
+
adopt?: (db: MigrationDatabase) => Promise<number> | number;
|
|
19
|
+
/** Contiguous migrations numbered from 1. */
|
|
20
|
+
migrations: readonly Migration[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates an `onMigrate` callback that applies each unapplied migration in order.
|
|
24
|
+
* RivetKit runs the callback inside its migration savepoint, making the complete
|
|
25
|
+
* ladder atomic when used with `db({ onMigrate })`.
|
|
26
|
+
*/
|
|
27
|
+
declare function migrations({ tableName, adopt, migrations: ladder, }: MigrationsOptions): (db: MigrationDatabase) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
export { DEFAULT_MIGRATION_TABLE_NAME, type Migration, type MigrationDatabase, type MigrationsOptions, migrations };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { R as RawAccess } from '../config-BxOimoGX.js';
|
|
2
|
+
|
|
3
|
+
declare const DEFAULT_MIGRATION_TABLE_NAME = "rivetkit_schema_version";
|
|
4
|
+
type MigrationDatabase = Pick<RawAccess, "execute">;
|
|
5
|
+
type Migration = {
|
|
6
|
+
version: number;
|
|
7
|
+
sql: string;
|
|
8
|
+
up?: never;
|
|
9
|
+
} | {
|
|
10
|
+
version: number;
|
|
11
|
+
sql?: never;
|
|
12
|
+
up: (db: MigrationDatabase) => Promise<void> | void;
|
|
13
|
+
};
|
|
14
|
+
interface MigrationsOptions {
|
|
15
|
+
/** A table owned by this schema. Override this when multiple schemas share a database. */
|
|
16
|
+
tableName?: string;
|
|
17
|
+
/** Detect the version of a schema that predates its migration table. */
|
|
18
|
+
adopt?: (db: MigrationDatabase) => Promise<number> | number;
|
|
19
|
+
/** Contiguous migrations numbered from 1. */
|
|
20
|
+
migrations: readonly Migration[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates an `onMigrate` callback that applies each unapplied migration in order.
|
|
24
|
+
* RivetKit runs the callback inside its migration savepoint, making the complete
|
|
25
|
+
* ladder atomic when used with `db({ onMigrate })`.
|
|
26
|
+
*/
|
|
27
|
+
declare function migrations({ tableName, adopt, migrations: ladder, }: MigrationsOptions): (db: MigrationDatabase) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
export { DEFAULT_MIGRATION_TABLE_NAME, type Migration, type MigrationDatabase, type MigrationsOptions, migrations };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/unstable/migrations.ts
|
|
2
|
+
var DEFAULT_MIGRATION_TABLE_NAME = "rivetkit_schema_version";
|
|
3
|
+
function migrations({
|
|
4
|
+
tableName = DEFAULT_MIGRATION_TABLE_NAME,
|
|
5
|
+
adopt,
|
|
6
|
+
migrations: ladder
|
|
7
|
+
}) {
|
|
8
|
+
validateTableName(tableName);
|
|
9
|
+
validateLadder(ladder);
|
|
10
|
+
return async (database) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const quotedTableName = `"${tableName}"`;
|
|
13
|
+
await database.execute(`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS ${quotedTableName} (
|
|
15
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
16
|
+
schema_version INTEGER NOT NULL CHECK (
|
|
17
|
+
schema_version BETWEEN 0 AND ${Number.MAX_SAFE_INTEGER}
|
|
18
|
+
)
|
|
19
|
+
) STRICT
|
|
20
|
+
`);
|
|
21
|
+
const rows = await database.execute(
|
|
22
|
+
`SELECT schema_version FROM ${quotedTableName} WHERE singleton = 1`
|
|
23
|
+
);
|
|
24
|
+
if (rows.length > 1) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`invalid migration table "${tableName}": expected at most one version row, received ${rows.length}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const rawCurrent = (_a = rows[0]) == null ? void 0 : _a.schema_version;
|
|
30
|
+
let current = rows.length === 0 ? 0 : rawCurrent;
|
|
31
|
+
if (rows.length === 0 && adopt) {
|
|
32
|
+
current = await adopt(database);
|
|
33
|
+
}
|
|
34
|
+
if (typeof current !== "number" || !Number.isSafeInteger(current) || current < 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`invalid schema version ${String(current)} in migration table "${tableName}"`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (current > ladder.length) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`migration version ${current} in "${tableName}" is newer than supported version ${ladder.length}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (rows.length === 0 && current > 0) {
|
|
45
|
+
await writeVersion(database, quotedTableName, current);
|
|
46
|
+
}
|
|
47
|
+
for (const migration of ladder.slice(current)) {
|
|
48
|
+
if (migration.sql !== void 0) {
|
|
49
|
+
await database.execute(migration.sql);
|
|
50
|
+
} else {
|
|
51
|
+
await migration.up(database);
|
|
52
|
+
}
|
|
53
|
+
await writeVersion(database, quotedTableName, migration.version);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function writeVersion(database, quotedTableName, version) {
|
|
58
|
+
await database.execute(
|
|
59
|
+
`INSERT INTO ${quotedTableName} (singleton, schema_version)
|
|
60
|
+
VALUES (1, ?)
|
|
61
|
+
ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,
|
|
62
|
+
version
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function validateTableName(tableName) {
|
|
66
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`invalid migration table name "${tableName}": expected a SQLite identifier`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function validateLadder(ladder) {
|
|
73
|
+
if (ladder.length === 0) {
|
|
74
|
+
throw new Error("migration ladder must not be empty");
|
|
75
|
+
}
|
|
76
|
+
for (const [index, migration] of ladder.entries()) {
|
|
77
|
+
const expectedVersion = index + 1;
|
|
78
|
+
if (migration.version !== expectedVersion) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`invalid migration ladder: expected version ${expectedVersion}, received ${migration.version}`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const hasSql = typeof migration.sql === "string";
|
|
84
|
+
const hasUp = typeof migration.up === "function";
|
|
85
|
+
if (hasSql === hasUp) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`invalid migration ${migration.version}: expected exactly one of sql or up`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (hasSql && migration.sql.trim().length === 0) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`invalid migration ${migration.version}: SQL is empty`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
DEFAULT_MIGRATION_TABLE_NAME,
|
|
99
|
+
migrations
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=migrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/unstable/migrations.ts"],"sourcesContent":["import type { RawAccess } from \"@/common/database/config\";\n\nexport const DEFAULT_MIGRATION_TABLE_NAME = \"rivetkit_schema_version\";\n\nexport type MigrationDatabase = Pick<RawAccess, \"execute\">;\n\nexport type Migration =\n\t| {\n\t\t\tversion: number;\n\t\t\tsql: string;\n\t\t\tup?: never;\n\t }\n\t| {\n\t\t\tversion: number;\n\t\t\tsql?: never;\n\t\t\tup: (db: MigrationDatabase) => Promise<void> | void;\n\t };\n\nexport interface MigrationsOptions {\n\t/** A table owned by this schema. Override this when multiple schemas share a database. */\n\ttableName?: string;\n\t/** Detect the version of a schema that predates its migration table. */\n\tadopt?: (db: MigrationDatabase) => Promise<number> | number;\n\t/** Contiguous migrations numbered from 1. */\n\tmigrations: readonly Migration[];\n}\n\n/**\n * Creates an `onMigrate` callback that applies each unapplied migration in order.\n * RivetKit runs the callback inside its migration savepoint, making the complete\n * ladder atomic when used with `db({ onMigrate })`.\n */\nexport function migrations({\n\ttableName = DEFAULT_MIGRATION_TABLE_NAME,\n\tadopt,\n\tmigrations: ladder,\n}: MigrationsOptions): (db: MigrationDatabase) => Promise<void> {\n\tvalidateTableName(tableName);\n\tvalidateLadder(ladder);\n\n\treturn async (database) => {\n\t\tconst quotedTableName = `\"${tableName}\"`;\n\t\tawait database.execute(`\n\t\t\tCREATE TABLE IF NOT EXISTS ${quotedTableName} (\n\t\t\t\tsingleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n\t\t\t\tschema_version INTEGER NOT NULL CHECK (\n\t\t\t\t\tschema_version BETWEEN 0 AND ${Number.MAX_SAFE_INTEGER}\n\t\t\t\t)\n\t\t\t) STRICT\n\t\t`);\n\n\t\tconst rows = await database.execute<{ schema_version: unknown }>(\n\t\t\t`SELECT schema_version FROM ${quotedTableName} WHERE singleton = 1`,\n\t\t);\n\t\tif (rows.length > 1) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration table \"${tableName}\": expected at most one version row, received ${rows.length}`,\n\t\t\t);\n\t\t}\n\n\t\tconst rawCurrent = rows[0]?.schema_version;\n\t\tlet current = rows.length === 0 ? 0 : rawCurrent;\n\t\tif (rows.length === 0 && adopt) {\n\t\t\tcurrent = await adopt(database);\n\t\t}\n\t\tif (\n\t\t\ttypeof current !== \"number\" ||\n\t\t\t!Number.isSafeInteger(current) ||\n\t\t\tcurrent < 0\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid schema version ${String(current)} in migration table \"${tableName}\"`,\n\t\t\t);\n\t\t}\n\t\tif (current > ladder.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`migration version ${current} in \"${tableName}\" is newer than supported version ${ladder.length}`,\n\t\t\t);\n\t\t}\n\t\tif (rows.length === 0 && current > 0) {\n\t\t\tawait writeVersion(database, quotedTableName, current);\n\t\t}\n\n\t\tfor (const migration of ladder.slice(current)) {\n\t\t\tif (migration.sql !== undefined) {\n\t\t\t\tawait database.execute(migration.sql);\n\t\t\t} else {\n\t\t\t\tawait migration.up(database);\n\t\t\t}\n\t\t\tawait writeVersion(database, quotedTableName, migration.version);\n\t\t}\n\t};\n}\n\nasync function writeVersion(\n\tdatabase: MigrationDatabase,\n\tquotedTableName: string,\n\tversion: number,\n): Promise<void> {\n\tawait database.execute(\n\t\t`INSERT INTO ${quotedTableName} (singleton, schema_version)\n\t\t VALUES (1, ?)\n\t\t ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,\n\t\tversion,\n\t);\n}\n\nfunction validateTableName(tableName: string): void {\n\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {\n\t\tthrow new Error(\n\t\t\t`invalid migration table name \"${tableName}\": expected a SQLite identifier`,\n\t\t);\n\t}\n}\n\nfunction validateLadder(ladder: readonly Migration[]): void {\n\tif (ladder.length === 0) {\n\t\tthrow new Error(\"migration ladder must not be empty\");\n\t}\n\n\tfor (const [index, migration] of ladder.entries()) {\n\t\tconst expectedVersion = index + 1;\n\t\tif (migration.version !== expectedVersion) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration ladder: expected version ${expectedVersion}, received ${migration.version}`,\n\t\t\t);\n\t\t}\n\t\tconst hasSql = typeof migration.sql === \"string\";\n\t\tconst hasUp = typeof migration.up === \"function\";\n\t\tif (hasSql === hasUp) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration ${migration.version}: expected exactly one of sql or up`,\n\t\t\t);\n\t\t}\n\t\tif (hasSql && migration.sql.trim().length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid migration ${migration.version}: SQL is empty`,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"mappings":";AAEO,IAAM,+BAA+B;AA8BrC,SAAS,WAAW;AAAA,EAC1B,YAAY;AAAA,EACZ;AAAA,EACA,YAAY;AACb,GAAgE;AAC/D,oBAAkB,SAAS;AAC3B,iBAAe,MAAM;AAErB,SAAO,OAAO,aAAa;AAxC5B;AAyCE,UAAM,kBAAkB,IAAI,SAAS;AACrC,UAAM,SAAS,QAAQ;AAAA,gCACO,eAAe;AAAA;AAAA;AAAA,oCAGX,OAAO,gBAAgB;AAAA;AAAA;AAAA,GAGxD;AAED,UAAM,OAAO,MAAM,SAAS;AAAA,MAC3B,8BAA8B,eAAe;AAAA,IAC9C;AACA,QAAI,KAAK,SAAS,GAAG;AACpB,YAAM,IAAI;AAAA,QACT,4BAA4B,SAAS,iDAAiD,KAAK,MAAM;AAAA,MAClG;AAAA,IACD;AAEA,UAAM,cAAa,UAAK,CAAC,MAAN,mBAAS;AAC5B,QAAI,UAAU,KAAK,WAAW,IAAI,IAAI;AACtC,QAAI,KAAK,WAAW,KAAK,OAAO;AAC/B,gBAAU,MAAM,MAAM,QAAQ;AAAA,IAC/B;AACA,QACC,OAAO,YAAY,YACnB,CAAC,OAAO,cAAc,OAAO,KAC7B,UAAU,GACT;AACD,YAAM,IAAI;AAAA,QACT,0BAA0B,OAAO,OAAO,CAAC,wBAAwB,SAAS;AAAA,MAC3E;AAAA,IACD;AACA,QAAI,UAAU,OAAO,QAAQ;AAC5B,YAAM,IAAI;AAAA,QACT,qBAAqB,OAAO,QAAQ,SAAS,qCAAqC,OAAO,MAAM;AAAA,MAChG;AAAA,IACD;AACA,QAAI,KAAK,WAAW,KAAK,UAAU,GAAG;AACrC,YAAM,aAAa,UAAU,iBAAiB,OAAO;AAAA,IACtD;AAEA,eAAW,aAAa,OAAO,MAAM,OAAO,GAAG;AAC9C,UAAI,UAAU,QAAQ,QAAW;AAChC,cAAM,SAAS,QAAQ,UAAU,GAAG;AAAA,MACrC,OAAO;AACN,cAAM,UAAU,GAAG,QAAQ;AAAA,MAC5B;AACA,YAAM,aAAa,UAAU,iBAAiB,UAAU,OAAO;AAAA,IAChE;AAAA,EACD;AACD;AAEA,eAAe,aACd,UACA,iBACA,SACgB;AAChB,QAAM,SAAS;AAAA,IACd,eAAe,eAAe;AAAA;AAAA;AAAA,IAG9B;AAAA,EACD;AACD;AAEA,SAAS,kBAAkB,WAAyB;AACnD,MAAI,CAAC,2BAA2B,KAAK,SAAS,GAAG;AAChD,UAAM,IAAI;AAAA,MACT,iCAAiC,SAAS;AAAA,IAC3C;AAAA,EACD;AACD;AAEA,SAAS,eAAe,QAAoC;AAC3D,MAAI,OAAO,WAAW,GAAG;AACxB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACrD;AAEA,aAAW,CAAC,OAAO,SAAS,KAAK,OAAO,QAAQ,GAAG;AAClD,UAAM,kBAAkB,QAAQ;AAChC,QAAI,UAAU,YAAY,iBAAiB;AAC1C,YAAM,IAAI;AAAA,QACT,8CAA8C,eAAe,cAAc,UAAU,OAAO;AAAA,MAC7F;AAAA,IACD;AACA,UAAM,SAAS,OAAO,UAAU,QAAQ;AACxC,UAAM,QAAQ,OAAO,UAAU,OAAO;AACtC,QAAI,WAAW,OAAO;AACrB,YAAM,IAAI;AAAA,QACT,qBAAqB,UAAU,OAAO;AAAA,MACvC;AAAA,IACD;AACA,QAAI,UAAU,UAAU,IAAI,KAAK,EAAE,WAAW,GAAG;AAChD,YAAM,IAAI;AAAA,QACT,qBAAqB,UAAU,OAAO;AAAA,MACvC;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
package/dist/tsup/utils.cjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var _chunk2SGPZEAJcjs = require('./chunk-2SGPZEAJ.cjs');
|
|
23
23
|
require('./chunk-4FC7TVS6.cjs');
|
|
24
24
|
|
|
25
25
|
|
|
@@ -42,5 +42,5 @@ require('./chunk-4FC7TVS6.cjs');
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
exports.EXTRA_ERROR_LOG =
|
|
45
|
+
exports.EXTRA_ERROR_LOG = _chunk2SGPZEAJcjs.EXTRA_ERROR_LOG; exports.SinglePromiseQueue = _chunk2SGPZEAJcjs.SinglePromiseQueue; exports.VERSION = _chunk2SGPZEAJcjs.VERSION; exports.arrayBuffersEqual = _chunk2SGPZEAJcjs.arrayBuffersEqual; exports.assertUnreachable = _chunk2SGPZEAJcjs.assertUnreachable; exports.bufferToArrayBuffer = _chunk2SGPZEAJcjs.bufferToArrayBuffer; exports.combineUrlPath = _chunk2SGPZEAJcjs.combineUrlPath; exports.dbg = _chunk2SGPZEAJcjs.dbg; exports.detectRuntime = _chunk2SGPZEAJcjs.detectRuntime; exports.getEnvUniversal = _chunk2SGPZEAJcjs.getEnvUniversal; exports.httpUserAgent = _chunk2SGPZEAJcjs.httpUserAgent; exports.interval = _chunk2SGPZEAJcjs.interval; exports.joinSignals = _chunk2SGPZEAJcjs.joinSignals; exports.jsonParseCompat = _chunk2SGPZEAJcjs.jsonParseCompat; exports.jsonStringifyCompat = _chunk2SGPZEAJcjs.jsonStringifyCompat; exports.promiseWithResolvers = _chunk2SGPZEAJcjs.promiseWithResolvers; exports.setLongTimeout = _chunk2SGPZEAJcjs.setLongTimeout; exports.sleep = _chunk2SGPZEAJcjs.sleep; exports.stringifyError = _chunk2SGPZEAJcjs.stringifyError; exports.toUint8Array = _chunk2SGPZEAJcjs.toUint8Array;
|
|
46
46
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/tsup/utils.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } var _class; var _class2;
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunkTQHMPWL6cjs = require('../chunk-TQHMPWL6.cjs');
|
|
4
|
+
require('../chunk-UIZZCJ5W.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkHNHLBM3Ycjs = require('../chunk-HNHLBM3Y.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var _chunkMYWZCDMLcjs = require('../chunk-MYWZCDML.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunk2SGPZEAJcjs = require('../chunk-2SGPZEAJ.cjs');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
@@ -716,13 +716,13 @@ function workflow(fn, options = {}) {
|
|
|
716
716
|
function getWorkflowInspector(actorId) {
|
|
717
717
|
let workflowInspector = workflowInspectors.get(actorId);
|
|
718
718
|
if (!workflowInspector) {
|
|
719
|
-
workflowInspector =
|
|
719
|
+
workflowInspector = _chunkTQHMPWL6cjs.createWorkflowInspectorAdapter.call(void 0, );
|
|
720
720
|
workflowInspectors.set(actorId, workflowInspector);
|
|
721
721
|
}
|
|
722
722
|
return workflowInspector;
|
|
723
723
|
}
|
|
724
724
|
async function run(runCtx) {
|
|
725
|
-
const actor = runCtx[
|
|
725
|
+
const actor = runCtx[_chunkHNHLBM3Ycjs.ACTOR_CONTEXT_INTERNAL_SYMBOL];
|
|
726
726
|
_invariant2.default.call(void 0, actor, "workflow() requires an actor instance");
|
|
727
727
|
const workflowInspector = getWorkflowInspector(actor.id);
|
|
728
728
|
const driver = new ActorWorkflowDriver(actor, runCtx);
|
|
@@ -784,20 +784,20 @@ function workflow(fn, options = {}) {
|
|
|
784
784
|
if (shouldRethrowWorkflowError(error)) {
|
|
785
785
|
runCtx.log.error({
|
|
786
786
|
msg: "workflow run failed",
|
|
787
|
-
error:
|
|
787
|
+
error: _chunk2SGPZEAJcjs.stringifyError.call(void 0, error)
|
|
788
788
|
});
|
|
789
789
|
throw error;
|
|
790
790
|
}
|
|
791
791
|
runCtx.log.warn({
|
|
792
792
|
msg: "workflow failed and will sleep until woken",
|
|
793
|
-
error:
|
|
793
|
+
error: _chunk2SGPZEAJcjs.stringifyError.call(void 0, error)
|
|
794
794
|
});
|
|
795
795
|
} finally {
|
|
796
796
|
runCtx.abortSignal.removeEventListener("abort", onAbort);
|
|
797
797
|
}
|
|
798
798
|
}
|
|
799
799
|
const runWithConfig = run;
|
|
800
|
-
runWithConfig[
|
|
800
|
+
runWithConfig[_chunkHNHLBM3Ycjs.RUN_FUNCTION_CONFIG_SYMBOL] = {
|
|
801
801
|
icon: "diagram-project",
|
|
802
802
|
// Drop the per-actor inspector when the actor is destroyed so this map
|
|
803
803
|
// does not retain one inspector (and its encoded history) per actor id
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WorkflowErrorEvent } from '@rivetkit/workflow-engine';
|
|
2
2
|
export { Loop, TryBlockCatchKind, TryBlockConfig, TryBlockFailure, TryBlockResult, TryStepCatchKind, TryStepConfig, TryStepFailure, TryStepResult, WorkflowError, WorkflowErrorEvent } from '@rivetkit/workflow-engine';
|
|
3
|
-
import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-
|
|
3
|
+
import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-BobvQpex.cjs';
|
|
4
4
|
import { A as AnyDatabaseProvider } from '../config-BxOimoGX.cjs';
|
|
5
|
-
import { d as WorkflowContext } from '../context-
|
|
6
|
-
export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-
|
|
5
|
+
import { d as WorkflowContext } from '../context-YEBNJrws.cjs';
|
|
6
|
+
export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-YEBNJrws.cjs';
|
|
7
7
|
import 'zod/v4';
|
|
8
8
|
import '@rivetkit/rivetkit-wasm';
|
|
9
9
|
import 'zod';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { WorkflowErrorEvent } from '@rivetkit/workflow-engine';
|
|
2
2
|
export { Loop, TryBlockCatchKind, TryBlockConfig, TryBlockFailure, TryBlockResult, TryStepCatchKind, TryStepConfig, TryStepFailure, TryStepResult, WorkflowError, WorkflowErrorEvent } from '@rivetkit/workflow-engine';
|
|
3
|
-
import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-
|
|
3
|
+
import { E as EventSchemaConfig, Q as QueueSchemaConfig, h as RunContext } from '../config-BRpVbJCD.js';
|
|
4
4
|
import { A as AnyDatabaseProvider } from '../config-BxOimoGX.js';
|
|
5
|
-
import { d as WorkflowContext } from '../context-
|
|
6
|
-
export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-
|
|
5
|
+
import { d as WorkflowContext } from '../context-Cj-DFyiy.js';
|
|
6
|
+
export { e as WorkflowBranchConfig, W as WorkflowBranchContextOf, a as WorkflowContextOf, f as WorkflowLoopConfig, b as WorkflowLoopContextOf, g as WorkflowStepConfig, h as WorkflowStepContext, c as WorkflowStepContextOf, i as WorkflowTryConfig, j as WorkflowTryStepConfig } from '../context-Cj-DFyiy.js';
|
|
7
7
|
import 'zod/v4';
|
|
8
8
|
import '@rivetkit/rivetkit-wasm';
|
|
9
9
|
import 'zod';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWorkflowInspectorAdapter
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-7YQJXWBW.js";
|
|
4
|
+
import "../chunk-6D2WRHJV.js";
|
|
5
5
|
import {
|
|
6
6
|
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
7
7
|
RUN_FUNCTION_CONFIG_SYMBOL
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-QWLJCP3X.js";
|
|
9
9
|
import {
|
|
10
10
|
makeWorkflowKey,
|
|
11
11
|
workflowStoragePrefix
|
|
12
12
|
} from "../chunk-JI6GZ2C2.js";
|
|
13
13
|
import {
|
|
14
14
|
stringifyError
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-OG4OR2CM.js";
|
|
16
16
|
import {
|
|
17
17
|
RivetError,
|
|
18
18
|
isActorAbortedError
|