@hot-updater/cloudflare 1.0.0-rc.2 → 1.0.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/index.cjs +95 -870
  2. package/dist/index.d.cts +724 -6
  3. package/dist/index.d.mts +724 -6
  4. package/dist/index.mjs +93 -870
  5. package/dist/init/index.cjs +11768 -0
  6. package/dist/init/index.d.cts +5 -1
  7. package/dist/init/index.d.mts +5 -1
  8. package/dist/init/index.mjs +11761 -1
  9. package/dist/worker/index.cjs +59 -859
  10. package/dist/worker/index.d.cts +725 -11
  11. package/dist/worker/index.d.mts +725 -11
  12. package/dist/worker/index.mjs +62 -863
  13. package/package.json +9 -13
  14. package/sql/bundles.sql +109 -190
  15. package/src/d1Database.ts +61 -40
  16. package/src/d1Executor.ts +84 -0
  17. package/src/d1Schema.ts +26 -0
  18. package/src/index.ts +1 -0
  19. package/src/plugins.ts +8 -0
  20. package/src/r2S3Storage.ts +4 -4
  21. package/src/r2Storage.ts +2 -2
  22. package/src/r2WorkerStorage.ts +4 -4
  23. package/src/worker/d1Database.ts +21 -27
  24. package/src/worker/index.ts +1 -0
  25. package/worker/dist/README.md +1 -1
  26. package/worker/dist/index.js +9682 -6206
  27. package/worker/dist/index.js.map +4 -4
  28. package/worker/migrations/0001_hot-updater_1.0.0.sql +109 -205
  29. package/worker/src/index.ts +2 -2
  30. package/dist/iac/index.cjs +0 -12566
  31. package/dist/iac/index.d.cts +0 -9
  32. package/dist/iac/index.d.mts +0 -9
  33. package/dist/iac/index.mjs +0 -12558
  34. package/src/d1Database.spec.ts +0 -178
  35. package/src/d1Implementation.spec.ts +0 -252
  36. package/src/d1Implementation.ts +0 -742
  37. package/src/d1Query.spec.ts +0 -46
  38. package/src/d1Query.ts +0 -89
  39. package/src/d1Rows.spec.ts +0 -111
  40. package/src/d1Rows.ts +0 -326
  41. package/src/d1Sql.spec.ts +0 -30
  42. package/src/d1Sql.ts +0 -175
  43. package/src/r2Storage.spec.ts +0 -346
  44. package/src/r2WorkerStorage.spec.ts +0 -184
  45. package/src/utils/createWrangler.spec.ts +0 -75
  46. package/src/worker/d1Database.spec.ts +0 -33
  47. package/worker/src/databaseMigration.integration.spec.ts +0 -130
  48. package/worker/src/databasePlugins.integration.spec.ts +0 -292
  49. package/worker/src/index.integration.spec.ts +0 -190
  50. package/worker/src/storagePlugin.integration.spec.ts +0 -59
  51. package/worker/src/testWorker.ts +0 -5
@@ -9,10 +9,10 @@ import { Upload } from "@aws-sdk/lib-storage";
9
9
  import {
10
10
  createStorageKeyBuilder,
11
11
  createStorageDownloadUrl,
12
- createStoragePlugin,
12
+ createStorageAdapter,
13
13
  createStorageUri,
14
14
  parseStorageUri,
15
- type StoragePluginWith,
15
+ type StorageAdapterWith,
16
16
  } from "@hot-updater/plugin-core";
17
17
 
