@nymphjs/client 1.0.0-beta.98 → 1.0.0-beta.99
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/CHANGELOG.md +6 -0
- package/dist/Nymph.types.d.ts +4 -0
- package/lib/Entity.d.ts +155 -0
- package/lib/Entity.js +585 -0
- package/lib/Entity.js.map +1 -0
- package/lib/Entity.types.d.ts +200 -0
- package/lib/Entity.types.js +3 -0
- package/lib/Entity.types.js.map +1 -0
- package/lib/EntityWeakCache.d.ts +6 -0
- package/lib/EntityWeakCache.js +32 -0
- package/lib/EntityWeakCache.js.map +1 -0
- package/lib/HttpRequester.d.ts +78 -0
- package/lib/HttpRequester.js +375 -0
- package/lib/HttpRequester.js.map +1 -0
- package/lib/Nymph.d.ts +111 -0
- package/lib/Nymph.js +426 -0
- package/lib/Nymph.js.map +1 -0
- package/lib/Nymph.types.d.ts +169 -0
- package/lib/Nymph.types.js +3 -0
- package/lib/Nymph.types.js.map +1 -0
- package/lib/PubSub.d.ts +63 -0
- package/lib/PubSub.js +596 -0
- package/lib/PubSub.js.map +1 -0
- package/lib/PubSub.types.d.ts +31 -0
- package/lib/PubSub.types.js +3 -0
- package/lib/PubSub.types.js.map +1 -0
- package/lib/entityRefresh.d.ts +5 -0
- package/lib/entityRefresh.js +83 -0
- package/lib/entityRefresh.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +34 -0
- package/lib/index.js.map +1 -0
- package/lib/utils.d.ts +8 -0
- package/lib/utils.js +97 -0
- package/lib/utils.js.map +1 -0
- package/package.json +2 -2
- package/src/Nymph.types.ts +6 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerError = exports.ClientError = exports.RedirectError = exports.SuccessError = exports.InformationalError = exports.HttpError = exports.ConnectionError = exports.ConnectionClosedUnexpectedlyError = exports.InvalidResponseError = void 0;
|
|
4
|
+
const fetch_event_source_hperrin_1 = require("fetch-event-source-hperrin");
|
|
5
|
+
class HttpRequester {
|
|
6
|
+
static makeUrl(url, data) {
|
|
7
|
+
if (!data) {
|
|
8
|
+
return url;
|
|
9
|
+
}
|
|
10
|
+
for (let [key, value] of Object.entries(data)) {
|
|
11
|
+
url =
|
|
12
|
+
url +
|
|
13
|
+
(url.indexOf('?') !== -1 ? '&' : '?') +
|
|
14
|
+
encodeURIComponent(key) +
|
|
15
|
+
'=' +
|
|
16
|
+
encodeURIComponent(JSON.stringify(value));
|
|
17
|
+
}
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
constructor(ponyFetch) {
|
|
21
|
+
this.requestCallbacks = [];
|
|
22
|
+
this.responseCallbacks = [];
|
|
23
|
+
this.iteratorCallbacks = [];
|
|
24
|
+
this.fetch = ponyFetch ? ponyFetch : (...args) => fetch(...args);
|
|
25
|
+
}
|
|
26
|
+
on(event, callback) {
|
|
27
|
+
const prop = (event + 'Callbacks');
|
|
28
|
+
if (!(prop in this)) {
|
|
29
|
+
throw new Error('Invalid event type.');
|
|
30
|
+
}
|
|
31
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
32
|
+
this[prop].push(callback);
|
|
33
|
+
return () => this.off(event, callback);
|
|
34
|
+
}
|
|
35
|
+
off(event, callback) {
|
|
36
|
+
const prop = (event + 'Callbacks');
|
|
37
|
+
if (!(prop in this)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
41
|
+
const i = this[prop].indexOf(callback);
|
|
42
|
+
if (i > -1) {
|
|
43
|
+
// @ts-ignore: The callback should always be the right type here.
|
|
44
|
+
this[prop].splice(i, 1);
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
async GET(opt) {
|
|
49
|
+
return await this._httpRequest('GET', opt);
|
|
50
|
+
}
|
|
51
|
+
async POST(opt) {
|
|
52
|
+
return await this._httpRequest('POST', opt);
|
|
53
|
+
}
|
|
54
|
+
async POST_ITERATOR(opt) {
|
|
55
|
+
return await this._iteratorRequest('POST', opt);
|
|
56
|
+
}
|
|
57
|
+
async PUT(opt) {
|
|
58
|
+
return await this._httpRequest('PUT', opt);
|
|
59
|
+
}
|
|
60
|
+
async PATCH(opt) {
|
|
61
|
+
return await this._httpRequest('PATCH', opt);
|
|
62
|
+
}
|
|
63
|
+
async DELETE(opt) {
|
|
64
|
+
return await this._httpRequest('DELETE', opt);
|
|
65
|
+
}
|
|
66
|
+
async _httpRequest(method, opt) {
|
|
67
|
+
const dataString = JSON.stringify(opt.data);
|
|
68
|
+
let url = opt.url;
|
|
69
|
+
if (method === 'GET') {
|
|
70
|
+
// TODO: what should this size be?
|
|
71
|
+
// && dataString.length < 1) {
|
|
72
|
+
url = HttpRequester.makeUrl(opt.url, opt.data);
|
|
73
|
+
}
|
|
74
|
+
const options = {
|
|
75
|
+
method,
|
|
76
|
+
headers: opt.headers ?? {},
|
|
77
|
+
credentials: 'include',
|
|
78
|
+
};
|
|
79
|
+
if (method !== 'GET' && opt.data) {
|
|
80
|
+
options.headers['Content-Type'] =
|
|
81
|
+
'application/json';
|
|
82
|
+
options.body = dataString;
|
|
83
|
+
}
|
|
84
|
+
for (let i = 0; i < this.requestCallbacks.length; i++) {
|
|
85
|
+
this.requestCallbacks[i] && this.requestCallbacks[i](this, url, options);
|
|
86
|
+
}
|
|
87
|
+
const response = await this.fetch(url, options);
|
|
88
|
+
let text;
|
|
89
|
+
try {
|
|
90
|
+
text = await response.text();
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
throw new InvalidResponseError('Server response did not contain valid text body.');
|
|
94
|
+
}
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
let errObj;
|
|
97
|
+
try {
|
|
98
|
+
errObj = JSON.parse(text);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
if (!(e instanceof SyntaxError)) {
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (typeof errObj !== 'object') {
|
|
106
|
+
errObj = {
|
|
107
|
+
textStatus: response.statusText,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
errObj.status = response.status;
|
|
111
|
+
throw response.status < 200
|
|
112
|
+
? new InformationalError(response, errObj)
|
|
113
|
+
: response.status < 300
|
|
114
|
+
? new SuccessError(response, errObj)
|
|
115
|
+
: response.status < 400
|
|
116
|
+
? new RedirectError(response, errObj)
|
|
117
|
+
: response.status < 500
|
|
118
|
+
? new ClientError(response, errObj)
|
|
119
|
+
: new ServerError(response, errObj);
|
|
120
|
+
}
|
|
121
|
+
for (let i = 0; i < this.responseCallbacks.length; i++) {
|
|
122
|
+
this.responseCallbacks[i] &&
|
|
123
|
+
this.responseCallbacks[i](this, response, text);
|
|
124
|
+
}
|
|
125
|
+
if (opt.dataType === 'json') {
|
|
126
|
+
if (!text.length) {
|
|
127
|
+
throw new InvalidResponseError('Server response was empty.');
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return JSON.parse(text);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (!(e instanceof SyntaxError)) {
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
throw new InvalidResponseError('Server response was invalid: ' + JSON.stringify(text));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
return text;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async _iteratorRequest(method, opt) {
|
|
144
|
+
const dataString = JSON.stringify(opt.data);
|
|
145
|
+
let url = opt.url;
|
|
146
|
+
if (method === 'GET') {
|
|
147
|
+
// TODO: what should this size be?
|
|
148
|
+
// && dataString.length < 1) {
|
|
149
|
+
url = HttpRequester.makeUrl(opt.url, opt.data);
|
|
150
|
+
}
|
|
151
|
+
const hasBody = method !== 'GET' && opt.data;
|
|
152
|
+
const headers = opt.headers ?? {};
|
|
153
|
+
if (hasBody) {
|
|
154
|
+
headers['Content-Type'] = 'application/json';
|
|
155
|
+
}
|
|
156
|
+
for (let i = 0; i < this.iteratorCallbacks.length; i++) {
|
|
157
|
+
this.iteratorCallbacks[i] &&
|
|
158
|
+
this.iteratorCallbacks[i](this, url, headers);
|
|
159
|
+
}
|
|
160
|
+
const responses = [];
|
|
161
|
+
let nextResponseResolve;
|
|
162
|
+
let nextResponseReadyPromise = new Promise((res) => {
|
|
163
|
+
nextResponseResolve = res;
|
|
164
|
+
});
|
|
165
|
+
let responsesDone = false;
|
|
166
|
+
let serverResponse;
|
|
167
|
+
const ctrl = new AbortController();
|
|
168
|
+
(0, fetch_event_source_hperrin_1.fetchEventSource)(url, {
|
|
169
|
+
openWhenHidden: true,
|
|
170
|
+
fetch: this.fetch,
|
|
171
|
+
method,
|
|
172
|
+
headers,
|
|
173
|
+
credentials: 'include',
|
|
174
|
+
body: hasBody ? dataString : undefined,
|
|
175
|
+
signal: ctrl.signal,
|
|
176
|
+
async onopen(response) {
|
|
177
|
+
serverResponse = response;
|
|
178
|
+
if (response.ok) {
|
|
179
|
+
if (response.headers.get('content-type') === fetch_event_source_hperrin_1.EventStreamContentType) {
|
|
180
|
+
throw new InvalidResponseError('Server response is not an event stream.');
|
|
181
|
+
}
|
|
182
|
+
// Response is ok, wait for messages.
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
let text = '';
|
|
186
|
+
try {
|
|
187
|
+
text = await response.text();
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
// Ignore error here.
|
|
191
|
+
}
|
|
192
|
+
let errObj;
|
|
193
|
+
try {
|
|
194
|
+
errObj = JSON.parse(text);
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
if (!(e instanceof SyntaxError)) {
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (typeof errObj !== 'object') {
|
|
202
|
+
errObj = {
|
|
203
|
+
textStatus: response.statusText,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
errObj.status = response.status;
|
|
207
|
+
throw response.status < 200
|
|
208
|
+
? new InformationalError(response, errObj)
|
|
209
|
+
: response.status < 300
|
|
210
|
+
? new SuccessError(response, errObj)
|
|
211
|
+
: response.status < 400
|
|
212
|
+
? new RedirectError(response, errObj)
|
|
213
|
+
: response.status < 500
|
|
214
|
+
? new ClientError(response, errObj)
|
|
215
|
+
: new ServerError(response, errObj);
|
|
216
|
+
},
|
|
217
|
+
onmessage(event) {
|
|
218
|
+
if (event.event === 'next') {
|
|
219
|
+
let text = event.data;
|
|
220
|
+
if (opt.dataType === 'json') {
|
|
221
|
+
if (!text.length) {
|
|
222
|
+
responses.push(new InvalidResponseError('Server response was empty.'));
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
try {
|
|
226
|
+
responses.push(JSON.parse(text));
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
if (!(e instanceof SyntaxError)) {
|
|
230
|
+
responses.push(e);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
responses.push(new InvalidResponseError('Server response was invalid: ' + JSON.stringify(text)));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
responses.push(text);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (event.event === 'error') {
|
|
243
|
+
let text = event.data;
|
|
244
|
+
let errObj;
|
|
245
|
+
try {
|
|
246
|
+
errObj = JSON.parse(text);
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
if (!(e instanceof SyntaxError)) {
|
|
250
|
+
throw e;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (typeof errObj !== 'object') {
|
|
254
|
+
errObj = {
|
|
255
|
+
status: 500,
|
|
256
|
+
textStatus: 'Iterator Error',
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
responses.push(errObj.status < 200
|
|
260
|
+
? new InformationalError(serverResponse, errObj)
|
|
261
|
+
: errObj.status < 300
|
|
262
|
+
? new SuccessError(serverResponse, errObj)
|
|
263
|
+
: errObj.status < 400
|
|
264
|
+
? new RedirectError(serverResponse, errObj)
|
|
265
|
+
: errObj.status < 500
|
|
266
|
+
? new ClientError(serverResponse, errObj)
|
|
267
|
+
: new ServerError(serverResponse, errObj));
|
|
268
|
+
}
|
|
269
|
+
else if (event.event === 'finished') {
|
|
270
|
+
responsesDone = true;
|
|
271
|
+
}
|
|
272
|
+
else if (event.event === 'ping') {
|
|
273
|
+
// Ignore keep-alive pings.
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const resolve = nextResponseResolve;
|
|
277
|
+
if (!responsesDone) {
|
|
278
|
+
nextResponseReadyPromise = new Promise((res) => {
|
|
279
|
+
nextResponseResolve = res;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// Resolve the promise to continue any waiting iterator.
|
|
283
|
+
resolve();
|
|
284
|
+
},
|
|
285
|
+
onclose() {
|
|
286
|
+
responses.push(new ConnectionClosedUnexpectedlyError('The connection to the server was closed unexpectedly.'));
|
|
287
|
+
responsesDone = true;
|
|
288
|
+
nextResponseResolve();
|
|
289
|
+
},
|
|
290
|
+
onerror(err) {
|
|
291
|
+
// Rethrow to stop the operation.
|
|
292
|
+
throw err;
|
|
293
|
+
},
|
|
294
|
+
}).catch((err) => {
|
|
295
|
+
responses.push(new ConnectionError('The connection could not be established: ' + err));
|
|
296
|
+
responsesDone = true;
|
|
297
|
+
nextResponseResolve();
|
|
298
|
+
});
|
|
299
|
+
const iterator = {
|
|
300
|
+
abortController: ctrl,
|
|
301
|
+
async *[Symbol.asyncIterator]() {
|
|
302
|
+
do {
|
|
303
|
+
await nextResponseReadyPromise;
|
|
304
|
+
while (responses.length) {
|
|
305
|
+
yield responses.shift();
|
|
306
|
+
}
|
|
307
|
+
} while (!responsesDone);
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
return iterator;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
exports.default = HttpRequester;
|
|
314
|
+
class InvalidResponseError extends Error {
|
|
315
|
+
constructor(message) {
|
|
316
|
+
super(message);
|
|
317
|
+
this.name = 'InvalidResponseError';
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.InvalidResponseError = InvalidResponseError;
|
|
321
|
+
class ConnectionClosedUnexpectedlyError extends Error {
|
|
322
|
+
constructor(message) {
|
|
323
|
+
super(message);
|
|
324
|
+
this.name = 'ConnectionClosedUnexpectedlyError';
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
exports.ConnectionClosedUnexpectedlyError = ConnectionClosedUnexpectedlyError;
|
|
328
|
+
class ConnectionError extends Error {
|
|
329
|
+
constructor(message) {
|
|
330
|
+
super(message);
|
|
331
|
+
this.name = 'ConnectionError';
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
exports.ConnectionError = ConnectionError;
|
|
335
|
+
class HttpError extends Error {
|
|
336
|
+
constructor(name, response, errObj) {
|
|
337
|
+
super(errObj.textStatus);
|
|
338
|
+
this.name = name;
|
|
339
|
+
this.status = response.status;
|
|
340
|
+
this.statusText = response.statusText;
|
|
341
|
+
Object.assign(this, errObj);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.HttpError = HttpError;
|
|
345
|
+
class InformationalError extends HttpError {
|
|
346
|
+
constructor(response, errObj) {
|
|
347
|
+
super('InformationalError', response, errObj);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.InformationalError = InformationalError;
|
|
351
|
+
class SuccessError extends HttpError {
|
|
352
|
+
constructor(response, errObj) {
|
|
353
|
+
super('SuccessError', response, errObj);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
exports.SuccessError = SuccessError;
|
|
357
|
+
class RedirectError extends HttpError {
|
|
358
|
+
constructor(response, errObj) {
|
|
359
|
+
super('RedirectError', response, errObj);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
exports.RedirectError = RedirectError;
|
|
363
|
+
class ClientError extends HttpError {
|
|
364
|
+
constructor(response, errObj) {
|
|
365
|
+
super('ClientError', response, errObj);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
exports.ClientError = ClientError;
|
|
369
|
+
class ServerError extends HttpError {
|
|
370
|
+
constructor(response, errObj) {
|
|
371
|
+
super('ServerError', response, errObj);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
exports.ServerError = ServerError;
|
|
375
|
+
//# sourceMappingURL=HttpRequester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRequester.js","sourceRoot":"","sources":["../src/HttpRequester.ts"],"names":[],"mappings":";;;AAAA,2EAGoC;AA8BpC,MAAqB,aAAa;IAMhC,MAAM,CAAC,OAAO,CAAC,GAAW,EAAE,IAA0B;QACpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,GAAG,CAAC;QACb,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,GAAG;gBACD,GAAG;oBACH,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;oBACrC,kBAAkB,CAAC,GAAG,CAAC;oBACvB,GAAG;oBACH,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,YAAY,SAA8C;QAnBlD,qBAAgB,GAAmC,EAAE,CAAC;QACtD,sBAAiB,GAAoC,EAAE,CAAC;QACxD,sBAAiB,GAAoC,EAAE,CAAC;QAkB9D,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,SA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CAAC;IACzC,CAAC;CACF;AAJD,kCAIC;AAED,MAAa,WAAY,SAAQ,SAAS;IACxC,YAAY,QAAkB,EAAE,MAA8B;QAC5D,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;CACF;AAJD,kCAIC"}
|
package/lib/Nymph.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import Entity, { type EntityInstanceType } from './Entity';
|
|
2
|
+
import type { EntityConstructor, EntityInterface, EntityJson, ServerCallResponse, ServerCallStaticResponse } from './Entity.types';
|
|
3
|
+
import EntityWeakCache from './EntityWeakCache';
|
|
4
|
+
import type { AbortableAsyncIterator } from './HttpRequester';
|
|
5
|
+
import type { EventType, NymphOptions, Options, RequestCallback, ResponseCallback, Selector } from './Nymph.types';
|
|
6
|
+
import type PubSub from './PubSub';
|
|
7
|
+
export default class Nymph {
|
|
8
|
+
/**
|
|
9
|
+
* And optional PubSub client instance.
|
|
10
|
+
*/
|
|
11
|
+
pubsub: PubSub | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* A simple map of names to Entity classes.
|
|
14
|
+
*/
|
|
15
|
+
private entityClasses;
|
|
16
|
+
/**
|
|
17
|
+
* The entity class for this instance of Nymph.
|
|
18
|
+
*/
|
|
19
|
+
Entity: typeof Entity;
|
|
20
|
+
private requestCallbacks;
|
|
21
|
+
private responseCallbacks;
|
|
22
|
+
private restUrl;
|
|
23
|
+
private weakCache;
|
|
24
|
+
/**
|
|
25
|
+
* Headers that will be sent with every request.
|
|
26
|
+
*
|
|
27
|
+
* These are used by Tilmeld for authentication.
|
|
28
|
+
*/
|
|
29
|
+
headers: {
|
|
30
|
+
[k: string]: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The entity cache.
|
|
34
|
+
*/
|
|
35
|
+
cache: EntityWeakCache;
|
|
36
|
+
constructor(NymphOptions: NymphOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Add your class to this instance.
|
|
39
|
+
*
|
|
40
|
+
* This will create a class that extends your class within this instance of
|
|
41
|
+
* Nymph and return it. You can then use this class's constructor and methods,
|
|
42
|
+
* which will use this instance of Nymph.
|
|
43
|
+
*
|
|
44
|
+
* Because this creates a subclass, don't use the class
|
|
45
|
+
* returned from `getEntityClass` to check with `instanceof`.
|
|
46
|
+
*/
|
|
47
|
+
addEntityClass<T extends EntityConstructor>(entityClass: T): T;
|
|
48
|
+
getEntityClass<T extends EntityConstructor>(className: T): T;
|
|
49
|
+
getEntityClass(className: string): EntityConstructor;
|
|
50
|
+
newUID(name: string): Promise<number>;
|
|
51
|
+
setUID(name: string, value: number): Promise<any>;
|
|
52
|
+
getUID(name: string): Promise<number>;
|
|
53
|
+
deleteUID(name: string): Promise<any>;
|
|
54
|
+
saveEntity(entity: EntityInterface): Promise<EntityInterface>;
|
|
55
|
+
saveEntities(entities: EntityInterface[]): Promise<boolean | EntityInterface[]>;
|
|
56
|
+
patchEntity(entity: EntityInterface): Promise<EntityInterface>;
|
|
57
|
+
patchEntities(entities: EntityInterface[]): Promise<boolean | EntityInterface[]>;
|
|
58
|
+
private requestWithMethod;
|
|
59
|
+
getEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
60
|
+
return: 'count';
|
|
61
|
+
}, ...selectors: Selector[]): Promise<number>;
|
|
62
|
+
getEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
63
|
+
return: 'guid';
|
|
64
|
+
}, ...selectors: Selector[]): Promise<string | null>;
|
|
65
|
+
getEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T> | null>;
|
|
66
|
+
getEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
67
|
+
return: 'count';
|
|
68
|
+
}, guid: string): Promise<number>;
|
|
69
|
+
getEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
70
|
+
return: 'guid';
|
|
71
|
+
}, guid: string): Promise<string | null>;
|
|
72
|
+
getEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T>, guid: string): Promise<EntityInstanceType<T> | null>;
|
|
73
|
+
getEntityData<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
74
|
+
return: 'count';
|
|
75
|
+
}, ...selectors: Selector[]): Promise<number>;
|
|
76
|
+
getEntityData<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
77
|
+
return: 'guid';
|
|
78
|
+
}, ...selectors: Selector[]): Promise<string | null>;
|
|
79
|
+
getEntityData<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): Promise<EntityJson<T> | null>;
|
|
80
|
+
getEntityData<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
81
|
+
return: 'count';
|
|
82
|
+
}, guid: string): Promise<number>;
|
|
83
|
+
getEntityData<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
84
|
+
return: 'guid';
|
|
85
|
+
}, guid: string): Promise<string | null>;
|
|
86
|
+
getEntityData<T extends EntityConstructor = EntityConstructor>(options: Options<T>, guid: string): Promise<EntityJson<T> | null>;
|
|
87
|
+
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
88
|
+
return: 'count';
|
|
89
|
+
}, ...selectors: Selector[]): Promise<number>;
|
|
90
|
+
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
|
|
91
|
+
return: 'guid';
|
|
92
|
+
}, ...selectors: Selector[]): Promise<string[]>;
|
|
93
|
+
getEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): Promise<EntityInstanceType<T>[]>;
|
|
94
|
+
initEntity<T extends EntityConstructor = EntityConstructor>(entityJSON: EntityJson<T>): EntityInstanceType<T>;
|
|
95
|
+
getEntityFromCache<T extends EntityConstructor = EntityConstructor>(EntityClass: EntityConstructor, guid: string): EntityInstanceType<T> | null;
|
|
96
|
+
setEntityToCache(EntityClass: EntityConstructor, entity: EntityInterface): void;
|
|
97
|
+
initEntitiesFromData<T extends any>(item: T): T;
|
|
98
|
+
deleteEntity(entity: EntityInterface | EntityInterface[], _plural?: boolean): Promise<any>;
|
|
99
|
+
deleteEntities(entities: EntityInterface[]): Promise<any>;
|
|
100
|
+
serverCall(entity: EntityInterface, method: string, params: any[], stateless?: boolean): Promise<ServerCallResponse>;
|
|
101
|
+
serverCallStatic(className: string, method: string, params: any[]): Promise<ServerCallStaticResponse>;
|
|
102
|
+
serverCallStaticIterator(className: string, method: string, params: any[]): Promise<AbortableAsyncIterator<ServerCallStaticResponse>>;
|
|
103
|
+
on<T extends EventType>(event: T, callback: T extends 'request' ? RequestCallback : T extends 'response' ? ResponseCallback : never): () => boolean;
|
|
104
|
+
off<T extends EventType>(event: T, callback: T extends 'request' ? RequestCallback : T extends 'response' ? ResponseCallback : never): boolean;
|
|
105
|
+
}
|
|
106
|
+
export declare class ClassNotAvailableError extends Error {
|
|
107
|
+
constructor(message: string);
|
|
108
|
+
}
|
|
109
|
+
export declare class InvalidRequestError extends Error {
|
|
110
|
+
constructor(message: string);
|
|
111
|
+
}
|