@opra/client 0.5.0 → 0.7.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/constants.js +6 -0
- package/cjs/http/http-client.js +164 -0
- package/cjs/http/http-collection-service.js +40 -0
- package/cjs/http/http-request.js +66 -0
- package/cjs/http/http-response.js +2 -0
- package/cjs/http/http-singleton-service.js +16 -0
- package/cjs/http/http-types.js +2 -0
- package/cjs/http/requests/batch-request.js +80 -0
- package/cjs/http/requests/collection-create-request.js +35 -0
- package/cjs/http/requests/collection-delete-many-request.js +28 -0
- package/cjs/http/requests/collection-delete-request.js +29 -0
- package/cjs/http/requests/collection-get-request.js +37 -0
- package/cjs/http/requests/collection-search-request.js +44 -0
- package/cjs/http/requests/collection-update-many-request.js +31 -0
- package/cjs/http/requests/collection-update-request.js +40 -0
- package/cjs/http/requests/http-singleton-get-request.js +31 -0
- package/cjs/http/utils/merge-raw-http-requests.util.js +29 -0
- package/cjs/index.js +15 -13
- package/cjs/interfaces/http-options.interface.js +2 -0
- package/cjs/interfaces/http-request-config.interface.js +2 -0
- package/esm/client-error.d.ts +1 -1
- package/esm/constants.d.ts +3 -0
- package/esm/constants.js +3 -0
- package/esm/http/http-client.d.ts +26 -0
- package/esm/http/http-client.js +160 -0
- package/esm/http/http-collection-service.d.ts +22 -0
- package/esm/http/http-collection-service.js +36 -0
- package/esm/http/http-request.d.ts +25 -0
- package/esm/http/http-request.js +62 -0
- package/esm/http/http-response.d.ts +14 -0
- package/esm/http/http-response.js +1 -0
- package/esm/http/http-singleton-service.d.ts +10 -0
- package/esm/http/http-singleton-service.js +12 -0
- package/esm/http/http-types.d.ts +26 -0
- package/esm/http/http-types.js +1 -0
- package/esm/http/requests/batch-request.d.ts +18 -0
- package/esm/http/requests/batch-request.js +76 -0
- package/esm/http/requests/collection-create-request.d.ts +12 -0
- package/esm/http/requests/collection-create-request.js +31 -0
- package/esm/http/requests/collection-delete-many-request.d.ts +11 -0
- package/esm/http/requests/collection-delete-many-request.js +24 -0
- package/esm/http/requests/collection-delete-request.d.ts +12 -0
- package/esm/http/requests/collection-delete-request.js +25 -0
- package/esm/http/requests/collection-get-request.d.ts +12 -0
- package/esm/http/requests/collection-get-request.js +33 -0
- package/esm/http/requests/collection-search-request.d.ts +11 -0
- package/esm/http/requests/collection-search-request.js +40 -0
- package/esm/http/requests/collection-update-many-request.d.ts +12 -0
- package/esm/http/requests/collection-update-many-request.js +27 -0
- package/esm/http/requests/collection-update-request.d.ts +13 -0
- package/esm/http/requests/collection-update-request.js +36 -0
- package/esm/http/requests/http-singleton-get-request.d.ts +11 -0
- package/esm/http/requests/http-singleton-get-request.js +27 -0
- package/esm/http/utils/merge-raw-http-requests.util.d.ts +2 -0
- package/esm/http/utils/merge-raw-http-requests.util.js +25 -0
- package/esm/index.d.ts +15 -13
- package/esm/index.js +15 -13
- package/esm/interfaces/http-options.interface.d.ts +20 -0
- package/esm/interfaces/http-options.interface.js +1 -0
- package/esm/interfaces/http-request-config.interface.d.ts +23 -0
- package/esm/interfaces/http-request-config.interface.js +1 -0
- package/esm/types.d.ts +7 -37
- package/package.json +24 -22
- package/umd/opra-client.umd.min.js +1 -0
- package/cjs/client-request.js +0 -48
- package/cjs/client.js +0 -139
- package/cjs/requests/batch-request.js +0 -136
- package/cjs/requests/collection-create-request.js +0 -35
- package/cjs/requests/collection-delete-many-request.js +0 -28
- package/cjs/requests/collection-delete-request.js +0 -29
- package/cjs/requests/collection-get-request.js +0 -35
- package/cjs/requests/collection-search-request.js +0 -44
- package/cjs/requests/collection-update-many-request.js +0 -31
- package/cjs/requests/collection-update-request.js +0 -38
- package/cjs/requests/singleton-get-request.js +0 -32
- package/cjs/services/collection-node.js +0 -42
- package/cjs/services/singleton-node.js +0 -18
- package/esm/client-request.d.ts +0 -17
- package/esm/client-request.js +0 -44
- package/esm/client.d.ts +0 -34
- package/esm/client.js +0 -134
- package/esm/requests/batch-request.d.ts +0 -19
- package/esm/requests/batch-request.js +0 -131
- package/esm/requests/collection-create-request.d.ts +0 -13
- package/esm/requests/collection-create-request.js +0 -31
- package/esm/requests/collection-delete-many-request.d.ts +0 -12
- package/esm/requests/collection-delete-many-request.js +0 -24
- package/esm/requests/collection-delete-request.d.ts +0 -13
- package/esm/requests/collection-delete-request.js +0 -25
- package/esm/requests/collection-get-request.d.ts +0 -13
- package/esm/requests/collection-get-request.js +0 -31
- package/esm/requests/collection-search-request.d.ts +0 -12
- package/esm/requests/collection-search-request.js +0 -40
- package/esm/requests/collection-update-many-request.d.ts +0 -13
- package/esm/requests/collection-update-many-request.js +0 -27
- package/esm/requests/collection-update-request.d.ts +0 -14
- package/esm/requests/collection-update-request.js +0 -34
- package/esm/requests/singleton-get-request.d.ts +0 -12
- package/esm/requests/singleton-get-request.js +0 -28
- package/esm/services/collection-node.d.ts +0 -24
- package/esm/services/collection-node.js +0 -38
- package/esm/services/singleton-node.d.ts +0 -12
- package/esm/services/singleton-node.js +0 -14
package/esm/client-request.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
import type { OpraClient } from './client.js';
|
|
4
|
-
import { ClientResponse, CommonQueryOptions } from './types.js';
|
|
5
|
-
export declare abstract class OpraClientRequest<T = any, TResponse extends ClientResponse<T> = ClientResponse<T>> extends Observable<TResponse> {
|
|
6
|
-
readonly client: OpraClient;
|
|
7
|
-
protected _send: (req: AxiosRequestConfig) => Promise<TResponse>;
|
|
8
|
-
options: CommonQueryOptions;
|
|
9
|
-
readonly id: string;
|
|
10
|
-
protected _promise?: Promise<TResponse>;
|
|
11
|
-
protected constructor(client: OpraClient, _send: (req: AxiosRequestConfig) => Promise<TResponse>, options?: CommonQueryOptions);
|
|
12
|
-
abstract prepare(): AxiosRequestConfig;
|
|
13
|
-
toPromise(): Promise<TResponse>;
|
|
14
|
-
execute(): Promise<TResponse>;
|
|
15
|
-
protected _execute(): Promise<TResponse>;
|
|
16
|
-
binding(): any;
|
|
17
|
-
}
|
package/esm/client-request.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { uid } from 'uid';
|
|
3
|
-
import { HeadersMap } from '@opra/common';
|
|
4
|
-
export class OpraClientRequest extends Observable {
|
|
5
|
-
client;
|
|
6
|
-
_send;
|
|
7
|
-
options;
|
|
8
|
-
id;
|
|
9
|
-
_promise;
|
|
10
|
-
constructor(client, _send, options = {}) {
|
|
11
|
-
super((subscriber) => {
|
|
12
|
-
this.execute().then(v => {
|
|
13
|
-
subscriber.next(v);
|
|
14
|
-
subscriber.complete();
|
|
15
|
-
}).catch(e => subscriber.error(e));
|
|
16
|
-
});
|
|
17
|
-
this.client = client;
|
|
18
|
-
this._send = _send;
|
|
19
|
-
this.options = options;
|
|
20
|
-
this.id = uid(10);
|
|
21
|
-
this.options = options;
|
|
22
|
-
}
|
|
23
|
-
async toPromise() {
|
|
24
|
-
return this.execute();
|
|
25
|
-
}
|
|
26
|
-
async execute() {
|
|
27
|
-
const promise = this._promise || (this._promise = this._execute());
|
|
28
|
-
return await promise;
|
|
29
|
-
}
|
|
30
|
-
async _execute() {
|
|
31
|
-
const req = this.prepare();
|
|
32
|
-
const headers = this.options.http?.headers
|
|
33
|
-
? new HeadersMap({ ...req.headers, ...this.options.http.headers }).toObject()
|
|
34
|
-
: req.headers;
|
|
35
|
-
return this._send({
|
|
36
|
-
...this.options.http,
|
|
37
|
-
...req,
|
|
38
|
-
headers
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
binding() {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
}
|
package/esm/client.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { TaskQueue } from 'power-tasks';
|
|
3
|
-
import { Type } from 'ts-gems';
|
|
4
|
-
import { OpraDocument } from '@opra/schema';
|
|
5
|
-
import { OpraClientRequest } from './client-request.js';
|
|
6
|
-
import { CollectionNode } from './services/collection-node.js';
|
|
7
|
-
import { SingletonNode } from './services/singleton-node.js';
|
|
8
|
-
import { ClientAdapter, ClientResponse, HttpRequestOptions } from './types.js';
|
|
9
|
-
export interface OpraClientOptions {
|
|
10
|
-
adapter?: ClientAdapter;
|
|
11
|
-
defaults?: HttpRequestOptions;
|
|
12
|
-
invalidateCache?: boolean;
|
|
13
|
-
concurrency?: number;
|
|
14
|
-
maxQueue?: number;
|
|
15
|
-
}
|
|
16
|
-
export declare class OpraClient {
|
|
17
|
-
protected _axios: AxiosInstance;
|
|
18
|
-
protected _metadata: OpraDocument;
|
|
19
|
-
protected _taskQueue: TaskQueue;
|
|
20
|
-
constructor(serviceUrl: string, options?: OpraClientOptions);
|
|
21
|
-
constructor(serviceUrl: string, metadata: OpraDocument, options?: OpraClientOptions);
|
|
22
|
-
get requestInterceptors(): AxiosInterceptorManager<AxiosRequestConfig>;
|
|
23
|
-
get responseInterceptors(): AxiosInterceptorManager<AxiosResponse>;
|
|
24
|
-
get serviceUrl(): string;
|
|
25
|
-
get initialized(): boolean;
|
|
26
|
-
get metadata(): OpraDocument;
|
|
27
|
-
init(): Promise<void>;
|
|
28
|
-
batch<TResponse extends ClientResponse<any> = ClientResponse<any>>(requests: OpraClientRequest[]): OpraClientRequest<any, TResponse>;
|
|
29
|
-
collection<T = any, TResponse extends ClientResponse<T> = ClientResponse<T>>(name: string): CollectionNode<T, TResponse>;
|
|
30
|
-
singleton<T = any, TResponse extends ClientResponse<T> = ClientResponse<T>>(name: string): SingletonNode<T, TResponse>;
|
|
31
|
-
protected _send<TResponse extends ClientResponse>(req: AxiosRequestConfig): Promise<TResponse>;
|
|
32
|
-
protected _assertMetadata(): void;
|
|
33
|
-
static create<T extends OpraClient>(this: Type<T>, serviceUrl: string, options?: OpraClientOptions): Promise<T>;
|
|
34
|
-
}
|
package/esm/client.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { TaskQueue } from 'power-tasks';
|
|
3
|
-
import { ResponsiveMap } from '@opra/common';
|
|
4
|
-
import { OpraDocument } from '@opra/schema';
|
|
5
|
-
import { normalizePath } from '@opra/url';
|
|
6
|
-
import { ClientError } from './client-error.js';
|
|
7
|
-
import { BatchRequest } from './requests/batch-request.js';
|
|
8
|
-
import { CollectionNode } from './services/collection-node.js';
|
|
9
|
-
import { SingletonNode } from './services/singleton-node.js';
|
|
10
|
-
const documentCache = new Map();
|
|
11
|
-
const documentCacheResolvers = new Map();
|
|
12
|
-
export class OpraClient {
|
|
13
|
-
_axios;
|
|
14
|
-
_metadata;
|
|
15
|
-
_taskQueue;
|
|
16
|
-
constructor(serviceUrl, arg1, arg2) {
|
|
17
|
-
let options;
|
|
18
|
-
if (arg1 instanceof OpraDocument) {
|
|
19
|
-
this._metadata = arg1;
|
|
20
|
-
options = arg2;
|
|
21
|
-
}
|
|
22
|
-
else
|
|
23
|
-
options = arg1 || arg2;
|
|
24
|
-
this._taskQueue = new TaskQueue({
|
|
25
|
-
maxQueue: options?.maxQueue,
|
|
26
|
-
concurrency: options?.concurrency
|
|
27
|
-
});
|
|
28
|
-
this._axios = axios.create();
|
|
29
|
-
this._axios.defaults.baseURL = normalizePath(serviceUrl);
|
|
30
|
-
this._axios.defaults.adapter = options?.adapter;
|
|
31
|
-
if (options?.defaults?.headers)
|
|
32
|
-
this._axios.defaults.headers.common = options.defaults.headers;
|
|
33
|
-
this._axios.defaults.auth = options?.defaults?.auth;
|
|
34
|
-
this._axios.defaults.timeout = options?.defaults?.timeout;
|
|
35
|
-
this._axios.defaults.timeoutErrorMessage = options?.defaults?.timeoutErrorMessage;
|
|
36
|
-
this._axios.defaults.xsrfCookieName = options?.defaults?.xsrfCookieName;
|
|
37
|
-
this._axios.defaults.xsrfHeaderName = options?.defaults?.xsrfHeaderName;
|
|
38
|
-
this._axios.defaults.maxRedirects = options?.defaults?.maxRedirects;
|
|
39
|
-
this._axios.defaults.maxRate = options?.defaults?.maxRate;
|
|
40
|
-
this._axios.defaults.httpAgent = options?.defaults?.httpAgent;
|
|
41
|
-
this._axios.defaults.httpsAgent = options?.defaults?.httpsAgent;
|
|
42
|
-
this._axios.defaults.proxy = options?.defaults?.proxy;
|
|
43
|
-
this._axios.defaults.validateStatus = options?.defaults?.validateStatus;
|
|
44
|
-
const document = documentCache.get(serviceUrl.toLowerCase());
|
|
45
|
-
if (document)
|
|
46
|
-
this._metadata = document;
|
|
47
|
-
}
|
|
48
|
-
get requestInterceptors() {
|
|
49
|
-
return this._axios.interceptors.request;
|
|
50
|
-
}
|
|
51
|
-
get responseInterceptors() {
|
|
52
|
-
return this._axios.interceptors.response;
|
|
53
|
-
}
|
|
54
|
-
get serviceUrl() {
|
|
55
|
-
return this._axios.defaults.baseURL || '';
|
|
56
|
-
}
|
|
57
|
-
get initialized() {
|
|
58
|
-
return !!this._metadata;
|
|
59
|
-
}
|
|
60
|
-
get metadata() {
|
|
61
|
-
this._assertMetadata();
|
|
62
|
-
return this._metadata;
|
|
63
|
-
}
|
|
64
|
-
async init() {
|
|
65
|
-
let promise = documentCacheResolvers.get(this.serviceUrl.toLowerCase());
|
|
66
|
-
if (promise) {
|
|
67
|
-
await promise;
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
promise = this._send({
|
|
71
|
-
method: 'GET',
|
|
72
|
-
url: '/$metadata',
|
|
73
|
-
});
|
|
74
|
-
documentCacheResolvers.set(this.serviceUrl.toLowerCase(), promise);
|
|
75
|
-
try {
|
|
76
|
-
const resp = await promise;
|
|
77
|
-
this._metadata = new OpraDocument(resp.data);
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
documentCacheResolvers.delete(this.serviceUrl.toLowerCase());
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
batch(requests) {
|
|
84
|
-
this._assertMetadata();
|
|
85
|
-
return new BatchRequest(this, requests, req => this._send(req));
|
|
86
|
-
}
|
|
87
|
-
collection(name) {
|
|
88
|
-
this._assertMetadata();
|
|
89
|
-
const resource = this.metadata.getCollectionResource(name);
|
|
90
|
-
return new CollectionNode(this, resource, req => this._send(req));
|
|
91
|
-
}
|
|
92
|
-
singleton(name) {
|
|
93
|
-
this._assertMetadata();
|
|
94
|
-
const resource = this.metadata.getSingletonResource(name);
|
|
95
|
-
return new SingletonNode(this, resource, req => this._send(req));
|
|
96
|
-
}
|
|
97
|
-
async _send(req) {
|
|
98
|
-
return this._taskQueue.enqueue(async () => {
|
|
99
|
-
const resp = await this._axios.request({
|
|
100
|
-
...req,
|
|
101
|
-
validateStatus: () => true
|
|
102
|
-
});
|
|
103
|
-
if ((resp.status >= 400 && resp.status < 600) &&
|
|
104
|
-
(this._axios.defaults.validateStatus && !this._axios.defaults.validateStatus(resp.status))) {
|
|
105
|
-
throw new ClientError({
|
|
106
|
-
message: resp.status + ' ' + resp.statusText,
|
|
107
|
-
status: resp.status,
|
|
108
|
-
issues: resp.data.errors
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const rawHeaders = (typeof resp.headers.toJSON === 'function'
|
|
112
|
-
? resp.headers.toJSON()
|
|
113
|
-
: { ...resp.headers });
|
|
114
|
-
const headers = new ResponsiveMap(rawHeaders);
|
|
115
|
-
return {
|
|
116
|
-
status: resp.status,
|
|
117
|
-
statusText: resp.statusText,
|
|
118
|
-
data: resp.data,
|
|
119
|
-
rawHeaders,
|
|
120
|
-
headers
|
|
121
|
-
};
|
|
122
|
-
}).toPromise();
|
|
123
|
-
}
|
|
124
|
-
_assertMetadata() {
|
|
125
|
-
if (!this._metadata)
|
|
126
|
-
throw new Error('You must call init() to before using the client instance');
|
|
127
|
-
}
|
|
128
|
-
static async create(serviceUrl, options) {
|
|
129
|
-
const client = new this(serviceUrl, options);
|
|
130
|
-
if (!client._metadata)
|
|
131
|
-
await client.init();
|
|
132
|
-
return client;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import type { OpraClient } from '../client.js';
|
|
3
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
4
|
-
import { ClientResponse, CommonQueryOptions, OpraBatchRequestOptions } from '../types.js';
|
|
5
|
-
export declare const CRLF = "\r\n";
|
|
6
|
-
export declare class BatchRequest<TResponse extends ClientResponse = ClientResponse>// todo
|
|
7
|
-
extends OpraClientRequest<any, TResponse> {
|
|
8
|
-
readonly client: OpraClient;
|
|
9
|
-
readonly requests: OpraClientRequest[];
|
|
10
|
-
options: OpraBatchRequestOptions & CommonQueryOptions;
|
|
11
|
-
protected _results: WeakMap<OpraClientRequest<any, ClientResponse<any>>, {
|
|
12
|
-
error?: Error | undefined;
|
|
13
|
-
response?: ClientResponse<any> | undefined;
|
|
14
|
-
}>;
|
|
15
|
-
protected _listeners: Set<(error: Error | undefined, response?: ClientResponse) => void>;
|
|
16
|
-
constructor(client: OpraClient, requests: OpraClientRequest[], send: (req: AxiosRequestConfig) => Promise<TResponse>, options?: OpraBatchRequestOptions & CommonQueryOptions);
|
|
17
|
-
prepare(): AxiosRequestConfig;
|
|
18
|
-
protected _execute(): Promise<TResponse>;
|
|
19
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import Highland from 'highland';
|
|
2
|
-
import { uid } from 'uid';
|
|
3
|
-
import { HeadersMap } from '@opra/common';
|
|
4
|
-
import { OpraURL } from '@opra/url';
|
|
5
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
6
|
-
export const CRLF = '\r\n';
|
|
7
|
-
export class BatchRequest// todo
|
|
8
|
-
extends OpraClientRequest {
|
|
9
|
-
client;
|
|
10
|
-
requests;
|
|
11
|
-
options;
|
|
12
|
-
_results = new WeakMap();
|
|
13
|
-
_listeners = new Set();
|
|
14
|
-
constructor(client, requests, send, options = {}) {
|
|
15
|
-
super(client, send, options);
|
|
16
|
-
this.client = client;
|
|
17
|
-
this.requests = requests;
|
|
18
|
-
this.options = options;
|
|
19
|
-
requests.forEach(request => {
|
|
20
|
-
Object.defineProperty(request, '_execute', {
|
|
21
|
-
writable: true,
|
|
22
|
-
enumerable: false,
|
|
23
|
-
configurable: true,
|
|
24
|
-
value: () => {
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
const x = this._results.get(request);
|
|
27
|
-
if (x) {
|
|
28
|
-
if (x.error)
|
|
29
|
-
return reject(x.error);
|
|
30
|
-
return resolve(x.response);
|
|
31
|
-
}
|
|
32
|
-
const callback = (e, r) => {
|
|
33
|
-
this._listeners.delete(callback);
|
|
34
|
-
if (e)
|
|
35
|
-
return reject(e);
|
|
36
|
-
resolve(r);
|
|
37
|
-
};
|
|
38
|
-
this._listeners.add(callback);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
prepare() {
|
|
45
|
-
const { boundary, stream } = buildBatchStream(this);
|
|
46
|
-
const headers = {
|
|
47
|
-
'Content-Type': 'multipart/mixed;boundary=' + boundary
|
|
48
|
-
};
|
|
49
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
50
|
-
url.path.join('/$batch');
|
|
51
|
-
return {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
url: url.address,
|
|
54
|
-
params: url.searchParams,
|
|
55
|
-
headers,
|
|
56
|
-
data: stream
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async _execute() {
|
|
60
|
-
const req = this.prepare();
|
|
61
|
-
return this._send(req);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function buildBatchStream(batch) {
|
|
65
|
-
const chunks = [];
|
|
66
|
-
let batchIndex = 0;
|
|
67
|
-
let level = 0;
|
|
68
|
-
const processBatch = (_batch) => {
|
|
69
|
-
const boundary = `batch_${++batchIndex}_L${level}_${uid(10)}`;
|
|
70
|
-
for (const req of _batch.requests) {
|
|
71
|
-
chunks.push('--' + boundary + CRLF);
|
|
72
|
-
if (req instanceof BatchRequest) {
|
|
73
|
-
const contentHeaderIndex = chunks.push('');
|
|
74
|
-
chunks.push('Content-Transfer-Encoding: binary' + CRLF + CRLF);
|
|
75
|
-
level++;
|
|
76
|
-
const subBoundary = processBatch(req);
|
|
77
|
-
level--;
|
|
78
|
-
processBatch[contentHeaderIndex] = 'Content-Type: multipart/mixed;boundary=' + subBoundary + CRLF;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const prepared = req.prepare();
|
|
82
|
-
let s = 'Content-Type: application/http' + CRLF +
|
|
83
|
-
'Content-Transfer-Encoding: binary' + CRLF +
|
|
84
|
-
'Content-ID:' + req.id + CRLF +
|
|
85
|
-
CRLF +
|
|
86
|
-
(prepared.method || 'GET').toUpperCase() + ' ' + prepared.url + ' HTTP/1.1' + CRLF;
|
|
87
|
-
const headers = new HeadersMap(prepared.headers);
|
|
88
|
-
let data;
|
|
89
|
-
let contentType = '';
|
|
90
|
-
if (prepared.data) {
|
|
91
|
-
if (typeof prepared.data === 'string') {
|
|
92
|
-
contentType = 'text/plain; charset=utf-8';
|
|
93
|
-
data = prepared.data;
|
|
94
|
-
}
|
|
95
|
-
else if (Highland.isStream(prepared.data) || Buffer.isBuffer(prepared.data)) {
|
|
96
|
-
data = prepared.data;
|
|
97
|
-
}
|
|
98
|
-
else if (typeof prepared.data.stream === 'function') {
|
|
99
|
-
contentType = prepared.data.type || 'binary';
|
|
100
|
-
data = prepared.data.stream(); // File and Blob
|
|
101
|
-
}
|
|
102
|
-
else if (typeof prepared.data === 'object') {
|
|
103
|
-
contentType = 'application/json; charset=utf-8';
|
|
104
|
-
data = JSON.stringify(prepared.data);
|
|
105
|
-
}
|
|
106
|
-
else
|
|
107
|
-
throw new TypeError(`Invalid data type ${typeof prepared.data}`);
|
|
108
|
-
}
|
|
109
|
-
if (contentType && !headers.has('Content-Type'))
|
|
110
|
-
headers.set('Content-Type', contentType);
|
|
111
|
-
headers.forEach((v, k) => {
|
|
112
|
-
s += k + ': ' + (Array.isArray(v) ? v.join(';') : v) + CRLF;
|
|
113
|
-
});
|
|
114
|
-
if (data) {
|
|
115
|
-
if (typeof data === 'string')
|
|
116
|
-
chunks.push(s + CRLF + data + CRLF + CRLF);
|
|
117
|
-
else {
|
|
118
|
-
chunks.push(s + CRLF);
|
|
119
|
-
chunks.push(data);
|
|
120
|
-
chunks.push(CRLF + CRLF);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else
|
|
124
|
-
chunks.push(s + CRLF + CRLF);
|
|
125
|
-
}
|
|
126
|
-
chunks.push('--' + boundary + '--' + CRLF);
|
|
127
|
-
return boundary;
|
|
128
|
-
};
|
|
129
|
-
const boundary = processBatch(batch);
|
|
130
|
-
return { boundary, stream: Highland(chunks).flatten() };
|
|
131
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionCreateQueryOptions, CollectionResourceInfo } from '@opra/schema';
|
|
3
|
-
import type { OpraClient } from '../client.js';
|
|
4
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
5
|
-
import { ClientResponse, CommonQueryOptions, PartialInput } from '../types.js';
|
|
6
|
-
export declare class CollectionCreateRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
|
|
7
|
-
readonly client: OpraClient;
|
|
8
|
-
readonly resource: CollectionResourceInfo;
|
|
9
|
-
data: PartialInput<T>;
|
|
10
|
-
options: CollectionCreateQueryOptions & CommonQueryOptions;
|
|
11
|
-
constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, data: PartialInput<T>, options?: CollectionCreateQueryOptions & CommonQueryOptions);
|
|
12
|
-
prepare(): AxiosRequestConfig;
|
|
13
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
3
|
-
export class CollectionCreateRequest extends OpraClientRequest {
|
|
4
|
-
client;
|
|
5
|
-
resource;
|
|
6
|
-
data;
|
|
7
|
-
options;
|
|
8
|
-
constructor(client, send, resource, data, options = {}) {
|
|
9
|
-
super(client, send, options);
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.resource = resource;
|
|
12
|
-
this.data = data;
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
prepare() {
|
|
16
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
17
|
-
url.path.join(this.resource.name);
|
|
18
|
-
if (this.options.include)
|
|
19
|
-
url.searchParams.set('$include', this.options.include);
|
|
20
|
-
if (this.options.pick)
|
|
21
|
-
url.searchParams.set('$pick', this.options.pick);
|
|
22
|
-
if (this.options.omit)
|
|
23
|
-
url.searchParams.set('$omit', this.options.omit);
|
|
24
|
-
return {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
url: url.address,
|
|
27
|
-
data: this.data,
|
|
28
|
-
params: url.searchParams
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionDeleteManyQueryOptions, CollectionResourceInfo } from '@opra/schema';
|
|
3
|
-
import type { OpraClient } from '../client.js';
|
|
4
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
5
|
-
import { ClientResponse, CommonQueryOptions } from '../types.js';
|
|
6
|
-
export declare class CollectionDeleteManyRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
|
|
7
|
-
readonly client: OpraClient;
|
|
8
|
-
readonly resource: CollectionResourceInfo;
|
|
9
|
-
options: CollectionDeleteManyQueryOptions & CommonQueryOptions;
|
|
10
|
-
constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, options?: CollectionDeleteManyQueryOptions & CommonQueryOptions);
|
|
11
|
-
prepare(): AxiosRequestConfig;
|
|
12
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
3
|
-
export class CollectionDeleteManyRequest extends OpraClientRequest {
|
|
4
|
-
client;
|
|
5
|
-
resource;
|
|
6
|
-
options;
|
|
7
|
-
constructor(client, send, resource, options = {}) {
|
|
8
|
-
super(client, send, options);
|
|
9
|
-
this.client = client;
|
|
10
|
-
this.resource = resource;
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
prepare() {
|
|
14
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
15
|
-
url.path.join(this.resource.name);
|
|
16
|
-
if (this.options.filter)
|
|
17
|
-
url.searchParams.set('$filter', this.options.filter);
|
|
18
|
-
return {
|
|
19
|
-
method: 'DELETE',
|
|
20
|
-
url: url.address,
|
|
21
|
-
params: url.searchParams
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionResourceInfo } from '@opra/schema';
|
|
3
|
-
import type { OpraClient } from '../client.js';
|
|
4
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
5
|
-
import { ClientResponse, CommonQueryOptions } from '../types.js';
|
|
6
|
-
export declare class CollectionDeleteRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
|
|
7
|
-
readonly client: OpraClient;
|
|
8
|
-
readonly resource: CollectionResourceInfo;
|
|
9
|
-
keyValue: any;
|
|
10
|
-
options: CommonQueryOptions;
|
|
11
|
-
constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, keyValue: any, options?: CommonQueryOptions);
|
|
12
|
-
prepare(): AxiosRequestConfig;
|
|
13
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
3
|
-
export class CollectionDeleteRequest extends OpraClientRequest {
|
|
4
|
-
client;
|
|
5
|
-
resource;
|
|
6
|
-
keyValue;
|
|
7
|
-
options;
|
|
8
|
-
constructor(client, send, resource, keyValue, options = {}) {
|
|
9
|
-
super(client, send, options);
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.resource = resource;
|
|
12
|
-
this.keyValue = keyValue;
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
prepare() {
|
|
16
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
17
|
-
url.path.join(this.resource.name);
|
|
18
|
-
url.path.get(url.path.size - 1).key = this.keyValue;
|
|
19
|
-
return {
|
|
20
|
-
method: 'DELETE',
|
|
21
|
-
url: url.address,
|
|
22
|
-
params: url.searchParams
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionGetQueryOptions, CollectionResourceInfo } from '@opra/schema';
|
|
3
|
-
import type { OpraClient } from '../client.js';
|
|
4
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
5
|
-
import { ClientResponse, CommonQueryOptions } from '../types.js';
|
|
6
|
-
export declare class CollectionGetRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
|
|
7
|
-
readonly client: OpraClient;
|
|
8
|
-
readonly resource: CollectionResourceInfo;
|
|
9
|
-
keyValue: any;
|
|
10
|
-
options: CollectionGetQueryOptions & CommonQueryOptions;
|
|
11
|
-
constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, keyValue: any, options?: CollectionGetQueryOptions & CommonQueryOptions);
|
|
12
|
-
prepare(): AxiosRequestConfig;
|
|
13
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
3
|
-
export class CollectionGetRequest extends OpraClientRequest {
|
|
4
|
-
client;
|
|
5
|
-
resource;
|
|
6
|
-
keyValue;
|
|
7
|
-
options;
|
|
8
|
-
constructor(client, send, resource, keyValue, options = {}) {
|
|
9
|
-
super(client, send, options);
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.resource = resource;
|
|
12
|
-
this.keyValue = keyValue;
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
prepare() {
|
|
16
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
17
|
-
url.path.join(this.resource.name);
|
|
18
|
-
url.path.get(url.path.size - 1).key = this.keyValue;
|
|
19
|
-
if (this.options.include)
|
|
20
|
-
url.searchParams.set('$include', this.options.include);
|
|
21
|
-
if (this.options.pick)
|
|
22
|
-
url.searchParams.set('$pick', this.options.pick);
|
|
23
|
-
if (this.options.omit)
|
|
24
|
-
url.searchParams.set('$omit', this.options.omit);
|
|
25
|
-
return {
|
|
26
|
-
method: 'GET',
|
|
27
|
-
url: url.address,
|
|
28
|
-
params: url.searchParams
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionResourceInfo, CollectionSearchQueryOptions } from '@opra/schema';
|
|
3
|
-
import type { OpraClient } from '../client.js';
|
|
4
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
5
|
-
import { ClientResponse, CommonQueryOptions } from '../types.js';
|
|
6
|
-
export declare class CollectionSearchRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
|
|
7
|
-
readonly client: OpraClient;
|
|
8
|
-
readonly resource: CollectionResourceInfo;
|
|
9
|
-
options: CollectionSearchQueryOptions & CommonQueryOptions;
|
|
10
|
-
constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, options?: CollectionSearchQueryOptions & CommonQueryOptions);
|
|
11
|
-
prepare(): AxiosRequestConfig;
|
|
12
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
3
|
-
export class CollectionSearchRequest extends OpraClientRequest {
|
|
4
|
-
client;
|
|
5
|
-
resource;
|
|
6
|
-
options;
|
|
7
|
-
constructor(client, send, resource, options = {}) {
|
|
8
|
-
super(client, send, options);
|
|
9
|
-
this.client = client;
|
|
10
|
-
this.resource = resource;
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
prepare() {
|
|
14
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
15
|
-
url.path.join(this.resource.name);
|
|
16
|
-
if (this.options.include)
|
|
17
|
-
url.searchParams.set('$include', this.options.include);
|
|
18
|
-
if (this.options.pick)
|
|
19
|
-
url.searchParams.set('$pick', this.options.pick);
|
|
20
|
-
if (this.options.omit)
|
|
21
|
-
url.searchParams.set('$omit', this.options.omit);
|
|
22
|
-
if (this.options.sort)
|
|
23
|
-
url.searchParams.set('$sort', this.options.sort);
|
|
24
|
-
if (this.options.filter)
|
|
25
|
-
url.searchParams.set('$filter', this.options.filter);
|
|
26
|
-
if (this.options.limit != null)
|
|
27
|
-
url.searchParams.set('$limit', this.options.limit);
|
|
28
|
-
if (this.options.skip != null)
|
|
29
|
-
url.searchParams.set('$skip', this.options.skip);
|
|
30
|
-
if (this.options.count != null)
|
|
31
|
-
url.searchParams.set('$count', this.options.count);
|
|
32
|
-
if (this.options.distinct != null)
|
|
33
|
-
url.searchParams.set('$distinct', this.options.distinct);
|
|
34
|
-
return {
|
|
35
|
-
method: 'GET',
|
|
36
|
-
url: url.address,
|
|
37
|
-
params: url.searchParams
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { CollectionResourceInfo, CollectionUpdateManyQueryOptions } from '@opra/schema';
|
|
3
|
-
import type { OpraClient } from '../client.js';
|
|
4
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
5
|
-
import { ClientResponse, CommonQueryOptions, PartialInput } from '../types.js';
|
|
6
|
-
export declare class CollectionUpdateManyRequest<T, TResponse extends ClientResponse<T>> extends OpraClientRequest<T, TResponse> {
|
|
7
|
-
readonly client: OpraClient;
|
|
8
|
-
readonly resource: CollectionResourceInfo;
|
|
9
|
-
data: PartialInput<T>;
|
|
10
|
-
options: CollectionUpdateManyQueryOptions & CommonQueryOptions;
|
|
11
|
-
constructor(client: OpraClient, send: (req: AxiosRequestConfig) => Promise<TResponse>, resource: CollectionResourceInfo, data: PartialInput<T>, options?: CollectionUpdateManyQueryOptions & CommonQueryOptions);
|
|
12
|
-
prepare(): AxiosRequestConfig;
|
|
13
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { OpraURL } from '@opra/url';
|
|
2
|
-
import { OpraClientRequest } from '../client-request.js';
|
|
3
|
-
export class CollectionUpdateManyRequest extends OpraClientRequest {
|
|
4
|
-
client;
|
|
5
|
-
resource;
|
|
6
|
-
data;
|
|
7
|
-
options;
|
|
8
|
-
constructor(client, send, resource, data, options = {}) {
|
|
9
|
-
super(client, send, options);
|
|
10
|
-
this.client = client;
|
|
11
|
-
this.resource = resource;
|
|
12
|
-
this.data = data;
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
prepare() {
|
|
16
|
-
const url = new OpraURL(this.client.serviceUrl);
|
|
17
|
-
url.path.join(this.resource.name);
|
|
18
|
-
if (this.options.filter)
|
|
19
|
-
url.searchParams.set('$filter', this.options.filter);
|
|
20
|
-
return {
|
|
21
|
-
method: 'PATCH',
|
|
22
|
-
url: url.address,
|
|
23
|
-
data: this.data,
|
|
24
|
-
params: url.searchParams
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|