@webiny/db 6.4.5 → 6.6.0-alpha.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.
@@ -0,0 +1 @@
1
+ export { DbRegistry, DbRegistryFeature } from "../../features/DbRegistry/index.js";
@@ -0,0 +1 @@
1
+ export { DbRegistry, DbRegistryFeature } from "../../features/DbRegistry/index.js";
@@ -0,0 +1,12 @@
1
+ import { DbRegistry as DbRegistryAbstraction } from "./abstractions.js";
2
+ declare class DbRegistryImpl implements DbRegistryAbstraction.Interface {
3
+ private readonly items;
4
+ register<T = unknown>(input: DbRegistryAbstraction.RegisterParams<T>): void;
5
+ getOneItem<T = unknown>(cb: (item: DbRegistryAbstraction.RegistryItem<T>) => boolean): DbRegistryAbstraction.RegistryItem<T>;
6
+ getItem<T = unknown>(cb: (item: DbRegistryAbstraction.RegistryItem<T>) => boolean): DbRegistryAbstraction.RegistryItem<T> | null;
7
+ getItems<T = unknown>(cb: (item: DbRegistryAbstraction.RegistryItem<T>) => boolean): DbRegistryAbstraction.RegistryItem<T>[];
8
+ }
9
+ export declare const DbRegistry: typeof DbRegistryImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IRegistry>;
11
+ };
12
+ export {};
@@ -1,4 +1,5 @@
1
- class DbRegistry {
1
+ import { DbRegistry } from "./abstractions.js";
2
+ class DbRegistryImpl {
2
3
  register(input) {
3
4
  const key = `${input.app}-${input.tags.sort().join("-")}`;
4
5
  if (this.items[key]) throw new Error(`Item with app "${input.app}" and tags "${input.tags.join(", ")}" is already registered.`);
@@ -27,6 +28,10 @@ class DbRegistry {
27
28
  this.items = {};
28
29
  }
29
30
  }
30
- export { DbRegistry };
31
+ const DbRegistry_DbRegistry = DbRegistry.createImplementation({
32
+ implementation: DbRegistryImpl,
33
+ dependencies: []
34
+ });
35
+ export { DbRegistry_DbRegistry as DbRegistry };
31
36
 
32
37
  //# sourceMappingURL=DbRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/DbRegistry/DbRegistry.js","sources":["../../../src/features/DbRegistry/DbRegistry.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport { DbRegistry as DbRegistryAbstraction } from \"./abstractions.js\";\n\nclass DbRegistryImpl implements DbRegistryAbstraction.Interface {\n private readonly items: GenericRecord<string, DbRegistryAbstraction.RegistryItem> = {};\n\n public register<T = unknown>(input: DbRegistryAbstraction.RegisterParams<T>): void {\n const key = `${input.app}-${input.tags.sort().join(\"-\")}`;\n\n if (this.items[key]) {\n throw new Error(\n `Item with app \"${input.app}\" and tags \"${input.tags.join(\n \", \"\n )}\" is already registered.`\n );\n }\n this.items[key] = input;\n }\n\n public getOneItem<T = unknown>(\n cb: (item: DbRegistryAbstraction.RegistryItem<T>) => boolean\n ): DbRegistryAbstraction.RegistryItem<T> {\n const item = this.getItem(cb);\n if (!item) {\n throw new Error(\"Item not found.\");\n }\n return item;\n }\n\n public getItem<T = unknown>(\n cb: (item: DbRegistryAbstraction.RegistryItem<T>) => boolean\n ): DbRegistryAbstraction.RegistryItem<T> | null {\n const items = this.getItems(cb);\n if (items.length === 0) {\n return null;\n } else if (items.length > 1) {\n throw new Error(\"More than one item found with the provided criteria.\");\n }\n return items[0];\n }\n\n public getItems<T = unknown>(\n cb: (item: DbRegistryAbstraction.RegistryItem<T>) => boolean\n ): DbRegistryAbstraction.RegistryItem<T>[] {\n const results: DbRegistryAbstraction.RegistryItem<T>[] = [];\n for (const key in this.items) {\n const item = this.items[key] as DbRegistryAbstraction.RegistryItem<T>;\n if (cb(item)) {\n results.push(item);\n }\n }\n\n return results;\n }\n}\n\nexport const DbRegistry = DbRegistryAbstraction.createImplementation({\n implementation: DbRegistryImpl,\n dependencies: []\n});\n"],"names":["DbRegistryImpl","input","key","Error","cb","item","items","results","DbRegistry","DbRegistryAbstraction"],"mappings":";AAGA,MAAMA;IAGK,SAAsBC,KAA8C,EAAQ;QAC/E,MAAMC,MAAM,GAAGD,MAAM,GAAG,CAAC,CAAC,EAAEA,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM;QAEzD,IAAI,IAAI,CAAC,KAAK,CAACC,IAAI,EACf,MAAM,IAAIC,MACN,CAAC,eAAe,EAAEF,MAAM,GAAG,CAAC,YAAY,EAAEA,MAAM,IAAI,CAAC,IAAI,CACrD,MACF,wBAAwB,CAAC;QAGnC,IAAI,CAAC,KAAK,CAACC,IAAI,GAAGD;IACtB;IAEO,WACHG,EAA4D,EACvB;QACrC,MAAMC,OAAO,IAAI,CAAC,OAAO,CAACD;QAC1B,IAAI,CAACC,MACD,MAAM,IAAIF,MAAM;QAEpB,OAAOE;IACX;IAEO,QACHD,EAA4D,EAChB;QAC5C,MAAME,QAAQ,IAAI,CAAC,QAAQ,CAACF;QAC5B,IAAIE,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAO;QACJ,IAAIA,MAAM,MAAM,GAAG,GACtB,MAAM,IAAIH,MAAM;QAEpB,OAAOG,KAAK,CAAC,EAAE;IACnB;IAEO,SACHF,EAA4D,EACrB;QACvC,MAAMG,UAAmD,EAAE;QAC3D,IAAK,MAAML,OAAO,IAAI,CAAC,KAAK,CAAE;YAC1B,MAAMG,OAAO,IAAI,CAAC,KAAK,CAACH,IAAI;YAC5B,IAAIE,GAAGC,OACHE,QAAQ,IAAI,CAACF;QAErB;QAEA,OAAOE;IACX;;aAjDiB,KAAK,GAA8D,CAAC;;AAkDzF;AAEO,MAAMC,wBAAaC,WAAAA,oBAA0C,CAAC;IACjE,gBAAgBT;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,29 @@
1
+ import type { NonEmptyArray } from "@webiny/api/types.js";
2
+ export interface IRegistryRegisterParams<T = unknown> {
3
+ item: T;
4
+ app: string;
5
+ tags: NonEmptyArray<string>;
6
+ }
7
+ export interface IRegistryItem<T = unknown> {
8
+ item: T;
9
+ app: string;
10
+ tags: NonEmptyArray<string>;
11
+ }
12
+ export interface IRegistry {
13
+ register<T = unknown>(params: IRegistryRegisterParams<T>): void;
14
+ /**
15
+ * Throws an error if more than one item is found or there is no item found.
16
+ */
17
+ getOneItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>;
18
+ /**
19
+ * Throws an error if more than one item is found.
20
+ */
21
+ getItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T> | null;
22
+ getItems<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>[];
23
+ }
24
+ export declare const DbRegistry: import("@webiny/di").Abstraction<IRegistry>;
25
+ export declare namespace DbRegistry {
26
+ type Interface = IRegistry;
27
+ type RegisterParams<T = unknown> = IRegistryRegisterParams<T>;
28
+ type RegistryItem<T = unknown> = IRegistryItem<T>;
29
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const DbRegistry = createAbstraction("Db/DbRegistry");
3
+ export { DbRegistry };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/DbRegistry/abstractions.js","sources":["../../../src/features/DbRegistry/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { NonEmptyArray } from \"@webiny/api/types.js\";\n\nexport interface IRegistryRegisterParams<T = unknown> {\n item: T;\n app: string;\n tags: NonEmptyArray<string>;\n}\n\nexport interface IRegistryItem<T = unknown> {\n item: T;\n app: string;\n tags: NonEmptyArray<string>;\n}\n\nexport interface IRegistry {\n register<T = unknown>(params: IRegistryRegisterParams<T>): void;\n /**\n * Throws an error if more than one item is found or there is no item found.\n */\n getOneItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>;\n /**\n * Throws an error if more than one item is found.\n */\n getItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T> | null;\n getItems<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>[];\n}\n\nexport const DbRegistry = createAbstraction<IRegistry>(\"Db/DbRegistry\");\n\nexport namespace DbRegistry {\n export type Interface = IRegistry;\n export type RegisterParams<T = unknown> = IRegistryRegisterParams<T>;\n export type RegistryItem<T = unknown> = IRegistryItem<T>;\n}\n"],"names":["DbRegistry","createAbstraction"],"mappings":";AA4BO,MAAMA,aAAaC,kBAA6B"}
@@ -0,0 +1,4 @@
1
+ export declare const DbRegistryFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,14 @@
1
+ import { createFeature } from "@webiny/feature/api/index.js";
2
+ import { DbRegistry } from "./DbRegistry.js";
3
+ const registeredContainers = new WeakSet();
4
+ const DbRegistryFeature = createFeature({
5
+ name: "DbRegistry",
6
+ register: (container)=>{
7
+ if (registeredContainers.has(container)) return;
8
+ registeredContainers.add(container);
9
+ container.register(DbRegistry).inSingletonScope();
10
+ }
11
+ });
12
+ export { DbRegistryFeature };
13
+
14
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/DbRegistry/feature.js","sources":["../../../src/features/DbRegistry/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DbRegistry } from \"./DbRegistry.js\";\n\n/**\n * Track containers DbRegistry has already been registered on. The container's `register()` APPENDS\n * registrations and `resolve()` uses the LAST one, caching singletons per-registration — so calling\n * this feature twice on the same container creates a second DbRegistry singleton and orphans the\n * first. That breaks consumers that register into DbRegistry at different times (e.g. the CMS\n * storage `beforeInit` registers entities into registration #1, while a later resolve — like the\n * search-index-tasks sync — gets the empty registration #2). Registering once per container\n * keeps a single shared instance.\n */\nconst registeredContainers = new WeakSet<object>();\n\nexport const DbRegistryFeature = createFeature({\n name: \"DbRegistry\",\n register: container => {\n if (registeredContainers.has(container)) {\n return;\n }\n registeredContainers.add(container);\n container.register(DbRegistry).inSingletonScope();\n }\n});\n"],"names":["registeredContainers","WeakSet","DbRegistryFeature","createFeature","container","DbRegistry"],"mappings":";;AAYA,MAAMA,uBAAuB,IAAIC;AAE1B,MAAMC,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAAUC,CAAAA;QACN,IAAIJ,qBAAqB,GAAG,CAACI,YACzB;QAEJJ,qBAAqB,GAAG,CAACI;QACzBA,UAAU,QAAQ,CAACC,YAAY,gBAAgB;IACnD;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { DbRegistryFeature } from "./feature.js";
2
+ export { DbRegistry } from "./abstractions.js";
@@ -0,0 +1,2 @@
1
+ export { DbRegistryFeature } from "./feature.js";
2
+ export { DbRegistry } from "./abstractions.js";
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { DbRegistry } from "./DbRegistry.js";
2
1
  import type { IStore } from "./store/types.js";
