@opra/core 0.0.13 → 0.1.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.
- package/cjs/enums/http-headers.enum.js +2 -1
- package/cjs/implementation/adapter-utils/entity-resource-execute.util.js +84 -0
- package/cjs/implementation/adapter-utils/resource-execute.util.js +11 -0
- package/cjs/implementation/adapter-utils/resource-prepare.util.js +11 -0
- package/cjs/implementation/{adapter/adapter.js → adapter.js} +21 -18
- package/cjs/implementation/{adapter/express-adapter.js → express-adapter.js} +0 -0
- package/cjs/implementation/{adapter/http-adapter.js → http-adapter.js} +26 -24
- package/cjs/implementation/query-context.js +5 -3
- package/cjs/index.js +5 -15
- package/cjs/{services/entity-resource-controller.js → interfaces/entity-service.interface.js} +0 -0
- package/cjs/interfaces/query.interface.js +10 -10
- package/cjs/services/json-data-service.js +11 -5
- package/cjs/utils/{string-path-to-object-tree.js → path-to-tree.js} +3 -3
- package/esm/enums/http-headers.enum.d.ts +2 -1
- package/esm/enums/http-headers.enum.js +2 -1
- package/esm/implementation/adapter-utils/entity-resource-execute.util.d.ts +3 -0
- package/esm/implementation/adapter-utils/entity-resource-execute.util.js +80 -0
- package/esm/implementation/adapter-utils/resource-execute.util.d.ts +3 -0
- package/esm/implementation/adapter-utils/resource-execute.util.js +7 -0
- package/esm/implementation/adapter-utils/resource-prepare.util.d.ts +3 -0
- package/esm/implementation/adapter-utils/resource-prepare.util.js +7 -0
- package/esm/implementation/{adapter/adapter.d.ts → adapter.d.ts} +5 -5
- package/esm/implementation/{adapter/adapter.js → adapter.js} +18 -15
- package/esm/implementation/{adapter/express-adapter.d.ts → express-adapter.d.ts} +2 -2
- package/esm/implementation/{adapter/express-adapter.js → express-adapter.js} +0 -0
- package/esm/implementation/{adapter/http-adapter.d.ts → http-adapter.d.ts} +6 -7
- package/esm/implementation/{adapter/http-adapter.js → http-adapter.js} +25 -23
- package/esm/implementation/query-context.d.ts +3 -4
- package/esm/implementation/query-context.js +5 -3
- package/esm/index.d.ts +5 -15
- package/esm/index.js +5 -15
- package/esm/{services/entity-resource-controller.d.ts → interfaces/entity-service.interface.d.ts} +0 -0
- package/esm/{services/entity-resource-controller.js → interfaces/entity-service.interface.js} +0 -0
- package/esm/interfaces/query.interface.d.ts +25 -26
- package/esm/interfaces/query.interface.js +10 -10
- package/esm/services/json-data-service.d.ts +2 -2
- package/esm/services/json-data-service.js +11 -5
- package/esm/types.d.ts +1 -8
- package/esm/utils/create-i18n.d.ts +1 -1
- package/esm/utils/path-to-tree.d.ts +4 -0
- package/esm/utils/{string-path-to-object-tree.js → path-to-tree.js} +1 -1
- package/package.json +6 -6
- package/cjs/constants.js +0 -6
- package/cjs/decorators/api-entity-resource.decorator.js +0 -24
- package/cjs/decorators/api-resolver.decorator.js +0 -13
- package/cjs/implementation/data-type/complex-type.js +0 -53
- package/cjs/implementation/data-type/data-type.js +0 -47
- package/cjs/implementation/data-type/entity-type.js +0 -34
- package/cjs/implementation/data-type/simple-type.js +0 -30
- package/cjs/implementation/opra-document.js +0 -112
- package/cjs/implementation/opra-service.js +0 -81
- package/cjs/implementation/resource/container-resource-handler.js +0 -30
- package/cjs/implementation/resource/entity-resource-handler.js +0 -103
- package/cjs/implementation/resource/resource-handler.js +0 -45
- package/cjs/implementation/schema-generator.js +0 -184
- package/cjs/interfaces/metadata/api-resolver.metadata.js +0 -2
- package/cjs/interfaces/metadata/opra-schema.metadata.js +0 -11
- package/cjs/interfaces/resource-container.interface.js +0 -2
- package/cjs/utils/class-utils.js +0 -37
- package/cjs/utils/headers.js +0 -58
- package/cjs/utils/internal-data-types.js +0 -81
- package/cjs/utils/responsive-object.js +0 -49
- package/cjs/utils/terminal-utils.js +0 -7
- package/esm/constants.d.ts +0 -3
- package/esm/constants.js +0 -3
- package/esm/decorators/api-entity-resource.decorator.d.ts +0 -5
- package/esm/decorators/api-entity-resource.decorator.js +0 -19
- package/esm/decorators/api-resolver.decorator.d.ts +0 -2
- package/esm/decorators/api-resolver.decorator.js +0 -9
- package/esm/implementation/data-type/complex-type.d.ts +0 -19
- package/esm/implementation/data-type/complex-type.js +0 -48
- package/esm/implementation/data-type/data-type.d.ts +0 -17
- package/esm/implementation/data-type/data-type.js +0 -43
- package/esm/implementation/data-type/entity-type.d.ts +0 -10
- package/esm/implementation/data-type/entity-type.js +0 -29
- package/esm/implementation/data-type/simple-type.d.ts +0 -15
- package/esm/implementation/data-type/simple-type.js +0 -26
- package/esm/implementation/opra-document.d.ts +0 -26
- package/esm/implementation/opra-document.js +0 -107
- package/esm/implementation/opra-service.d.ts +0 -20
- package/esm/implementation/opra-service.js +0 -76
- package/esm/implementation/resource/container-resource-handler.d.ts +0 -14
- package/esm/implementation/resource/container-resource-handler.js +0 -26
- package/esm/implementation/resource/entity-resource-handler.d.ts +0 -18
- package/esm/implementation/resource/entity-resource-handler.js +0 -98
- package/esm/implementation/resource/resource-handler.d.ts +0 -15
- package/esm/implementation/resource/resource-handler.js +0 -40
- package/esm/implementation/schema-generator.d.ts +0 -21
- package/esm/implementation/schema-generator.js +0 -180
- package/esm/interfaces/metadata/api-resolver.metadata.d.ts +0 -3
- package/esm/interfaces/metadata/api-resolver.metadata.js +0 -1
- package/esm/interfaces/metadata/opra-schema.metadata.d.ts +0 -7
- package/esm/interfaces/metadata/opra-schema.metadata.js +0 -10
- package/esm/interfaces/resource-container.interface.d.ts +0 -6
- package/esm/interfaces/resource-container.interface.js +0 -1
- package/esm/utils/class-utils.d.ts +0 -6
- package/esm/utils/class-utils.js +0 -30
- package/esm/utils/headers.d.ts +0 -9
- package/esm/utils/headers.js +0 -55
- package/esm/utils/internal-data-types.d.ts +0 -5
- package/esm/utils/internal-data-types.js +0 -78
- package/esm/utils/responsive-object.d.ts +0 -3
- package/esm/utils/responsive-object.js +0 -45
- package/esm/utils/string-path-to-object-tree.d.ts +0 -4
- package/esm/utils/terminal-utils.d.ts +0 -4
- package/esm/utils/terminal-utils.js +0 -4
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { isPromise } from 'util/types';
|
|
2
|
-
import { DATATYPE_METADATA, DATATYPE_PROPERTIES, OpraSchema } from '@opra/schema';
|
|
3
|
-
import { RESOLVER_METADATA, RESOURCE_METADATA } from '../constants.js';
|
|
4
|
-
import { isConstructor, resolveClassAsync } from '../utils/class-utils.js';
|
|
5
|
-
import { builtinClassMap, internalDataTypes, primitiveDataTypeNames } from '../utils/internal-data-types.js';
|
|
6
|
-
const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
|
|
7
|
-
export class SchemaGenerator {
|
|
8
|
-
_dataTypes = {};
|
|
9
|
-
_resources = {};
|
|
10
|
-
constructor() {
|
|
11
|
-
//
|
|
12
|
-
}
|
|
13
|
-
async addDataType(thunk) {
|
|
14
|
-
thunk = isPromise(thunk) ? await thunk : thunk;
|
|
15
|
-
if (typeof thunk === 'function') {
|
|
16
|
-
if (!isConstructor(thunk))
|
|
17
|
-
return this.addDataType(await thunk());
|
|
18
|
-
if (builtinClassMap.has(thunk))
|
|
19
|
-
return this.addDataType(builtinClassMap.get(thunk));
|
|
20
|
-
const ctor = thunk;
|
|
21
|
-
const metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, ctor);
|
|
22
|
-
if (!metadata)
|
|
23
|
-
throw new TypeError(`Class "${ctor}" has no type metadata`);
|
|
24
|
-
// Add base data type
|
|
25
|
-
let base;
|
|
26
|
-
let baseCtor = Object.getPrototypeOf(ctor);
|
|
27
|
-
if (Reflect.hasMetadata(DATATYPE_METADATA, baseCtor)) {
|
|
28
|
-
while (!Reflect.hasOwnMetadata(DATATYPE_METADATA, baseCtor)) {
|
|
29
|
-
baseCtor = Object.getPrototypeOf(baseCtor);
|
|
30
|
-
}
|
|
31
|
-
const baseSchema = await this.addDataType(baseCtor);
|
|
32
|
-
base = baseSchema.name;
|
|
33
|
-
}
|
|
34
|
-
const schema = {
|
|
35
|
-
...metadata,
|
|
36
|
-
ctor,
|
|
37
|
-
base
|
|
38
|
-
};
|
|
39
|
-
const properties = Reflect.getMetadata(DATATYPE_PROPERTIES, ctor.prototype);
|
|
40
|
-
if (properties) {
|
|
41
|
-
for (const [k, p] of Object.entries(properties)) {
|
|
42
|
-
let type = p.type || 'string';
|
|
43
|
-
if (typeof type !== 'string') {
|
|
44
|
-
const propSchema = await this.addDataType(type);
|
|
45
|
-
type = propSchema.name;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
if (internalDataTypes.has(type))
|
|
49
|
-
await this.addDataType(internalDataTypes.get(type));
|
|
50
|
-
}
|
|
51
|
-
schema.properties = schema.properties || {};
|
|
52
|
-
schema.properties[k] = { ...p, type };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return this.addDataType(schema);
|
|
56
|
-
}
|
|
57
|
-
if (!OpraSchema.isDataType(thunk))
|
|
58
|
-
throw new TypeError(`Invalid data type schema`);
|
|
59
|
-
// Check if datatype previously added
|
|
60
|
-
const currentSchema = this._dataTypes[thunk.name];
|
|
61
|
-
if (currentSchema) {
|
|
62
|
-
if (!(currentSchema.kind === thunk.kind && currentSchema.ctor && currentSchema.ctor === thunk.ctor))
|
|
63
|
-
throw new Error(`An other instance of "${currentSchema.name}" data type previously defined`);
|
|
64
|
-
return currentSchema;
|
|
65
|
-
}
|
|
66
|
-
if (OpraSchema.isSimpleType(thunk) && !primitiveDataTypeNames.includes(thunk.type))
|
|
67
|
-
throw new Error(`"type" of SimpleType schema must be one of enumerated value (${primitiveDataTypeNames})`);
|
|
68
|
-
return this._dataTypes[thunk.name] = {
|
|
69
|
-
...thunk
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
async addResource(instance) {
|
|
73
|
-
if (isConstructor(instance))
|
|
74
|
-
throw new Error(`You should provide Resource instance instead of Resource class`);
|
|
75
|
-
const proto = Object.getPrototypeOf(instance);
|
|
76
|
-
const ctor = proto.constructor;
|
|
77
|
-
const metadata = Reflect.getMetadata(RESOURCE_METADATA, ctor);
|
|
78
|
-
let resourceSchema;
|
|
79
|
-
if (metadata) {
|
|
80
|
-
const name = metadata.name || ctor.name.replace(/Resource$/, '');
|
|
81
|
-
const t = typeof metadata.type === 'function'
|
|
82
|
-
? await resolveClassAsync(metadata.type)
|
|
83
|
-
: metadata.type;
|
|
84
|
-
const type = typeof t === 'function'
|
|
85
|
-
? (await this.addDataType(t)).name
|
|
86
|
-
: t;
|
|
87
|
-
resourceSchema = {
|
|
88
|
-
...metadata,
|
|
89
|
-
type,
|
|
90
|
-
name,
|
|
91
|
-
instance,
|
|
92
|
-
resolvers: {}
|
|
93
|
-
};
|
|
94
|
-
if (OpraSchema.isEntityResource(resourceSchema)) {
|
|
95
|
-
for (const methodName of entityMethods) {
|
|
96
|
-
let fn = instance[methodName];
|
|
97
|
-
if (typeof fn === 'function') {
|
|
98
|
-
const info = resourceSchema.resolvers[methodName] = {
|
|
99
|
-
...Reflect.getMetadata(RESOLVER_METADATA, proto, methodName)
|
|
100
|
-
};
|
|
101
|
-
if (!info.forbidden) {
|
|
102
|
-
info.handler = fn.bind(instance);
|
|
103
|
-
fn = instance['pre_' + methodName];
|
|
104
|
-
if (typeof fn === 'function')
|
|
105
|
-
resourceSchema['pre_' + methodName] = fn.bind(instance);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else
|
|
109
|
-
resourceSchema.resolvers[methodName] = { forbidden: true };
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else
|
|
114
|
-
resourceSchema = instance;
|
|
115
|
-
if (OpraSchema.isResource(resourceSchema)) {
|
|
116
|
-
if (OpraSchema.isEntityResource(resourceSchema)) {
|
|
117
|
-
const t = this._dataTypes[resourceSchema.type];
|
|
118
|
-
if (!t)
|
|
119
|
-
throw new Error(`Resource registration error. Type "${resourceSchema.type}" not found.`);
|
|
120
|
-
if (this._resources[resourceSchema.name])
|
|
121
|
-
throw new Error(`An other instance of "${resourceSchema.name}" resource previously defined`);
|
|
122
|
-
this._resources[resourceSchema.name] = resourceSchema;
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
throw new Error(`Invalid resource metadata`);
|
|
126
|
-
}
|
|
127
|
-
throw new Error(`Invalid resource object`);
|
|
128
|
-
}
|
|
129
|
-
static async generateDocumentSchema(args) {
|
|
130
|
-
const generator = new SchemaGenerator();
|
|
131
|
-
if (args.types) {
|
|
132
|
-
for (const thunk of args.types) {
|
|
133
|
-
await generator.addDataType(thunk);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const types = Object.keys(generator._dataTypes).sort()
|
|
137
|
-
.map(name => generator._dataTypes[name]);
|
|
138
|
-
return {
|
|
139
|
-
version: '1',
|
|
140
|
-
...args,
|
|
141
|
-
types
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
static async generateServiceSchema(args) {
|
|
145
|
-
const generator = new SchemaGenerator();
|
|
146
|
-
if (args.types) {
|
|
147
|
-
for (const thunk of args.types) {
|
|
148
|
-
await generator.addDataType(thunk);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (args.resources) {
|
|
152
|
-
for (const resource of args.resources) {
|
|
153
|
-
await generator.addResource(resource);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const types = Object.keys(generator._dataTypes)
|
|
157
|
-
.map(name => generator._dataTypes[name])
|
|
158
|
-
.sort((a, b) => {
|
|
159
|
-
if (a.kind !== b.kind) {
|
|
160
|
-
if (a.kind === 'SimpleType')
|
|
161
|
-
return -1;
|
|
162
|
-
if (b.kind === 'SimpleType')
|
|
163
|
-
return 1;
|
|
164
|
-
if (a.kind === 'ComplexType')
|
|
165
|
-
return -1;
|
|
166
|
-
if (b.kind === 'ComplexType')
|
|
167
|
-
return 1;
|
|
168
|
-
}
|
|
169
|
-
return (a.name < b.name ? -1 : 1);
|
|
170
|
-
});
|
|
171
|
-
const resources = Object.keys(generator._resources).sort()
|
|
172
|
-
.map(name => generator._resources[name]);
|
|
173
|
-
return {
|
|
174
|
-
version: '1',
|
|
175
|
-
...args,
|
|
176
|
-
types,
|
|
177
|
-
resources
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
2
|
-
import { OpraSchema } from '@opra/schema';
|
|
3
|
-
import { TypeThunkAsync } from '../../types.js';
|
|
4
|
-
export declare type EntityResourceMetadata = StrictOmit<OpraSchema.EntityResource, 'type' | 'name' | 'resolvers'> & {
|
|
5
|
-
type: TypeThunkAsync | string;
|
|
6
|
-
name?: string;
|
|
7
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
/*
|
|
3
|
-
export type ResourceReadOperationMetadata = StrictOmit<OpraSchema.ResourceReadOperation, 'handler'>;
|
|
4
|
-
export type ResourceSearchOperationMetadata = StrictOmit<OpraSchema.ResourceSearchOperation, 'handler'>;
|
|
5
|
-
export type ResourceCreateOperationMetadata = StrictOmit<OpraSchema.ResourceCreateOperation, 'handler'>;
|
|
6
|
-
export type ResourceUpdateOperationMetadata = StrictOmit<OpraSchema.ResourceUpdateOperation, 'handler'>;
|
|
7
|
-
export type ResourcePatchOperationMetadata = StrictOmit<OpraSchema.ResourcePatchOperation, 'handler'>;
|
|
8
|
-
export type ResourceDeleteOperationMetadata = StrictOmit<OpraSchema.ResourceDeleteOperation, 'handler'>;
|
|
9
|
-
export type ResourceExecuteOperationMetadata = StrictOmit<OpraSchema.ResourceExecuteOperation, 'handler'>;
|
|
10
|
-
*/
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EntityResourceHandler } from '../implementation/resource/entity-resource-handler.js';
|
|
2
|
-
import { ResourceHandler } from '../implementation/resource/resource-handler.js';
|
|
3
|
-
export interface IResourceContainer {
|
|
4
|
-
getResource<T extends ResourceHandler>(name: string): T;
|
|
5
|
-
getEntityResource(name: string): EntityResourceHandler;
|
|
6
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
import { TypeThunk, TypeThunkAsync } from '../types.js';
|
|
3
|
-
export declare function isConstructor(obj: any): obj is Type;
|
|
4
|
-
export declare function resolveClass<T>(typeOrFunc: TypeThunk<T>): Type<T>;
|
|
5
|
-
export declare function resolveClassAsync<T>(typeOrFunc: TypeThunkAsync<T>): Promise<Type<T>>;
|
|
6
|
-
export declare function isInternalClass(t: any): boolean;
|
package/esm/utils/class-utils.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const knownInternalClasses = [String, Number, Boolean, Date];
|
|
2
|
-
export function isConstructor(obj) {
|
|
3
|
-
return typeof obj === 'function' &&
|
|
4
|
-
!!(obj.prototype && obj.prototype.constructor);
|
|
5
|
-
}
|
|
6
|
-
export function resolveClass(typeOrFunc) {
|
|
7
|
-
if (typeof typeOrFunc === 'function' && !isConstructor(typeOrFunc)) {
|
|
8
|
-
typeOrFunc = typeOrFunc();
|
|
9
|
-
if (isConstructor(typeOrFunc))
|
|
10
|
-
return typeOrFunc;
|
|
11
|
-
throw new TypeError(`Function must return a constructor`);
|
|
12
|
-
}
|
|
13
|
-
if (isConstructor(typeOrFunc))
|
|
14
|
-
return typeOrFunc;
|
|
15
|
-
throw new TypeError(`${typeOrFunc} is not a constructor`);
|
|
16
|
-
}
|
|
17
|
-
export async function resolveClassAsync(typeOrFunc) {
|
|
18
|
-
if (typeof typeOrFunc === 'function' && !isConstructor(typeOrFunc)) {
|
|
19
|
-
typeOrFunc = await typeOrFunc();
|
|
20
|
-
if (isConstructor(typeOrFunc))
|
|
21
|
-
return typeOrFunc;
|
|
22
|
-
throw new TypeError(`Function must return a constructor`);
|
|
23
|
-
}
|
|
24
|
-
if (isConstructor(typeOrFunc))
|
|
25
|
-
return typeOrFunc;
|
|
26
|
-
throw new TypeError(`${typeOrFunc} is not a constructor`);
|
|
27
|
-
}
|
|
28
|
-
export function isInternalClass(t) {
|
|
29
|
-
return knownInternalClasses.includes(t) || Buffer.isBuffer(t);
|
|
30
|
-
}
|
package/esm/utils/headers.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Opaque } from 'ts-gems';
|
|
2
|
-
export declare type HeadersObject = Opaque<Record<string, any>, 'HeadersObject'>;
|
|
3
|
-
/**
|
|
4
|
-
* Create a proxy that ensures header keys are always formatted according to well known header names
|
|
5
|
-
*/
|
|
6
|
-
export declare namespace Headers {
|
|
7
|
-
function from(obj: object): HeadersObject;
|
|
8
|
-
function create(): HeadersObject;
|
|
9
|
-
}
|
package/esm/utils/headers.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { HttpHeaders } from '../enums/index.js';
|
|
2
|
-
const wellKnownHeaders = Object.values(HttpHeaders)
|
|
3
|
-
.reduce((target, k) => {
|
|
4
|
-
target[k.toLowerCase()] = k;
|
|
5
|
-
return target;
|
|
6
|
-
}, {});
|
|
7
|
-
const wrapKey = (prop) => {
|
|
8
|
-
return typeof prop == 'string' ? wellKnownHeaders[prop.toLowerCase()] || prop : prop;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Create a proxy that ensures header keys are always formatted according to well known header names
|
|
12
|
-
*/
|
|
13
|
-
export var Headers;
|
|
14
|
-
(function (Headers) {
|
|
15
|
-
function from(obj) {
|
|
16
|
-
const headers = create();
|
|
17
|
-
for (const [k, v] of Object.entries(obj))
|
|
18
|
-
headers[k] = v;
|
|
19
|
-
return headers;
|
|
20
|
-
}
|
|
21
|
-
Headers.from = from;
|
|
22
|
-
function create() {
|
|
23
|
-
return new Proxy({}, {
|
|
24
|
-
set: (target, prop, value, receiver) => {
|
|
25
|
-
let key = prop;
|
|
26
|
-
if (typeof key === 'string')
|
|
27
|
-
key = wellKnownHeaders[key.toLowerCase()] || key;
|
|
28
|
-
const result = Reflect.set(target, key, value, receiver);
|
|
29
|
-
/* istanbul ignore next */
|
|
30
|
-
if (!result && Object.isFrozen(target))
|
|
31
|
-
throw new TypeError('Cannot add property, object is not extensible');
|
|
32
|
-
return result;
|
|
33
|
-
},
|
|
34
|
-
get: (target, prop, receiver) => {
|
|
35
|
-
return Reflect.get(target, wrapKey(prop), receiver);
|
|
36
|
-
},
|
|
37
|
-
deleteProperty: (target, prop) => {
|
|
38
|
-
return Reflect.deleteProperty(target, wrapKey(prop));
|
|
39
|
-
},
|
|
40
|
-
defineProperty: (target, prop, descriptor) => {
|
|
41
|
-
let key = prop;
|
|
42
|
-
if (typeof key === 'string')
|
|
43
|
-
key = wellKnownHeaders[key.toLowerCase()] || key;
|
|
44
|
-
return Reflect.defineProperty(target, key, descriptor);
|
|
45
|
-
},
|
|
46
|
-
getOwnPropertyDescriptor: (target, prop) => {
|
|
47
|
-
return Reflect.getOwnPropertyDescriptor(target, wrapKey(prop));
|
|
48
|
-
},
|
|
49
|
-
has: (target, prop) => {
|
|
50
|
-
return Reflect.has(target, wrapKey(prop));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
Headers.create = create;
|
|
55
|
-
})(Headers || (Headers = {}));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Type } from 'ts-gems';
|
|
2
|
-
import { OpraSchema } from '@opra/schema';
|
|
3
|
-
export declare const primitiveDataTypeNames: string[];
|
|
4
|
-
export declare const builtinClassMap: Map<Type<any>, OpraSchema.DataType>;
|
|
5
|
-
export declare const internalDataTypes: Map<string, OpraSchema.DataType>;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export const primitiveDataTypeNames = ['boolean', 'number', 'string', 'null'];
|
|
2
|
-
export const builtinClassMap = new Map();
|
|
3
|
-
export const internalDataTypes = new Map();
|
|
4
|
-
const internalDataTypeArray = [
|
|
5
|
-
{
|
|
6
|
-
kind: 'SimpleType',
|
|
7
|
-
name: 'boolean',
|
|
8
|
-
type: 'boolean',
|
|
9
|
-
description: 'Simple true/false value',
|
|
10
|
-
ctor: Boolean
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
kind: 'SimpleType',
|
|
14
|
-
name: 'string',
|
|
15
|
-
type: 'string',
|
|
16
|
-
description: 'A sequence of characters',
|
|
17
|
-
ctor: String
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
kind: 'SimpleType',
|
|
21
|
-
name: 'number',
|
|
22
|
-
type: 'number',
|
|
23
|
-
description: 'Both Integer as well as Floating-Point numbers',
|
|
24
|
-
ctor: Number
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
kind: 'SimpleType',
|
|
28
|
-
name: 'integer',
|
|
29
|
-
type: 'number',
|
|
30
|
-
base: 'number',
|
|
31
|
-
description: 'Integer number',
|
|
32
|
-
ctor: Number
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
kind: 'ComplexType',
|
|
36
|
-
name: 'object',
|
|
37
|
-
description: 'Object type with additional properties',
|
|
38
|
-
additionalProperties: true,
|
|
39
|
-
ctor: Object
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
kind: 'SimpleType',
|
|
43
|
-
name: 'date',
|
|
44
|
-
type: 'string',
|
|
45
|
-
description: 'Date',
|
|
46
|
-
format: 'date',
|
|
47
|
-
ctor: Date
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
kind: 'SimpleType',
|
|
51
|
-
name: 'date-time',
|
|
52
|
-
type: 'string',
|
|
53
|
-
description: 'Date time value',
|
|
54
|
-
format: 'date-time',
|
|
55
|
-
ctor: Date
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
kind: 'SimpleType',
|
|
59
|
-
name: 'time',
|
|
60
|
-
type: 'string',
|
|
61
|
-
description: 'Time value',
|
|
62
|
-
format: 'time',
|
|
63
|
-
ctor: String
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
kind: 'SimpleType',
|
|
67
|
-
name: 'buffer',
|
|
68
|
-
type: 'string',
|
|
69
|
-
description: 'Buffer value',
|
|
70
|
-
format: 'base64',
|
|
71
|
-
ctor: Buffer
|
|
72
|
-
}
|
|
73
|
-
];
|
|
74
|
-
internalDataTypeArray.forEach(sch => {
|
|
75
|
-
internalDataTypes.set(sch.name, sch);
|
|
76
|
-
if (sch.ctor && !builtinClassMap.has(sch.ctor))
|
|
77
|
-
builtinClassMap.set(sch.ctor, sch);
|
|
78
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export function Responsive(wrapped) {
|
|
2
|
-
wrapped = wrapped || {};
|
|
3
|
-
const keyMap = {};
|
|
4
|
-
Object.keys(wrapped).forEach(k => keyMap[k.toLowerCase()] = k);
|
|
5
|
-
const wrapKey = (prop) => {
|
|
6
|
-
return typeof prop == 'string' ? keyMap[prop.toLowerCase()] : prop;
|
|
7
|
-
};
|
|
8
|
-
return new Proxy(wrapped, {
|
|
9
|
-
set: (target, prop, value, receiver) => {
|
|
10
|
-
let key = prop;
|
|
11
|
-
if (typeof key === 'string') {
|
|
12
|
-
const keyLower = key.toLowerCase();
|
|
13
|
-
key = keyMap[keyLower] = keyMap[keyLower] || key;
|
|
14
|
-
}
|
|
15
|
-
const result = Reflect.set(target, key, value, receiver);
|
|
16
|
-
if (!result && Object.isFrozen(target))
|
|
17
|
-
throw new TypeError('Cannot add property, object is not extensible');
|
|
18
|
-
return result;
|
|
19
|
-
},
|
|
20
|
-
get: (target, prop, receiver) => {
|
|
21
|
-
return Reflect.get(target, wrapKey(prop), receiver);
|
|
22
|
-
},
|
|
23
|
-
deleteProperty: (target, prop) => {
|
|
24
|
-
const key = wrapKey(prop);
|
|
25
|
-
if (typeof prop === 'string') {
|
|
26
|
-
delete keyMap[prop.toLowerCase()];
|
|
27
|
-
}
|
|
28
|
-
return Reflect.deleteProperty(target, key);
|
|
29
|
-
},
|
|
30
|
-
defineProperty: (target, prop, descriptor) => {
|
|
31
|
-
let key = prop;
|
|
32
|
-
if (typeof key === 'string') {
|
|
33
|
-
const keyLower = key.toLowerCase();
|
|
34
|
-
key = keyMap[keyLower] = keyMap[keyLower] || key;
|
|
35
|
-
}
|
|
36
|
-
return Reflect.defineProperty(target, key, descriptor);
|
|
37
|
-
},
|
|
38
|
-
getOwnPropertyDescriptor: (target, prop) => {
|
|
39
|
-
return Reflect.getOwnPropertyDescriptor(target, wrapKey(prop));
|
|
40
|
-
},
|
|
41
|
-
has: (target, prop) => {
|
|
42
|
-
return Reflect.has(target, wrapKey(prop));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|