@opra/core 0.1.1 → 0.3.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 (86) hide show
  1. package/cjs/enums/http-headers.enum.js +3 -2
  2. package/cjs/implementation/adapter-utils/entity-resource-execute.util.js +36 -34
  3. package/cjs/implementation/adapter-utils/resource-prepare.util.js +1 -1
  4. package/cjs/implementation/adapter.js +14 -19
  5. package/cjs/implementation/express-adapter.js +3 -0
  6. package/cjs/implementation/headers-map.js +18 -0
  7. package/cjs/implementation/http-adapter.js +65 -79
  8. package/cjs/implementation/query-context.js +12 -19
  9. package/cjs/index.js +1 -3
  10. package/cjs/services/json-collection-service.js +505 -0
  11. package/cjs/utils/path-to-tree.js +7 -5
  12. package/esm/enums/http-headers.enum.d.ts +3 -2
  13. package/esm/enums/http-headers.enum.js +3 -2
  14. package/esm/implementation/adapter-utils/entity-resource-execute.util.d.ts +2 -2
  15. package/esm/implementation/adapter-utils/entity-resource-execute.util.js +35 -33
  16. package/esm/implementation/adapter-utils/resource-execute.util.d.ts +2 -2
  17. package/esm/implementation/adapter-utils/resource-prepare.util.d.ts +2 -2
  18. package/esm/implementation/adapter-utils/resource-prepare.util.js +1 -1
  19. package/esm/implementation/adapter.d.ts +5 -5
  20. package/esm/implementation/adapter.js +12 -17
  21. package/esm/implementation/express-adapter.d.ts +2 -2
  22. package/esm/implementation/express-adapter.js +2 -0
  23. package/esm/implementation/headers-map.d.ts +5 -0
  24. package/esm/implementation/headers-map.js +14 -0
  25. package/esm/implementation/http-adapter.d.ts +6 -6
  26. package/esm/implementation/http-adapter.js +61 -75
  27. package/esm/implementation/query-context.d.ts +10 -16
  28. package/esm/implementation/query-context.js +11 -17
  29. package/esm/index.d.ts +1 -3
  30. package/esm/index.js +1 -3
  31. package/esm/interfaces/entity-service.interface.d.ts +8 -6
  32. package/esm/services/json-collection-service.d.ts +85 -0
  33. package/esm/services/json-collection-service.js +500 -0
  34. package/esm/types.d.ts +0 -3
  35. package/esm/utils/path-to-tree.d.ts +1 -1
  36. package/esm/utils/path-to-tree.js +7 -5
  37. package/i18n/en/error.json +5 -5
  38. package/package.json +10 -7
  39. package/cjs/exception/api-exception.js +0 -68
  40. package/cjs/exception/http-errors/bad-request.error.js +0 -26
  41. package/cjs/exception/http-errors/failed-dependency.error.js +0 -25
  42. package/cjs/exception/http-errors/forbidden.error.js +0 -27
  43. package/cjs/exception/http-errors/internal-server.error.js +0 -27
  44. package/cjs/exception/http-errors/method-not-allowed.error.js +0 -26
  45. package/cjs/exception/http-errors/not-acceptable.error.js +0 -26
  46. package/cjs/exception/http-errors/not-found.error.js +0 -29
  47. package/cjs/exception/http-errors/unauthorized.error.js +0 -26
  48. package/cjs/exception/http-errors/unprocessable-entity.error.js +0 -25
  49. package/cjs/exception/index.js +0 -15
  50. package/cjs/exception/resource-errors/resource-conflict.error.js +0 -19
  51. package/cjs/exception/resource-errors/resource-not-found.error.js +0 -19
  52. package/cjs/exception/wrap-error.js +0 -17
  53. package/cjs/interfaces/query.interface.js +0 -207
  54. package/cjs/services/json-data-service.js +0 -252
  55. package/esm/exception/api-exception.d.ts +0 -40
  56. package/esm/exception/api-exception.js +0 -64
  57. package/esm/exception/http-errors/bad-request.error.d.ts +0 -10
  58. package/esm/exception/http-errors/bad-request.error.js +0 -22
  59. package/esm/exception/http-errors/failed-dependency.error.d.ts +0 -9
  60. package/esm/exception/http-errors/failed-dependency.error.js +0 -21
  61. package/esm/exception/http-errors/forbidden.error.d.ts +0 -11
  62. package/esm/exception/http-errors/forbidden.error.js +0 -23
  63. package/esm/exception/http-errors/internal-server.error.d.ts +0 -9
  64. package/esm/exception/http-errors/internal-server.error.js +0 -22
  65. package/esm/exception/http-errors/method-not-allowed.error.d.ts +0 -10
  66. package/esm/exception/http-errors/method-not-allowed.error.js +0 -22
  67. package/esm/exception/http-errors/not-acceptable.error.d.ts +0 -10
  68. package/esm/exception/http-errors/not-acceptable.error.js +0 -22
  69. package/esm/exception/http-errors/not-found.error.d.ts +0 -13
  70. package/esm/exception/http-errors/not-found.error.js +0 -25
  71. package/esm/exception/http-errors/unauthorized.error.d.ts +0 -10
  72. package/esm/exception/http-errors/unauthorized.error.js +0 -22
  73. package/esm/exception/http-errors/unprocessable-entity.error.d.ts +0 -9
  74. package/esm/exception/http-errors/unprocessable-entity.error.js +0 -21
  75. package/esm/exception/index.d.ts +0 -12
  76. package/esm/exception/index.js +0 -12
  77. package/esm/exception/resource-errors/resource-conflict.error.d.ts +0 -4
  78. package/esm/exception/resource-errors/resource-conflict.error.js +0 -15
  79. package/esm/exception/resource-errors/resource-not-found.error.d.ts +0 -4
  80. package/esm/exception/resource-errors/resource-not-found.error.js +0 -15
  81. package/esm/exception/wrap-error.d.ts +0 -2
  82. package/esm/exception/wrap-error.js +0 -13
  83. package/esm/interfaces/query.interface.d.ts +0 -115
  84. package/esm/interfaces/query.interface.js +0 -203
  85. package/esm/services/json-data-service.d.ts +0 -68
  86. package/esm/services/json-data-service.js +0 -247
