@furystack/repository 5.0.32 → 6.0.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.
Files changed (39) hide show
  1. package/dist/data-set.js +2 -2
  2. package/dist/dataset.spec.js +106 -69
  3. package/dist/dataset.spec.js.map +1 -1
  4. package/dist/helpers.js +22 -0
  5. package/dist/helpers.js.map +1 -0
  6. package/dist/index.js +4 -4
  7. package/dist/index.js.map +1 -1
  8. package/dist/repository.js +2 -2
  9. package/dist/repository.js.map +1 -1
  10. package/dist/repository.spec.js +4 -3
  11. package/dist/repository.spec.js.map +1 -1
  12. package/package.json +9 -8
  13. package/src/dataset.spec.ts +127 -146
  14. package/src/helpers.ts +24 -0
  15. package/src/index.ts +1 -1
  16. package/src/repository.spec.ts +5 -6
  17. package/{dist → types}/data-set-setting.d.ts +0 -0
  18. package/{dist → types}/data-set-setting.d.ts.map +0 -0
  19. package/{dist → types}/data-set.d.ts +0 -0
  20. package/{dist → types}/data-set.d.ts.map +0 -0
  21. package/types/dataset.spec.d.ts +2 -0
  22. package/types/dataset.spec.d.ts.map +1 -0
  23. package/types/helpers.d.ts +19 -0
  24. package/types/helpers.d.ts.map +1 -0
  25. package/{dist → types}/index.d.ts +1 -1
  26. package/{dist → types}/index.d.ts.map +1 -1
  27. package/{dist → types}/repository.d.ts +0 -0
  28. package/{dist → types}/repository.d.ts.map +0 -0
  29. package/types/repository.spec.d.ts +2 -0
  30. package/types/repository.spec.d.ts.map +1 -0
  31. package/dist/dataset.spec.d.ts +0 -2
  32. package/dist/dataset.spec.d.ts.map +0 -1
  33. package/dist/injector-extension.d.ts +0 -32
  34. package/dist/injector-extension.d.ts.map +0 -1
  35. package/dist/injector-extension.js +0 -12
  36. package/dist/injector-extension.js.map +0 -1
  37. package/dist/repository.spec.d.ts +0 -2
  38. package/dist/repository.spec.d.ts.map +0 -1
  39. package/src/injector-extension.ts +0 -45
package/src/helpers.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { Constructable } from '@furystack/inject'
2
+ import { Injector } from '@furystack/inject'
3
+ import { Repository } from './repository'
4
+
5
+ /**
6
+ * Returns a Repository on an injector
7
+ *
8
+ * @param injector The Injector instance
9
+ * @returns The Repository instance
10
+ */
11
+ export const getRepository = (injector: Injector) => injector.getInstance(Repository)
12
+
13
+ /**
14
+ *
15
+ * @param injector The Injector instance
16
+ * @param model The Model
17
+ * @param primaryKey The Primary Key field
18
+ * @returns A Repository DataSet for a specific model
19
+ */
20
+ export const getDataSetFor = <T, TPrimaryKey extends keyof T>(
21
+ injector: Injector,
22
+ model: Constructable<T>,
23
+ primaryKey: TPrimaryKey,
24
+ ) => injector.getInstance(Repository).getDataSetFor(model, primaryKey)
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './repository'
2
2
  export * from './data-set'
3
3
  export * from './data-set-setting'
4
- import './injector-extension'
4
+ export * from './helpers'
@@ -1,7 +1,7 @@
1
1
  import { Injector } from '@furystack/inject'
2
2
  import { using } from '@furystack/utils'
3
- import './injector-extension'
4
- import { InMemoryStore } from '@furystack/core'
3
+ import { getDataSetFor, getRepository } from './helpers'
4
+ import { addStore, InMemoryStore } from '@furystack/core'
5
5
  import { DataSet } from './data-set'
6
6
 
7
7
  describe('Repository', () => {
@@ -10,11 +10,10 @@ describe('Repository', () => {
10
10
  class ExampleClass {
11
11
  id!: number
12
12
  }
13
- i.setupStores((sm) => sm.addStore(new InMemoryStore({ model: ExampleClass, primaryKey: 'id' }))).setupRepository(
14
- (r) => r.createDataSet(ExampleClass, 'id', {}),
15
- )
13
+ addStore(i, new InMemoryStore({ model: ExampleClass, primaryKey: 'id' }))
14
+ getRepository(i).createDataSet(ExampleClass, 'id', {})
16
15
 
17
- const dataSet = i.getDataSetFor(ExampleClass, 'id')
16
+ const dataSet = getDataSetFor(i, ExampleClass, 'id')
18
17
  expect(dataSet).toBeInstanceOf(DataSet)
19
18
  })
20
19
  })
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dataset.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataset.spec.d.ts","sourceRoot":"","sources":["../src/dataset.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { Constructable } from '@furystack/inject';
2
+ import { Injector } from '@furystack/inject';
3
+ import { Repository } from './repository';
4
+ /**
5
+ * Returns a Repository on an injector
6
+ *
7
+ * @param injector The Injector instance
8
+ * @returns The Repository instance
9
+ */
10
+ export declare const getRepository: (injector: Injector) => Repository;
11
+ /**
12
+ *
13
+ * @param injector The Injector instance
14
+ * @param model The Model
15
+ * @param primaryKey The Primary Key field
16
+ * @returns A Repository DataSet for a specific model
17
+ */
18
+ export declare const getDataSetFor: <T, TPrimaryKey extends keyof T>(injector: Injector, model: Constructable<T>, primaryKey: TPrimaryKey) => import("./data-set").DataSet<T, TPrimaryKey>;
19
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,aAAa,aAAc,QAAQ,eAAqC,CAAA;AAErF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,6CACd,QAAQ,mGAGkD,CAAA"}
@@ -1,5 +1,5 @@
1
1
  export * from './repository';
