@hot-updater/plugin-core 0.21.11 → 0.21.13

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.
@@ -0,0 +1,63 @@
1
+ import { StoragePlugin, StoragePluginHooks } from "./types/index.cjs";
2
+
3
+ //#region src/createStoragePlugin.d.ts
4
+
5
+ /**
6
+ * Storage plugin methods without name and supportedProtocol
7
+ */
8
+ type StoragePluginMethods = Omit<StoragePlugin, "name" | "supportedProtocol">;
9
+ /**
10
+ * Factory function that creates storage plugin methods
11
+ */
12
+ type StoragePluginFactory<TConfig> = (config: TConfig) => StoragePluginMethods;
13
+ /**
14
+ * Configuration options for creating a storage plugin
15
+ */
16
+ interface CreateStoragePluginOptions<TConfig> {
17
+ /**
18
+ * The name of the storage plugin (e.g., "s3Storage", "r2Storage")
19
+ */
20
+ name: string;
21
+ /**
22
+ * The protocol that this storage plugin supports (e.g., "s3", "r2", "gs").
23
+ *
24
+ * This value is stored in the database and is used by the server to understand
25
+ * how to fetch assets.
26
+ * For example, if the protocol is "s3", assets will be stored in the format:
27
+ * s3://bucketName/key
28
+ */
29
+ supportedProtocol: string;
30
+ /**
31
+ * Function that creates the storage plugin methods (upload, delete, getDownloadUrl)
32
+ */
33
+ factory: StoragePluginFactory<TConfig>;
34
+ }
35
+ /**
36
+ * Creates a storage plugin with lazy initialization and automatic hook execution.
37
+ *
38
+ * This factory function abstracts the double currying pattern used by all storage plugins,
39
+ * ensuring consistent lazy initialization behavior across different storage providers.
40
+ * Hooks are automatically executed at appropriate times without requiring manual invocation.
41
+ *
42
+ * @param options - Configuration options for the storage plugin
43
+ * @returns A double-curried function that lazily initializes the storage plugin
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * export const s3Storage = createStoragePlugin<S3StorageConfig>({
48
+ * name: "s3Storage",
49
+ * supportedProtocol: "s3",
50
+ * factory: (config) => {
51
+ * const client = new S3Client(config);
52
+ * return {
53
+ * async upload(key, filePath) { ... },
54
+ * async delete(storageUri) { ... },
55
+ * async getDownloadUrl(storageUri) { ... }
56
+ * };
57
+ * }
58
+ * });
59
+ * ```
60
+ */
61
+ declare const createStoragePlugin: <TConfig>(options: CreateStoragePluginOptions<TConfig>) => (config: TConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
62
+ //#endregion
63
+ export { CreateStoragePluginOptions, createStoragePlugin };
@@ -0,0 +1,63 @@
1
+ import { StoragePlugin, StoragePluginHooks } from "./types/index.js";
2
+
3
+ //#region src/createStoragePlugin.d.ts
4
+
5
+ /**
6
+ * Storage plugin methods without name and supportedProtocol
7
+ */
8
+ type StoragePluginMethods = Omit<StoragePlugin, "name" | "supportedProtocol">;
9
+ /**
10
+ * Factory function that creates storage plugin methods
11
+ */
12
+ type StoragePluginFactory<TConfig> = (config: TConfig) => StoragePluginMethods;
13
+ /**
14
+ * Configuration options for creating a storage plugin
15
+ */
16
+ interface CreateStoragePluginOptions<TConfig> {
17
+ /**
18
+ * The name of the storage plugin (e.g., "s3Storage", "r2Storage")
19
+ */
20
+ name: string;
21
+ /**
22
+ * The protocol that this storage plugin supports (e.g., "s3", "r2", "gs").
23
+ *
24
+ * This value is stored in the database and is used by the server to understand
25
+ * how to fetch assets.
26
+ * For example, if the protocol is "s3", assets will be stored in the format:
27
+ * s3://bucketName/key
28
+ */
29
+ supportedProtocol: string;
30
+ /**
31
+ * Function that creates the storage plugin methods (upload, delete, getDownloadUrl)
32
+ */
33
+ factory: StoragePluginFactory<TConfig>;
34
+ }
35
+ /**
36
+ * Creates a storage plugin with lazy initialization and automatic hook execution.
37
+ *
38
+ * This factory function abstracts the double currying pattern used by all storage plugins,
39
+ * ensuring consistent lazy initialization behavior across different storage providers.
40
+ * Hooks are automatically executed at appropriate times without requiring manual invocation.
41
+ *
42
+ * @param options - Configuration options for the storage plugin
43
+ * @returns A double-curried function that lazily initializes the storage plugin
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * export const s3Storage = createStoragePlugin<S3StorageConfig>({
48
+ * name: "s3Storage",
49
+ * supportedProtocol: "s3",
50
+ * factory: (config) => {
51
+ * const client = new S3Client(config);
52
+ * return {
53
+ * async upload(key, filePath) { ... },
54
+ * async delete(storageUri) { ... },
55
+ * async getDownloadUrl(storageUri) { ... }
56
+ * };
57
+ * }
58
+ * });
59
+ * ```
60
+ */
61
+ declare const createStoragePlugin: <TConfig>(options: CreateStoragePluginOptions<TConfig>) => (config: TConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
62
+ //#endregion
63
+ export { CreateStoragePluginOptions, createStoragePlugin };
@@ -0,0 +1,56 @@
1
+ //#region src/createStoragePlugin.ts
2
+ /**
3
+ * Creates a storage plugin with lazy initialization and automatic hook execution.
4
+ *
5
+ * This factory function abstracts the double currying pattern used by all storage plugins,
6
+ * ensuring consistent lazy initialization behavior across different storage providers.
7
+ * Hooks are automatically executed at appropriate times without requiring manual invocation.
8
+ *
9
+ * @param options - Configuration options for the storage plugin
10
+ * @returns A double-curried function that lazily initializes the storage plugin
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * export const s3Storage = createStoragePlugin<S3StorageConfig>({
15
+ * name: "s3Storage",
16
+ * supportedProtocol: "s3",
17
+ * factory: (config) => {
18
+ * const client = new S3Client(config);
19
+ * return {
20
+ * async upload(key, filePath) { ... },
21
+ * async delete(storageUri) { ... },
22
+ * async getDownloadUrl(storageUri) { ... }
23
+ * };
24
+ * }
25
+ * });
26
+ * ```
27
+ */
28
+ const createStoragePlugin = (options) => {
29
+ return (config, hooks) => {
30
+ return () => {
31
+ let cachedMethods = null;
32
+ const getMethods = () => {
33
+ if (!cachedMethods) cachedMethods = options.factory(config);
34
+ return cachedMethods;
35
+ };
36
+ return {
37
+ name: options.name,
38
+ supportedProtocol: options.supportedProtocol,
39
+ async upload(key, filePath) {
40
+ const result = await getMethods().upload(key, filePath);
41
+ await hooks?.onStorageUploaded?.();
42
+ return result;
43
+ },
44
+ async delete(storageUri) {
45
+ return getMethods().delete(storageUri);
46
+ },
47
+ async getDownloadUrl(storageUri) {
48
+ return getMethods().getDownloadUrl(storageUri);
49
+ }
50
+ };
51
+ };
52
+ };
53
+ };
54
+
55
+ //#endregion
56
+ export { createStoragePlugin };
package/dist/index.cjs CHANGED
@@ -3,6 +3,7 @@ const require_compressionFormat = require('./compressionFormat.cjs');
3
3
  const require_createDatabasePlugin = require('./createDatabasePlugin.cjs');
4
4
  const require_createBlobDatabasePlugin = require('./createBlobDatabasePlugin.cjs');
5
5
  const require_createStorageKeyBuilder = require('./createStorageKeyBuilder.cjs');
6
+ const require_createStoragePlugin = require('./createStoragePlugin.cjs');
6
7
  const require_semverSatisfies = require('./semverSatisfies.cjs');
7
8
  const require_filterCompatibleAppVersions = require('./filterCompatibleAppVersions.cjs');
8
9
  const require_generateMinBundleId = require('./generateMinBundleId.cjs');
@@ -12,6 +13,7 @@ exports.calculatePagination = require_calculatePagination.calculatePagination;
12
13
  exports.createBlobDatabasePlugin = require_createBlobDatabasePlugin.createBlobDatabasePlugin;
13
14
  exports.createDatabasePlugin = require_createDatabasePlugin.createDatabasePlugin;
14
15
  exports.createStorageKeyBuilder = require_createStorageKeyBuilder.createStorageKeyBuilder;
16
+ exports.createStoragePlugin = require_createStoragePlugin.createStoragePlugin;
15
17
  exports.detectCompressionFormat = require_compressionFormat.detectCompressionFormat;
16
18
  exports.filterCompatibleAppVersions = require_filterCompatibleAppVersions.filterCompatibleAppVersions;
17
19
  exports.generateMinBundleId = require_generateMinBundleId.generateMinBundleId;
package/dist/index.d.cts CHANGED
@@ -2,11 +2,12 @@ import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./
2
2
  import { BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabasePlugin, DatabasePluginHooks, NativeBuildArgs, PaginationInfo, Platform, PlatformConfig, StoragePlugin, StoragePluginHooks } from "./types/index.cjs";
3
3
  import { PaginatedResult, PaginationOptions, calculatePagination } from "./calculatePagination.cjs";
4
4
  import { CompressionFormat, CompressionFormatInfo, detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.cjs";
5
- import { createBlobDatabasePlugin } from "./createBlobDatabasePlugin.cjs";
6
- import { AbstractDatabasePlugin, createDatabasePlugin } from "./createDatabasePlugin.cjs";
5
+ import { BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.cjs";
6
+ import { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin } from "./createDatabasePlugin.cjs";
7
7
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.cjs";
8
+ import { CreateStoragePluginOptions, createStoragePlugin } from "./createStoragePlugin.cjs";
8
9
  import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.cjs";
9
10
  import { generateMinBundleId } from "./generateMinBundleId.cjs";
10
11
  import { ParsedStorageUri, parseStorageUri } from "./parseStorageUri.cjs";
11
12
  import { semverSatisfies } from "./semverSatisfies.cjs";
12
- export { AbstractDatabasePlugin, BasePluginArgs, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, DatabasePlugin, DatabasePluginHooks, HasMultipleCallSignatures, NativeBuildArgs, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequiredDeep, StoragePlugin, StoragePluginHooks, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies };
13
+ export { AbstractDatabasePlugin, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginOptions, CreateStoragePluginOptions, DatabasePlugin, DatabasePluginHooks, HasMultipleCallSignatures, NativeBuildArgs, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequiredDeep, StoragePlugin, StoragePluginHooks, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies };
package/dist/index.d.ts CHANGED
@@ -2,11 +2,12 @@ import { BuiltIns, HasMultipleCallSignatures, Primitive, RequiredDeep } from "./
2
2
  import { BasePluginArgs, BuildPlugin, BuildPluginConfig, Bundle, ConfigInput, DatabasePlugin, DatabasePluginHooks, NativeBuildArgs, PaginationInfo, Platform, PlatformConfig, StoragePlugin, StoragePluginHooks } from "./types/index.js";
3
3
  import { PaginatedResult, PaginationOptions, calculatePagination } from "./calculatePagination.js";
4
4
  import { CompressionFormat, CompressionFormatInfo, detectCompressionFormat, getCompressionMimeType, getContentType } from "./compressionFormat.js";
5
- import { createBlobDatabasePlugin } from "./createBlobDatabasePlugin.js";
6
- import { AbstractDatabasePlugin, createDatabasePlugin } from "./createDatabasePlugin.js";
5
+ import { BlobOperations, createBlobDatabasePlugin } from "./createBlobDatabasePlugin.js";
6
+ import { AbstractDatabasePlugin, CreateDatabasePluginOptions, createDatabasePlugin } from "./createDatabasePlugin.js";
7
7
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.js";
8
+ import { CreateStoragePluginOptions, createStoragePlugin } from "./createStoragePlugin.js";
8
9
  import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.js";
9
10
  import { generateMinBundleId } from "./generateMinBundleId.js";
10
11
  import { ParsedStorageUri, parseStorageUri } from "./parseStorageUri.js";
11
12
  import { semverSatisfies } from "./semverSatisfies.js";
12
- export { AbstractDatabasePlugin, BasePluginArgs, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, DatabasePlugin, DatabasePluginHooks, HasMultipleCallSignatures, NativeBuildArgs, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequiredDeep, StoragePlugin, StoragePluginHooks, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies };
13
+ export { AbstractDatabasePlugin, BasePluginArgs, BlobOperations, BuildPlugin, BuildPluginConfig, BuiltIns, Bundle, CompressionFormat, CompressionFormatInfo, ConfigInput, CreateDatabasePluginOptions, CreateStoragePluginOptions, DatabasePlugin, DatabasePluginHooks, HasMultipleCallSignatures, NativeBuildArgs, PaginatedResult, PaginationInfo, PaginationOptions, ParsedStorageUri, Platform, PlatformConfig, Primitive, RequiredDeep, StoragePlugin, StoragePluginHooks, calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies };
package/dist/index.js CHANGED
@@ -3,9 +3,10 @@ import { detectCompressionFormat, getCompressionMimeType, getContentType } from
3
3
  import { createDatabasePlugin } from "./createDatabasePlugin.js";
4
4
  import { createBlobDatabasePlugin } from "./createBlobDatabasePlugin.js";
5
5
  import { createStorageKeyBuilder } from "./createStorageKeyBuilder.js";
6
+ import { createStoragePlugin } from "./createStoragePlugin.js";
6
7
  import { semverSatisfies } from "./semverSatisfies.js";
7
8
  import { filterCompatibleAppVersions } from "./filterCompatibleAppVersions.js";
8
9
  import { generateMinBundleId } from "./generateMinBundleId.js";
9
10
  import { parseStorageUri } from "./parseStorageUri.js";
10
11
 
11
- export { calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies };
12
+ export { calculatePagination, createBlobDatabasePlugin, createDatabasePlugin, createStorageKeyBuilder, createStoragePlugin, detectCompressionFormat, filterCompatibleAppVersions, generateMinBundleId, getCompressionMimeType, getContentType, parseStorageUri, semverSatisfies };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/plugin-core",
3
- "version": "0.21.11",
3
+ "version": "0.21.13",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -42,12 +42,12 @@
42
42
  "es-toolkit": "^1.32.0",
43
43
  "mime": "^4.0.4",
44
44
  "semver": "^7.7.2",
45
- "@hot-updater/core": "0.21.11"
45
+ "@hot-updater/core": "0.21.13"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/semver": "^7.5.8",
49
49
  "typescript": "5.8.2",
50
- "@hot-updater/test-utils": "0.21.11"
50
+ "@hot-updater/test-utils": "0.21.13"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "tsdown",