@hot-updater/server 0.34.0 → 0.35.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.
@@ -1,3 +1,5 @@
1
+ import { readFile } from "fs/promises";
2
+
1
3
  import type { Bundle } from "@hot-updater/core";
2
4
  import { NIL_UUID } from "@hot-updater/core";
3
5
  import type {
@@ -10,7 +12,8 @@ import { createDatabasePlugin } from "@hot-updater/plugin-core";
10
12
  import { describe, expect, expectTypeOf, it, vi } from "vitest";
11
13
 
12
14
  import type { DatabaseAdapterCapabilities, Migrator } from "./db/types";
13
- import { createHotUpdater } from "./runtime";
15
+ import { createHotUpdater } from "./index";
16
+ import type { HandlerAPI, HandlerOptions, HandlerRoutes } from "./index";
14
17
  import { HOT_UPDATER_SERVER_VERSION } from "./version";
15
18
 
16
19
  const bundle: Bundle = {
@@ -97,6 +100,64 @@ const createSchemaManagedDatabase = (
97
100
  });
98
101
 
99
102
  describe("runtime createHotUpdater", () => {
103
+ it("publishes db tooling subpath and removes the runtime subpath", async () => {
104
+ const packageJson = JSON.parse(
105
+ await readFile(new URL("../package.json", import.meta.url), "utf-8"),
106
+ ) as {
107
+ exports: Record<string, unknown>;
108
+ };
109
+
110
+ expect(packageJson.exports["./db"]).toBeDefined();
111
+ expect(packageJson.exports["./runtime"]).toBeUndefined();
112
+ });
113
+
114
+ it("exports runtime-safe handler types from the root entry", () => {
115
+ expectTypeOf<HandlerAPI>().toHaveProperty("getBundles");
116
+ expectTypeOf<HandlerOptions>().toHaveProperty("routes");
117
+ expectTypeOf<HandlerRoutes>().toEqualTypeOf<{
118
+ updateCheck: boolean;
119
+ bundles: boolean;
120
+ }>();
121
+ });
122
+
123
+ it("exports the root runtime API without database capabilities", () => {
124
+ const database: DatabasePlugin<TestContext> = {
125
+ name: "testDatabase",
126
+ async appendBundle() {},
127
+ async commitBundle() {},
128
+ async deleteBundle() {},
129
+ async getBundleById() {
130
+ return null;
131
+ },
132
+ async getBundles() {
133
+ return {
134
+ data: [],
135
+ pagination: {
136
+ currentPage: 1,
137
+ hasNextPage: false,
138
+ hasPreviousPage: false,
139
+ total: 0,
140
+ totalPages: 0,
141
+ },
142
+ };
143
+ },
144
+ async getChannels() {
145
+ return [];
146
+ },
147
+ async updateBundle() {},
148
+ };
149
+
150
+ const hotUpdater = createHotUpdater({ database });
151
+
152
+ expect(hotUpdater.basePath).toBe("/api");
153
+ expect(hotUpdater.adapterName).toBe("testDatabase");
154
+ expect(hotUpdater.handler).toEqual(expect.any(Function));
155
+ expect("createMigrator" in hotUpdater).toBe(false);
156
+ expect("generateSchema" in hotUpdater).toBe(false);
157
+ expectTypeOf(hotUpdater).not.toHaveProperty("createMigrator");
158
+ expectTypeOf(hotUpdater).not.toHaveProperty("generateSchema");
159
+ });
160
+
100
161
  it("requires storages to implement the runtime profile", () => {
101
162
  const database: DatabasePlugin<TestContext> = {
102
163
  name: "testDatabase",
@@ -1,7 +1,7 @@
1
1
  import type { Bundle } from "@hot-updater/core";
2
2
 
3
3
  export type { Bundle } from "@hot-updater/core";
4
- export type { HotUpdaterAPI } from "../db";
4
+ export type { HotUpdaterAPI } from "../createHotUpdaterCore";
5
5
 
6
6
  export interface PaginationInfo {
7
7
  total: number;
@@ -1,22 +0,0 @@
1
- import { HandlerRoutes, createHandler } from "./handler.cjs";
2
- import { HOT_UPDATER_SERVER_VERSION } from "./version.cjs";
3
- import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./db/types.cjs";
4
- import { HotUpdaterContext, RuntimeStoragePlugin } from "@hot-updater/plugin-core";
5
-
6
- //#region src/runtime.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
- };
12
- interface CreateHotUpdaterOptions<TContext = unknown> {
13
- database: DatabaseAdapter<TContext>;
14
- storages?: (RuntimeStoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
15
- storagePlugins?: (RuntimeStoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
16
- basePath?: string;
17
- cwd?: string;
18
- routes?: HandlerRoutes;
19
- }
20
- declare function createHotUpdater<TContext = unknown>(options: CreateHotUpdaterOptions<TContext>): HotUpdaterAPI<TContext>;
21
- //#endregion
22
- export { CreateHotUpdaterOptions, HOT_UPDATER_SERVER_VERSION, HotUpdaterAPI, createHandler, createHotUpdater };
@@ -1,22 +0,0 @@
1
- import { HandlerRoutes, createHandler } from "./handler.mjs";
2
- import { HOT_UPDATER_SERVER_VERSION } from "./version.mjs";
3
- import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./db/types.mjs";
4
- import { HotUpdaterContext, RuntimeStoragePlugin } from "@hot-updater/plugin-core";
5
-
6
- //#region src/runtime.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
- };
12
- interface CreateHotUpdaterOptions<TContext = unknown> {
13
- database: DatabaseAdapter<TContext>;
14
- storages?: (RuntimeStoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
15
- storagePlugins?: (RuntimeStoragePlugin<TContext> | StoragePluginFactory<TContext>)[];
16
- basePath?: string;
17
- cwd?: string;
18
- routes?: HandlerRoutes;
19
- }
20
- declare function createHotUpdater<TContext = unknown>(options: CreateHotUpdaterOptions<TContext>): HotUpdaterAPI<TContext>;
21
- //#endregion
22
- export { CreateHotUpdaterOptions, HOT_UPDATER_SERVER_VERSION, HotUpdaterAPI, createHandler, createHotUpdater };