@@ -1,21 +0,0 @@
1
- import { translate } from '@opra/i18n';
2
- import { HttpStatus } from '../../enums/index.js';
3
- import { ApiException } from '../api-exception.js';
4
- /**
5
- * 422 Unprocessable Entity
6
- * The request was well-formed but was unable to be followed due to semantic errors.
7
- */
8
- export class UnprocessableEntityError extends ApiException {
9
- constructor(response, cause) {
10
- super(response, cause);
11
- this.status = HttpStatus.UNPROCESSABLE_ENTITY;
12
- }
13
- _initResponse(response) {
14
- super._initResponse({
15
- message: translate('error:UNPROCESSABLE_ENTITY'),
16
- severity: 'error',
17
- code: 'UNPROCESSABLE_ENTITY',
18
- ...response
19
- });
20
- }
21
- }
@@ -1,12 +0,0 @@
1
- export * from './api-exception.js';
2
- export * from './http-errors/bad-request.error.js';
3
- export * from './http-errors/failed-dependency.error.js';
4
- export * from './http-errors/forbidden.error.js';
5
- export * from './http-errors/internal-server.error.js';
6
- export * from './http-errors/method-not-allowed.error.js';
7
- export * from './http-errors/not-acceptable.error.js';
8
- export * from './http-errors/not-found.error.js';
9
- export * from './http-errors/unauthorized.error.js';
10
- export * from './http-errors/unprocessable-entity.error.js';
11
- export * from './resource-errors/resource-conflict.error.js';
12
- export * from './resource-errors/resource-not-found.error.js';
@@ -1,12 +0,0 @@
1
- export * from './api-exception.js';
2
- export * from './http-errors/bad-request.error.js';
3
- export * from './http-errors/failed-dependency.error.js';
4
- export * from './http-errors/forbidden.error.js';
5
- export * from './http-errors/internal-server.error.js';
6
- export * from './http-errors/method-not-allowed.error.js';
7
- export * from './http-errors/not-acceptable.error.js';
8
- export * from './http-errors/not-found.error.js';
9
- export * from './http-errors/unauthorized.error.js';
10
- export * from './http-errors/unprocessable-entity.error.js';
11
- export * from './resource-errors/resource-conflict.error.js';
12
- export * from './resource-errors/resource-not-found.error.js';
@@ -1,4 +0,0 @@
1
- import { ApiException } from '../api-exception.js';
2
- export declare class ResourceConflictError extends ApiException {
3
- constructor(resource: string, fields: string | string[], cause?: Error);
4
- }
@@ -1,15 +0,0 @@
1
- import { translate } from '@opra/i18n';
2
- import { HttpStatus } from '../../enums/index.js';
3
- import { ApiException } from '../api-exception.js';
4
- export class ResourceConflictError extends ApiException {
5
- constructor(resource, fields, cause) {
6
- super({
7
- message: translate(`error:RESOURCE_CONFLICT`, { resource, fields }),
8
- severity: 'error',
9
- code: 'RESOURCE_CONFLICT',
10
- subject: resource,
11
- location: fields
12
- }, cause);
13
- this.status = HttpStatus.CONFLICT;
14
- }
15
- }
@@ -1,4 +0,0 @@
1
- import { ApiException } from '../api-exception.js';
2
- export declare class ResourceNotFoundError extends ApiException {
3
- constructor(resource: string, keyValue: any, cause?: Error);
4
- }
@@ -1,15 +0,0 @@
1
- import { translate } from '@opra/i18n';
2
- import { HttpStatus } from '../../enums/index.js';
3
- import { ApiException } from '../api-exception.js';
4
- export class ResourceNotFoundError extends ApiException {
5
- constructor(resource, keyValue, cause) {
6
- super({
7
- message: translate(`error:RESOURCE_NOT_FOUND`, { resource: resource + '@' + keyValue }),
8
- severity: 'error',
9
- code: 'RESOURCE_NOT_FOUND',
10
- subject: resource,
11
- key: keyValue
12
- }, cause);
13
- this.status = HttpStatus.NOT_FOUND;
14
- }
15
- }
@@ -1,2 +0,0 @@
1
- import { ApiException, ErrorResponse } from './api-exception.js';
2
- export declare function wrapError(response: string | ErrorResponse | Error): ApiException;
@@ -1,13 +0,0 @@
1
- import { ApiException } from './api-exception.js';
2
- import { InternalServerError } from './http-errors/internal-server.error.js';
3
- export function wrapError(response) {
4
- if (response instanceof ApiException)
5
- return response;
6
- if (response instanceof Error) {
7
- const x = response;
8
- if (typeof x.status === 'number' || typeof x.getStatus === 'function')
9
- return new ApiException(response);
10
- return new InternalServerError(response);
11
- }
12
- return new InternalServerError();
13
- }
@@ -1,115 +0,0 @@
1
- import { StrictOmit } from 'ts-gems';
2
- import { EntityResource, OpraSchema } from '@opra/schema';
3
- import { Expression } from '@opra/url';
4
- import { KeyValue, QueryType } from '../types.js';
5
- export declare type OpraQuery = OpraGetSchemaQuery | OpraCreateQuery | OpraGetEntityQuery | OpraSearchQuery | OpraUpdateQuery | OpraUpdateManyQuery | OpraDeleteQuery | OpraDeleteManyQuery;
6
- interface BaseOpraQuery {
7
- queryType: QueryType;
8
- scope: OpraSchema.QueryScope;
9
- operation: OpraSchema.OperationType;
10
- }
11
- export interface OpraGetSchemaQuery extends BaseOpraQuery {
12
- queryType: 'schema';
13
- scope: OpraSchema.QueryScope;
14
- operation: 'read';
15
- resourcePath: string[];
16
- }
17
- export interface OpraCreateQuery extends BaseOpraQuery {
18
- queryType: 'create';
19
- scope: 'collection';
20
- operation: 'create';
21
- resource: EntityResource;
22
- data: {};
23
- pick?: string[];
24
- omit?: string[];
25
- include?: string[];
26
- }
27
- export interface OpraGetEntityQuery extends BaseOpraQuery {
28
- queryType: 'get';
29
- scope: 'instance';
30
- operation: 'read';
31
- resource: EntityResource;
32
- keyValue: KeyValue;
33
- pick?: string[];
34
- omit?: string[];
35
- include?: string[];
36
- nested?: OpraPropertyQuery;
37
- }
38
- export interface OpraPropertyQuery extends BaseOpraQuery {
39
- queryType: 'get';
40
- scope: 'property';
41
- operation: 'read';
42
- property: OpraSchema.Field;
43
- nested?: OpraPropertyQuery;
44
- }
45
- export interface OpraUpdateQuery extends BaseOpraQuery {
46
- queryType: 'update';
47
- scope: 'instance';
48
- operation: 'update';
49
- resource: EntityResource;
50
- keyValue: KeyValue;
51
- data: {};
52
- pick?: string[];
53
- omit?: string[];
54
- include?: string[];
55
- }
56
- export interface OpraUpdateManyQuery extends BaseOpraQuery {
57
- queryType: 'updateMany';
58
- scope: 'collection';
59
- operation: 'update';
60
- resource: EntityResource;
61
- filter?: string | Expression;
62
- data: {};
63
- }
64
- export interface OpraDeleteQuery extends BaseOpraQuery {
65
- queryType: 'delete';
66
- scope: 'instance';
67
- operation: 'delete';
68
- resource: EntityResource;
69
- keyValue: KeyValue;
70
- }
71
- export interface OpraDeleteManyQuery extends BaseOpraQuery {
72
- queryType: 'deleteMany';
73
- scope: 'collection';
74
- operation: 'delete';
75
- resource: EntityResource;
76
- filter?: string | Expression;
77
- }
78
- export interface OpraSearchQuery extends BaseOpraQuery {
79
- queryType: 'search';
80
- scope: 'collection';
81
- operation: 'read';
82
- resource: EntityResource;
83
- pick?: string[];
84
- omit?: string[];
85
- include?: string[];
86
- filter?: string | Expression;
87
- limit?: number;
88
- skip?: number;
89
- distinct?: boolean;
90
- count?: boolean;
91
- sort?: string[];
92
- }
93
- export declare type CreateQueryOptions = StrictOmit<OpraCreateQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'data'>;
94
- export declare type GetEntityQueryOptions = StrictOmit<OpraGetEntityQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'keyValue'>;
95
- export declare type SearchQueryOptions = StrictOmit<OpraSearchQuery, 'queryType' | 'scope' | 'operation' | 'resource'>;
96
- export declare type UpdateQueryOptions = StrictOmit<OpraUpdateQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'keyValue' | 'data'>;
97
- export declare type UpdateManyQueryOptions = StrictOmit<OpraUpdateManyQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'data'>;
98
- export declare type DeleteQueryOptions = StrictOmit<OpraDeleteQuery, 'queryType' | 'scope' | 'operation' | 'resource' | 'keyValue'>;
99
- export declare type DeleteManyQueryOption = StrictOmit<OpraDeleteManyQuery, 'queryType' | 'scope' | 'operation' | 'resource'>;
100
- export declare namespace OpraQuery {
101
- function forCreate(resource: EntityResource, values: {}, options?: CreateQueryOptions): OpraCreateQuery;
102
- function forGetSchema(resourcePath: string[], options?: GetEntityQueryOptions): OpraGetSchemaQuery;
103
- function forGetEntity(resource: EntityResource, key: KeyValue, options?: GetEntityQueryOptions): OpraGetEntityQuery;
104
- function forSearch(resource: EntityResource, options?: SearchQueryOptions): OpraSearchQuery;
105
- function forGetProperty(property: OpraSchema.Field, options?: StrictOmit<OpraPropertyQuery, 'queryType' | 'scope' | 'operation' | 'property'>): OpraPropertyQuery;
106
- function forUpdate(resource: EntityResource, keyValue: KeyValue, values: any, options?: UpdateQueryOptions): OpraUpdateQuery;
107
- function forUpdateMany(resource: EntityResource, values: any, options?: UpdateManyQueryOptions): OpraUpdateManyQuery;
108
- function forDelete(resource: EntityResource, key: KeyValue): OpraDeleteQuery;
109
- function forDeleteMany(resource: EntityResource, options?: DeleteManyQueryOption): OpraDeleteManyQuery;
110
- function isCreateQuery(q: any): q is OpraCreateQuery;
111
- function isSearchQuery(q: any): q is OpraSearchQuery;
112
- function isReadQuery(q: any): q is OpraGetEntityQuery;
113
- function isDeleteQuery(q: any): q is OpraDeleteQuery;
114
- }
115
- export {};
@@ -1,203 +0,0 @@
1
- import _ from 'lodash';
2
- import { ComplexType } from '@opra/schema';
3
- import { pathToTree } from '../utils/path-to-tree.js';
4
- export var OpraQuery;
5
- (function (OpraQuery) {
6
- function forCreate(resource, values, options) {
7
- if (options?.pick)
8
- options.pick = normalizePick(resource, options.pick);
9
- if (options?.omit)
10
- options.omit = normalizePick(resource, options.omit);
11
- if (options?.include)
12
- options.include = normalizePick(resource, options.include);
13
- const out = {
14
- queryType: 'create',
15
- scope: 'collection',
16
- operation: 'create',
17
- resource,
18
- data: values
19
- };
20
- Object.assign(out, _.omit(options, Object.keys(out)));
21
- return out;
22
- }
23
- OpraQuery.forCreate = forCreate;
24
- function forGetSchema(resourcePath, options) {
25
- // if (options?.pick)
26
- // options.pick = normalizePick(resource, options.pick);
27
- // if (options?.omit)
28
- // options.omit = normalizePick(resource, options.omit);
29
- // if (options?.include)
30
- // options.include = normalizePick(resource, options.include);
31
- const out = {
32
- queryType: 'schema',
33
- scope: 'instance',
34
- resourcePath,
35
- operation: 'read',
36
- };
37
- Object.assign(out, _.omit(options, Object.keys(out)));
38
- return out;
39
- }
40
- OpraQuery.forGetSchema = forGetSchema;
41
- function forGetEntity(resource, key, options) {
42
- if (options?.pick)
43
- options.pick = normalizePick(resource, options.pick);
44
- if (options?.omit)
45
- options.omit = normalizePick(resource, options.omit);
46
- if (options?.include)
47
- options.include = normalizePick(resource, options.include);
48
- checkKeyFields(resource, key);
49
- const out = {
50
- queryType: 'get',
51
- scope: 'instance',
52
- operation: 'read',
53
- resource,
54
- keyValue: key
55
- };
56
- Object.assign(out, _.omit(options, Object.keys(out)));
57
- return out;
58
- }
59
- OpraQuery.forGetEntity = forGetEntity;
60
- function forSearch(resource, options) {
61
- if (options?.pick)
62
- options.pick = normalizePick(resource, options.pick);
63
- if (options?.omit)
64
- options.omit = normalizePick(resource, options.omit);
65
- if (options?.include)
66
- options.include = normalizePick(resource, options.include);
67
- if (options?.sort)
68
- options.sort = normalizePick(resource, options.sort); // todo check allowed sort fields
69
- const out = {
70
- queryType: 'search',
71
- scope: 'collection',
72
- operation: 'read',
73
- resource
74
- };
75
- Object.assign(out, _.omit(options, Object.keys(out)));
76
- return out;
77
- }
78
- OpraQuery.forSearch = forSearch;
79
- function forGetProperty(property, options) {
80
- const out = {
81
- queryType: 'get',
82
- scope: 'property',
83
- operation: 'read',
84
- property
85
- };
86
- Object.assign(out, _.omit(options, Object.keys(out)));
87
- return out;
88
- }
89
- OpraQuery.forGetProperty = forGetProperty;
90
- function forUpdate(resource, keyValue, values, options) {
91
- if (options?.pick)
92
- options.pick = normalizePick(resource, options.pick);
93
- if (options?.omit)
94
- options.omit = normalizePick(resource, options.omit);
95
- if (options?.include)
96
- options.include = normalizePick(resource, options.include);
97
- checkKeyFields(resource, keyValue);
98
- const out = {
99
- queryType: 'update',
100
- scope: 'instance',
101
- operation: 'update',
102
- resource,
103
- keyValue,
104
- data: values
105
- };
106
- Object.assign(out, _.omit(options, Object.keys(out)));
107
- return out;
108
- }
109
- OpraQuery.forUpdate = forUpdate;
110
- function forUpdateMany(resource, values, options) {
111
- const out = {
112
- queryType: 'updateMany',
113
- scope: 'collection',
114
- operation: 'update',
115
- resource,
116
- data: values
117
- };
118
- Object.assign(out, _.omit(options, Object.keys(out)));
119
- return out;
120
- }
121
- OpraQuery.forUpdateMany = forUpdateMany;
122
- function forDelete(resource, key) {
123
- checkKeyFields(resource, key);
124
- return {
125
- queryType: 'delete',
126
- scope: 'instance',
127
- operation: 'delete',
128
- resource,
129
- keyValue: key
130
- };
131
- }
132
- OpraQuery.forDelete = forDelete;
133
- function forDeleteMany(resource, options) {
134
- const out = {
135
- queryType: 'deleteMany',
136
- scope: 'collection',
137
- operation: 'delete',
138
- resource,
139
- };
140
- Object.assign(out, _.omit(options, Object.keys(out)));
141
- return out;
142
- }
143
- OpraQuery.forDeleteMany = forDeleteMany;
144
- function isCreateQuery(q) {
145
- return q && typeof q === 'object' && q.scope === 'collection' && q.queryType === 'create';
146
- }
147
- OpraQuery.isCreateQuery = isCreateQuery;
148
- function isSearchQuery(q) {
149
- return q && typeof q === 'object' && q.scope === 'collection' && q.queryType === 'search';
150
- }
151
- OpraQuery.isSearchQuery = isSearchQuery;
152
- function isReadQuery(q) {
153
- return q && typeof q === 'object' && q.scope === 'instance' && q.queryType === 'read';
154
- }
155
- OpraQuery.isReadQuery = isReadQuery;
156
- function isDeleteQuery(q) {
157
- return q && typeof q === 'object' && q.scope === 'instance' && q.queryType === 'delete';
158
- }
159
- OpraQuery.isDeleteQuery = isDeleteQuery;
160
- })(OpraQuery || (OpraQuery = {}));
161
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
162
- function checkKeyFields(resource, key) {
163
- if (!resource.dataType.primaryKey)
164
- throw new Error(`"${resource.name}" has no primary key`);
165
- }
166
- function normalizePick(resource, fields) {
167
- const fieldsTree = pathToTree(fields) || {};
168
- return _normalizeFieldsList([], resource.service, resource, resource.dataType, fieldsTree, '', {
169
- additionalFields: true
170
- });
171
- }
172
- function _normalizeFieldsList(target, service, resource, dataType, node, parentPath = '', options) {
173
- let curPath = '';
174
- for (const k of Object.keys(node)) {
175
- const nodeVal = node[k];
176
- const prop = dataType?.fields.get(k);
177
- if (!prop) {
178
- curPath = parentPath ? parentPath + '.' + k : k;
179
- if (!options?.additionalFields || (dataType && !dataType.additionalFields))
180
- throw new TypeError(`Unknown field path "${resource.name + '.' + curPath}"`);
181
- if (typeof nodeVal === 'object')
182
- _normalizeFieldsList(target, service, resource, undefined, nodeVal, curPath, options);
183
- else
184
- target.push(curPath);
185
- continue;
186
- }
187
- curPath = parentPath ? parentPath + '.' + prop.name : prop.name;
188
- const propType = service.getDataType(prop.type || 'string');
189
- if (typeof nodeVal === 'object') {
190
- if (!(propType && propType instanceof ComplexType))
191
- throw new TypeError(`"${curPath}" is not a complex type and has no sub fields`);
192
- if (target.findIndex(x => x === parentPath) >= 0)
193
- continue;
194
- target = _normalizeFieldsList(target, service, resource, propType, nodeVal, curPath, options);
195
- continue;
196
- }
197
- if (target.findIndex(x => x.startsWith(curPath + '.')) >= 0) {
198
- target = target.filter(x => !x.startsWith(curPath + '.'));
199
- }
200
- target.push(curPath);
201
- }
202
- return target;
203
- }
@@ -1,68 +0,0 @@
1
- import { Maybe } from 'ts-gems';
2
- import { Expression } from '@opra/url';
3
- import { QueryContext } from '../implementation/query-context.js';
4
- import { IEntityService } from '../interfaces/entity-service.interface.js';
5
- import { OpraQuery } from '../interfaces/query.interface.js';
6
- import { EntityInput, EntityOutput, QueryType } from '../types.js';
7
- export interface JsonDataServiceAgs<T> {
8
- resourceName: string;
9
- data: T[];
10
- primaryKey: string;
11
- }
12
- export declare namespace JsonDataService {
13
- type GetOptions = {
14
- pick?: string[];
15
- omit?: string[];
16
- include?: string[];
17
- };
18
- type SearchOptions = {
19
- pick?: string[];
20
- omit?: string[];
21
- include?: string[];
22
- limit?: number;
23
- skip?: number;
24
- distinct?: boolean;
25
- total?: boolean;
26
- filter?: string | Expression | {};
27
- };
28
- type CreateOptions = {
29
- pick?: string[];
30
- omit?: string[];
31
- include?: string[];
32
- };
33
- type UpdateOptions = {
34
- pick?: string[];
35
- omit?: string[];
36
- include?: string[];
37
- };
38
- type UpdateManyOptions = {
39
- filter?: string | Expression | {};
40
- };
41
- type DeleteManyOptions = {
42
- filter?: string | Expression | {};
43
- };
44
- }
45
- export declare class JsonDataService<T, TOutput = EntityOutput<T>> implements IEntityService {
46
- resourceName: string;
47
- data: T[];
48
- primaryKey: string;
49
- constructor(args: JsonDataServiceAgs<T>);
50
- processRequest(ctx: QueryContext): any;
51
- get(keyValue: any, options?: JsonDataService.GetOptions): Maybe<TOutput>;
52
- count(options?: JsonDataService.SearchOptions): Maybe<number>;
53
- search(options?: JsonDataService.SearchOptions): Maybe<TOutput>[];
54
- create(data: EntityInput<T>, options?: JsonDataService.CreateOptions): TOutput;
55
- update(keyValue: any, data: EntityInput<T>, options?: JsonDataService.UpdateOptions): Maybe<TOutput>;
56
- updateMany(data: EntityInput<T>, options?: JsonDataService.UpdateManyOptions): number;
57
- delete(keyValue: any): boolean;
58
- deleteMany(options?: JsonDataService.DeleteManyOptions): number;
59
- static filterFields(obj: any, pick: string[] | undefined, omit: string[] | undefined, include: string[] | undefined): any;
60
- static prepare(query: OpraQuery): {
61
- method: QueryType;
62
- options: any;
63
- keyValue?: any;
64
- values?: any;
65
- args: any[];
66
- };
67
- static convertFilter(str: string | Expression | undefined | {}): any;
68
- }