telepact 1.0.0-alpha.253 → 1.0.0-alpha.264
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/README.md +3 -2
- package/dist/index.cjs.js +19 -17
- package/dist/index.esm.js +19 -17
- package/dist/index.iife.js +19 -17
- package/dist/src/FunctionRouter.d.ts +8 -0
- package/dist/src/FunctionRouter.js +30 -0
- package/dist/src/FunctionRouter.js.map +1 -0
- package/dist/src/MockServer.js +3 -2
- package/dist/src/MockServer.js.map +1 -1
- package/dist/src/Server.d.ts +4 -8
- package/dist/src/Server.js +3 -16
- package/dist/src/Server.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Server:
|
|
|
21
21
|
```ts
|
|
22
22
|
import * as fs from 'fs';
|
|
23
23
|
import * as path from 'path';
|
|
24
|
-
import { Message, Server, ServerOptions, TelepactSchema, TelepactSchemaFiles } from 'telepact';
|
|
24
|
+
import { FunctionRouter, Message, Server, ServerOptions, TelepactSchema, TelepactSchemaFiles } from 'telepact';
|
|
25
25
|
|
|
26
26
|
const files = new TelepactSchemaFiles('/directory/containing/api/files', fs, path);
|
|
27
27
|
const schema = TelepactSchema.fromFileJsonMap(files.filenamesToJson);
|
|
@@ -49,7 +49,8 @@ options.middleware = async (requestMessage: Message, functionRouter): Promise<Me
|
|
|
49
49
|
log.info("Function finished", {function: functionName});
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
const
|
|
52
|
+
const functionRouter = new FunctionRouter(functionRoutes);
|
|
53
|
+
const server = new Server(schema, functionRouter, options);
|
|
53
54
|
|
|
54
55
|
// Wire up request/response bytes from your transport of choice
|
|
55
56
|
transport.receive(async (requestBytes: Uint8Array): Promise<Uint8Array> => {
|
package/dist/index.cjs.js
CHANGED
|
@@ -1099,6 +1099,21 @@ class ClientOptions {
|
|
|
1099
1099
|
}
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
|
+
class FunctionRouter {
|
|
1103
|
+
functionRoutes;
|
|
1104
|
+
constructor(functionRoutes) {
|
|
1105
|
+
this.functionRoutes = functionRoutes;
|
|
1106
|
+
}
|
|
1107
|
+
async route(requestMessage) {
|
|
1108
|
+
const functionName = requestMessage.getBodyTarget();
|
|
1109
|
+
const functionRoute = this.functionRoutes[functionName];
|
|
1110
|
+
if (functionRoute === undefined) {
|
|
1111
|
+
throw new Error(`Unknown function: ${functionName}`);
|
|
1112
|
+
}
|
|
1113
|
+
return await functionRoute(functionName, requestMessage);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1102
1117
|
function serverBinaryEncode(message, binaryEncoder) {
|
|
1103
1118
|
const headers = message[0];
|
|
1104
1119
|
const messageBody = message[1];
|
|
@@ -2350,20 +2365,6 @@ class ServerBase64Encoder extends Base64Encoder {
|
|
|
2350
2365
|
}
|
|
2351
2366
|
}
|
|
2352
2367
|
|
|
2353
|
-
class FunctionRouter {
|
|
2354
|
-
functionRoutes;
|
|
2355
|
-
constructor(functionRoutes) {
|
|
2356
|
-
this.functionRoutes = functionRoutes;
|
|
2357
|
-
}
|
|
2358
|
-
async route(requestMessage) {
|
|
2359
|
-
const functionName = requestMessage.getBodyTarget();
|
|
2360
|
-
const functionRoute = this.functionRoutes[functionName];
|
|
2361
|
-
if (functionRoute === undefined) {
|
|
2362
|
-
throw new Error(`Unknown function: ${functionName}`);
|
|
2363
|
-
}
|
|
2364
|
-
return await functionRoute(functionName, requestMessage);
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
2368
|
class Server {
|
|
2368
2369
|
functionRouter;
|
|
2369
2370
|
middleware;
|
|
@@ -2373,8 +2374,8 @@ class Server {
|
|
|
2373
2374
|
onAuth;
|
|
2374
2375
|
telepactSchema;
|
|
2375
2376
|
serializer;
|
|
2376
|
-
constructor(telepactSchema,
|
|
2377
|
-
this.functionRouter =
|
|
2377
|
+
constructor(telepactSchema, functionRouter, options) {
|
|
2378
|
+
this.functionRouter = functionRouter;
|
|
2378
2379
|
this.middleware = options.middleware;
|
|
2379
2380
|
this.onError = options.onError;
|
|
2380
2381
|
this.onRequest = options.onRequest;
|
|
@@ -11886,7 +11887,8 @@ class MockServer {
|
|
|
11886
11887
|
serverOptions.authRequired = false;
|
|
11887
11888
|
serverOptions.middleware = async (requestMessage) => await this.handle(requestMessage);
|
|
11888
11889
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
11889
|
-
|
|
11890
|
+
const functionRouter = new FunctionRouter({});
|
|
11891
|
+
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
11890
11892
|
}
|
|
11891
11893
|
random;
|
|
11892
11894
|
enableGeneratedDefaultStub;
|
package/dist/index.esm.js
CHANGED
|
@@ -1097,6 +1097,21 @@ class ClientOptions {
|
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
|
+
class FunctionRouter {
|
|
1101
|
+
functionRoutes;
|
|
1102
|
+
constructor(functionRoutes) {
|
|
1103
|
+
this.functionRoutes = functionRoutes;
|
|
1104
|
+
}
|
|
1105
|
+
async route(requestMessage) {
|
|
1106
|
+
const functionName = requestMessage.getBodyTarget();
|
|
1107
|
+
const functionRoute = this.functionRoutes[functionName];
|
|
1108
|
+
if (functionRoute === undefined) {
|
|
1109
|
+
throw new Error(`Unknown function: ${functionName}`);
|
|
1110
|
+
}
|
|
1111
|
+
return await functionRoute(functionName, requestMessage);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1100
1115
|
function serverBinaryEncode(message, binaryEncoder) {
|
|
1101
1116
|
const headers = message[0];
|
|
1102
1117
|
const messageBody = message[1];
|
|
@@ -2348,20 +2363,6 @@ class ServerBase64Encoder extends Base64Encoder {
|
|
|
2348
2363
|
}
|
|
2349
2364
|
}
|
|
2350
2365
|
|
|
2351
|
-
class FunctionRouter {
|
|
2352
|
-
functionRoutes;
|
|
2353
|
-
constructor(functionRoutes) {
|
|
2354
|
-
this.functionRoutes = functionRoutes;
|
|
2355
|
-
}
|
|
2356
|
-
async route(requestMessage) {
|
|
2357
|
-
const functionName = requestMessage.getBodyTarget();
|
|
2358
|
-
const functionRoute = this.functionRoutes[functionName];
|
|
2359
|
-
if (functionRoute === undefined) {
|
|
2360
|
-
throw new Error(`Unknown function: ${functionName}`);
|
|
2361
|
-
}
|
|
2362
|
-
return await functionRoute(functionName, requestMessage);
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
2366
|
class Server {
|
|
2366
2367
|
functionRouter;
|
|
2367
2368
|
middleware;
|
|
@@ -2371,8 +2372,8 @@ class Server {
|
|
|
2371
2372
|
onAuth;
|
|
2372
2373
|
telepactSchema;
|
|
2373
2374
|
serializer;
|
|
2374
|
-
constructor(telepactSchema,
|
|
2375
|
-
this.functionRouter =
|
|
2375
|
+
constructor(telepactSchema, functionRouter, options) {
|
|
2376
|
+
this.functionRouter = functionRouter;
|
|
2376
2377
|
this.middleware = options.middleware;
|
|
2377
2378
|
this.onError = options.onError;
|
|
2378
2379
|
this.onRequest = options.onRequest;
|
|
@@ -11884,7 +11885,8 @@ class MockServer {
|
|
|
11884
11885
|
serverOptions.authRequired = false;
|
|
11885
11886
|
serverOptions.middleware = async (requestMessage) => await this.handle(requestMessage);
|
|
11886
11887
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
11887
|
-
|
|
11888
|
+
const functionRouter = new FunctionRouter({});
|
|
11889
|
+
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
11888
11890
|
}
|
|
11889
11891
|
random;
|
|
11890
11892
|
enableGeneratedDefaultStub;
|
package/dist/index.iife.js
CHANGED
|
@@ -1097,6 +1097,21 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
|
+
class FunctionRouter {
|
|
1101
|
+
functionRoutes;
|
|
1102
|
+
constructor(functionRoutes) {
|
|
1103
|
+
this.functionRoutes = functionRoutes;
|
|
1104
|
+
}
|
|
1105
|
+
async route(requestMessage) {
|
|
1106
|
+
const functionName = requestMessage.getBodyTarget();
|
|
1107
|
+
const functionRoute = this.functionRoutes[functionName];
|
|
1108
|
+
if (functionRoute === undefined) {
|
|
1109
|
+
throw new Error(`Unknown function: ${functionName}`);
|
|
1110
|
+
}
|
|
1111
|
+
return await functionRoute(functionName, requestMessage);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1100
1115
|
function serverBinaryEncode(message, binaryEncoder) {
|
|
1101
1116
|
const headers = message[0];
|
|
1102
1117
|
const messageBody = message[1];
|
|
@@ -2348,20 +2363,6 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
2348
2363
|
}
|
|
2349
2364
|
}
|
|
2350
2365
|
|
|
2351
|
-
class FunctionRouter {
|
|
2352
|
-
functionRoutes;
|
|
2353
|
-
constructor(functionRoutes) {
|
|
2354
|
-
this.functionRoutes = functionRoutes;
|
|
2355
|
-
}
|
|
2356
|
-
async route(requestMessage) {
|
|
2357
|
-
const functionName = requestMessage.getBodyTarget();
|
|
2358
|
-
const functionRoute = this.functionRoutes[functionName];
|
|
2359
|
-
if (functionRoute === undefined) {
|
|
2360
|
-
throw new Error(`Unknown function: ${functionName}`);
|
|
2361
|
-
}
|
|
2362
|
-
return await functionRoute(functionName, requestMessage);
|
|
2363
|
-
}
|
|
2364
|
-
}
|
|
2365
2366
|
class Server {
|
|
2366
2367
|
functionRouter;
|
|
2367
2368
|
middleware;
|
|
@@ -2371,8 +2372,8 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
2371
2372
|
onAuth;
|
|
2372
2373
|
telepactSchema;
|
|
2373
2374
|
serializer;
|
|
2374
|
-
constructor(telepactSchema,
|
|
2375
|
-
this.functionRouter =
|
|
2375
|
+
constructor(telepactSchema, functionRouter, options) {
|
|
2376
|
+
this.functionRouter = functionRouter;
|
|
2376
2377
|
this.middleware = options.middleware;
|
|
2377
2378
|
this.onError = options.onError;
|
|
2378
2379
|
this.onRequest = options.onRequest;
|
|
@@ -11884,7 +11885,8 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
11884
11885
|
serverOptions.authRequired = false;
|
|
11885
11886
|
serverOptions.middleware = async (requestMessage) => await this.handle(requestMessage);
|
|
11886
11887
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
11887
|
-
|
|
11888
|
+
const functionRouter = new FunctionRouter({});
|
|
11889
|
+
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
11888
11890
|
}
|
|
11889
11891
|
random;
|
|
11890
11892
|
enableGeneratedDefaultStub;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Message } from './Message.js';
|
|
2
|
+
export type FunctionRoute = (functionName: string, requestMessage: Message) => Promise<Message>;
|
|
3
|
+
export type FunctionRoutes = Record<string, FunctionRoute>;
|
|
4
|
+
export declare class FunctionRouter {
|
|
5
|
+
functionRoutes: FunctionRoutes;
|
|
6
|
+
constructor(functionRoutes: FunctionRoutes);
|
|
7
|
+
route(requestMessage: Message): Promise<Message>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//|
|
|
2
|
+
//| Copyright The Telepact Authors
|
|
3
|
+
//|
|
|
4
|
+
//| Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
//| you may not use this file except in compliance with the License.
|
|
6
|
+
//| You may obtain a copy of the License at
|
|
7
|
+
//|
|
|
8
|
+
//| https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//|
|
|
10
|
+
//| Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
//| distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
//| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
//| See the License for the specific language governing permissions and
|
|
14
|
+
//| limitations under the License.
|
|
15
|
+
//|
|
|
16
|
+
export class FunctionRouter {
|
|
17
|
+
functionRoutes;
|
|
18
|
+
constructor(functionRoutes) {
|
|
19
|
+
this.functionRoutes = functionRoutes;
|
|
20
|
+
}
|
|
21
|
+
async route(requestMessage) {
|
|
22
|
+
const functionName = requestMessage.getBodyTarget();
|
|
23
|
+
const functionRoute = this.functionRoutes[functionName];
|
|
24
|
+
if (functionRoute === undefined) {
|
|
25
|
+
throw new Error(`Unknown function: ${functionName}`);
|
|
26
|
+
}
|
|
27
|
+
return await functionRoute(functionName, requestMessage);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=FunctionRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FunctionRouter.js","sourceRoot":"","sources":["../../src/FunctionRouter.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAOH,MAAM,OAAO,cAAc;IACvB,cAAc,CAAiB;IAE/B,YAAY,cAA8B;QACtC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,cAAuB;QAC/B,MAAM,YAAY,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;QACpD,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;QACxD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,qBAAqB,YAAY,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,MAAM,aAAa,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAC7D,CAAC;CACJ"}
|
package/dist/src/MockServer.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
//| limitations under the License.
|
|
15
15
|
//|
|
|
16
16
|
import { TelepactSchema } from './TelepactSchema.js';
|
|
17
|
-
import { Server, ServerOptions as ServerOptions } from './Server.js';
|
|
17
|
+
import { FunctionRouter, Server, ServerOptions as ServerOptions } from './Server.js';
|
|
18
18
|
import { RandomGenerator } from './RandomGenerator.js';
|
|
19
19
|
import { mockHandle } from './internal/mock/MockHandle.js';
|
|
20
20
|
export class MockServer {
|
|
@@ -33,7 +33,8 @@ export class MockServer {
|
|
|
33
33
|
serverOptions.authRequired = false;
|
|
34
34
|
serverOptions.middleware = async (requestMessage) => await this.handle(requestMessage);
|
|
35
35
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
36
|
-
|
|
36
|
+
const functionRouter = new FunctionRouter({});
|
|
37
|
+
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
37
38
|
}
|
|
38
39
|
random;
|
|
39
40
|
enableGeneratedDefaultStub;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockServer.js","sourceRoot":"","sources":["../../src/MockServer.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC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,CAAC;IACrC,gCAAgC,GAAG,IAAI,CAAC;IACxC,4BAA4B,GAAG,CAAC,CAAC;IACjC,4BAA4B,GAAG,CAAC,CAAC;CACpC"}
|
package/dist/src/Server.d.ts
CHANGED
|
@@ -3,15 +3,11 @@ import { Message } from './Message.js';
|
|
|
3
3
|
import { TelepactSchema } from './TelepactSchema.js';
|
|
4
4
|
import { Serialization } from './Serialization.js';
|
|
5
5
|
import { Response } from './Response.js';
|
|
6
|
-
|
|
7
|
-
export type FunctionRoutes = Record<string, FunctionRoute>;
|
|
6
|
+
import { FunctionRouter } from './FunctionRouter.js';
|
|
8
7
|
export type Middleware = (requestMessage: Message, functionRouter: FunctionRouter) => Promise<Message>;
|
|
9
8
|
export type UpdateHeaders = (headers: Record<string, any>) => void;
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
constructor(functionRoutes: FunctionRoutes);
|
|
13
|
-
route(requestMessage: Message): Promise<Message>;
|
|
14
|
-
}
|
|
9
|
+
export { FunctionRouter } from './FunctionRouter.js';
|
|
10
|
+
export type { FunctionRoute, FunctionRoutes } from './FunctionRouter.js';
|
|
15
11
|
export declare class Server {
|
|
16
12
|
functionRouter: FunctionRouter;
|
|
17
13
|
middleware: Middleware;
|
|
@@ -21,7 +17,7 @@ export declare class Server {
|
|
|
21
17
|
onAuth: (headers: Record<string, any>) => Record<string, any>;
|
|
22
18
|
telepactSchema: TelepactSchema;
|
|
23
19
|
serializer: Serializer;
|
|
24
|
-
constructor(telepactSchema: TelepactSchema,
|
|
20
|
+
constructor(telepactSchema: TelepactSchema, functionRouter: FunctionRouter, options: ServerOptions);
|
|
25
21
|
process(requestMessageBytes: Uint8Array, updateHeaders?: UpdateHeaders): Promise<Response>;
|
|
26
22
|
}
|
|
27
23
|
export declare class ServerOptions {
|
package/dist/src/Server.js
CHANGED
|
@@ -19,20 +19,7 @@ import { ServerBinaryEncoder } from './internal/binary/ServerBinaryEncoder.js';
|
|
|
19
19
|
import { constructBinaryEncoding } from './internal/binary/ConstructBinaryEncoding.js';
|
|
20
20
|
import { processBytes } from './internal/ProcessBytes.js';
|
|
21
21
|
import { ServerBase64Encoder } from './internal/binary/ServerBase64Encoder.js';
|
|
22
|
-
export
|
|
23
|
-
functionRoutes;
|
|
24
|
-
constructor(functionRoutes) {
|
|
25
|
-
this.functionRoutes = functionRoutes;
|
|
26
|
-
}
|
|
27
|
-
async route(requestMessage) {
|
|
28
|
-
const functionName = requestMessage.getBodyTarget();
|
|
29
|
-
const functionRoute = this.functionRoutes[functionName];
|
|
30
|
-
if (functionRoute === undefined) {
|
|
31
|
-
throw new Error(`Unknown function: ${functionName}`);
|
|
32
|
-
}
|
|
33
|
-
return await functionRoute(functionName, requestMessage);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
22
|
+
export { FunctionRouter } from './FunctionRouter.js';
|
|
36
23
|
export class Server {
|
|
37
24
|
functionRouter;
|
|
38
25
|
middleware;
|
|
@@ -42,8 +29,8 @@ export class Server {
|
|
|
42
29
|
onAuth;
|
|
43
30
|
telepactSchema;
|
|
44
31
|
serializer;
|
|
45
|
-
constructor(telepactSchema,
|
|
46
|
-
this.functionRouter =
|
|
32
|
+
constructor(telepactSchema, functionRouter, options) {
|
|
33
|
+
this.functionRouter = functionRouter;
|
|
47
34
|
this.middleware = options.middleware;
|
|
48
35
|
this.onError = options.onError;
|
|
49
36
|
this.onRequest = options.onRequest;
|
package/dist/src/Server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../src/Server.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC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GAAG,CAAC,CAAM,EAAE,EAAE,GAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,CAAC,CAAU,EAAE,EAAE,GAAE,CAAC,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAU,EAAE,EAAE,GAAE,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,CAAC,OAA4B,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,UAAU,GAAG,KAAK,EAAE,cAAuB,EAAE,cAA8B,EAAoB,EAAE,CAClG,MAAM,cAAc,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,IAAI,oBAAoB,EAAE,CAAC;IACpD,CAAC;CACJ"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;A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