@hot-updater/server 0.28.0 → 0.29.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.
Files changed (84) hide show
  1. package/dist/adapters/drizzle.cjs +7 -7
  2. package/dist/adapters/drizzle.mjs +2 -0
  3. package/dist/adapters/kysely.cjs +7 -7
  4. package/dist/adapters/kysely.mjs +2 -0
  5. package/dist/adapters/mongodb.cjs +7 -7
  6. package/dist/adapters/mongodb.mjs +2 -0
  7. package/dist/adapters/prisma.cjs +7 -7
  8. package/dist/adapters/prisma.mjs +2 -0
  9. package/dist/calculatePagination.cjs +1 -3
  10. package/dist/{calculatePagination.js → calculatePagination.mjs} +1 -2
  11. package/dist/db/index.cjs +24 -15
  12. package/dist/db/index.d.cts +12 -9
  13. package/dist/db/index.d.mts +30 -0
  14. package/dist/db/index.mjs +45 -0
  15. package/dist/db/ormCore.cjs +247 -138
  16. package/dist/db/ormCore.d.cts +35 -17
  17. package/dist/db/ormCore.d.mts +44 -0
  18. package/dist/db/ormCore.mjs +386 -0
  19. package/dist/db/pluginCore.cjs +145 -40
  20. package/dist/db/pluginCore.mjs +176 -0
  21. package/dist/db/types.cjs +1 -3
  22. package/dist/db/types.d.cts +14 -21
  23. package/dist/db/types.d.mts +24 -0
  24. package/dist/db/{types.js → types.mjs} +1 -2
  25. package/dist/handler.cjs +117 -48
  26. package/dist/handler.d.cts +28 -18
  27. package/dist/handler.d.mts +47 -0
  28. package/dist/handler.mjs +217 -0
  29. package/dist/index.cjs +5 -5
  30. package/dist/index.d.cts +3 -3
  31. package/dist/index.d.mts +5 -0
  32. package/dist/index.mjs +4 -0
  33. package/dist/internalRouter.cjs +54 -0
  34. package/dist/internalRouter.mjs +52 -0
  35. package/dist/node.cjs +2 -3
  36. package/dist/node.d.cts +0 -1
  37. package/dist/{node.d.ts → node.d.mts} +1 -2
  38. package/dist/{node.js → node.mjs} +1 -2
  39. package/dist/route.cjs +7 -0
  40. package/dist/route.mjs +7 -0
  41. package/dist/runtime.cjs +42 -0
  42. package/dist/runtime.d.cts +21 -0
  43. package/dist/runtime.d.mts +21 -0
  44. package/dist/runtime.mjs +40 -0
  45. package/dist/schema/v0_21_0.cjs +1 -5
  46. package/dist/schema/{v0_21_0.js → v0_21_0.mjs} +1 -3
  47. package/dist/schema/v0_29_0.cjs +24 -0
  48. package/dist/schema/v0_29_0.mjs +24 -0
  49. package/dist/types/{index.d.ts → index.d.mts} +1 -1
  50. package/package.json +18 -18
  51. package/src/db/index.spec.ts +64 -29
  52. package/src/db/index.ts +55 -35
  53. package/src/db/ormCore.ts +438 -210
  54. package/src/db/ormUpdateCheck.bench.ts +261 -0
  55. package/src/db/pluginCore.ts +298 -49
  56. package/src/db/pluginUpdateCheck.bench.ts +250 -0
  57. package/src/db/types.ts +52 -27
  58. package/src/{handler-standalone-integration.spec.ts → handler-standalone.integration.spec.ts} +106 -0
  59. package/src/handler.spec.ts +156 -0
  60. package/src/handler.ts +296 -77
  61. package/src/internalRouter.ts +104 -0
  62. package/src/route.ts +7 -0
  63. package/src/runtime.spec.ts +277 -0
  64. package/src/runtime.ts +121 -0
  65. package/src/schema/v0_29_0.ts +26 -0
  66. package/dist/_virtual/rolldown_runtime.cjs +0 -25
  67. package/dist/adapters/drizzle.js +0 -3
  68. package/dist/adapters/kysely.js +0 -3
  69. package/dist/adapters/mongodb.js +0 -3
  70. package/dist/adapters/prisma.js +0 -3
  71. package/dist/db/index.d.ts +0 -27
  72. package/dist/db/index.js +0 -36
  73. package/dist/db/ormCore.d.ts +0 -26
  74. package/dist/db/ormCore.js +0 -273
  75. package/dist/db/pluginCore.js +0 -69
  76. package/dist/db/types.d.ts +0 -31
  77. package/dist/handler.d.ts +0 -37
  78. package/dist/handler.js +0 -146
  79. package/dist/index.d.ts +0 -5
  80. package/dist/index.js +0 -5
  81. /package/dist/adapters/{drizzle.d.ts → drizzle.d.mts} +0 -0
  82. /package/dist/adapters/{kysely.d.ts → kysely.d.mts} +0 -0
  83. /package/dist/adapters/{mongodb.d.ts → mongodb.d.mts} +0 -0
  84. /package/dist/adapters/{prisma.d.ts → prisma.d.mts} +0 -0