2
2
  export * from './data-set';
3
3
  export * from './data-set-setting';
4
- import './injector-extension';
4
+ export * from './helpers';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,OAAO,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA"}
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=repository.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.spec.d.ts","sourceRoot":"","sources":["../src/repository.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- import './injector-extension';
2
- //# sourceMappingURL=dataset.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dataset.spec.d.ts","sourceRoot":"","sources":["../src/dataset.spec.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAA"}
@@ -1,32 +0,0 @@
1
- import { Constructable } from '@furystack/inject';
2
- import { DataSet } from './data-set';
3
- import { Repository } from './repository';
4
- declare module '@furystack/inject/dist/injector' {
5
- /**
6
- * Defines an extended Injector instance
7
- */
8
- interface Injector {
9
- /**
10
- * Sets up a Repository on an injector
11
- * usage example:
12
- * ````ts
13
- * injector
14
- * .setupStores(sm => {
15
- * sm.useMongoDb(TestEntry, 'mongodb://localhost:27017', 'test', 'TestEntries')
16
- * .useMongoDb(User, 'mongodb://localhost:27017', 'test', 'users')
17
- * })
18
- * .setupRepository(repo => {
19
- * repo.createDataSet(User, { name: 'users', onEntityAdded: (ev) => console.log('New user added', ev.entity) })
20
- * })
21
- *
22
- * const userDataSet = injector.getDataSetFor(User)
23
- * ````
24
- */
25
- setupRepository: (builder: (repository: Repository) => void) => this;
26
- /**
27
- * Returns a DataSet for a specific model
28
- */
29
- getDataSetFor: <T, TPrimaryKey extends keyof T>(model: Constructable<T>, primaryKey: TPrimaryKey) => DataSet<T, TPrimaryKey>;
30
- }
31
- }
32
- //# sourceMappingURL=injector-extension.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"injector-extension.d.ts","sourceRoot":"","sources":["../src/injector-extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,QAAQ,iCAAiC,CAAC;IAC/C;;OAEG;IACH,UAAiB,QAAQ;QACvB;;;;;;;;;;;;;;;WAeG;QACH,eAAe,EAAE,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,KAAK,IAAI,CAAA;QACpE;;WAEG;QACH,aAAa,EAAE,CAAC,CAAC,EAAE,WAAW,SAAS,MAAM,CAAC,EAC5C,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EACvB,UAAU,EAAE,WAAW,KACpB,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,CAAA;KAC7B;CACF"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const injector_1 = require("@furystack/inject/dist/injector");
4
- const repository_1 = require("./repository");
5
- injector_1.Injector.prototype.setupRepository = function (builder) {
6
- builder(this.getInstance(repository_1.Repository));
7
- return this;
8
- };
9
- injector_1.Injector.prototype.getDataSetFor = function (model, primaryKey) {
10
- return this.getInstance(repository_1.Repository).getDataSetFor(model, primaryKey);
11
- };
12
- //# sourceMappingURL=injector-extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"injector-extension.js","sourceRoot":"","sources":["../src/injector-extension.ts"],"names":[],"mappings":";;AACA,8DAA0D;AAE1D,6CAAyC;AAkCzC,mBAAQ,CAAC,SAAS,CAAC,eAAe,GAAG,UAAU,OAAO;IACpD,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,uBAAU,CAAC,CAAC,CAAA;IACrC,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,mBAAQ,CAAC,SAAS,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,UAAU;IAC5D,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAU,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;AACtE,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- import './injector-extension';
2
- //# sourceMappingURL=repository.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repository.spec.d.ts","sourceRoot":"","sources":["../src/repository.spec.ts"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,CAAA"}
@@ -1,45 +0,0 @@
1
- import { Constructable } from '@furystack/inject'
2
- import { Injector } from '@furystack/inject/dist/injector'
3
- import { DataSet } from './data-set'
4
- import { Repository } from './repository'
5
-
6
- declare module '@furystack/inject/dist/injector' {
7
- /**
8
- * Defines an extended Injector instance
9
- */
10
- export interface Injector {
11
- /**
12
- * Sets up a Repository on an injector
13
- * usage example:
14
- * ````ts
15
- * injector
16
- * .setupStores(sm => {
17
- * sm.useMongoDb(TestEntry, 'mongodb://localhost:27017', 'test', 'TestEntries')
18
- * .useMongoDb(User, 'mongodb://localhost:27017', 'test', 'users')
19
- * })
20
- * .setupRepository(repo => {
21
- * repo.createDataSet(User, { name: 'users', onEntityAdded: (ev) => console.log('New user added', ev.entity) })
22
- * })
23
- *
24
- * const userDataSet = injector.getDataSetFor(User)
25
- * ````
26
- */
27
- setupRepository: (builder: (repository: Repository) => void) => this
28
- /**
29
- * Returns a DataSet for a specific model
30
- */
31
- getDataSetFor: <T, TPrimaryKey extends keyof T>(
32
- model: Constructable<T>,
33
- primaryKey: TPrimaryKey,
34
- ) => DataSet<T, TPrimaryKey>
35
- }
36
- }
37
-
38
- Injector.prototype.setupRepository = function (builder) {
39
- builder(this.getInstance(Repository))
40
- return this
41
- }
42
-
43
- Injector.prototype.getDataSetFor = function (model, primaryKey) {
44
- return this.getInstance(Repository).getDataSetFor(model, primaryKey)
45
- }