18
18
  export interface R2S3StorageConfig extends S3ClientConfig {
@@ -43,7 +43,7 @@ const isObjectNotFoundError = (error: unknown) => {
43
43
 
44
44
  export const createR2S3Storage = (
45
45
  config: R2S3StorageConfig,
46
- ): StoragePluginWith<"put" | "get" | "exists" | "delete"> => {
46
+ ): StorageAdapterWith<"put" | "get" | "exists" | "delete"> => {
47
47
  const {
48
48
  accountId,
49
49
  basePath,
@@ -75,7 +75,7 @@ export const createR2S3Storage = (
75
75
  return parsed;
76
76
  };
77
77
 
78
- return createStoragePlugin({
78
+ return createStorageAdapter({
79
79
  name: "r2Storage",
80
80
  protocol: "r2",
81
81
  async put({ key, body, contentLength, contentType }) {
package/src/r2Storage.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { StoragePluginWith } from "@hot-updater/plugin-core";
1
+ import type { StorageAdapterWith } from "@hot-updater/plugin-core";
2
2
 
3
3
  import { createR2S3Storage, type R2S3StorageConfig } from "./r2S3Storage";
4
4
 
@@ -7,7 +7,7 @@ export type { R2S3StorageConfig };
7
7
 
8
8
  export const r2Storage = (
9
9
  config: R2S3StorageConfig,
10
- ): StoragePluginWith<"put" | "get" | "exists" | "delete"> => {
10
+ ): StorageAdapterWith<"put" | "get" | "exists" | "delete"> => {
11
11
  if (!config.credentials) {
12
12
  throw new Error(
13
13
  "r2Storage requires S3-compatible credentials. The Wrangler fallback was removed.",
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createStorageKeyBuilder,
3
3
  createStorageDownloadUrl,
4
- createStoragePlugin,
4
+ createStorageAdapter,
5
5
  createStorageUri,
6
6
  parseStorageUri,
7
- type StoragePluginWith,
7
+ type StorageAdapterWith,
8
8
  } from "@hot-updater/plugin-core";
9
9
 
10
10
  export interface CloudflareWorkerStorageConfig {
@@ -16,7 +16,7 @@ export interface CloudflareWorkerStorageConfig {
16
16
 
17
17
  export const r2WorkerStorage = (
18
18
  config: CloudflareWorkerStorageConfig,
19
- ): StoragePluginWith<
19
+ ): StorageAdapterWith<
20
20
  "put" | "get" | "getDownloadUrl" | "exists" | "delete"
21
21
  > => {
22
22
  const getStorageKey = createStorageKeyBuilder(config.basePath);
@@ -32,7 +32,7 @@ export const r2WorkerStorage = (
32
32
  return parsed;
33
33
  };
34
34
 
35
- return createStoragePlugin({
35
+ return createStorageAdapter({
36
36
  name: "r2Storage",
37
37
  protocol: "r2",
38
38
  async put({ key, body, contentLength, contentType }) {
@@ -1,14 +1,14 @@
1
- import { createDatabasePlugin } from "@hot-updater/plugin-core";
2
- import { createDatabasePluginAdapter } from "@hot-updater/plugin-core/internal";
1
+ import type { EngineDatabase } from "@hot-updater/plugin-core";
3
2
 
4
- import { createD1Implementation } from "../d1Implementation";
5
-
6
- type D1Result = {
7
- readonly results?: readonly unknown[];
8
- };
3
+ import {
4
+ createD1Database,
5
+ D1ExecutionError,
6
+ type D1ResultLike,
7
+ toSqlResult,
8
+ } from "../d1Executor";
9
9
 
10
10
  type D1BoundStatement = {
11
- all: () => Promise<D1Result>;
11
+ all: () => Promise<D1ResultLike>;
12
12
  };
13
13
 
14
14
  type D1PreparedStatement = {
@@ -17,36 +17,30 @@ type D1PreparedStatement = {
17
17
 
18
18
  export type D1Like = {
19
19
  prepare(sql: string): D1PreparedStatement;
20
- batch(statements: D1BoundStatement[]): Promise<readonly D1Result[]>;
20
+ batch(statements: D1BoundStatement[]): Promise<readonly D1ResultLike[]>;
21
21
  };
22
22
 
23
23
  export interface CloudflareWorkerDatabaseEnv {
24
24
  readonly DB: D1Like;
25
25
  }
26
26
 
27
- export const d1Database = (database: D1Like) => {
28
- const implementation = createD1Implementation({
29
- async query(sql, params) {
30
- const result = await database
31
- .prepare(sql)
32
- .bind(...params)
33
- .all();
34
- return result.results ?? [];
35
- },
27
+ /** Hot Updater's database on a D1 binding, inside a Worker. */
28
+ export const d1Database = (database: D1Like): EngineDatabase =>
29
+ createD1Database({
30
+ query: async ({ sql, params }) =>
31
+ toSqlResult(
32
+ await database
33
+ .prepare(sql)
34
+ .bind(...params)
35
+ .all(),
36
+ ),
36
37
  async batch(statements) {
37
38
  const results = await database.batch(
38
39
  statements.map(({ sql, params }) =>
39
40
  database.prepare(sql).bind(...params),
40
41
  ),
41
42
  );
42
- return results.map(({ results }) => results ?? []);
43
+ if (results.length !== statements.length) throw new D1ExecutionError();
44
+ return results.map(toSqlResult);
43
45
  },
44
46
  });
45
- const adapter = createDatabasePluginAdapter("d1Database", implementation);
46
- return createDatabasePlugin({
47
- name: "d1Database",
48
- models: adapter.models,
49
- commit: adapter.commit,
50
- ...(adapter.dispose ? { dispose: adapter.dispose } : {}),
51
- });
52
- };
@@ -1,4 +1,5 @@
1
1
  export { d1Database, type D1Like } from "./d1Database";
2
+ export { plugins } from "../plugins";
2
3
  export {
3
4
  r2WorkerStorage as r2Storage,
4
5
  type CloudflareWorkerStorageConfig,
@@ -1 +1 @@
1
- This folder contains the built output assets for the worker "hot-updater" generated at 2026-08-31T11:14:10.721Z.
1
+ This folder contains the built output assets for the worker "hot-updater" generated at 2026-10-02T03:30:33.543Z.