@@ -1,9 +1,9 @@
1
-
2
-
3
1
  var fumadb_adapters_drizzle = require("fumadb/adapters/drizzle");
4
- Object.keys(fumadb_adapters_drizzle).forEach(function (k) {
5
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
- enumerable: true,
7
- get: function () { return fumadb_adapters_drizzle[k]; }
8
- });
2
+ Object.keys(fumadb_adapters_drizzle).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return fumadb_adapters_drizzle[k];
7
+ }
8
+ });
9
9
  });
@@ -0,0 +1,2 @@
1
+ export * from "fumadb/adapters/drizzle";
2
+ export {};
@@ -1,9 +1,9 @@
1
-
2
-
3
1
  var fumadb_adapters_kysely = require("fumadb/adapters/kysely");
4
- Object.keys(fumadb_adapters_kysely).forEach(function (k) {
5
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
- enumerable: true,
7
- get: function () { return fumadb_adapters_kysely[k]; }
8
- });
2
+ Object.keys(fumadb_adapters_kysely).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return fumadb_adapters_kysely[k];
7
+ }
8
+ });
9
9
  });
@@ -0,0 +1,2 @@
1
+ export * from "fumadb/adapters/kysely";
2
+ export {};
@@ -1,9 +1,9 @@
1
-
2
-
3
1
  var fumadb_adapters_mongodb = require("fumadb/adapters/mongodb");
4
- Object.keys(fumadb_adapters_mongodb).forEach(function (k) {
5
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
- enumerable: true,
7
- get: function () { return fumadb_adapters_mongodb[k]; }
8
- });
2
+ Object.keys(fumadb_adapters_mongodb).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return fumadb_adapters_mongodb[k];
7
+ }
8
+ });
9
9
  });
@@ -0,0 +1,2 @@
1
+ export * from "fumadb/adapters/mongodb";
2
+ export {};
@@ -1,9 +1,9 @@
1
-
2
-
3
1
  var fumadb_adapters_prisma = require("fumadb/adapters/prisma");
4
- Object.keys(fumadb_adapters_prisma).forEach(function (k) {
5
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
- enumerable: true,
7
- get: function () { return fumadb_adapters_prisma[k]; }
8
- });
2
+ Object.keys(fumadb_adapters_prisma).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return fumadb_adapters_prisma[k];
7
+ }
8
+ });
9
9
  });
