@opra/core 0.0.8 → 0.0.9

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 (69) hide show
  1. package/cjs/exception/api-exception.js +30 -33
  2. package/cjs/exception/errors/bad-request.error.js +6 -3
  3. package/cjs/exception/errors/failed-dependency.error.js +6 -3
  4. package/cjs/exception/errors/forbidden.error.js +6 -3
  5. package/cjs/exception/errors/internal-server.error.js +9 -4
  6. package/cjs/exception/errors/method-not-allowed.error.js +6 -3
  7. package/cjs/exception/errors/not-found.error.js +6 -3
  8. package/cjs/exception/errors/unauthorized.error.js +6 -3
  9. package/cjs/exception/errors/unprocessable-entity.error.js +6 -3
  10. package/cjs/exception/wrap-error.js +1 -1
  11. package/cjs/implementation/adapter/adapter.js +29 -26
  12. package/cjs/implementation/adapter/express-adapter.js +40 -9
  13. package/cjs/implementation/adapter/http-adapter.js +27 -34
  14. package/cjs/implementation/{execution-context.js → query-context.js} +18 -22
  15. package/cjs/implementation/resource/entity-resource-handler.js +16 -12
  16. package/cjs/implementation/resource/resource-handler.js +1 -1
  17. package/cjs/implementation/schema-generator.js +38 -51
  18. package/cjs/index.js +3 -4
  19. package/cjs/interfaces/{http-context.interface.js → execution-context.interface.js} +0 -0
  20. package/cjs/interfaces/{execution-query.interface.js → query.interface.js} +16 -16
  21. package/cjs/utils/internal-data-types.js +54 -17
  22. package/esm/exception/api-exception.d.ts +3 -2
  23. package/esm/exception/api-exception.js +30 -33
  24. package/esm/exception/errors/bad-request.error.d.ts +2 -1
  25. package/esm/exception/errors/bad-request.error.js +6 -3
  26. package/esm/exception/errors/failed-dependency.error.d.ts +2 -1
  27. package/esm/exception/errors/failed-dependency.error.js +6 -3
  28. package/esm/exception/errors/forbidden.error.d.ts +2 -1
  29. package/esm/exception/errors/forbidden.error.js +6 -3
  30. package/esm/exception/errors/internal-server.error.d.ts +2 -1
  31. package/esm/exception/errors/internal-server.error.js +8 -4
  32. package/esm/exception/errors/method-not-allowed.error.d.ts +2 -1
  33. package/esm/exception/errors/method-not-allowed.error.js +6 -3
  34. package/esm/exception/errors/not-found.error.d.ts +2 -1
  35. package/esm/exception/errors/not-found.error.js +6 -3
  36. package/esm/exception/errors/unauthorized.error.d.ts +2 -1
  37. package/esm/exception/errors/unauthorized.error.js +6 -3
  38. package/esm/exception/errors/unprocessable-entity.error.d.ts +2 -1
  39. package/esm/exception/errors/unprocessable-entity.error.js +6 -3
  40. package/esm/exception/wrap-error.js +1 -1
  41. package/esm/implementation/adapter/adapter.d.ts +22 -14
  42. package/esm/implementation/adapter/adapter.js +29 -26
  43. package/esm/implementation/adapter/express-adapter.d.ts +2 -2
  44. package/esm/implementation/adapter/express-adapter.js +40 -9
  45. package/esm/implementation/adapter/http-adapter.d.ts +11 -12
  46. package/esm/implementation/adapter/http-adapter.js +27 -34
  47. package/esm/implementation/query-context.d.ts +32 -0
  48. package/esm/implementation/{execution-context.js → query-context.js} +15 -18
  49. package/esm/implementation/resource/container-resource-handler.d.ts +2 -2
  50. package/esm/implementation/resource/entity-resource-handler.d.ts +3 -3
  51. package/esm/implementation/resource/entity-resource-handler.js +16 -12
  52. package/esm/implementation/resource/resource-handler.d.ts +3 -3
  53. package/esm/implementation/resource/resource-handler.js +1 -1
  54. package/esm/implementation/schema-generator.js +38 -51
  55. package/esm/index.d.ts +3 -4
  56. package/esm/index.js +3 -4
  57. package/esm/interfaces/execution-context.interface.d.ts +39 -0
  58. package/esm/interfaces/{http-context.interface.js → execution-context.interface.js} +0 -0
  59. package/esm/interfaces/{execution-query.interface.d.ts → query.interface.d.ts} +31 -25
  60. package/esm/interfaces/{execution-query.interface.js → query.interface.js} +15 -15
  61. package/esm/services/entity-resource-controller.d.ts +11 -11
  62. package/esm/utils/internal-data-types.d.ts +2 -1
  63. package/esm/utils/internal-data-types.js +53 -16
  64. package/package.json +6 -5
  65. package/cjs/interfaces/user-context.interface.js +0 -2
  66. package/esm/implementation/execution-context.d.ts +0 -42
  67. package/esm/interfaces/http-context.interface.d.ts +0 -23
  68. package/esm/interfaces/user-context.interface.d.ts +0 -3
  69. package/esm/interfaces/user-context.interface.js +0 -1
