@fjell/lib-sequelize 4.3.1

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 (91) hide show
  1. package/LICENSE +202 -0
  2. package/dist/src/Coordinate.d.ts +4 -0
  3. package/dist/src/Coordinate.js +7 -0
  4. package/dist/src/Coordinate.js.map +1 -0
  5. package/dist/src/Definition.d.ts +7 -0
  6. package/dist/src/Definition.js +16 -0
  7. package/dist/src/Definition.js.map +1 -0
  8. package/dist/src/EventCoordinator.d.ts +5 -0
  9. package/dist/src/EventCoordinator.js +56 -0
  10. package/dist/src/EventCoordinator.js.map +1 -0
  11. package/dist/src/Instance.d.ts +8 -0
  12. package/dist/src/Instance.js +14 -0
  13. package/dist/src/Instance.js.map +1 -0
  14. package/dist/src/KeyMaster.d.ts +4 -0
  15. package/dist/src/KeyMaster.js +58 -0
  16. package/dist/src/KeyMaster.js.map +1 -0
  17. package/dist/src/Operations.d.ts +5 -0
  18. package/dist/src/Operations.js +22 -0
  19. package/dist/src/Operations.js.map +1 -0
  20. package/dist/src/Options.d.ts +7 -0
  21. package/dist/src/Options.js +16 -0
  22. package/dist/src/Options.js.map +1 -0
  23. package/dist/src/QueryBuilder.d.ts +11 -0
  24. package/dist/src/QueryBuilder.js +161 -0
  25. package/dist/src/QueryBuilder.js.map +1 -0
  26. package/dist/src/RowProcessor.d.ts +3 -0
  27. package/dist/src/RowProcessor.js +11 -0
  28. package/dist/src/RowProcessor.js.map +1 -0
  29. package/dist/src/contained/Instance.d.ts +8 -0
  30. package/dist/src/contained/Instance.js +14 -0
  31. package/dist/src/contained/Instance.js.map +1 -0
  32. package/dist/src/contained/index.d.ts +1 -0
  33. package/dist/src/contained/index.js +2 -0
  34. package/dist/src/contained/index.js.map +1 -0
  35. package/dist/src/index.d.ts +7 -0
  36. package/dist/src/index.js +8 -0
  37. package/dist/src/index.js.map +1 -0
  38. package/dist/src/logger.d.ts +2 -0
  39. package/dist/src/logger.js +4 -0
  40. package/dist/src/logger.js.map +1 -0
  41. package/dist/src/ops/all.d.ts +4 -0
  42. package/dist/src/ops/all.js +47 -0
  43. package/dist/src/ops/all.js.map +1 -0
  44. package/dist/src/ops/create.d.ts +10 -0
  45. package/dist/src/ops/create.js +14 -0
  46. package/dist/src/ops/create.js.map +1 -0
  47. package/dist/src/ops/find.d.ts +4 -0
  48. package/dist/src/ops/find.js +26 -0
  49. package/dist/src/ops/find.js.map +1 -0
  50. package/dist/src/ops/get.d.ts +4 -0
  51. package/dist/src/ops/get.js +36 -0
  52. package/dist/src/ops/get.js.map +1 -0
  53. package/dist/src/ops/one.d.ts +4 -0
  54. package/dist/src/ops/one.js +17 -0
  55. package/dist/src/ops/one.js.map +1 -0
  56. package/dist/src/ops/remove.d.ts +5 -0
  57. package/dist/src/ops/remove.js +56 -0
  58. package/dist/src/ops/remove.js.map +1 -0
  59. package/dist/src/ops/update.d.ts +4 -0
  60. package/dist/src/ops/update.js +49 -0
  61. package/dist/src/ops/update.js.map +1 -0
  62. package/dist/src/primary/Instance.d.ts +8 -0
  63. package/dist/src/primary/Instance.js +17 -0
  64. package/dist/src/primary/Instance.js.map +1 -0
  65. package/dist/src/primary/index.d.ts +1 -0
  66. package/dist/src/primary/index.js +2 -0
  67. package/dist/src/primary/index.js.map +1 -0
  68. package/eslint.config.mjs +70 -0
  69. package/package.json +61 -0
  70. package/src/Coordinate.ts +16 -0
  71. package/src/Definition.ts +49 -0
  72. package/src/EventCoordinator.ts +103 -0
  73. package/src/Instance.ts +45 -0
  74. package/src/KeyMaster.ts +90 -0
  75. package/src/Operations.ts +42 -0
  76. package/src/Options.ts +41 -0
  77. package/src/QueryBuilder.ts +208 -0
  78. package/src/RowProcessor.ts +23 -0
  79. package/src/contained/Instance.ts +45 -0
  80. package/src/contained/index.ts +1 -0
  81. package/src/index.ts +7 -0
  82. package/src/logger.ts +5 -0
  83. package/src/ops/all.ts +76 -0
  84. package/src/ops/create.ts +40 -0
  85. package/src/ops/find.ts +49 -0
  86. package/src/ops/get.ts +67 -0
  87. package/src/ops/one.ts +37 -0
  88. package/src/ops/remove.ts +81 -0
  89. package/src/ops/update.ts +78 -0
  90. package/src/primary/Instance.ts +41 -0
  91. package/src/primary/index.ts +1 -0