@@ -0,0 +1,2 @@
1
+ export * from "fumadb/adapters/prisma";
2
+ export {};
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/calculatePagination.ts
3
2
  /**
4
3
  * Calculate pagination information based on total count, limit, and offset
@@ -22,6 +21,5 @@ function calculatePagination(total, options) {
22
21
  totalPages
23
22
  };
24
23
  }
25
-
26
24
  //#endregion
27
- exports.calculatePagination = calculatePagination;
25
+ exports.calculatePagination = calculatePagination;
@@ -21,6 +21,5 @@ function calculatePagination(total, options) {
21
21
  totalPages
22
22
  };
23
23
  }
24
-
25
24
  //#endregion
26
- export { calculatePagination };
25
+ export { calculatePagination };
package/dist/db/index.cjs CHANGED
@@ -1,36 +1,45 @@
1
- const require_handler = require('../handler.cjs');
2
- const require_ormCore = require('./ormCore.cjs');
3
- const require_pluginCore = require('./pluginCore.cjs');
4
- const require_types = require('./types.cjs');
5
-
1
+ const require_handler = require("../handler.cjs");
2
+ const require_route = require("../route.cjs");
3
+ const require_ormCore = require("./ormCore.cjs");
4
+ const require_pluginCore = require("./pluginCore.cjs");
5
+ const require_types = require("./types.cjs");
6
6
  //#region src/db/index.ts
7
7
  function createHotUpdater(options) {
8
- const storagePlugins = (options?.storages ?? options?.storagePlugins ?? []).map((plugin) => typeof plugin === "function" ? plugin() : plugin);
9
- const resolveFileUrl = async (storageUri) => {
8
+ const basePath = require_route.normalizeBasePath(options.basePath ?? "/api");
9
+ const storagePlugins = (options.storages ?? options.storagePlugins ?? []).map((plugin) => typeof plugin === "function" ? plugin() : plugin);
10
+ const resolveStoragePluginUrl = async (storageUri, context) => {
10
11
  if (!storageUri) return null;
11
12
  const protocol = new URL(storageUri).protocol.replace(":", "");
12
13
  if (protocol === "http" || protocol === "https") return storageUri;
13
14
  const plugin = storagePlugins.find((p) => p.supportedProtocol === protocol);
14
15
  if (!plugin) throw new Error(`No storage plugin for protocol: ${protocol}`);
15
- const { fileUrl } = await plugin.getDownloadUrl(storageUri);
16
+ const { fileUrl } = await plugin.getDownloadUrl(storageUri, context);
16
17
  if (!fileUrl) throw new Error("Storage plugin returned empty fileUrl");
17
18
  return fileUrl;
18
19
  };
19
- let core;
20
+ const resolveFileUrl = async (storageUri, context) => {
21
+ return resolveStoragePluginUrl(storageUri, context);
22
+ };
20
23
  const database = options.database;
21
- if (require_types.isDatabasePluginFactory(database) || require_types.isDatabasePlugin(database)) core = require_pluginCore.createPluginDatabaseCore(require_types.isDatabasePluginFactory(database) ? database() : database, resolveFileUrl);
22
- else core = require_ormCore.createOrmDatabaseCore({
24
+ const core = require_types.isDatabasePluginFactory(database) || require_types.isDatabasePlugin(database) ? require_pluginCore.createPluginDatabaseCore(require_types.isDatabasePluginFactory(database) ? database() : database, resolveFileUrl) : require_ormCore.createOrmDatabaseCore({
23
25
  database,
24
26
  resolveFileUrl
25
27
  });
26
- return {
28
+ const api = {
27
29
  ...core.api,
28
- handler: require_handler.createHandler(core.api, options?.basePath ? { basePath: options.basePath } : {}),
30
+ handler: require_handler.createHandler(core.api, {
31
+ basePath,
32
+ routes: options.routes
33
+ }),
29
34
  adapterName: core.adapterName,
30
35
  createMigrator: core.createMigrator,
31
36
  generateSchema: core.generateSchema
32
37
  };
38
+ return {
39
+ ...api,
40
+ basePath,
41
+ handler: api.handler
42
+ };
33
43
  }
34
-
35
44
  //#endregion
36
- exports.createHotUpdater = createHotUpdater;
45
+ exports.createHotUpdater = createHotUpdater;
@@ -1,27 +1,30 @@
1
+ import { HandlerRoutes } from "../handler.cjs";
1
2
  import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./types.cjs";
2
3
  import { HotUpdaterClient, HotUpdaterDB, Migrator } from "./ormCore.cjs";
3
- import { StoragePlugin } from "@hot-updater/plugin-core";
4
+ import { HotUpdaterContext, StoragePlugin } from "@hot-updater/plugin-core";
4
5
 
5
6
  //#region src/db/index.d.ts
6
- type HotUpdaterAPI = DatabaseAPI & {
7
- handler: (request: Request) => Promise<Response>;
7
+ type HotUpdaterAPI<TContext = unknown> = DatabaseAPI<TContext> & {
8
+ basePath: string;
9
+ handler: (request: Request, context?: HotUpdaterContext<TContext>) => Promise<Response>;
8
10
  adapterName: string;
9
11
  createMigrator: () => Migrator;
10
12
  generateSchema: HotUpdaterClient["generateSchema"];
11
13
  };
12
- interface HotUpdaterOptions {
13
- database: DatabaseAdapter;
14
+ interface CreateHotUpdaterOptions<TContext = unknown> {
15
+ database: DatabaseAdapter<TContext>;
14
16
  /**
15
17
  * Storage plugins for handling file uploads and downloads.
16
18
  */
