@hot-updater/postgres 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.
package/dist/index.cjs CHANGED
@@ -1908,107 +1908,104 @@ const getUpdateInfo = (pool, args) => {
1908
1908
 
1909
1909
  //#endregion
1910
1910
  //#region src/postgres.ts
1911
- const postgres = (config, hooks) => {
1912
- return (0, __hot_updater_plugin_core.createDatabasePlugin)("postgres", {
1913
- getContext: () => {
1914
- const pool = new pg.Pool(config);
1915
- return {
1916
- db: new kysely.Kysely({ dialect: new kysely.PostgresDialect({ pool }) }),
1917
- pool
1918
- };
1919
- },
1920
- async onUnmount(context) {
1921
- await context.db.destroy();
1922
- await context.pool.end();
1923
- },
1924
- async getBundleById(context, bundleId) {
1925
- const data = await context.db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
1926
- if (!data) return null;
1927
- return {
1928
- enabled: data.enabled,
1929
- shouldForceUpdate: data.should_force_update,
1930
- fileHash: data.file_hash,
1931
- gitCommitHash: data.git_commit_hash,
1932
- id: data.id,
1933
- message: data.message,
1934
- platform: data.platform,
1935
- targetAppVersion: data.target_app_version,
1936
- channel: data.channel,
1937
- storageUri: data.storage_uri,
1938
- fingerprintHash: data.fingerprint_hash
1939
- };
1940
- },
1941
- async getBundles(context, options) {
1942
- const { where, limit, offset } = options ?? {};
1943
- let countQuery = context.db.selectFrom("bundles");
1944
- if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
1945
- if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
1946
- const total = (await countQuery.select(context.db.fn.count("id").as("total")).executeTakeFirst())?.total || 0;
1947
- let query = context.db.selectFrom("bundles").orderBy("id", "desc");
1948
- if (where?.channel) query = query.where("channel", "=", where.channel);
1949
- if (where?.platform) query = query.where("platform", "=", where.platform);
1950
- if (limit) query = query.limit(limit);
1951
- if (offset) query = query.offset(offset);
1952
- return {
1953
- data: (await query.selectAll().execute()).map((bundle) => ({
1954
- enabled: bundle.enabled,
1955
- shouldForceUpdate: bundle.should_force_update,
1956
- fileHash: bundle.file_hash,
1957
- gitCommitHash: bundle.git_commit_hash,
1958
- id: bundle.id,
1959
- message: bundle.message,
1960
- platform: bundle.platform,
1961
- targetAppVersion: bundle.target_app_version,
1962
- channel: bundle.channel,
1963
- storageUri: bundle.storage_uri,
1964
- fingerprintHash: bundle.fingerprint_hash
1965
- })),
1966
- pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
1967
- limit,
1968
- offset
1969
- })
1970
- };
1971
- },
1972
- async getChannels(context) {
1973
- return (await context.db.selectFrom("bundles").select("channel").groupBy("channel").execute()).map((bundle) => bundle.channel);
1974
- },
1975
- async commitBundle(context, { changedSets }) {
1976
- if (changedSets.length === 0) return;
1977
- await context.db.transaction().execute(async (tx) => {
1978
- for (const op of changedSets) if (op.operation === "delete") {
1979
- if ((await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst()).numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
1980
- } else if (op.operation === "insert" || op.operation === "update") {
1981
- const bundle = op.data;
1982
- await tx.insertInto("bundles").values({
1983
- id: bundle.id,
1984
- enabled: bundle.enabled,
1985
- should_force_update: bundle.shouldForceUpdate,
1986
- file_hash: bundle.fileHash,
1987
- git_commit_hash: bundle.gitCommitHash,
1988
- message: bundle.message,
1989
- platform: bundle.platform,
1990
- target_app_version: bundle.targetAppVersion,
1991
- channel: bundle.channel,
1992
- storage_uri: bundle.storageUri,
1993
- fingerprint_hash: bundle.fingerprintHash
1994
- }).onConflict((oc) => oc.column("id").doUpdateSet({
1911
+ const postgres = (0, __hot_updater_plugin_core.createDatabasePlugin)({
1912
+ name: "postgres",
1913
+ factory: (config) => {
1914
+ const pool = new pg.Pool(config);
1915
+ const db = new kysely.Kysely({ dialect: new kysely.PostgresDialect({ pool }) });
1916
+ return {
1917
+ async onUnmount() {
1918
+ await db.destroy();
1919
+ await pool.end();
1920
+ },
1921
+ async getBundleById(bundleId) {
1922
+ const data = await db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
1923
+ if (!data) return null;
1924
+ return {
1925
+ enabled: data.enabled,
1926
+ shouldForceUpdate: data.should_force_update,
1927
+ fileHash: data.file_hash,
1928
+ gitCommitHash: data.git_commit_hash,
1929
+ id: data.id,
1930
+ message: data.message,
1931
+ platform: data.platform,
1932
+ targetAppVersion: data.target_app_version,
1933
+ channel: data.channel,
1934
+ storageUri: data.storage_uri,
1935
+ fingerprintHash: data.fingerprint_hash
1936
+ };
1937
+ },
1938
+ async getBundles(options) {
1939
+ const { where, limit, offset } = options ?? {};
1940
+ let countQuery = db.selectFrom("bundles");
1941
+ if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
1942
+ if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
1943
+ const total = (await countQuery.select(db.fn.count("id").as("total")).executeTakeFirst())?.total || 0;
1944
+ let query = db.selectFrom("bundles").orderBy("id", "desc");
1945
+ if (where?.channel) query = query.where("channel", "=", where.channel);
1946
+ if (where?.platform) query = query.where("platform", "=", where.platform);
1947
+ if (limit) query = query.limit(limit);
1948
+ if (offset) query = query.offset(offset);
1949
+ return {
1950
+ data: (await query.selectAll().execute()).map((bundle) => ({
1995
1951
  enabled: bundle.enabled,
1996
- should_force_update: bundle.shouldForceUpdate,
1997
- file_hash: bundle.fileHash,
1998
- git_commit_hash: bundle.gitCommitHash,
1952
+ shouldForceUpdate: bundle.should_force_update,
1953
+ fileHash: bundle.file_hash,
1954
+ gitCommitHash: bundle.git_commit_hash,
1955
+ id: bundle.id,
1999
1956
  message: bundle.message,
2000
1957
  platform: bundle.platform,
2001
- target_app_version: bundle.targetAppVersion,
1958
+ targetAppVersion: bundle.target_app_version,
2002
1959
  channel: bundle.channel,
2003
- storage_uri: bundle.storageUri,
2004
- fingerprint_hash: bundle.fingerprintHash
2005
- })).execute();
2006
- }
2007
- });
2008
- hooks?.onDatabaseUpdated?.();
2009
- }
2010
- }, hooks);
2011
- };
1960
+ storageUri: bundle.storage_uri,
1961
+ fingerprintHash: bundle.fingerprint_hash
1962
+ })),
1963
+ pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
1964
+ limit,
1965
+ offset
1966
+ })
1967
+ };
1968
+ },
1969
+ async getChannels() {
1970
+ return (await db.selectFrom("bundles").select("channel").groupBy("channel").execute()).map((bundle) => bundle.channel);
1971
+ },
1972
+ async commitBundle({ changedSets }) {
1973
+ if (changedSets.length === 0) return;
1974
+ await db.transaction().execute(async (tx) => {
1975
+ for (const op of changedSets) if (op.operation === "delete") {
1976
+ if ((await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst()).numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
1977
+ } else if (op.operation === "insert" || op.operation === "update") {
1978
+ const bundle = op.data;
1979
+ await tx.insertInto("bundles").values({
1980
+ id: bundle.id,
1981
+ enabled: bundle.enabled,
1982
+ should_force_update: bundle.shouldForceUpdate,
1983
+ file_hash: bundle.fileHash,
1984
+ git_commit_hash: bundle.gitCommitHash,
1985
+ message: bundle.message,
1986
+ platform: bundle.platform,
1987
+ target_app_version: bundle.targetAppVersion,
1988
+ channel: bundle.channel,
1989
+ storage_uri: bundle.storageUri,
1990
+ fingerprint_hash: bundle.fingerprintHash
1991
+ }).onConflict((oc) => oc.column("id").doUpdateSet({
1992
+ enabled: bundle.enabled,
1993
+ should_force_update: bundle.shouldForceUpdate,
1994
+ file_hash: bundle.fileHash,
1995
+ git_commit_hash: bundle.gitCommitHash,
1996
+ message: bundle.message,
1997
+ platform: bundle.platform,
1998
+ target_app_version: bundle.targetAppVersion,
1999
+ channel: bundle.channel,
2000
+ storage_uri: bundle.storageUri,
2001
+ fingerprint_hash: bundle.fingerprintHash
2002
+ })).execute();
2003
+ }
2004
+ });
2005
+ }
2006
+ };
2007
+ }
2008
+ });
2012
2009
 