@@ -0,0 +1,17 @@
1
+ import { Primary } from '@fjell/lib';
2
+ import { createDefinition } from '../Definition';
3
+ import { createOperations } from '../Operations';
4
+ import LibLogger from '../logger';
5
+ const logger = LibLogger.get('lib-sequelize', 'primary', 'instance');
6
+ // eslint-disable-next-line max-params
7
+ export function createInstance(keyType, models, libOptions = {}, scopes = []) {
8
+ logger.debug('createInstance', { keyType, models, libOptions, scopes });
9
+ const definition = createDefinition([keyType], scopes, libOptions);
10
+ const operations = createOperations(models, definition);
11
+ return {
12
+ definition,
13
+ operations: Primary.wrapOperations(operations, definition),
14
+ models
15
+ };
16
+ }
17
+ //# sourceMappingURL=Instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Instance.js","sourceRoot":"","sources":["../../../src/primary/Instance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,OAAO,SAAS,MAAM,UAAU,CAAC;AAEjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,eAAe,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AASrE,sCAAsC;AACtC,MAAM,UAAU,cAAc,CAI5B,OAAU,EACV,MAA0B,EAC1B,aAA4B,EAAE,EAC9B,SAAmB,EAAE;IAErB,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IACxE,MAAM,UAAU,GAAG,gBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAEnE,MAAM,UAAU,GAAG,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAExD,OAAO;QACL,UAAU;QACV,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,UAAU,CAAC;QAC1D,MAAM;KACW,CAAC;AAEtB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './Instance';
@@ -0,0 +1,2 @@
1
+ export * from './Instance';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/primary/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1,70 @@
1
+ import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
+ import tsParser from "@typescript-eslint/parser";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import js from "@eslint/js";
6
+ import { FlatCompat } from "@eslint/eslintrc";
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const compat = new FlatCompat({
11
+ baseDirectory: __dirname,
12
+ recommendedConfig: js.configs.recommended,
13
+ allConfig: js.configs.all
14
+ });
15
+
16
+ export default [{
17
+ ignores: ["**/dist", "**/node_modules"],
18
+ }, ...compat.extends("plugin:@typescript-eslint/recommended"), {
19
+ plugins: {
20
+ "@typescript-eslint": typescriptEslint,
21
+ },
22
+
23
+ languageOptions: {
24
+ parser: tsParser,
25
+ },
26
+
27
+ rules: {
28
+ "@typescript-eslint/no-unused-expressions": "off",
29
+ "no-console": 0,
30
+ "no-unused-vars": "off",
31
+
32
+ "max-len": ["error", {
33
+ code: 120,
34
+ }],
35
+
36
+ "max-depth": ["error", 4],
37
+ "max-params": ["error", 4],
38
+ "max-lines": ["error", 500],
39
+
40
+ "no-multiple-empty-lines": ["error", {
41
+ max: 1,
42
+ maxEOF: 1,
43
+ }],
44
+
45
+ "no-trailing-spaces": ["error", {
46
+ skipBlankLines: true,
47
+ }],
48
+
49
+ indent: ["error", 2, {
50
+ SwitchCase: 1,
51
+ }],
52
+
53
+ "sort-imports": ["error", {
54
+ ignoreCase: true,
55
+ ignoreDeclarationSort: true,
56
+ ignoreMemberSort: false,
57
+ memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
58
+ }],
59
+
60
+ "no-var": "error",
61
+ "no-undefined": "error",
62
+ "@typescript-eslint/no-unused-vars": "error",
63
+ "@typescript-eslint/ban-ts-comment": "off",
64
+ "@typescript-eslint/no-explicit-any": "off",
65
+
66
+ "no-restricted-imports": ["error", {
67
+ patterns: ["..*", "src/*"],
68
+ }],
69
+ },
70
+ }];
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@fjell/lib-sequelize",
3
+ "version": "4.3.1",
4
+ "license": "UNLICENSED",
5
+ "description": "Sequelize Library for Fjell",
6
+ "engines": {
7
+ "node": ">=21"
8
+ },
9
+ "main": "dist/src/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "require": "./dist/src/index.js",
13
+ "import": "./dist/src/index.js",
14
+ "types": "./dist/src/index.d.ts"
15
+ }
16
+ },
17
+ "type": "module",
18
+ "scripts": {
19
+ "build": "yarn run lint && tsc && tsc-alias -p tsconfig.json",
20
+ "dev": "concurrently \"tsc -w\" \"tsc-alias -w\"",
21
+ "lint": "eslint .",
22
+ "clean": "rimraf dist",
23
+ "test": "yarn run lint && NODE_OPTIONS='--experimental-require-module' yarn run jest --coverage"
24
+ },
25
+ "dependencies": {
26
+ "@fjell/core": "^4.3.1",
27
+ "@fjell/lib": "^4.3.0",
28
+ "@fjell/logging": "^4.3.4",
29
+ "dayjs": "^1.11.13",
30
+ "deepmerge": "^4.3.1",
31
+ "multer": "^1.4.5-lts.1",
32
+ "sequelize": "^6.37.5",
33
+ "specifier-resolution-node": "^1.1.4",
34
+ "winston": "^3.17.0"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/preset-env": "^7.26.9",
38
+ "@babel/preset-react": "^7.26.3",
39
+ "@babel/preset-typescript": "^7.26.0",
40
+ "@tsconfig/recommended": "^1.0.8",
41
+ "@types/jest": "^29.5.14",
42
+ "@types/multer": "^1.4.11",
43
+ "@types/node": "^20.10.4",
44
+ "@typescript-eslint/eslint-plugin": "^7",
45
+ "@typescript-eslint/parser": "^7",
46
+ "concurrently": "^8.2.2",
47
+ "eslint": "^8.57.1",
48
+ "jest": "^29.7.0",
49
+ "nodemon": "^3.1.9",
50
+ "rimraf": "^6.0.1",
51
+ "ts-jest": "^29.2.5",
52
+ "ts-node": "^10.9.2",
53
+ "tsc-alias": "^1.8.10",
54
+ "typescript": "^5.7.3"
55
+ },
56
+ "packageManager": "yarn@4.6.0",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/getfjell/lib-sequelize.git"
60
+ }
61
+ }
@@ -0,0 +1,16 @@
1
+ import { ItemTypeArray } from '@fjell/core';
2
+ import * as Library from '@fjell/lib';
3
+
4
+ export const SCOPE_SEQUELIZE = 'sequelize';
5
+
6
+ export const createCoordinate = <
7
+ S extends string,
8
+ L1 extends string = never,
9
+ L2 extends string = never,
10
+ L3 extends string = never,
11
+ L4 extends string = never,
12
+ L5 extends string = never
13
+ >(kta: ItemTypeArray<S, L1, L2, L3, L4, L5>, scopes?: string[]) => {
14
+ const coordinate = Library.createCoordinate(kta,[SCOPE_SEQUELIZE, ...(scopes || [])])
15
+ return coordinate;
16
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ Item,
3
+ ItemTypeArray
4
+ } from '@fjell/core';
5
+
6
+ import * as Library from '@fjell/lib';
7
+ import { createCoordinate } from './Coordinate';
8
+ import { createOptions } from './Options';
9
+ import { Options } from './Options';
10
+ import LibLogger from './logger';
11
+
12
+ const logger = LibLogger.get('lib-sequelize', 'Definition');
13
+
14
+ export interface Definition<
15
+ V extends Item<S, L1, L2, L3, L4, L5>,
16
+ S extends string,
17
+ L1 extends string = never,
18
+ L2 extends string = never,
19
+ L3 extends string = never,
20
+ L4 extends string = never,
21
+ L5 extends string = never
22
+ > extends Library.Definition<V, S, L1, L2, L3, L4, L5> {
23
+ options: Options<V, S, L1, L2, L3, L4, L5>;
24
+ }
25
+
26
+ export function createDefinition<
27
+ V extends Item<S, L1, L2, L3, L4, L5>,
28
+ S extends string,
29
+ L1 extends string = never,
30
+ L2 extends string = never,
31
+ L3 extends string = never,
32
+ L4 extends string = never,
33
+ L5 extends string = never
34
+ >(
35
+ kta: ItemTypeArray<S, L1, L2, L3, L4, L5>,
36
+ scopes: string[],
37
+ libOptions?: Options<V, S, L1, L2, L3, L4, L5>,
38
+ ): Definition<V, S, L1, L2, L3, L4, L5> {
39
+ logger.debug('createDefinition', { kta, scopes, libOptions });
40
+ const coordinate = createCoordinate(kta, scopes);
41
+ const options = createOptions(libOptions);
42
+
43
+ const definition = Library.createDefinition(coordinate, options);
44
+
45
+ return {
46
+ ...definition,
47
+ options,
48
+ }
49
+ }
@@ -0,0 +1,103 @@
1
+ import {
2
+ Evented,
3
+ ItemProperties,
4
+ ManagedEvents
5
+ } from '@fjell/core';
6
+ import deepmerge from 'deepmerge';
7
+
8
+ import LibLogger from '@/logger';
9
+
10
+ const logger = LibLogger.get("sequelize", "EventCoordinator");
11
+
12
+ export const createEvents = <
13
+ S extends string,
14
+ L1 extends string = never,
15
+ L2 extends string = never,
16
+ L3 extends string = never,
17
+ L4 extends string = never,
18
+ L5 extends string = never
19
+ >(item: ItemProperties<S, L1, L2, L3, L4, L5>):
20
+ ItemProperties<S, L1, L2, L3, L4, L5> => {
21
+ logger.default('Creating Events', { item });
22
+ const currentDate = new Date();
23
+
24
+ let events = item.events;
25
+
26
+ if (events) {
27
+ if (!events.created) {
28
+ events = deepmerge(events, { created: { at: currentDate } });
29
+ }
30
+ if (!events.updated) {
31
+ events = deepmerge(events, { updated: { at: currentDate } });
32
+ }
33
+ if (!events.deleted) {
34
+ events = deepmerge(events, { deleted: { at: null } });
35
+ }
36
+
37
+ } else {
38
+ events = {
39
+ created: { at: currentDate },
40
+ updated: { at: currentDate },
41
+ deleted: { at: null },
42
+ };
43
+ }
44
+
45
+ return deepmerge(item, { events }) as
46
+ ItemProperties<S, L1, L2, L3, L4, L5>;
47
+ }
48
+
49
+ export const updateEvents = <
50
+ S extends string,
51
+ L1 extends string = never,
52
+ L2 extends string = never,
53
+ L3 extends string = never,
54
+ L4 extends string = never,
55
+ L5 extends string = never
56
+ >(item: ItemProperties<S, L1, L2, L3, L4, L5>):
57
+ ItemProperties<S, L1, L2, L3, L4, L5> => {
58
+ logger.default('Updating Events', { item });
59
+ const currentDate = new Date();
60
+ const events: Evented = {
61
+ updated: { at: currentDate },
62
+ };
63
+
64
+ // TODO: This is clean-up code, we should remove it
65
+ // If the event lacks a created data, let's just insert it here...
66
+ if (!item.events || !item.events.created || !item.events.created.at) {
67
+ events.created = { at: currentDate };
68
+ }
69
+
70
+ return deepmerge(item, { events }) as ItemProperties<S, L1, L2, L3, L4, L5>;
71
+ }
72
+ //#endregion
73
+
74
+ export const populateEvents = <
75
+ S extends string,
76
+ L1 extends string = never,
77
+ L2 extends string = never,
78
+ L3 extends string = never,
79
+ L4 extends string = never,
80
+ L5 extends string = never
81
+ >(item: ItemProperties<S, L1, L2, L3, L4, L5>): ItemProperties<S, L1, L2, L3, L4, L5> => {
82
+ const events: ManagedEvents = {
83
+ created: { at: item.createdAt },
84
+ updated: { at: item.updatedAt },
85
+ deleted: { at: null }
86
+ };
87
+ item.events = events;
88
+ return item;
89
+ }
90
+
91
+ export const removeEvents = <
92
+ S extends string,
93
+ L1 extends string = never,
94
+ L2 extends string = never,
95
+ L3 extends string = never,
96
+ L4 extends string = never,
97
+ L5 extends string = never
98
+ >(item: ItemProperties<S, L1, L2, L3, L4, L5>): ItemProperties<S, L1, L2, L3, L4, L5> => {
99
+ logger.default('Removing Events', { item });
100
+ delete item.events;
101
+ return item;
102
+ }
103
+
@@ -0,0 +1,45 @@
1
+ import * as Library from '@fjell/lib';
2
+ import { Item, ItemTypeArray } from '@fjell/core';
3
+ import { createDefinition } from './Definition';
4
+ import { createOperations } from './Operations';
5
+ import { ModelStatic } from 'sequelize';
6
+ import { Options } from './Options';
7
+
8
+ export interface Instance<
9
+ V extends Item<S, L1, L2, L3, L4, L5>,
10
+ S extends string,
11
+ L1 extends string = never,
12
+ L2 extends string = never,
13
+ L3 extends string = never,
14
+ L4 extends string = never,
15
+ L5 extends string = never
16
+ > extends Library.Instance<V, S, L1, L2, L3, L4, L5> {
17
+ models: ModelStatic<any>[];
18
+ }
19
+
20
+ // eslint-disable-next-line max-params
21
+ export function createInstance<
22
+ V extends Item<S, L1, L2, L3, L4, L5>,
23
+ S extends string,
24
+ L1 extends string = never,
25
+ L2 extends string = never,
26
+ L3 extends string = never,
27
+ L4 extends string = never,
28
+ L5 extends string = never
29
+ >(
30
+ keyTypes: ItemTypeArray<S, L1, L2, L3, L4, L5>,
31
+ models: ModelStatic<any>[],
32
+ libOptions: Options<V, S, L1, L2, L3, L4, L5> = {},
33
+ scopes: string[] = [],
34
+ ): Instance<V, S, L1, L2, L3, L4, L5> {
35
+
36
+ const definition = createDefinition(keyTypes, scopes, libOptions);
37
+ const operations = createOperations(models, definition);
38
+
39
+ return {
40
+ definition,
41
+ operations: Library.wrapOperations(operations, definition),
42
+ models
43
+ }
44
+
45
+ }
@@ -0,0 +1,90 @@
1
+ import {
2
+ AllItemTypeArrays,
3
+ Item,
4
+ ItemProperties
5
+ } from '@fjell/core';
6
+
7
+ import LibLogger from '@/logger';
8
+
9
+ const logger = LibLogger.get('sequelize', 'KeyMaster');
10
+
11
+ export const removeKey = <
12
+ S extends string,
13
+ L1 extends string = never,
14
+ L2 extends string = never,
15
+ L3 extends string = never,
16
+ L4 extends string = never,
17
+ L5 extends string = never
18
+ >(
19
+ item: ItemProperties<S, L1, L2, L3, L4, L5>
20
+ ): ItemProperties<S, L1, L2, L3, L4, L5> => {
21
+ logger.default('Removing Key', { item });
22
+ delete item.key;
23
+ return item;
24
+ }
25
+
26
+ export const populateKey = <
27
+ S extends string,
28
+ L1 extends string = never,
29
+ L2 extends string = never,
30
+ L3 extends string = never,
31
+ L4 extends string = never,
32
+ L5 extends string = never
33
+ >(
34
+ item: ItemProperties<S, L1, L2, L3, L4, L5>,
35
+ keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>
36
+ ): ItemProperties<S, L1, L2, L3, L4, L5> => {
37
+ if( keyTypes.length === 1 ) {
38
+ item.key = { kt: keyTypes[0], pk: item.id };
39
+ delete item.id;
40
+ } else if( keyTypes.length === 2 ) {
41
+ item.key = {
42
+ kt: keyTypes[0], pk: item.id,
43
+ // TODO: Shouldn't this be inspecting the model to get the primary key type?
44
+ loc: [{ kt: keyTypes[1], lk: item[keyTypes[1] + 'Id']}],
45
+ };
46
+ delete item.id;
47
+ delete item[keyTypes[1] + 'Id'];
48
+ } else {
49
+ throw new Error('Not implemented');
50
+ }
51
+ return item;
52
+ }
53
+
54
+ export const addKey = <
55
+ S extends string,
56
+ L1 extends string = never,
57
+ L2 extends string = never,
58
+ L3 extends string = never,
59
+ L4 extends string = never,
60
+ L5 extends string = never
61
+ >(
62
+ item: Partial<Item<S, L1, L2, L3, L4, L5>>,
63
+ keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>
64
+ ): void => {
65
+ logger.default('Adding Key', { item });
66
+ const key = {};
67
+ if (Array.isArray(keyTypes) && keyTypes.length > 1) {
68
+ const type = [...keyTypes];
69
+ const pkType = type.shift();
70
+ Object.assign(key, { kt: pkType, pk: item.id });
71
+ // TODO: This is really just for primary items
72
+ if (type.length === 1) {
73
+ // TODO: This should be looking at the model to get the primary key of the reference item or association
74
+ const locKeyTypeId = type[0] + 'Id';
75
+ Object.assign(key, { loc: [{ kt: type[0], lk: item[locKeyTypeId] }] });
76
+ } else if (type.length === 2) {
77
+ throw new Error('Not implemented');
78
+ } else if (type.length === 3) {
79
+ throw new Error('Not implemented');
80
+ } else if (type.length === 4) {
81
+ throw new Error('Not implemented');
82
+ } else if (type.length === 5) {
83
+ throw new Error('Not implemented');
84
+ }
85
+ } else {
86
+ Object.assign(key, { kt: keyTypes[0], pk: item.id });
87
+ }
88
+ Object.assign(item, { key });
89
+ };
90
+
@@ -0,0 +1,42 @@
1
+ import { Item } from "@fjell/core";
2
+
3
+ import * as Library from "@fjell/lib";
4
+ import { getAllOperation } from "./ops/all";
5
+ import { getCreateOperation } from "./ops/create";
6
+ import { getFindOperation } from "./ops/find";
7
+ import { getGetOperation } from "./ops/get";
8
+ import { getOneOperation } from "./ops/one";
9
+ import { getRemoveOperation } from "./ops/remove";
10
+ import { getUpdateOperation } from "./ops/update";
11
+ import { ModelStatic } from "sequelize";
12
+ import { Definition } from "@fjell/lib";
13
+
14
+ export const createOperations = <
15
+ V extends Item<S, L1, L2, L3, L4, L5>,
16
+ S extends string,
17
+ L1 extends string = never,
18
+ L2 extends string = never,
19
+ L3 extends string = never,
20
+ L4 extends string = never,
21
+ L5 extends string = never,
22
+ >(
23
+ models: Array<ModelStatic<any>>,
24
+ definition: Definition<V, S, L1, L2, L3, L4, L5>,
25
+ // eslint-disable-next-line max-params
26
+ ): Library.Operations<V, S, L1, L2, L3, L4, L5> => {
27
+
28
+ const operations = {} as Library.Operations<V, S, L1, L2, L3, L4, L5>;
29
+
30
+ operations.all = getAllOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
31
+ operations.one = getOneOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
32
+ operations.create = getCreateOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
33
+ operations.update = getUpdateOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
34
+ operations.get = getGetOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
35
+ operations.remove = getRemoveOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
36
+ operations.find = getFindOperation<V, S, L1, L2, L3, L4, L5>(models, definition);
37
+ operations.upsert = () => {
38
+ throw new Error('Not implemented');
39
+ };
40
+
41
+ return operations;
42
+ }
package/src/Options.ts ADDED
@@ -0,0 +1,41 @@
1
+ import * as Library from '@fjell/lib';
2
+ import { Item } from '@fjell/core';
3
+ import deepmerge from 'deepmerge';
4
+
5
+ export interface Options<
6
+ V extends Item<S, L1, L2, L3, L4, L5>,
7
+ S extends string,
8
+ L1 extends string = never,
9
+ L2 extends string = never,
10
+ L3 extends string = never,
11
+ L4 extends string = never,
12
+ L5 extends string = never
13
+ > extends Library.Options<V, S, L1, L2, L3, L4, L5> {
14
+ deleteOnRemove?: boolean;
15
+ }
16
+
17
+ export const defaultOptions: Options<any, any, any, any, any, any, any> = {
18
+ deleteOnRemove: false,
19
+ };
20
+
21
+ export const createOptions = <
22
+ V extends Item<S, L1, L2, L3, L4, L5>,
23
+ S extends string,
24
+ L1 extends string = never,
25
+ L2 extends string = never,
26
+ L3 extends string = never,
27
+ L4 extends string = never,
28
+ L5 extends string = never
29
+ >(libOptions?: Options<V, S, L1, L2, L3, L4, L5>): Options<V, S, L1, L2, L3, L4, L5> => {
30
+ const defaultOptions = {
31
+ deleteOnRemove: false,
32
+ } as Options<V, S, L1, L2, L3, L4, L5>;
33
+
34
+ const options = Library.createOptions(libOptions);
35
+
36
+ const mergedOptions = deepmerge(defaultOptions, options);
37
+
38
+ return {
39
+ ...mergedOptions,
40
+ } as Options<V, S, L1, L2, L3, L4, L5>;
41
+ }