17
- storages?: (StoragePlugin | StoragePluginFactory)[];
19
+ storages?: (StoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
18
20
  /**
19
21
  * @deprecated Use `storages` instead. This field will be removed in a future version.
20
22
  */
21
- storagePlugins?: (StoragePlugin | StoragePluginFactory)[];
23
+ storagePlugins?: (StoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
22
24
  basePath?: string;
23
25
  cwd?: string;
26
+ routes?: HandlerRoutes;
24
27
  }
25
- declare function createHotUpdater(options: HotUpdaterOptions): HotUpdaterAPI;
28
+ declare function createHotUpdater<TContext = unknown>(options: CreateHotUpdaterOptions<TContext>): HotUpdaterAPI<TContext>;
26
29
  //#endregion
27
- export { HotUpdaterAPI, createHotUpdater };
30
+ export { CreateHotUpdaterOptions, HotUpdaterAPI, createHotUpdater };
@@ -0,0 +1,30 @@
1
+ import { HandlerRoutes } from "../handler.mjs";
2
+ import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./types.mjs";
3
+ import { HotUpdaterClient, HotUpdaterDB, Migrator } from "./ormCore.mjs";
4
+ import { HotUpdaterContext, StoragePlugin } from "@hot-updater/plugin-core";
5
+
6
+ //#region src/db/index.d.ts
7
+ type HotUpdaterAPI<TContext = unknown> = DatabaseAPI<TContext> & {
8
+ basePath: string;
9
+ handler: (request: Request, context?: HotUpdaterContext<TContext>) => Promise<Response>;
10
+ adapterName: string;
11
+ createMigrator: () => Migrator;
12
+ generateSchema: HotUpdaterClient["generateSchema"];
13
+ };
14
+ interface CreateHotUpdaterOptions<TContext = unknown> {
15
+ database: DatabaseAdapter<TContext>;
16
+ /**
17
+ * Storage plugins for handling file uploads and downloads.
18
+ */
19
+ storages?: (StoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
20
+ /**
21
+ * @deprecated Use `storages` instead. This field will be removed in a future version.
22
+ */
23
+ storagePlugins?: (StoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
24
+ basePath?: string;
25
+ cwd?: string;
26
+ routes?: HandlerRoutes;
27
+ }
28
+ declare function createHotUpdater<TContext = unknown>(options: CreateHotUpdaterOptions<TContext>): HotUpdaterAPI<TContext>;
29
+ //#endregion
30
+ export { CreateHotUpdaterOptions, HotUpdaterAPI, createHotUpdater };
@@ -0,0 +1,45 @@
1
+ import { createHandler } from "../handler.mjs";
2
+ import { normalizeBasePath } from "../route.mjs";
3
+ import { createOrmDatabaseCore } from "./ormCore.mjs";
4
+ import { createPluginDatabaseCore } from "./pluginCore.mjs";
5
+ import { isDatabasePlugin, isDatabasePluginFactory } from "./types.mjs";
6
+ //#region src/db/index.ts
7
+ function createHotUpdater(options) {
8
+ const basePath = normalizeBasePath(options.basePath ?? "/api");
9
+ const storagePlugins = (options.storages ?? options.storagePlugins ?? []).map((plugin) => typeof plugin === "function" ? plugin() : plugin);
10
+ const resolveStoragePluginUrl = async (storageUri, context) => {
11
+ if (!storageUri) return null;
12
+ const protocol = new URL(storageUri).protocol.replace(":", "");
13
+ if (protocol === "http" || protocol === "https") return storageUri;
14
+ const plugin = storagePlugins.find((p) => p.supportedProtocol === protocol);
15
+ if (!plugin) throw new Error(`No storage plugin for protocol: ${protocol}`);
16
+ const { fileUrl } = await plugin.getDownloadUrl(storageUri, context);
17
+ if (!fileUrl) throw new Error("Storage plugin returned empty fileUrl");
18
+ return fileUrl;
19
+ };
20
+ const resolveFileUrl = async (storageUri, context) => {
21
+ return resolveStoragePluginUrl(storageUri, context);
22
+ };
23
+ const database = options.database;
24
+ const core = isDatabasePluginFactory(database) || isDatabasePlugin(database) ? createPluginDatabaseCore(isDatabasePluginFactory(database) ? database() : database, resolveFileUrl) : createOrmDatabaseCore({
25
+ database,
26
+ resolveFileUrl
27
+ });
28
+ const api = {
29
+ ...core.api,
30
+ handler: createHandler(core.api, {
31
+ basePath,
32
+ routes: options.routes
33
+ }),
34
+ adapterName: core.adapterName,
35
+ createMigrator: core.createMigrator,
36
+ generateSchema: core.generateSchema
37
+ };
38
+ return {
39
+ ...api,
40
+ basePath,
41
+ handler: api.handler
42
+ };
43
+ }
44
+ //#endregion
45
+ export { createHotUpdater };