2013
2010
  //#endregion
2014
2011
  exports.appVersionStrategy = appVersionStrategy;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { AppVersionGetBundlesArgs, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
2
2
  import pg, { PoolConfig } from "pg";
3
3
  import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
4
- import { DatabasePluginHooks } from "@hot-updater/plugin-core";
5
4
 
6
5
  //#region src/getUpdateInfo.d.ts
7
6
  declare const appVersionStrategy: (pool: pg.Pool, {
@@ -15,6 +14,6 @@ declare const getUpdateInfo: (pool: pg.Pool, args: GetBundlesArgs) => Promise<Up
15
14
  //#endregion
16
15
  //#region src/postgres.d.ts
17
16
  interface PostgresConfig extends PoolConfig {}
18
- declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => () => _hot_updater_plugin_core0.DatabasePlugin;
17
+ declare const postgres: (config: PostgresConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
19
18
  //#endregion
20
19
  export { PostgresConfig, appVersionStrategy, getUpdateInfo, postgres };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { AppVersionGetBundlesArgs, GetBundlesArgs, UpdateInfo } from "@hot-updater/core";
2
2
  import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
3
- import { DatabasePluginHooks } from "@hot-updater/plugin-core";
4
3
  import pg, { PoolConfig } from "pg";
5
4
 
6
5
  //#region src/getUpdateInfo.d.ts
@@ -15,6 +14,6 @@ declare const getUpdateInfo: (pool: pg.Pool, args: GetBundlesArgs) => Promise<Up
15
14
  //#endregion
16
15
  //#region src/postgres.d.ts
17
16
  interface PostgresConfig extends PoolConfig {}
18
- declare const postgres: (config: PostgresConfig, hooks?: DatabasePluginHooks) => () => _hot_updater_plugin_core0.DatabasePlugin;
17
+ declare const postgres: (config: PostgresConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
19
18
  //#endregion
20
19
  export { PostgresConfig, appVersionStrategy, getUpdateInfo, postgres };
package/dist/index.js CHANGED
@@ -1906,107 +1906,104 @@ const getUpdateInfo = (pool, args) => {
1906
1906
 
1907
1907
  //#endregion
1908
1908
  //#region src/postgres.ts
1909
- const postgres = (config, hooks) => {
1910
- return createDatabasePlugin("postgres", {
1911
- getContext: () => {
1912
- const pool = new Pool(config);
1913
- return {
1914
- db: new Kysely({ dialect: new PostgresDialect({ pool }) }),
1915
- pool
1916
- };
1917
- },
1918
- async onUnmount(context) {
1919
- await context.db.destroy();
1920
- await context.pool.end();
1921
- },
1922
- async getBundleById(context, bundleId) {
1923
- const data = await context.db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
1924
- if (!data) return null;
1925
- return {
1926
- enabled: data.enabled,
1927
- shouldForceUpdate: data.should_force_update,
1928
- fileHash: data.file_hash,
1929
- gitCommitHash: data.git_commit_hash,
1930
- id: data.id,
1931
- message: data.message,
1932
- platform: data.platform,
1933
- targetAppVersion: data.target_app_version,
1934
- channel: data.channel,
1935
- storageUri: data.storage_uri,
1936
- fingerprintHash: data.fingerprint_hash
1937
- };
1938
- },
1939
- async getBundles(context, options) {
1940
- const { where, limit, offset } = options ?? {};
1941
- let countQuery = context.db.selectFrom("bundles");
1942
- if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
1943
- if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
1944
- const total = (await countQuery.select(context.db.fn.count("id").as("total")).executeTakeFirst())?.total || 0;
1945
- let query = context.db.selectFrom("bundles").orderBy("id", "desc");
1946
- if (where?.channel) query = query.where("channel", "=", where.channel);
1947
- if (where?.platform) query = query.where("platform", "=", where.platform);
1948
- if (limit) query = query.limit(limit);
1949
- if (offset) query = query.offset(offset);
1950
- return {
1951
- data: (await query.selectAll().execute()).map((bundle) => ({
1952
- enabled: bundle.enabled,
1953
- shouldForceUpdate: bundle.should_force_update,
1954
- fileHash: bundle.file_hash,
1955
- gitCommitHash: bundle.git_commit_hash,
1956
- id: bundle.id,
1957
- message: bundle.message,
1958
- platform: bundle.platform,
1959
- targetAppVersion: bundle.target_app_version,
1960
- channel: bundle.channel,
1961
- storageUri: bundle.storage_uri,
1962
- fingerprintHash: bundle.fingerprint_hash
1963
- })),
1964
- pagination: calculatePagination(total, {
1965
- limit,
1966
- offset
1967
- })
1968
- };
1969
- },
1970
- async getChannels(context) {
1971
- return (await context.db.selectFrom("bundles").select("channel").groupBy("channel").execute()).map((bundle) => bundle.channel);
1972
- },
1973
- async commitBundle(context, { changedSets }) {
1974
- if (changedSets.length === 0) return;
1975
- await context.db.transaction().execute(async (tx) => {
1976
- for (const op of changedSets) if (op.operation === "delete") {
1977
- if ((await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst()).numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
1978
- } else if (op.operation === "insert" || op.operation === "update") {
1979
- const bundle = op.data;
1980
- await tx.insertInto("bundles").values({
1981
- id: bundle.id,
1982
- enabled: bundle.enabled,
1983
- should_force_update: bundle.shouldForceUpdate,
1984
- file_hash: bundle.fileHash,
1985
- git_commit_hash: bundle.gitCommitHash,
1986
- message: bundle.message,
1987
- platform: bundle.platform,
1988
- target_app_version: bundle.targetAppVersion,
1989
- channel: bundle.channel,
1990
- storage_uri: bundle.storageUri,
1991
- fingerprint_hash: bundle.fingerprintHash
1992
- }).onConflict((oc) => oc.column("id").doUpdateSet({
1909
+ const postgres = createDatabasePlugin({
1910
+ name: "postgres",
1911
+ factory: (config) => {
1912
+ const pool = new Pool(config);
1913
+ const db = new Kysely({ dialect: new PostgresDialect({ pool }) });
1914
+ return {
1915
+ async onUnmount() {
1916
+ await db.destroy();
1917
+ await pool.end();
1918
+ },
1919
+ async getBundleById(bundleId) {
1920
+ const data = await db.selectFrom("bundles").selectAll().where("id", "=", bundleId).executeTakeFirst();
1921
+ if (!data) return null;
1922
+ return {
1923
+ enabled: data.enabled,
1924
+ shouldForceUpdate: data.should_force_update,
1925
+ fileHash: data.file_hash,
1926
+ gitCommitHash: data.git_commit_hash,
1927
+ id: data.id,
1928
+ message: data.message,
1929
+ platform: data.platform,
1930
+ targetAppVersion: data.target_app_version,
1931
+ channel: data.channel,
1932
+ storageUri: data.storage_uri,
1933
+ fingerprintHash: data.fingerprint_hash
1934
+ };
1935
+ },
1936
+ async getBundles(options) {
1937
+ const { where, limit, offset } = options ?? {};
1938
+ let countQuery = db.selectFrom("bundles");
1939
+ if (where?.channel) countQuery = countQuery.where("channel", "=", where.channel);
1940
+ if (where?.platform) countQuery = countQuery.where("platform", "=", where.platform);
1941
+ const total = (await countQuery.select(db.fn.count("id").as("total")).executeTakeFirst())?.total || 0;
1942
+ let query = db.selectFrom("bundles").orderBy("id", "desc");
1943
+ if (where?.channel) query = query.where("channel", "=", where.channel);
1944
+ if (where?.platform) query = query.where("platform", "=", where.platform);
1945
+ if (limit) query = query.limit(limit);
1946
+ if (offset) query = query.offset(offset);
1947
+ return {
1948
+ data: (await query.selectAll().execute()).map((bundle) => ({
1993
1949
  enabled: bundle.enabled,
1994
- should_force_update: bundle.shouldForceUpdate,
1995
- file_hash: bundle.fileHash,
1996
- git_commit_hash: bundle.gitCommitHash,
1950
+ shouldForceUpdate: bundle.should_force_update,
1951
+ fileHash: bundle.file_hash,
1952
+ gitCommitHash: bundle.git_commit_hash,
1953
+ id: bundle.id,
1997
1954
  message: bundle.message,
1998
1955
  platform: bundle.platform,
1999
- target_app_version: bundle.targetAppVersion,
1956
+ targetAppVersion: bundle.target_app_version,
2000
1957
  channel: bundle.channel,
2001
- storage_uri: bundle.storageUri,
2002
- fingerprint_hash: bundle.fingerprintHash
2003
- })).execute();
2004
- }
2005
- });
2006
- hooks?.onDatabaseUpdated?.();
2007
- }
2008
- }, hooks);
2009
- };
1958
+ storageUri: bundle.storage_uri,
1959
+ fingerprintHash: bundle.fingerprint_hash
1960
+ })),
1961
+ pagination: calculatePagination(total, {
1962
+ limit,
1963
+ offset
1964
+ })
1965
+ };
1966
+ },
1967
+ async getChannels() {
1968
+ return (await db.selectFrom("bundles").select("channel").groupBy("channel").execute()).map((bundle) => bundle.channel);
1969
+ },
1970
+ async commitBundle({ changedSets }) {
1971
+ if (changedSets.length === 0) return;
1972
+ await db.transaction().execute(async (tx) => {
1973
+ for (const op of changedSets) if (op.operation === "delete") {
1974
+ if ((await tx.deleteFrom("bundles").where("id", "=", op.data.id).executeTakeFirst()).numDeletedRows === 0n) throw new Error(`Bundle with id ${op.data.id} not found`);
1975
+ } else if (op.operation === "insert" || op.operation === "update") {
1976
+ const bundle = op.data;
1977
+ await tx.insertInto("bundles").values({
1978
+ id: bundle.id,
1979
+ enabled: bundle.enabled,
1980
+ should_force_update: bundle.shouldForceUpdate,
1981
+ file_hash: bundle.fileHash,
1982
+ git_commit_hash: bundle.gitCommitHash,
1983
+ message: bundle.message,
1984
+ platform: bundle.platform,
1985
+ target_app_version: bundle.targetAppVersion,
1986
+ channel: bundle.channel,
1987
+ storage_uri: bundle.storageUri,
1988
+ fingerprint_hash: bundle.fingerprintHash
1989
+ }).onConflict((oc) => oc.column("id").doUpdateSet({
1990
+ enabled: bundle.enabled,
1991
+ should_force_update: bundle.shouldForceUpdate,
1992
+ file_hash: bundle.fileHash,
1993
+ git_commit_hash: bundle.gitCommitHash,
1994
+ message: bundle.message,
1995
+ platform: bundle.platform,
1996
+ target_app_version: bundle.targetAppVersion,
1997
+ channel: bundle.channel,
1998
+ storage_uri: bundle.storageUri,
1999
+ fingerprint_hash: bundle.fingerprintHash
2000
+ })).execute();
2001
+ }
2002
+ });
2003
+ }
2004
+ };
2005
+ }
2006
+ });
2010
2007
 
2011
2008
  //#endregion
2012
2009
  export { appVersionStrategy, getUpdateInfo, postgres };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-updater/postgres",
3
3
  "type": "module",
4
- "version": "0.21.11",
4
+ "version": "0.21.13",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -31,16 +31,16 @@
31
31
  "dependencies": {
32
32
  "kysely": "^0.28.5",
33
33
  "pg": "^8.13.1",
34
- "@hot-updater/plugin-core": "0.21.11",
35
- "@hot-updater/core": "0.21.11"
34
+ "@hot-updater/core": "0.21.13",
35
+ "@hot-updater/plugin-core": "0.21.13"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@electric-sql/pglite": "^0.2.15",
39
39
  "@types/pg": "^8.11.10",
40
40
  "camelcase-keys": "^9.1.3",
41
41
  "pg-minify": "^1.6.5",
42
- "@hot-updater/js": "0.21.11",
43
- "@hot-updater/test-utils": "0.21.11"
42
+ "@hot-updater/js": "0.21.13",
43
+ "@hot-updater/test-utils": "0.21.13"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsdown",