@hot-updater/plugin-core 1.0.0-rc.14 → 1.0.0-rc.16

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 (163) hide show
  1. package/dist/bundleEventRow.cjs +42 -0
  2. package/dist/bundleEventRow.mjs +41 -0
  3. package/dist/bundleStorageLayout.cjs +7 -0
  4. package/dist/bundleStorageLayout.d.cts +5 -1
  5. package/dist/bundleStorageLayout.d.mts +5 -1
  6. package/dist/bundleStorageLayout.mjs +7 -1
  7. package/dist/contentType.cjs +9 -0
  8. package/dist/contentType.d.cts +4 -0
  9. package/dist/contentType.d.mts +4 -0
  10. package/dist/contentType.mjs +7 -0
  11. package/dist/coreApi.d.cts +131 -0
  12. package/dist/coreApi.d.mts +131 -0
  13. package/dist/database/adapter.cjs +37 -0
  14. package/dist/database/adapter.d.cts +150 -0
  15. package/dist/database/adapter.d.mts +150 -0
  16. package/dist/database/adapter.mjs +30 -0
  17. package/dist/database/memoryAdapter.cjs +102 -0
  18. package/dist/database/memoryAdapter.d.cts +16 -0
  19. package/dist/database/memoryAdapter.d.mts +16 -0
  20. package/dist/database/memoryAdapter.mjs +102 -0
  21. package/dist/database/values.cjs +110 -0
  22. package/dist/database/values.d.cts +30 -0
  23. package/dist/database/values.d.mts +30 -0
  24. package/dist/database/values.mjs +100 -0
  25. package/dist/database/verifyAdapter.cjs +129 -0
  26. package/dist/database/verifyAdapter.d.cts +29 -0
  27. package/dist/database/verifyAdapter.d.mts +29 -0
  28. package/dist/database/verifyAdapter.mjs +128 -0
  29. package/dist/databaseErrors.cjs +30 -0
  30. package/dist/databaseErrors.d.cts +21 -0
  31. package/dist/databaseErrors.d.mts +21 -0
  32. package/dist/databaseErrors.mjs +28 -0
  33. package/dist/databaseMetadata.cjs +2 -2
  34. package/dist/databaseMetadata.mjs +1 -1
  35. package/dist/databaseRows.cjs +0 -6
  36. package/dist/databaseRows.mjs +0 -6
  37. package/dist/index.cjs +14 -41
  38. package/dist/index.d.cts +15 -19
  39. package/dist/index.d.mts +15 -19
  40. package/dist/index.mjs +10 -16
  41. package/dist/insightsContract.cjs +65 -17
  42. package/dist/insightsContract.d.cts +6 -1
  43. package/dist/insightsContract.d.mts +6 -1
  44. package/dist/insightsContract.mjs +52 -5
  45. package/dist/insightsDistinctSummary.cjs +73 -0
  46. package/dist/insightsDistinctSummary.d.cts +12 -0
  47. package/dist/insightsDistinctSummary.d.mts +12 -0
  48. package/dist/insightsDistinctSummary.mjs +69 -0
  49. package/dist/insightsOverview.cjs +139 -0
  50. package/dist/insightsOverview.d.cts +42 -0
  51. package/dist/insightsOverview.d.mts +42 -0
  52. package/dist/insightsOverview.mjs +134 -0
  53. package/dist/internal.cjs +44 -8
  54. package/dist/internal.d.cts +12 -9
  55. package/dist/internal.d.mts +12 -9
  56. package/dist/internal.mjs +9 -4
  57. package/dist/releaseCatalogCompiler.cjs +1 -1
  58. package/dist/releaseCatalogCompiler.mjs +2 -2
  59. package/dist/releaseCatalogMutation.cjs +0 -292
  60. package/dist/releaseCatalogMutation.d.cts +4 -45
  61. package/dist/releaseCatalogMutation.d.mts +4 -45
  62. package/dist/releaseCatalogMutation.mjs +1 -288
  63. package/dist/releaseManagement.cjs +0 -221
  64. package/dist/releaseManagement.d.cts +4 -28
  65. package/dist/releaseManagement.d.mts +4 -28
  66. package/dist/releaseManagement.mjs +1 -216
  67. package/dist/types/databaseConfig.cjs +5 -0
  68. package/dist/types/databaseConfig.d.cts +33 -0
  69. package/dist/types/databaseConfig.d.mts +33 -0
  70. package/dist/types/databaseConfig.mjs +5 -0
  71. package/dist/types/databaseOperations.d.cts +5 -172
  72. package/dist/types/databaseOperations.d.mts +5 -172
  73. package/dist/types/databaseRows.d.cts +3 -6
  74. package/dist/types/databaseRows.d.mts +3 -6
  75. package/dist/types/index.cjs +2 -0
  76. package/dist/types/index.d.cts +9 -86
  77. package/dist/types/index.d.mts +9 -86
  78. package/dist/types/index.mjs +2 -1
  79. package/dist/types/insights.d.cts +172 -0
  80. package/dist/types/insights.d.mts +172 -0
  81. package/dist/types/internal.d.cts +4 -7
  82. package/dist/types/internal.d.mts +4 -7
  83. package/dist/types/models.d.cts +24 -0
  84. package/dist/types/models.d.mts +24 -0
  85. package/dist/types/public.d.cts +4 -2
  86. package/dist/types/public.d.mts +4 -2
  87. package/package.json +2 -2
  88. package/dist/calculatePagination.cjs +0 -25
  89. package/dist/calculatePagination.d.cts +0 -12
  90. package/dist/calculatePagination.d.mts +0 -12
  91. package/dist/calculatePagination.mjs +0 -25
  92. package/dist/compressionFormat.cjs +0 -62
  93. package/dist/compressionFormat.d.cts +0 -33
  94. package/dist/compressionFormat.d.mts +0 -33
  95. package/dist/compressionFormat.mjs +0 -58
  96. package/dist/createDatabasePlugin.cjs +0 -873
  97. package/dist/createDatabasePlugin.d.cts +0 -28
  98. package/dist/createDatabasePlugin.d.mts +0 -28
  99. package/dist/createDatabasePlugin.mjs +0 -869
  100. package/dist/databaseClient.cjs +0 -117
  101. package/dist/databaseClient.d.cts +0 -32
  102. package/dist/databaseClient.d.mts +0 -32
  103. package/dist/databaseClient.mjs +0 -114
  104. package/dist/databaseClientReads.cjs +0 -115
  105. package/dist/databaseClientReads.mjs +0 -113
  106. package/dist/databaseClientUpdates.cjs +0 -40
  107. package/dist/databaseClientUpdates.d.cts +0 -11
  108. package/dist/databaseClientUpdates.d.mts +0 -11
  109. package/dist/databaseClientUpdates.mjs +0 -38
  110. package/dist/databasePluginCrud.cjs +0 -87
  111. package/dist/databasePluginCrud.d.cts +0 -4
  112. package/dist/databasePluginCrud.d.mts +0 -4
  113. package/dist/databasePluginCrud.mjs +0 -86
  114. package/dist/databasePluginCrudValidation.d.cts +0 -6
  115. package/dist/databasePluginCrudValidation.d.mts +0 -6
  116. package/dist/databasePluginCrudValidationErrors.cjs +0 -11
  117. package/dist/databasePluginCrudValidationErrors.d.cts +0 -9
  118. package/dist/databasePluginCrudValidationErrors.d.mts +0 -9
  119. package/dist/databasePluginCrudValidationErrors.mjs +0 -11
  120. package/dist/databasePluginCrudValidationFields.cjs +0 -293
  121. package/dist/databasePluginCrudValidationFields.d.cts +0 -1
  122. package/dist/databasePluginCrudValidationFields.d.mts +0 -1
  123. package/dist/databasePluginCrudValidationFields.mjs +0 -281
  124. package/dist/databasePluginCrudValidationMutations.cjs +0 -88
  125. package/dist/databasePluginCrudValidationMutations.d.cts +0 -1
  126. package/dist/databasePluginCrudValidationMutations.d.mts +0 -1
  127. package/dist/databasePluginCrudValidationMutations.mjs +0 -82
  128. package/dist/databasePluginCrudValidationQueries.cjs +0 -103
  129. package/dist/databasePluginCrudValidationQueries.d.cts +0 -2
  130. package/dist/databasePluginCrudValidationQueries.d.mts +0 -2
  131. package/dist/databasePluginCrudValidationQueries.mjs +0 -97
  132. package/dist/databasePluginCrudValidationRows.cjs +0 -55
  133. package/dist/databasePluginCrudValidationRows.d.cts +0 -1
  134. package/dist/databasePluginCrudValidationRows.d.mts +0 -1
  135. package/dist/databasePluginCrudValidationRows.mjs +0 -53
  136. package/dist/databasePluginTransaction.cjs +0 -7
  137. package/dist/databasePluginTransaction.mjs +0 -7
  138. package/dist/insightsLatestQueries.cjs +0 -53
  139. package/dist/insightsLatestQueries.d.cts +0 -13
  140. package/dist/insightsLatestQueries.d.mts +0 -13
  141. package/dist/insightsLatestQueries.mjs +0 -52
  142. package/dist/paginateBundles.cjs +0 -53
  143. package/dist/paginateBundles.d.cts +0 -13
  144. package/dist/paginateBundles.d.mts +0 -13
  145. package/dist/paginateBundles.mjs +0 -53
  146. package/dist/queryBundles.cjs +0 -34
  147. package/dist/queryBundles.d.cts +0 -9
  148. package/dist/queryBundles.d.mts +0 -9
  149. package/dist/queryBundles.mjs +0 -32
  150. package/dist/requestBundleCache.cjs +0 -22
  151. package/dist/requestBundleCache.d.cts +0 -8
  152. package/dist/requestBundleCache.d.mts +0 -8
  153. package/dist/requestBundleCache.mjs +0 -22
  154. package/dist/types/database.d.cts +0 -5
  155. package/dist/types/database.d.mts +0 -5
  156. package/dist/types/databaseFields.cjs +0 -88
  157. package/dist/types/databaseFields.d.cts +0 -12
  158. package/dist/types/databaseFields.d.mts +0 -12
  159. package/dist/types/databaseFields.mjs +0 -88
  160. package/dist/types/databasePlugin.d.cts +0 -304
  161. package/dist/types/databasePlugin.d.mts +0 -304
  162. package/dist/types/databaseQuery.d.cts +0 -46
  163. package/dist/types/databaseQuery.d.mts +0 -46
@@ -1,117 +0,0 @@
1
- const require_createDatabasePlugin = require("./createDatabasePlugin.cjs");
2
- const require_databaseRows = require("./databaseRows.cjs");
3
- const require_databaseClientReads = require("./databaseClientReads.cjs");
4
- const require_databaseClientUpdates = require("./databaseClientUpdates.cjs");
5
- //#region src/databaseClient.ts
6
- var DatabaseBundleNotFoundError = class extends Error {
7
- bundleId;
8
- name = "DatabaseBundleNotFoundError";
9
- constructor(bundleId) {
10
- super(`Bundle "${bundleId}" was not found.`);
11
- this.bundleId = bundleId;
12
- }
13
- };
14
- var DatabasePatchInsertUnsupportedError = class extends Error {
15
- bundleId;
16
- pluginName;
17
- name = "DatabasePatchInsertUnsupportedError";
18
- constructor(bundleId, pluginName) {
19
- super(`Database plugin "${pluginName}" cannot atomically insert patches for bundle "${bundleId}".`);
20
- this.bundleId = bundleId;
21
- this.pluginName = pluginName;
22
- }
23
- };
24
- const insertChanges = (bundle) => [{
25
- model: "bundles",
26
- operation: "insert",
27
- row: require_databaseRows.bundleToRow(bundle)
28
- }, ...require_databaseRows.bundleToPatchRows(bundle).map((row) => ({
29
- model: "bundlePatches",
30
- operation: "insert",
31
- row
32
- }))];
33
- const updateChanges = (bundleId, update) => {
34
- const rowUpdate = require_databaseClientUpdates.bundleUpdateToRow(update);
35
- const patchesPresent = Object.hasOwn(update, "patches");
36
- return [{
37
- model: "bundles",
38
- operation: "update",
39
- where: { id: bundleId },
40
- update: rowUpdate
41
- }, ...patchesPresent ? [{
42
- model: "bundlePatches",
43
- operation: "delete",
44
- where: { bundleId }
45
- }, ...require_databaseClientUpdates.bundleUpdateToPatchRows(bundleId, update).map((row) => ({
46
- model: "bundlePatches",
47
- operation: "insert",
48
- row
49
- }))] : []];
50
- };
51
- const deleteChanges = (bundleId) => [{
52
- model: "bundles",
53
- operation: "delete",
54
- where: { id: bundleId }
55
- }];
56
- const createDatabaseClient = (plugin) => {
57
- const getBundleById = async (id) => {
58
- const row = await plugin.models.bundles.findById(id);
59
- if (!row) return null;
60
- return (await require_databaseClientReads.hydrateRows(plugin, [row]))[0] ?? null;
61
- };
62
- const insertChannel = (input) => plugin.models.channels.insert(input);
63
- const createMutationClient = (commit) => ({
64
- getBundleById,
65
- getBundles: (options) => require_databaseClientReads.responsePage(plugin, options),
66
- async getChannels() {
67
- return (await plugin.models.channels.list({})).channels;
68
- },
69
- insertChannel,
70
- async insertBundle(bundle) {
71
- try {
72
- await commit(insertChanges(bundle));
73
- } catch (error) {
74
- if (error instanceof require_createDatabasePlugin.DatabaseAtomicCommitUnsupportedError && require_databaseRows.bundleToPatchRows(bundle).length > 0) throw new DatabasePatchInsertUnsupportedError(bundle.id, plugin.name);
75
- throw error;
76
- }
77
- },
78
- async updateBundleById(bundleId, update) {
79
- try {
80
- if (!(await commit(updateChanges(bundleId, update))).committed) throw new DatabaseBundleNotFoundError(bundleId);
81
- } catch (error) {
82
- if (error instanceof require_createDatabasePlugin.DatabaseAtomicCommitUnsupportedError && Object.hasOwn(update, "patches")) throw new require_databaseClientUpdates.DatabasePatchUpdateUnsupportedError(bundleId, plugin.name);
83
- throw error;
84
- }
85
- },
86
- async deleteBundleById(bundleId) {
87
- const result = await commit(deleteChanges(bundleId));
88
- if (!result.committed && result.conflict.reason === "referenced") throw new require_createDatabasePlugin.DatabaseRowReferencedError();
89
- }
90
- });
91
- const runMutation = async (operation) => {
92
- const changes = [];
93
- const result = await operation(createMutationClient(async (input) => {
94
- changes.push(...input);
95
- return { committed: true };
96
- }));
97
- if (changes.length === 0) return result;
98
- const commitResult = await plugin.commit({ changes });
99
- if (!commitResult.committed) {
100
- const change = changes[commitResult.conflict.changeIndex];
101
- if (commitResult.conflict.reason === "referenced" && change?.model === "bundles" && change.operation === "delete") throw new require_createDatabasePlugin.DatabaseRowReferencedError();
102
- if (change?.model === "bundles" && change.operation === "update") throw new DatabaseBundleNotFoundError(change.where.id);
103
- throw new Error(`Database plugin "${plugin.name}" rejected a commit.`);
104
- }
105
- return result;
106
- };
107
- return {
108
- ...createMutationClient((changes) => plugin.commit({ changes })),
109
- deleteChannel: (input) => plugin.models.channels.delete(input),
110
- mutate: runMutation
111
- };
112
- };
113
- //#endregion
114
- exports.DatabaseBundleNotFoundError = DatabaseBundleNotFoundError;
115
- exports.DatabasePatchInsertUnsupportedError = DatabasePatchInsertUnsupportedError;
116
- exports.DatabasePatchUpdateUnsupportedError = require_databaseClientUpdates.DatabasePatchUpdateUnsupportedError;
117
- exports.createDatabaseClient = createDatabaseClient;
@@ -1,32 +0,0 @@
1
- import { ChannelRow } from "./types/databaseRows.cjs";
2
- import { BundleRepository, ChannelDeleteInput, ChannelDeleteResult, ChannelInsertInput, ChannelInsertResult } from "./types/databasePlugin.cjs";
3
- import { DatabaseBundleQueryOptions, PaginatedResult } from "./types/index.cjs";
4
- import { DatabasePatchUpdateUnsupportedError } from "./databaseClientUpdates.cjs";
5
- import { Bundle } from "@hot-updater/core";
6
- //#region src/databaseClient.d.ts
7
- interface DatabaseClient {
8
- getBundleById(id: string): Promise<Bundle | null>;
9
- getChannels(): Promise<readonly ChannelRow[]>;
10
- insertChannel(input: ChannelInsertInput): Promise<ChannelInsertResult>;
11
- deleteChannel(input: ChannelDeleteInput): Promise<ChannelDeleteResult>;
12
- getBundles(options: DatabaseBundleQueryOptions): Promise<PaginatedResult>;
13
- insertBundle(bundle: Bundle): Promise<void>;
14
- updateBundleById(bundleId: string, update: Partial<Bundle>): Promise<void>;
15
- deleteBundleById(bundleId: string): Promise<void>;
16
- mutate<TResult>(operation: (client: DatabaseMutationClient) => Promise<TResult>): Promise<TResult>;
17
- }
18
- type DatabaseMutationClient = Omit<DatabaseClient, "deleteChannel" | "mutate">;
19
- declare class DatabaseBundleNotFoundError extends Error {
20
- readonly bundleId: string;
21
- readonly name = "DatabaseBundleNotFoundError";
22
- constructor(bundleId: string);
23
- }
24
- declare class DatabasePatchInsertUnsupportedError extends Error {
25
- readonly bundleId: string;
26
- readonly pluginName: string;
27
- readonly name = "DatabasePatchInsertUnsupportedError";
28
- constructor(bundleId: string, pluginName: string);
29
- }
30
- declare const createDatabaseClient: (plugin: BundleRepository) => DatabaseClient;
31
- //#endregion
32
- export { DatabaseBundleNotFoundError, DatabaseClient, DatabaseMutationClient, DatabasePatchInsertUnsupportedError, DatabasePatchUpdateUnsupportedError, createDatabaseClient };
@@ -1,32 +0,0 @@
1
- import { ChannelRow } from "./types/databaseRows.mjs";
2
- import { BundleRepository, ChannelDeleteInput, ChannelDeleteResult, ChannelInsertInput, ChannelInsertResult } from "./types/databasePlugin.mjs";
3
- import { DatabaseBundleQueryOptions, PaginatedResult } from "./types/index.mjs";
4
- import { DatabasePatchUpdateUnsupportedError } from "./databaseClientUpdates.mjs";
5
- import { Bundle } from "@hot-updater/core";
6
- //#region src/databaseClient.d.ts
7
- interface DatabaseClient {
8
- getBundleById(id: string): Promise<Bundle | null>;
9
- getChannels(): Promise<readonly ChannelRow[]>;
10
- insertChannel(input: ChannelInsertInput): Promise<ChannelInsertResult>;
11
- deleteChannel(input: ChannelDeleteInput): Promise<ChannelDeleteResult>;
12
- getBundles(options: DatabaseBundleQueryOptions): Promise<PaginatedResult>;
13
- insertBundle(bundle: Bundle): Promise<void>;
14
- updateBundleById(bundleId: string, update: Partial<Bundle>): Promise<void>;
15
- deleteBundleById(bundleId: string): Promise<void>;
16
- mutate<TResult>(operation: (client: DatabaseMutationClient) => Promise<TResult>): Promise<TResult>;
17
- }
18
- type DatabaseMutationClient = Omit<DatabaseClient, "deleteChannel" | "mutate">;
19
- declare class DatabaseBundleNotFoundError extends Error {
20
- readonly bundleId: string;
21
- readonly name = "DatabaseBundleNotFoundError";
22
- constructor(bundleId: string);
23
- }
24
- declare class DatabasePatchInsertUnsupportedError extends Error {
25
- readonly bundleId: string;
26
- readonly pluginName: string;
27
- readonly name = "DatabasePatchInsertUnsupportedError";
28
- constructor(bundleId: string, pluginName: string);
29
- }
30
- declare const createDatabaseClient: (plugin: BundleRepository) => DatabaseClient;
31
- //#endregion
32
- export { DatabaseBundleNotFoundError, DatabaseClient, DatabaseMutationClient, DatabasePatchInsertUnsupportedError, DatabasePatchUpdateUnsupportedError, createDatabaseClient };
@@ -1,114 +0,0 @@
1
- import { DatabaseAtomicCommitUnsupportedError, DatabaseRowReferencedError } from "./createDatabasePlugin.mjs";
2
- import { bundleToPatchRows, bundleToRow } from "./databaseRows.mjs";
3
- import { hydrateRows, responsePage } from "./databaseClientReads.mjs";
4
- import { DatabasePatchUpdateUnsupportedError, bundleUpdateToPatchRows, bundleUpdateToRow } from "./databaseClientUpdates.mjs";
5
- //#region src/databaseClient.ts
6
- var DatabaseBundleNotFoundError = class extends Error {
7
- bundleId;
8
- name = "DatabaseBundleNotFoundError";
9
- constructor(bundleId) {
10
- super(`Bundle "${bundleId}" was not found.`);
11
- this.bundleId = bundleId;
12
- }
13
- };
14
- var DatabasePatchInsertUnsupportedError = class extends Error {
15
- bundleId;
16
- pluginName;
17
- name = "DatabasePatchInsertUnsupportedError";
18
- constructor(bundleId, pluginName) {
19
- super(`Database plugin "${pluginName}" cannot atomically insert patches for bundle "${bundleId}".`);
20
- this.bundleId = bundleId;
21
- this.pluginName = pluginName;
22
- }
23
- };
24
- const insertChanges = (bundle) => [{
25
- model: "bundles",
26
- operation: "insert",
27
- row: bundleToRow(bundle)
28
- }, ...bundleToPatchRows(bundle).map((row) => ({
29
- model: "bundlePatches",
30
- operation: "insert",
31
- row
32
- }))];
33
- const updateChanges = (bundleId, update) => {
34
- const rowUpdate = bundleUpdateToRow(update);
35
- const patchesPresent = Object.hasOwn(update, "patches");
36
- return [{
37
- model: "bundles",
38
- operation: "update",
39
- where: { id: bundleId },
40
- update: rowUpdate
41
- }, ...patchesPresent ? [{
42
- model: "bundlePatches",
43
- operation: "delete",
44
- where: { bundleId }
45
- }, ...bundleUpdateToPatchRows(bundleId, update).map((row) => ({
46
- model: "bundlePatches",
47
- operation: "insert",
48
- row
49
- }))] : []];
50
- };
51
- const deleteChanges = (bundleId) => [{
52
- model: "bundles",
53
- operation: "delete",
54
- where: { id: bundleId }
55
- }];
56
- const createDatabaseClient = (plugin) => {
57
- const getBundleById = async (id) => {
58
- const row = await plugin.models.bundles.findById(id);
59
- if (!row) return null;
60
- return (await hydrateRows(plugin, [row]))[0] ?? null;
61
- };
62
- const insertChannel = (input) => plugin.models.channels.insert(input);
63
- const createMutationClient = (commit) => ({
64
- getBundleById,
65
- getBundles: (options) => responsePage(plugin, options),
66
- async getChannels() {
67
- return (await plugin.models.channels.list({})).channels;
68
- },
69
- insertChannel,
70
- async insertBundle(bundle) {
71
- try {
72
- await commit(insertChanges(bundle));
73
- } catch (error) {
74
- if (error instanceof DatabaseAtomicCommitUnsupportedError && bundleToPatchRows(bundle).length > 0) throw new DatabasePatchInsertUnsupportedError(bundle.id, plugin.name);
75
- throw error;
76
- }
77
- },
78
- async updateBundleById(bundleId, update) {
79
- try {
80
- if (!(await commit(updateChanges(bundleId, update))).committed) throw new DatabaseBundleNotFoundError(bundleId);
81
- } catch (error) {
82
- if (error instanceof DatabaseAtomicCommitUnsupportedError && Object.hasOwn(update, "patches")) throw new DatabasePatchUpdateUnsupportedError(bundleId, plugin.name);
83
- throw error;
84
- }
85
- },
86
- async deleteBundleById(bundleId) {
87
- const result = await commit(deleteChanges(bundleId));
88
- if (!result.committed && result.conflict.reason === "referenced") throw new DatabaseRowReferencedError();
89
- }
90
- });
91
- const runMutation = async (operation) => {
92
- const changes = [];
93
- const result = await operation(createMutationClient(async (input) => {
94
- changes.push(...input);
95
- return { committed: true };
96
- }));
97
- if (changes.length === 0) return result;
98
- const commitResult = await plugin.commit({ changes });
99
- if (!commitResult.committed) {
100
- const change = changes[commitResult.conflict.changeIndex];
101
- if (commitResult.conflict.reason === "referenced" && change?.model === "bundles" && change.operation === "delete") throw new DatabaseRowReferencedError();
102
- if (change?.model === "bundles" && change.operation === "update") throw new DatabaseBundleNotFoundError(change.where.id);
103
- throw new Error(`Database plugin "${plugin.name}" rejected a commit.`);
104
- }
105
- return result;
106
- };
107
- return {
108
- ...createMutationClient((changes) => plugin.commit({ changes })),
109
- deleteChannel: (input) => plugin.models.channels.delete(input),
110
- mutate: runMutation
111
- };
112
- };
113
- //#endregion
114
- export { DatabaseBundleNotFoundError, DatabasePatchInsertUnsupportedError, DatabasePatchUpdateUnsupportedError, createDatabaseClient };
@@ -1,115 +0,0 @@
1
- const require_calculatePagination = require("./calculatePagination.cjs");
2
- const require_databasePluginCrudValidationErrors = require("./databasePluginCrudValidationErrors.cjs");
3
- const require_databasePluginCrudValidationQueries = require("./databasePluginCrudValidationQueries.cjs");
4
- const require_databaseRows = require("./databaseRows.cjs");
5
- //#region src/databaseClientReads.ts
6
- const PAGE_SIZE = 100;
7
- const mergeIdFilter = (where, id) => ({
8
- ...where,
9
- id: {
10
- ...where?.id,
11
- ...id
12
- }
13
- });
14
- const loadBundleRows = async (database, where) => {
15
- const finiteIds = where?.id?.in;
16
- if (finiteIds) {
17
- if (finiteIds.length === 0) return [];
18
- return [...await database.models.bundles.findMany({
19
- where,
20
- limit: finiteIds.length,
21
- offset: 0,
22
- orderBy: {
23
- field: "id",
24
- direction: "asc"
25
- }
26
- })];
27
- }
28
- const [cutoff] = await database.models.bundles.findMany({
29
- where,
30
- limit: 1,
31
- offset: 0,
32
- orderBy: {
33
- field: "id",
34
- direction: "desc"
35
- }
36
- });
37
- if (!cutoff) return [];
38
- const rows = [];
39
- let after;
40
- for (;;) {
41
- const page = await database.models.bundles.findMany({
42
- where: mergeIdFilter(where, {
43
- lte: cutoff.id,
44
- ...after ? { gt: after } : {}
45
- }),
46
- limit: PAGE_SIZE,
47
- offset: 0,
48
- orderBy: {
49
- field: "id",
50
- direction: "asc"
51
- }
52
- });
53
- rows.push(...page);
54
- if (page.length < PAGE_SIZE) return rows;
55
- after = page.at(-1)?.id;
56
- }
57
- };
58
- const hydrateRows = async (database, ownerRows) => {
59
- const patchRows = await database.models.bundlePatches.findByBundleIds(ownerRows.map(({ id }) => id));
60
- const ownerIds = new Set(ownerRows.map(({ id }) => id));
61
- const referencedIds = [...new Set(patchRows.map(({ base_bundle_id }) => base_bundle_id).filter((id) => !ownerIds.has(id)))];
62
- const referencedRows = referencedIds.length === 0 ? [] : await loadBundleRows(database, { id: { in: referencedIds } });
63
- return require_databaseRows.rowsToBundles(ownerRows, patchRows, referencedRows);
64
- };
65
- const cursorIdFilter = (cursor, direction) => {
66
- if (cursor?.after) return { [direction === "desc" ? "lt" : "gt"]: cursor.after };
67
- if (cursor?.before) return { [direction === "desc" ? "gt" : "lt"]: cursor.before };
68
- };
69
- const responsePage = async (database, options) => {
70
- require_databasePluginCrudValidationQueries.validateBundlePagination(options);
71
- const direction = options.orderBy?.direction ?? "desc";
72
- const offset = options.page ? Math.max(0, options.page - 1) * options.limit : 0;
73
- const cursor = options.page ? void 0 : options.cursor;
74
- const queryLimit = cursor ? options.limit + 1 : options.limit;
75
- if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(queryLimit) || !Number.isSafeInteger(offset + queryLimit)) throw new require_databasePluginCrudValidationErrors.DatabasePluginInputError("invalid-pagination");
76
- const cursorFilter = cursorIdFilter(cursor, direction);
77
- const where = cursorFilter ? mergeIdFilter(options.where, cursorFilter) : options.where;
78
- const queryDirection = cursor?.before ? direction === "desc" ? "asc" : "desc" : direction;
79
- const [queriedRows, total] = await Promise.all([database.models.bundles.findMany({
80
- where,
81
- limit: queryLimit,
82
- offset,
83
- orderBy: {
84
- field: "id",
85
- direction: queryDirection
86
- }
87
- }), database.models.bundles.count(options.where)]);
88
- const hasMore = cursor ? queriedRows.length > options.limit : false;
89
- const pageRows = cursor ? queriedRows.slice(0, options.limit) : queriedRows;
90
- const ownerRows = cursor?.before ? pageRows.toReversed() : pageRows;
91
- const pagination = require_calculatePagination.calculatePagination(total, {
92
- limit: options.limit,
93
- offset
94
- });
95
- const hasPreviousPage = cursor ? Boolean(cursor.after) || hasMore : pagination.hasPreviousPage;
96
- const hasNextPage = cursor ? Boolean(cursor.before) || hasMore : pagination.hasNextPage;
97
- const firstId = ownerRows[0]?.id;
98
- const lastId = ownerRows.at(-1)?.id;
99
- return {
100
- data: await hydrateRows(database, ownerRows),
101
- pagination: {
102
- ...pagination,
103
- hasNextPage,
104
- hasPreviousPage,
105
- ...hasNextPage && lastId ? { nextCursor: lastId } : {},
106
- ...hasPreviousPage && firstId ? { previousCursor: firstId } : {},
107
- ...!firstId && cursor?.after ? { previousCursor: cursor.after } : {},
108
- ...!lastId && cursor?.before ? { nextCursor: cursor.before } : {}
109
- }
110
- };
111
- };
112
- //#endregion
113
- exports.hydrateRows = hydrateRows;
114
- exports.loadBundleRows = loadBundleRows;
115
- exports.responsePage = responsePage;
@@ -1,113 +0,0 @@
1
- import { calculatePagination } from "./calculatePagination.mjs";
2
- import { DatabasePluginInputError } from "./databasePluginCrudValidationErrors.mjs";
3
- import { validateBundlePagination } from "./databasePluginCrudValidationQueries.mjs";
4
- import { rowsToBundles } from "./databaseRows.mjs";
5
- //#region src/databaseClientReads.ts
6
- const PAGE_SIZE = 100;
7
- const mergeIdFilter = (where, id) => ({
8
- ...where,
9
- id: {
10
- ...where?.id,
11
- ...id
12
- }
13
- });
14
- const loadBundleRows = async (database, where) => {
15
- const finiteIds = where?.id?.in;
16
- if (finiteIds) {
17
- if (finiteIds.length === 0) return [];
18
- return [...await database.models.bundles.findMany({
19
- where,
20
- limit: finiteIds.length,
21
- offset: 0,
22
- orderBy: {
23
- field: "id",
24
- direction: "asc"
25
- }
26
- })];
27
- }
28
- const [cutoff] = await database.models.bundles.findMany({
29
- where,
30
- limit: 1,
31
- offset: 0,
32
- orderBy: {
33
- field: "id",
34
- direction: "desc"
35
- }
36
- });
37
- if (!cutoff) return [];
38
- const rows = [];
39
- let after;
40
- for (;;) {
41
- const page = await database.models.bundles.findMany({
42
- where: mergeIdFilter(where, {
43
- lte: cutoff.id,
44
- ...after ? { gt: after } : {}
45
- }),
46
- limit: PAGE_SIZE,
47
- offset: 0,
48
- orderBy: {
49
- field: "id",
50
- direction: "asc"
51
- }
52
- });
53
- rows.push(...page);
54
- if (page.length < PAGE_SIZE) return rows;
55
- after = page.at(-1)?.id;
56
- }
57
- };
58
- const hydrateRows = async (database, ownerRows) => {
59
- const patchRows = await database.models.bundlePatches.findByBundleIds(ownerRows.map(({ id }) => id));
60
- const ownerIds = new Set(ownerRows.map(({ id }) => id));
61
- const referencedIds = [...new Set(patchRows.map(({ base_bundle_id }) => base_bundle_id).filter((id) => !ownerIds.has(id)))];
62
- const referencedRows = referencedIds.length === 0 ? [] : await loadBundleRows(database, { id: { in: referencedIds } });
63
- return rowsToBundles(ownerRows, patchRows, referencedRows);
64
- };
65
- const cursorIdFilter = (cursor, direction) => {
66
- if (cursor?.after) return { [direction === "desc" ? "lt" : "gt"]: cursor.after };
67
- if (cursor?.before) return { [direction === "desc" ? "gt" : "lt"]: cursor.before };
68
- };
69
- const responsePage = async (database, options) => {
70
- validateBundlePagination(options);
71
- const direction = options.orderBy?.direction ?? "desc";
72
- const offset = options.page ? Math.max(0, options.page - 1) * options.limit : 0;
73
- const cursor = options.page ? void 0 : options.cursor;
74
- const queryLimit = cursor ? options.limit + 1 : options.limit;
75
- if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(queryLimit) || !Number.isSafeInteger(offset + queryLimit)) throw new DatabasePluginInputError("invalid-pagination");
76
- const cursorFilter = cursorIdFilter(cursor, direction);
77
- const where = cursorFilter ? mergeIdFilter(options.where, cursorFilter) : options.where;
78
- const queryDirection = cursor?.before ? direction === "desc" ? "asc" : "desc" : direction;
79
- const [queriedRows, total] = await Promise.all([database.models.bundles.findMany({
80
- where,
81
- limit: queryLimit,
82
- offset,
83
- orderBy: {
84
- field: "id",
85
- direction: queryDirection
86
- }
87
- }), database.models.bundles.count(options.where)]);
88
- const hasMore = cursor ? queriedRows.length > options.limit : false;
89
- const pageRows = cursor ? queriedRows.slice(0, options.limit) : queriedRows;
90
- const ownerRows = cursor?.before ? pageRows.toReversed() : pageRows;
91
- const pagination = calculatePagination(total, {
92
- limit: options.limit,
93
- offset
94
- });
95
- const hasPreviousPage = cursor ? Boolean(cursor.after) || hasMore : pagination.hasPreviousPage;
96
- const hasNextPage = cursor ? Boolean(cursor.before) || hasMore : pagination.hasNextPage;
97
- const firstId = ownerRows[0]?.id;
98
- const lastId = ownerRows.at(-1)?.id;
99
- return {
100
- data: await hydrateRows(database, ownerRows),
101
- pagination: {
102
- ...pagination,
103
- hasNextPage,
104
- hasPreviousPage,
105
- ...hasNextPage && lastId ? { nextCursor: lastId } : {},
106
- ...hasPreviousPage && firstId ? { previousCursor: firstId } : {},
107
- ...!firstId && cursor?.after ? { previousCursor: cursor.after } : {},
108
- ...!lastId && cursor?.before ? { nextCursor: cursor.before } : {}
109
- }
110
- };
111
- };
112
- //#endregion
113
- export { hydrateRows, loadBundleRows, responsePage };
@@ -1,40 +0,0 @@
1
- const require_databaseMetadata = require("./databaseMetadata.cjs");
2
- let _hot_updater_core = require("@hot-updater/core");
3
- //#region src/databaseClientUpdates.ts
4
- var DatabasePatchUpdateUnsupportedError = class extends Error {
5
- bundleId;
6
- pluginName;
7
- name = "DatabasePatchUpdateUnsupportedError";
8
- constructor(bundleId, pluginName) {
9
- super(`Database plugin "${pluginName}" cannot atomically replace patches for bundle "${bundleId}".`);
10
- this.bundleId = bundleId;
11
- this.pluginName = pluginName;
12
- }
13
- };
14
- const bundleUpdateToRow = (update, _channelId) => {
15
- return {
16
- ...update.platform !== void 0 ? { platform: update.platform } : {},
17
- ...update.fileHash !== void 0 ? { file_hash: update.fileHash } : {},
18
- ...update.gitCommitHash !== void 0 ? { git_commit_hash: update.gitCommitHash } : {},
19
- ...update.storageUri !== void 0 ? { storage_uri: update.storageUri } : {},
20
- ...update.archiveByteSize !== void 0 ? { archive_byte_size: update.archiveByteSize } : {},
21
- ...update.metadata !== void 0 ? { metadata: require_databaseMetadata.bundleMetadataToRow(update.metadata) } : {},
22
- ...update.manifestStorageUri !== void 0 ? { manifest_storage_uri: update.manifestStorageUri } : {},
23
- ...update.manifestFileHash !== void 0 ? { manifest_file_hash: update.manifestFileHash } : {},
24
- ...update.assetBaseStorageUri !== void 0 ? { asset_base_storage_uri: update.assetBaseStorageUri } : {}
25
- };
26
- };
27
- const bundleUpdateToPatchRows = (bundleId, update) => (0, _hot_updater_core.getBundlePatches)({ patches: update.patches }).map((patch, orderIndex) => ({
28
- id: `${bundleId}:${patch.baseBundleId}`,
29
- bundle_id: bundleId,
30
- base_bundle_id: patch.baseBundleId,
31
- base_file_hash: patch.baseFileHash,
32
- patch_file_hash: patch.patchFileHash,
33
- patch_storage_uri: patch.patchStorageUri,
34
- byte_size: patch.byteSize,
35
- order_index: orderIndex
36
- }));
37
- //#endregion
38
- exports.DatabasePatchUpdateUnsupportedError = DatabasePatchUpdateUnsupportedError;
39
- exports.bundleUpdateToPatchRows = bundleUpdateToPatchRows;
40
- exports.bundleUpdateToRow = bundleUpdateToRow;
@@ -1,11 +0,0 @@
1
- import "./types/index.cjs";
2
- import { Bundle } from "@hot-updater/core";
3
- //#region src/databaseClientUpdates.d.ts
4
- declare class DatabasePatchUpdateUnsupportedError extends Error {
5
- readonly bundleId: string;
6
- readonly pluginName: string;
7
- readonly name = "DatabasePatchUpdateUnsupportedError";
8
- constructor(bundleId: string, pluginName: string);
9
- }
10
- //#endregion
11
- export { DatabasePatchUpdateUnsupportedError };
@@ -1,11 +0,0 @@
1
- import "./types/index.mjs";
2
- import { Bundle } from "@hot-updater/core";
3
- //#region src/databaseClientUpdates.d.ts
4
- declare class DatabasePatchUpdateUnsupportedError extends Error {
5
- readonly bundleId: string;
6
- readonly pluginName: string;
7
- readonly name = "DatabasePatchUpdateUnsupportedError";
8
- constructor(bundleId: string, pluginName: string);
9
- }
10
- //#endregion
11
- export { DatabasePatchUpdateUnsupportedError };
@@ -1,38 +0,0 @@
1
- import { bundleMetadataToRow } from "./databaseMetadata.mjs";
2
- import { getBundlePatches } from "@hot-updater/core";
3
- //#region src/databaseClientUpdates.ts
4
- var DatabasePatchUpdateUnsupportedError = class extends Error {
5
- bundleId;
6
- pluginName;
7
- name = "DatabasePatchUpdateUnsupportedError";
8
- constructor(bundleId, pluginName) {
9
- super(`Database plugin "${pluginName}" cannot atomically replace patches for bundle "${bundleId}".`);
10
- this.bundleId = bundleId;
11
- this.pluginName = pluginName;
12
- }
13
- };
14
- const bundleUpdateToRow = (update, _channelId) => {
15
- return {
16
- ...update.platform !== void 0 ? { platform: update.platform } : {},
17
- ...update.fileHash !== void 0 ? { file_hash: update.fileHash } : {},
18
- ...update.gitCommitHash !== void 0 ? { git_commit_hash: update.gitCommitHash } : {},
19
- ...update.storageUri !== void 0 ? { storage_uri: update.storageUri } : {},
20
- ...update.archiveByteSize !== void 0 ? { archive_byte_size: update.archiveByteSize } : {},
21
- ...update.metadata !== void 0 ? { metadata: bundleMetadataToRow(update.metadata) } : {},
22
- ...update.manifestStorageUri !== void 0 ? { manifest_storage_uri: update.manifestStorageUri } : {},
23
- ...update.manifestFileHash !== void 0 ? { manifest_file_hash: update.manifestFileHash } : {},
24
- ...update.assetBaseStorageUri !== void 0 ? { asset_base_storage_uri: update.assetBaseStorageUri } : {}
25
- };
26
- };
27
- const bundleUpdateToPatchRows = (bundleId, update) => getBundlePatches({ patches: update.patches }).map((patch, orderIndex) => ({
28
- id: `${bundleId}:${patch.baseBundleId}`,
29
- bundle_id: bundleId,
30
- base_bundle_id: patch.baseBundleId,
31
- base_file_hash: patch.baseFileHash,
32
- patch_file_hash: patch.patchFileHash,
33
- patch_storage_uri: patch.patchStorageUri,
34
- byte_size: patch.byteSize,
35
- order_index: orderIndex
36
- }));
37
- //#endregion
38
- export { DatabasePatchUpdateUnsupportedError, bundleUpdateToPatchRows, bundleUpdateToRow };