3
2
  export * from "./types.js";
4
3
  export interface DbDriver<T> extends IStore {
@@ -12,7 +11,6 @@ declare class Db<T> {
12
11
  driver: DbDriver<T>;
13
12
  readonly table?: string;
14
13
  readonly store: IStore;
15
- readonly registry: DbRegistry;
16
14
  constructor({ driver, table }: ConstructorArgs<T>);
17
15
  }
18
16
  export { Db };
package/index.js CHANGED
@@ -1,9 +1,7 @@
1
- import { DbRegistry } from "./DbRegistry.js";
2
1
  import { Store } from "./store/Store.js";
3
2
  export * from "./types.js";
4
3
  class Db {
5
4
  constructor({ driver, table }){
6
- this.registry = new DbRegistry();
7
5
  this.table = table;
8
6
  this.driver = driver;
9
7
  this.store = new Store({
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { DbRegistry } from \"~/DbRegistry.js\";\nimport type { IStore } from \"~/store/types.js\";\nimport { Store } from \"~/store/Store.js\";\n\nexport * from \"./types.js\";\n\nexport interface DbDriver<T> extends IStore {\n getClient(): T;\n}\n\nexport interface ConstructorArgs<T> {\n driver: DbDriver<T>;\n table?: string;\n}\n\nclass Db<T> {\n public driver: DbDriver<T>;\n public readonly table?: string;\n public readonly store: IStore;\n\n public readonly registry = new DbRegistry();\n\n constructor({ driver, table }: ConstructorArgs<T>) {\n this.table = table;\n this.driver = driver;\n this.store = new Store<T>({\n driver\n });\n }\n}\n\nexport { Db };\n"],"names":["Db","driver","table","DbRegistry","Store"],"mappings":";;;AAeA,MAAMA;IAOF,YAAY,EAAEC,MAAM,EAAEC,KAAK,EAAsB,CAAE;aAFnC,QAAQ,GAAG,IAAIC;QAG3B,IAAI,CAAC,KAAK,GAAGD;QACb,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,KAAK,GAAG,IAAIG,MAAS;YACtBH;QACJ;IACJ;AACJ"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { IStore } from \"~/store/types.js\";\nimport { Store } from \"~/store/Store.js\";\n\nexport * from \"./types.js\";\n\nexport interface DbDriver<T> extends IStore {\n getClient(): T;\n}\n\nexport interface ConstructorArgs<T> {\n driver: DbDriver<T>;\n table?: string;\n}\n\nclass Db<T> {\n public driver: DbDriver<T>;\n public readonly table?: string;\n public readonly store: IStore;\n\n constructor({ driver, table }: ConstructorArgs<T>) {\n this.table = table;\n this.driver = driver;\n this.store = new Store<T>({\n driver\n });\n }\n}\n\nexport { Db };\n"],"names":["Db","driver","table","Store"],"mappings":";;AAcA,MAAMA;IAKF,YAAY,EAAEC,MAAM,EAAEC,KAAK,EAAsB,CAAE;QAC/C,IAAI,CAAC,KAAK,GAAGA;QACb,IAAI,CAAC,MAAM,GAAGD;QACd,IAAI,CAAC,KAAK,GAAG,IAAIE,MAAS;YACtBF;QACJ;IACJ;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/db",
3
- "version": "6.4.5",
3
+ "version": "6.6.0-alpha.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -16,13 +16,14 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@webiny/api": "6.4.5",
19
+ "@webiny/api": "6.6.0-alpha.0",
20
+ "@webiny/feature": "6.6.0-alpha.0",
20
21
  "type-fest": "5.8.0"
21
22
  },
22
23
  "devDependencies": {
23
- "@webiny/build-tools": "6.4.5",
24
+ "@webiny/build-tools": "6.6.0-alpha.0",
24
25
  "rimraf": "6.1.3",
25
- "typescript": "6.0.3"
26
+ "typescript": "7.0.2"
26
27
  },
27
28
  "gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
28
29
  "webiny": {
package/types.d.ts CHANGED
@@ -1,24 +1 @@
1
- import type { NonEmptyArray } from "@webiny/api/types.js";
2
- export interface IRegistryRegisterParams<T = unknown> {
3
- item: T;
4
- app: string;
5
- tags: NonEmptyArray<string>;
6
- }
7
- export interface IRegistryItem<T = unknown> {
8
- item: T;
9
- app: string;
10
- tags: NonEmptyArray<string>;
11
- }
12
- export interface IRegistry {
13
- register<T = unknown>(params: IRegistryRegisterParams<T>): void;
14
- /**
15
- * Throws an error if more than one item is found or there is no item found.
16
- */
17
- getOneItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>;
18
- /**
19
- * Throws an error if more than one item is found.
20
- */
21
- getItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T> | null;
22
- getItems<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>[];
23
- }
24
1
  export * from "./store/types.js";
package/DbRegistry.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { IRegistry, IRegistryItem, IRegistryRegisterParams } from "./types.js";
2
- export declare class DbRegistry implements IRegistry {
3
- private readonly items;
4
- register<T = unknown>(input: IRegistryRegisterParams<T>): void;
5
- getOneItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>;
6
- getItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T> | null;
7
- getItems<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>[];
8
- }
package/DbRegistry.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"DbRegistry.js","sources":["../src/DbRegistry.ts"],"sourcesContent":["import type { IRegistry, IRegistryItem, IRegistryRegisterParams } from \"./types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport class DbRegistry implements IRegistry {\n private readonly items: GenericRecord<string, IRegistryItem> = {};\n\n public register<T = unknown>(input: IRegistryRegisterParams<T>): void {\n const key = `${input.app}-${input.tags.sort().join(\"-\")}`;\n\n if (this.items[key]) {\n throw new Error(\n `Item with app \"${input.app}\" and tags \"${input.tags.join(\n \", \"\n )}\" is already registered.`\n );\n }\n this.items[key] = input;\n }\n\n public getOneItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T> {\n const item = this.getItem(cb);\n if (!item) {\n throw new Error(\"Item not found.\");\n }\n return item;\n }\n\n public getItem<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T> | null {\n const items = this.getItems(cb);\n if (items.length === 0) {\n return null;\n } else if (items.length > 1) {\n throw new Error(\"More than one item found with the provided criteria.\");\n }\n return items[0];\n }\n\n public getItems<T = unknown>(cb: (item: IRegistryItem<T>) => boolean): IRegistryItem<T>[] {\n const results: IRegistryItem<T>[] = [];\n for (const key in this.items) {\n const item = this.items[key] as IRegistryItem<T>;\n if (cb(item)) {\n results.push(item);\n }\n }\n\n return results;\n }\n}\n"],"names":["DbRegistry","input","key","Error","cb","item","items","results"],"mappings":"AAGO,MAAMA;IAGF,SAAsBC,KAAiC,EAAQ;QAClE,MAAMC,MAAM,GAAGD,MAAM,GAAG,CAAC,CAAC,EAAEA,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM;QAEzD,IAAI,IAAI,CAAC,KAAK,CAACC,IAAI,EACf,MAAM,IAAIC,MACN,CAAC,eAAe,EAAEF,MAAM,GAAG,CAAC,YAAY,EAAEA,MAAM,IAAI,CAAC,IAAI,CACrD,MACF,wBAAwB,CAAC;QAGnC,IAAI,CAAC,KAAK,CAACC,IAAI,GAAGD;IACtB;IAEO,WAAwBG,EAAuC,EAAoB;QACtF,MAAMC,OAAO,IAAI,CAAC,OAAO,CAACD;QAC1B,IAAI,CAACC,MACD,MAAM,IAAIF,MAAM;QAEpB,OAAOE;IACX;IAEO,QAAqBD,EAAuC,EAA2B;QAC1F,MAAME,QAAQ,IAAI,CAAC,QAAQ,CAACF;QAC5B,IAAIE,AAAiB,MAAjBA,MAAM,MAAM,EACZ,OAAO;QACJ,IAAIA,MAAM,MAAM,GAAG,GACtB,MAAM,IAAIH,MAAM;QAEpB,OAAOG,KAAK,CAAC,EAAE;IACnB;IAEO,SAAsBF,EAAuC,EAAsB;QACtF,MAAMG,UAA8B,EAAE;QACtC,IAAK,MAAML,OAAO,IAAI,CAAC,KAAK,CAAE;YAC1B,MAAMG,OAAO,IAAI,CAAC,KAAK,CAACH,IAAI;YAC5B,IAAIE,GAAGC,OACHE,QAAQ,IAAI,CAACF;QAErB;QAEA,OAAOE;IACX;;aA3CiB,KAAK,GAAyC,CAAC;;AA4CpE"}