@@ -1,36 +1,33 @@
1
1
  import { OpraURLSearchParams } from '@opra/url';
2
2
  import { Headers } from '../utils/headers.js';
3
- export class ExecutionContext {
4
- type;
3
+ export class QueryContext {
5
4
  service;
6
- request;
7
- response;
8
- adapterContext;
9
- userContext;
10
- continueOnError;
11
- constructor(args) {
12
- Object.assign(this, args);
13
- }
14
- switchToHttp() {
15
- if (this.type !== 'http')
16
- throw new Error(`You can't access http context within an ${this.type} context`);
17
- return this.adapterContext;
18
- }
19
- }
20
- export class ExecutionRequest {
5
+ executionContext;
21
6
  query;
22
7
  params;
23
8
  headers;
24
9
  parentValue;
25
10
  resultPath;
11
+ response;
12
+ userContext;
13
+ continueOnError;
26
14
  constructor(args) {
27
15
  Object.assign(this, args);
16
+ this.response = new QueryResponse();
28
17
  this.params = this.params || new OpraURLSearchParams();
29
18
  this.headers = this.headers || Headers.create();
30
19
  this.resultPath = this.resultPath || '';
31
20
  }
21
+ get type() {
22
+ return this.executionContext.getType();
23
+ }
24
+ switchToHttp() {
25
+ if (this.type !== 'http')
26
+ throw new Error(`You can't access http context within an ${this.type} context`);
27
+ return this.executionContext;
28
+ }
32
29
  }
33
- export class ExecutionResponse {
30
+ export class QueryResponse {
34
31
  headers = Headers.create();
35
32
  errors = [];
36
33
  status;
@@ -1,7 +1,7 @@
1
1
  import { StrictOmit } from 'ts-gems';
2
2
  import { OpraSchema } from '@opra/schema';
3
3
  import { IResourceContainer } from '../../interfaces/resource-container.interface.js';
4
- import { ExecutionContext } from '../execution-context.js';
4
+ import { QueryContext } from '../query-context.js';
5
5
  import { EntityResourceHandler } from './entity-resource-handler.js';
6
6
  import { ResourceHandler } from './resource-handler.js';
7
7
  export declare type ContainerResourceControllerArgs = StrictOmit<OpraSchema.ContainerResource, 'kind'> & {};
@@ -10,5 +10,5 @@ export declare class ContainerResourceHandler extends ResourceHandler implements
10
10
  constructor(args: ContainerResourceControllerArgs);
11
11
  getResource<T extends ResourceHandler>(name: string): T;
12
12
  getEntityResource(name: string): EntityResourceHandler;
13
- execute(ctx: ExecutionContext): Promise<void>;
13
+ execute(ctx: QueryContext): Promise<void>;
14
14
  }
@@ -1,8 +1,8 @@
1
1
  import { StrictOmit } from 'ts-gems';
2
2
  import { OpraSchema } from '@opra/schema';
3
3
  import { EntityType } from '../data-type/entity-type.js';
4
- import { ExecutionContext } from '../execution-context.js';
5
4
  import { OpraService } from '../opra-service.js';
5
+ import { QueryContext } from '../query-context.js';
6
6
  import { ResourceHandler } from './resource-handler.js';
7
7
  export declare type EntityResourceControllerArgs = StrictOmit<OpraSchema.EntityResource, 'kind'> & {
8
8
  service: OpraService;
@@ -13,6 +13,6 @@ export declare class EntityResourceHandler extends ResourceHandler {
13
13
  readonly service: OpraService;
14
14
  readonly dataType: EntityType;
15
15
  constructor(args: EntityResourceControllerArgs);
16
- execute(ctx: ExecutionContext): Promise<void>;
17
- _executeFn(ctx: ExecutionContext, fnName: string): Promise<any>;
16
+ execute(ctx: QueryContext): Promise<void>;
17
+ _executeFn(ctx: QueryContext, fnName: string): Promise<any>;
18
18
  }
@@ -1,8 +1,9 @@
1
1
  import _ from 'lodash';
2
- import { ExecutionQuery } from '../../interfaces/execution-query.interface.js';
2
+ import { OpraQuery } from '../../interfaces/query.interface.js';
3
3
  import { EntityType } from '../data-type/entity-type.js';
4
4
  import { ResourceHandler } from './resource-handler.js';
5
- var isSearchQuery = ExecutionQuery.isSearchQuery;
5
+ var isSearchQuery = OpraQuery.isSearchQuery;
6
+ import { UnprocessableEntityError } from '../../exception/index.js';
6
7
  export class EntityResourceHandler extends ResourceHandler {
7
8
  service;
8
9
  dataType;
@@ -18,7 +19,7 @@ export class EntityResourceHandler extends ResourceHandler {
18
19
  throw new TypeError(`You should provide an EntityType for EntityResourceController`);
19
20
  }
20
21
  async execute(ctx) {
21
- const { query } = ctx.request;
22
+ const { query } = ctx;
22
23
  if (isSearchQuery(query)) {
23
24
  const promises = [];
24
25
  let search;
@@ -57,15 +58,18 @@ export class EntityResourceHandler extends ResourceHandler {
57
58
  if (typeof result === 'object')
58
59
  affectedRecords = result.affectedRows || result.affectedRecords;
59
60
  return { affectedRecords };
60
- default:
61
- result = Array.isArray(result) ? result[0] : result;
62
- if (result && ctx.request.resultPath) {
63
- const pathArray = ctx.request.resultPath.split('.');
64
- for (const property of pathArray) {
65
- result = result && typeof result === 'object' && result[property];
66
- }
67
- }
68
- return result;
69
61
  }
62
+ result = Array.isArray(result) ? result[0] : result;
63
+ if (!result)
64
+ throw new UnprocessableEntityError();
65
+ if (ctx.resultPath) {
66
+ const pathArray = ctx.resultPath.split('.');
67
+ for (const property of pathArray) {
68
+ result = result && typeof result === 'object' && result[property];
69
+ }
70
+ }
71
+ if (fnName === 'create')
72
+ ctx.response.status = 201;
73
+ return result;
70
74
  }
71
75
  }
@@ -1,6 +1,6 @@
1
1
  import { OpraSchema } from '@opra/schema';
2
2
  import { nodeInspectCustom } from '../../utils/terminal-utils.js';
3
- import { ExecutionContext } from '../execution-context.js';
3
+ import { QueryContext } from '../query-context.js';
4
4
  export declare abstract class ResourceHandler {
5
5
  protected readonly _args: OpraSchema.Resource & {
6
6
  prepare?: Function;
@@ -9,7 +9,7 @@ export declare abstract class ResourceHandler {
9
9
  get name(): string;
10
10
  get description(): string | undefined;
11
11
  toString(): string;
12
- prepare(ctx: ExecutionContext): Promise<void>;
13
- abstract execute(ctx: ExecutionContext): Promise<void>;
12
+ prepare(ctx: QueryContext): Promise<void>;
13
+ abstract execute(ctx: QueryContext): Promise<void>;
14
14
  [nodeInspectCustom](): string;
15
15
  }
@@ -14,7 +14,7 @@ export class ResourceHandler {
14
14
  return `[${Object.getPrototypeOf(this).constructor.name} ${this.name}]`;
15
15
  }
16
16
  async prepare(ctx) {
17
- const { query } = ctx.request;
17
+ const { query } = ctx;
18
18
  const fn = this._args['pre_' + query.queryType];
19
19
  if (fn && typeof fn === 'function') {
20
20
  await fn(ctx);
@@ -3,6 +3,7 @@ import { DATATYPE_METADATA, DATATYPE_PROPERTIES, OpraSchema } from '@opra/schema
3
3
  import { RESOURCE_METADATA } from '../constants.js';
4
4
  import { isConstructor, resolveClassAsync } from '../utils/class-utils.js';
5
5
  import { builtinClassMap, internalDataTypes, primitiveDataTypeNames } from '../utils/internal-data-types.js';
6
+ var isDataType = OpraSchema.isDataType;
6
7
  const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
7
8
  export class SchemaGenerator {
8
9
  _dataTypes = {};
@@ -11,24 +12,16 @@ export class SchemaGenerator {
11
12
  //
12
13
  }
13
14
  async addDataType(thunk) {
14
- let schema;
15
15
  thunk = isPromise(thunk) ? await thunk : thunk;
16
- if (typeof thunk === 'function' && !isConstructor(thunk))
17
- thunk = await thunk();
18
- if (!isConstructor(thunk) || OpraSchema.isDataType(thunk))
19
- throw new TypeError(`Function must return a type class or type schema`);
20
- if (isConstructor(thunk)) {
16
+ if (typeof thunk === 'function') {
17
+ if (!isConstructor(thunk))
18
+ return this.addDataType(await thunk());
19
+ if (builtinClassMap.has(thunk))
20
+ return this.addDataType(builtinClassMap.get(thunk));
21
21
  const ctor = thunk;
22
22
  const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, ctor);
23
23
  if (!metadata)
24
24
  throw new TypeError(`Class "${ctor}" has no type metadata`);
25
- schema = this._dataTypes[metadata.name];
26
- if (schema) {
27
- if (schema.kind !== metadata.kind ||
28
- (OpraSchema.isComplexType(schema) && schema.ctor !== ctor))
29
- throw new Error(`An other instance of "${schema.name}" data type previously defined`);
30
- return schema;
31
- }
32
25
  // Add base data type
33
26
  let base;
34
27
  let baseCtor = Object.getPrototypeOf(ctor);
@@ -39,49 +32,43 @@ export class SchemaGenerator {
39
32
  const baseSchema = await this.addDataType(baseCtor);
40
33
  base = baseSchema.name;
41
34
  }
42
- if (OpraSchema.isComplexType(metadata) || OpraSchema.isEntityType(metadata)) {
43
- schema = {
44
- ...metadata,
45
- ctor,
46
- base
47
- };
48
- const properties = Reflect.getMetadata(DATATYPE_PROPERTIES, ctor.prototype);
49
- if (properties) {
50
- for (const [k, p] of Object.entries(properties)) {
51
- let type;
52
- if (isConstructor(p.type) && builtinClassMap.has(p.type))
53
- type = builtinClassMap.get(p.type);
54
- else if (typeof p.type === 'function' || typeof p.type === 'object') {
55
- const t = await this.addDataType(p.type);
56
- type = t.name;
57
- }
58
- else
59
- type = p.type || 'string';
60
- if (internalDataTypes.has(type) && !this._dataTypes[type])
61
- this._dataTypes[type] = internalDataTypes.get(type.toLowerCase());
62
- schema.properties = schema.properties || {};
63
- schema.properties[k] = { ...p, type };
35
+ const schema = {
36
+ ...metadata,
37
+ ctor,
38
+ base
39
+ };
40
+ const properties = Reflect.getMetadata(DATATYPE_PROPERTIES, ctor.prototype);
41
+ if (properties) {
42
+ for (const [k, p] of Object.entries(properties)) {
43
+ let type = p.type || 'string';
44
+ if (typeof type !== 'string') {
45
+ const propSchema = await this.addDataType(type);
46
+ type = propSchema.name;
64
47
  }
48
+ else {
49
+ if (internalDataTypes.has(type))
50
+ await this.addDataType(internalDataTypes.get(type));
51
+ }
52
+ schema.properties = schema.properties || {};
53
+ schema.properties[k] = { ...p, type };
65
54
  }
66
55
  }
67
- else if (OpraSchema.isSimpleType(metadata)) {
68
- if (!primitiveDataTypeNames.includes(metadata.type))
69
- throw new Error(`"type" of SimpleType schema must be one of enumerated value (${primitiveDataTypeNames})`);
70
- schema = {
71
- ...metadata
72
- };
73
- }
74
- else
75
- /* istanbul ignore next */
76
- throw new TypeError(`Invalid metadata`);
56
+ return this.addDataType(schema);
77
57
  }
78
- else if (OpraSchema.isDataType(thunk)) {
79
- schema = thunk;
80
- }
81
- else
58
+ if (!isDataType(thunk))
82
59
  throw new TypeError(`Invalid data type schema`);
83
- this._dataTypes[schema.name] = schema;
84
- return schema;
60
+ // Check if datatype previously added
61
+ const currentSchema = this._dataTypes[thunk.name];
62
+ if (currentSchema) {
63
+ if (!(currentSchema.kind === thunk.kind && currentSchema.ctor && currentSchema.ctor === thunk.ctor))
64
+ throw new Error(`An other instance of "${currentSchema.name}" data type previously defined`);
65
+ return currentSchema;
66
+ }
67
+ if (OpraSchema.isSimpleType(thunk) && !primitiveDataTypeNames.includes(thunk.type))
68
+ throw new Error(`"type" of SimpleType schema must be one of enumerated value (${primitiveDataTypeNames})`);
69
+ return this._dataTypes[thunk.name] = {
70
+ ...thunk
71
+ };
85
72
  }
86
73
  async addResource(instance) {
87
74
  if (isConstructor(instance))
package/esm/index.d.ts CHANGED
@@ -4,11 +4,10 @@ export * from './types.js';
4
4
  export * from './enums/index.js';
5
5
  export * from './exception/index.js';
6
6
  export * from './decorators/entity-resource.decorator.js';
7
- export * from './interfaces/http-context.interface.js';
8
- export * from './interfaces/execution-query.interface.js';
7
+ export * from './interfaces/execution-context.interface.js';
8
+ export * from './interfaces/query.interface.js';
9
9
  export * from './interfaces/resource-container.interface.js';
10
- export * from './interfaces/user-context.interface.js';
11
- export * from './implementation/execution-context.js';
10
+ export * from './implementation/query-context.js';
12
11
  export * from './implementation/opra-document.js';
13
12
  export * from './implementation/opra-service.js';
14
13
  export * from './implementation/schema-generator.js';
package/esm/index.js CHANGED
@@ -4,11 +4,10 @@ export * from './types.js';
4
4
  export * from './enums/index.js';
5
5
  export * from './exception/index.js';
6
6
  export * from './decorators/entity-resource.decorator.js';
7
- export * from './interfaces/http-context.interface.js';
8
- export * from './interfaces/execution-query.interface.js';
7
+ export * from './interfaces/execution-context.interface.js';
8
+ export * from './interfaces/query.interface.js';
9
9
  export * from './interfaces/resource-container.interface.js';
10
- export * from './interfaces/user-context.interface.js';
11
- export * from './implementation/execution-context.js';
10
+ export * from './implementation/query-context.js';
12
11
  export * from './implementation/opra-document.js';
13
12
  export * from './implementation/opra-service.js';
14
13
  export * from './implementation/schema-generator.js';
@@ -0,0 +1,39 @@
1
+ export declare type ContextType = 'http' | 'ws' | 'rpc';
2
+ export declare type PlatformType = 'express';
3
+ export declare namespace IExecutionContext {
4
+ type OnFinishArgs = {
5
+ userContext: any;
6
+ failed: boolean;
7
+ };
8
+ }
9
+ export interface IExecutionContext {
10
+ getType(): ContextType;
11
+ getPlatform(): PlatformType;
12
+ switchToHttp(): IHttpExecutionContext;
13
+ onFinish(fn: (args: IExecutionContext.OnFinishArgs) => void | Promise<void>): any;
14
+ }
15
+ export interface IHttpExecutionContext extends IExecutionContext {
16
+ getRequest(): any;
17
+ getResponse(): any;
18
+ getRequestWrapper(): IHttpRequestWrapper;
19
+ getResponseWrapper(): IHttpResponseWrapper;
20
+ }
21
+ export interface IHttpRequestWrapper {
22
+ getInstance(): any;
23
+ getUrl(): string;
24
+ getMethod(): string;
25
+ getHeaderNames(): string[];
26
+ getHeader(name: string): string | undefined;
27
+ getHeaders(): Record<string, any>;
28
+ getBody(): any;
29
+ }
30
+ export interface IHttpResponseWrapper {
31
+ getInstance(): any;
32
+ getStatus(): number | undefined;
33
+ setStatus(value: number): this;
34
+ getHeaderNames(name: string): string[];
35
+ getHeader(name: string): string | undefined;
36
+ setHeader(name: string, value: string): this;
37
+ send(body: any): this;
38
+ end(): this;
39
+ }
@@ -3,13 +3,13 @@ import { OpraSchema } from '@opra/schema';
3
3
  import { Expression } from '@opra/url';
4
4
  import { EntityResourceHandler } from '../implementation/resource/entity-resource-handler.js';
5
5
  import { KeyValue, OperationType, QueryScope, QueryType } from '../types.js';
6
- export declare type ExecutionQuery = CreateQuery | ReadQuery | SearchQuery | UpdateQuery | UpdateManyQuery | DeleteQuery | DeleteManyQuery;
7
- interface BaseQuery {
6
+ export declare type OpraQuery = OpraCreateQuery | OpraGetQuery | OpraSearchQuery | OpraUpdateQuery | OpraUpdateManyQuery | OpraDeleteQuery | OpraDeleteManyQuery;
7
+ interface BaseOpraQuery {
8
8
  queryType: QueryType;
9
9
  scope: QueryScope;
10
10
  operationType: OperationType;
11
11
  }
12
- export interface CreateQuery extends BaseQuery {
12
+ export interface OpraCreateQuery extends BaseOpraQuery {
13
13
  queryType: 'create';
14
14
  scope: 'collection';
15
15
  operationType: 'create';
@@ -19,7 +19,7 @@ export interface CreateQuery extends BaseQuery {
19
19
  omit?: string[];
20
20
  include?: string[];
21
21
  }
22
- export interface ReadQuery extends BaseQuery {
22
+ export interface OpraGetQuery extends BaseOpraQuery {
23
23
  queryType: 'get';
24
24
  scope: 'instance';
25
25
  operationType: 'read';
@@ -28,16 +28,16 @@ export interface ReadQuery extends BaseQuery {
28
28
  pick?: string[];
29
29
  omit?: string[];
30
30
  include?: string[];
31
- nested?: PropertyQuery;
31
+ nested?: OpraPropertyQuery;
32
32
  }
33
- export interface PropertyQuery extends BaseQuery {
33
+ export interface OpraPropertyQuery extends BaseOpraQuery {
34
34
  queryType: 'get';
35
35
  scope: 'property';
36
36
  operationType: 'read';
37
37
  property: OpraSchema.Property;
38
- nested?: PropertyQuery;
38
+ nested?: OpraPropertyQuery;
39
39
  }
40
- export interface UpdateQuery extends BaseQuery {
40
+ export interface OpraUpdateQuery extends BaseOpraQuery {
41
41
  queryType: 'update';
42
42
  scope: 'instance';
43
43
  operationType: 'update';
@@ -48,7 +48,7 @@ export interface UpdateQuery extends BaseQuery {
48
48
  omit?: string[];
49
49
  include?: string[];
50
50
  }
51
- export interface UpdateManyQuery extends BaseQuery {
51
+ export interface OpraUpdateManyQuery extends BaseOpraQuery {
52
52
  queryType: 'updateMany';
53
53
  scope: 'collection';
54
54
  operationType: 'update';
@@ -56,21 +56,21 @@ export interface UpdateManyQuery extends BaseQuery {
56
56
  filter?: string | Expression;
57
57
  data: {};
58
58
  }
59
- export interface DeleteQuery extends BaseQuery {
59
+ export interface OpraDeleteQuery extends BaseOpraQuery {
60
60
  queryType: 'delete';
61
61
  scope: 'instance';
62
62
  operationType: 'delete';
63
63
  resource: EntityResourceHandler;
64
64
  keyValue: KeyValue;
65
65
  }
66
- export interface DeleteManyQuery extends BaseQuery {
66
+ export interface OpraDeleteManyQuery extends BaseOpraQuery {
67
67
  queryType: 'deleteMany';
68
68
  scope: 'collection';
69
69
  operationType: 'delete';
70
70
  resource: EntityResourceHandler;
71
71
  filter?: string | Expression;
72
72
  }
73
- export interface SearchQuery extends BaseQuery {
73
+ export interface OpraSearchQuery extends BaseOpraQuery {
74
74
  queryType: 'search';
75
75
  scope: 'collection';
76
76
  operationType: 'read';
@@ -85,18 +85,24 @@ export interface SearchQuery extends BaseQuery {
85
85
  count?: boolean;
86
86
  sort?: string[];
87
87
  }
88
- export declare namespace ExecutionQuery {
89
- function forCreate(resource: EntityResourceHandler, values: {}, options?: StrictOmit<CreateQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'data'>): CreateQuery;
90
- function forGet(resource: EntityResourceHandler, key: KeyValue, options?: StrictOmit<ReadQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'keyValue'>): ReadQuery;
91
- function forSearch(resource: EntityResourceHandler, options?: StrictOmit<SearchQuery, 'queryType' | 'scope' | 'operationType' | 'resource'>): SearchQuery;
92
- function forGetProperty(property: OpraSchema.Property, options?: StrictOmit<PropertyQuery, 'queryType' | 'scope' | 'operationType' | 'property'>): PropertyQuery;
93
- function forUpdate(resource: EntityResourceHandler, keyValue: KeyValue, values: any, options?: StrictOmit<UpdateQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'keyValue' | 'data'>): UpdateQuery;
94
- function forUpdateMany(resource: EntityResourceHandler, values: any, options?: StrictOmit<UpdateManyQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'data'>): UpdateManyQuery;
95
- function forDelete(resource: EntityResourceHandler, key: KeyValue): DeleteQuery;
96
- function forDeleteMany(resource: EntityResourceHandler, options?: StrictOmit<DeleteManyQuery, 'queryType' | 'scope' | 'operationType' | 'resource'>): DeleteManyQuery;
97
- function isCreateQuery(q: any): q is CreateQuery;
98
- function isSearchQuery(q: any): q is SearchQuery;
99
- function isReadQuery(q: any): q is ReadQuery;
100
- function isDeleteQuery(q: any): q is DeleteQuery;
88
+ export declare type CreateQueryOptions = StrictOmit<OpraCreateQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'data'>;
89
+ export declare type GetQueryOptions = StrictOmit<OpraGetQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'keyValue'>;
90
+ export declare type SearchQueryOptions = StrictOmit<OpraSearchQuery, 'queryType' | 'scope' | 'operationType' | 'resource'>;
91
+ export declare type UpdateQueryOptions = StrictOmit<OpraUpdateQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'keyValue' | 'data'>;
92
+ export declare type UpdateManyQueryOptions = StrictOmit<OpraUpdateManyQuery, 'queryType' | 'scope' | 'operationType' | 'resource' | 'data'>;
93
+ export declare type DeleteManyQueryOption = StrictOmit<OpraDeleteManyQuery, 'queryType' | 'scope' | 'operationType' | 'resource'>;
94
+ export declare namespace OpraQuery {
95
+ function forCreate(resource: EntityResourceHandler, values: {}, options?: CreateQueryOptions): OpraCreateQuery;
96
+ function forGet(resource: EntityResourceHandler, key: KeyValue, options?: GetQueryOptions): OpraGetQuery;
97
+ function forSearch(resource: EntityResourceHandler, options?: SearchQueryOptions): OpraSearchQuery;
98
+ function forGetProperty(property: OpraSchema.Property, options?: StrictOmit<OpraPropertyQuery, 'queryType' | 'scope' | 'operationType' | 'property'>): OpraPropertyQuery;
99
+ function forUpdate(resource: EntityResourceHandler, keyValue: KeyValue, values: any, options?: UpdateQueryOptions): OpraUpdateQuery;
100
+ function forUpdateMany(resource: EntityResourceHandler, values: any, options?: UpdateManyQueryOptions): OpraUpdateManyQuery;
101
+ function forDelete(resource: EntityResourceHandler, key: KeyValue): OpraDeleteQuery;
102
+ function forDeleteMany(resource: EntityResourceHandler, options?: DeleteManyQueryOption): OpraDeleteManyQuery;
103
+ function isCreateQuery(q: any): q is OpraCreateQuery;
104
+ function isSearchQuery(q: any): q is OpraSearchQuery;
105
+ function isReadQuery(q: any): q is OpraGetQuery;
106
+ function isDeleteQuery(q: any): q is OpraDeleteQuery;
101
107
  }
102
108
  export {};
@@ -1,8 +1,8 @@
1
1
  import _ from 'lodash';
2
2
  import { ComplexType } from '../implementation/data-type/complex-type.js';
3
3
  import { stringPathToObjectTree } from '../utils/string-path-to-object-tree.js';
4
- export var ExecutionQuery;
5
- (function (ExecutionQuery) {
4
+ export var OpraQuery;
5
+ (function (OpraQuery) {
6
6
  function forCreate(resource, values, options) {
7
7
  if (options?.pick)
8
8
  options.pick = normalizePick(resource, options.pick);
@@ -20,7 +20,7 @@ export var ExecutionQuery;
20
20
  Object.assign(out, _.omit(options, Object.keys(out)));
21
21
  return out;
22
22
  }
23
- ExecutionQuery.forCreate = forCreate;
23
+ OpraQuery.forCreate = forCreate;
24
24
  function forGet(resource, key, options) {
25
25
  if (options?.pick)
26
26
  options.pick = normalizePick(resource, options.pick);
@@ -39,7 +39,7 @@ export var ExecutionQuery;
39
39
  Object.assign(out, _.omit(options, Object.keys(out)));
40
40
  return out;
41
41
  }
42
- ExecutionQuery.forGet = forGet;
42
+ OpraQuery.forGet = forGet;
43
43
  function forSearch(resource, options) {
44
44
  if (options?.pick)
45
45
  options.pick = normalizePick(resource, options.pick);
@@ -58,7 +58,7 @@ export var ExecutionQuery;
58
58
  Object.assign(out, _.omit(options, Object.keys(out)));
59
59
  return out;
60
60
  }
61
- ExecutionQuery.forSearch = forSearch;
61
+ OpraQuery.forSearch = forSearch;
62
62
  function forGetProperty(property, options) {
63
63
  const out = {
64
64
  queryType: 'get',
@@ -69,7 +69,7 @@ export var ExecutionQuery;
69
69
  Object.assign(out, _.omit(options, Object.keys(out)));
70
70
  return out;
71
71
  }
72
- ExecutionQuery.forGetProperty = forGetProperty;
72
+ OpraQuery.forGetProperty = forGetProperty;
73
73
  function forUpdate(resource, keyValue, values, options) {
74
74
  if (options?.pick)
75
75
  options.pick = normalizePick(resource, options.pick);
@@ -89,7 +89,7 @@ export var ExecutionQuery;
89
89
  Object.assign(out, _.omit(options, Object.keys(out)));
90
90
  return out;
91
91
  }
92
- ExecutionQuery.forUpdate = forUpdate;
92
+ OpraQuery.forUpdate = forUpdate;
93
93
  function forUpdateMany(resource, values, options) {
94
94
  const out = {
95
95
  queryType: 'updateMany',
@@ -101,7 +101,7 @@ export var ExecutionQuery;
101
101
  Object.assign(out, _.omit(options, Object.keys(out)));
102
102
  return out;
103
103
  }
104
- ExecutionQuery.forUpdateMany = forUpdateMany;
104
+ OpraQuery.forUpdateMany = forUpdateMany;
105
105
  function forDelete(resource, key) {
106
106
  checkKeyFields(resource, key);
107
107
  return {
@@ -112,7 +112,7 @@ export var ExecutionQuery;
112
112
  keyValue: key
113
113
  };
114
114
  }
115
- ExecutionQuery.forDelete = forDelete;
115
+ OpraQuery.forDelete = forDelete;
116
116
  function forDeleteMany(resource, options) {
117
117
  const out = {
118
118
  queryType: 'deleteMany',
@@ -123,24 +123,24 @@ export var ExecutionQuery;
123
123
  Object.assign(out, _.omit(options, Object.keys(out)));
124
124
  return out;
125
125
  }
126
- ExecutionQuery.forDeleteMany = forDeleteMany;
126
+ OpraQuery.forDeleteMany = forDeleteMany;
127
127
  function isCreateQuery(q) {
128
128
  return q && typeof q === 'object' && q.scope === 'collection' && q.queryType === 'create';
129
129
  }
130
- ExecutionQuery.isCreateQuery = isCreateQuery;
130
+ OpraQuery.isCreateQuery = isCreateQuery;
131
131
  function isSearchQuery(q) {
132
132
  return q && typeof q === 'object' && q.scope === 'collection' && q.queryType === 'search';
133
133
  }
134
- ExecutionQuery.isSearchQuery = isSearchQuery;
134
+ OpraQuery.isSearchQuery = isSearchQuery;
135
135
  function isReadQuery(q) {
136
136
  return q && typeof q === 'object' && q.scope === 'instance' && q.queryType === 'read';
137
137
  }
138
- ExecutionQuery.isReadQuery = isReadQuery;
138
+ OpraQuery.isReadQuery = isReadQuery;
139
139
  function isDeleteQuery(q) {
140
140
  return q && typeof q === 'object' && q.scope === 'instance' && q.queryType === 'delete';
141
141
  }
142
- ExecutionQuery.isDeleteQuery = isDeleteQuery;
143
- })(ExecutionQuery || (ExecutionQuery = {}));
142
+ OpraQuery.isDeleteQuery = isDeleteQuery;
143
+ })(OpraQuery || (OpraQuery = {}));
144
144
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
145
145
  function checkKeyFields(resource, key) {
146
146
  if (!resource.dataType.primaryKey)
@@ -1,17 +1,17 @@
1
1
  import { Maybe } from 'ts-gems';
2
2
  import { EntityOutput } from '@sqb/connect';
3
- import { ExecutionContext } from '../implementation/execution-context.js';
3
+ import { QueryContext } from '../implementation/query-context.js';
4
4
  export interface IEntityService {
5
- processRequest(ctx: ExecutionContext): any;
5
+ processRequest(ctx: QueryContext): any;
6
6
  }
7
7
  export declare abstract class EntityResourceController<T> {
8
- search(ctx: ExecutionContext): Promise<Maybe<EntityOutput<T>>[]>;
9
- get(ctx: ExecutionContext): Promise<Maybe<EntityOutput<T>>>;
10
- count(ctx: ExecutionContext): Promise<Maybe<number>>;
11
- create(ctx: ExecutionContext): Promise<Maybe<EntityOutput<T>>>;
12
- update(ctx: ExecutionContext): Promise<Maybe<EntityOutput<T>>>;
13
- updateMany(ctx: ExecutionContext): Promise<Maybe<number>>;
14
- delete(ctx: ExecutionContext): Promise<Maybe<boolean | number>>;
15
- deleteMany(ctx: ExecutionContext): Promise<Maybe<number>>;
16
- abstract getService(ctx: ExecutionContext): IEntityService | Promise<IEntityService>;
8
+ search(ctx: QueryContext): Promise<Maybe<EntityOutput<T>>[]>;
9
+ get(ctx: QueryContext): Promise<Maybe<EntityOutput<T>>>;
10
+ count(ctx: QueryContext): Promise<Maybe<number>>;
11
+ create(ctx: QueryContext): Promise<Maybe<EntityOutput<T>>>;
12
+ update(ctx: QueryContext): Promise<Maybe<EntityOutput<T>>>;
13
+ updateMany(ctx: QueryContext): Promise<Maybe<number>>;
14
+ delete(ctx: QueryContext): Promise<Maybe<boolean | number>>;
15
+ deleteMany(ctx: QueryContext): Promise<Maybe<number>>;
16
+ abstract getService(ctx: QueryContext): IEntityService | Promise<IEntityService>;
17
17
  }
@@ -1,4 +1,5 @@
1
+ import { Type } from 'ts-gems';
1
2
  import { OpraSchema } from '@opra/schema';
2
- export declare const builtinClassMap: Map<any, any>;
3
3
  export declare const primitiveDataTypeNames: string[];
4
+ export declare const builtinClassMap: Map<Type<any>, OpraSchema.DataType>;
4
5
  export declare const internalDataTypes: Map<string, OpraSchema.DataType>;