@powersync/lib-services-framework 0.0.0-dev-20240620165410
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/LICENSE +67 -0
- package/README.md +3 -0
- package/dist/alerts/alerts-index.d.ts +2 -0
- package/dist/alerts/alerts-index.js +3 -0
- package/dist/alerts/alerts-index.js.map +1 -0
- package/dist/alerts/definitions.d.ts +13 -0
- package/dist/alerts/definitions.js +2 -0
- package/dist/alerts/definitions.js.map +1 -0
- package/dist/alerts/no-op-reporter.d.ts +2 -0
- package/dist/alerts/no-op-reporter.js +5 -0
- package/dist/alerts/no-op-reporter.js.map +1 -0
- package/dist/codec/codec-index.d.ts +2 -0
- package/dist/codec/codec-index.js +3 -0
- package/dist/codec/codec-index.js.map +1 -0
- package/dist/codec/codecs.d.ts +26 -0
- package/dist/codec/codecs.js +60 -0
- package/dist/codec/codecs.js.map +1 -0
- package/dist/codec/parsers.d.ts +15 -0
- package/dist/codec/parsers.js +56 -0
- package/dist/codec/parsers.js.map +1 -0
- package/dist/container.d.ts +48 -0
- package/dist/container.js +61 -0
- package/dist/container.js.map +1 -0
- package/dist/errors/errors-index.d.ts +2 -0
- package/dist/errors/errors-index.js +3 -0
- package/dist/errors/errors-index.js.map +1 -0
- package/dist/errors/framework-errors.d.ts +50 -0
- package/dist/errors/framework-errors.js +104 -0
- package/dist/errors/framework-errors.js.map +1 -0
- package/dist/errors/utils.d.ts +4 -0
- package/dist/errors/utils.js +18 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/Logger.d.ts +6 -0
- package/dist/logger/Logger.js +13 -0
- package/dist/logger/Logger.js.map +1 -0
- package/dist/logger/logger-index.d.ts +1 -0
- package/dist/logger/logger-index.js +2 -0
- package/dist/logger/logger-index.js.map +1 -0
- package/dist/router/endpoint.d.ts +7 -0
- package/dist/router/endpoint.js +18 -0
- package/dist/router/endpoint.js.map +1 -0
- package/dist/router/router-definitions.d.ts +44 -0
- package/dist/router/router-definitions.js +14 -0
- package/dist/router/router-definitions.js.map +1 -0
- package/dist/router/router-index.d.ts +3 -0
- package/dist/router/router-index.js +4 -0
- package/dist/router/router-index.js.map +1 -0
- package/dist/router/router-response.d.ts +24 -0
- package/dist/router/router-response.js +32 -0
- package/dist/router/router-response.js.map +1 -0
- package/dist/schema/definitions.d.ts +16 -0
- package/dist/schema/definitions.js +2 -0
- package/dist/schema/definitions.js.map +1 -0
- package/dist/schema/json-schema/keywords.d.ts +2 -0
- package/dist/schema/json-schema/keywords.js +27 -0
- package/dist/schema/json-schema/keywords.js.map +1 -0
- package/dist/schema/json-schema/parser.d.ts +39 -0
- package/dist/schema/json-schema/parser.js +100 -0
- package/dist/schema/json-schema/parser.js.map +1 -0
- package/dist/schema/schema-index.d.ts +5 -0
- package/dist/schema/schema-index.js +6 -0
- package/dist/schema/schema-index.js.map +1 -0
- package/dist/schema/utils.d.ts +15 -0
- package/dist/schema/utils.js +40 -0
- package/dist/schema/utils.js.map +1 -0
- package/dist/schema/validators/schema-validator.d.ts +21 -0
- package/dist/schema/validators/schema-validator.js +55 -0
- package/dist/schema/validators/schema-validator.js.map +1 -0
- package/dist/schema/validators/ts-codec-validator.d.ts +11 -0
- package/dist/schema/validators/ts-codec-validator.js +14 -0
- package/dist/schema/validators/ts-codec-validator.js.map +1 -0
- package/dist/signals/probes/fs-probes.d.ts +2 -0
- package/dist/signals/probes/fs-probes.js +43 -0
- package/dist/signals/probes/fs-probes.js.map +1 -0
- package/dist/signals/probes/memory-probes.d.ts +5 -0
- package/dist/signals/probes/memory-probes.js +29 -0
- package/dist/signals/probes/memory-probes.js.map +1 -0
- package/dist/signals/probes/probes.d.ts +12 -0
- package/dist/signals/probes/probes.js +2 -0
- package/dist/signals/probes/probes.js.map +1 -0
- package/dist/signals/signals-index.d.ts +4 -0
- package/dist/signals/signals-index.js +5 -0
- package/dist/signals/signals-index.js.map +1 -0
- package/dist/signals/termination-handler.d.ts +42 -0
- package/dist/signals/termination-handler.js +89 -0
- package/dist/signals/termination-handler.js.map +1 -0
- package/dist/system/LifeCycledSystem.d.ts +23 -0
- package/dist/system/LifeCycledSystem.js +32 -0
- package/dist/system/LifeCycledSystem.js.map +1 -0
- package/dist/system/system-index.d.ts +1 -0
- package/dist/system/system-index.js +2 -0
- package/dist/system/system-index.js.map +1 -0
- package/dist/utils/environment-variables.d.ts +11 -0
- package/dist/utils/environment-variables.js +51 -0
- package/dist/utils/environment-variables.js.map +1 -0
- package/dist/utils/utils-index.d.ts +1 -0
- package/dist/utils/utils-index.js +2 -0
- package/dist/utils/utils-index.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2023-2024 Journey Mobile, Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
### License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
|
|
24
|
+
|
|
25
|
+
### Permitted Purpose
|
|
26
|
+
|
|
27
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
|
|
28
|
+
|
|
29
|
+
1. substitutes for the Software;
|
|
30
|
+
2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
|
|
31
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
32
|
+
|
|
33
|
+
Permitted Purposes specifically include using the Software:
|
|
34
|
+
|
|
35
|
+
1. for your internal use and access;
|
|
36
|
+
2. for non-commercial education;
|
|
37
|
+
3. for non-commercial research; and
|
|
38
|
+
4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
|
|
39
|
+
|
|
40
|
+
### Patents
|
|
41
|
+
|
|
42
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
|
|
43
|
+
|
|
44
|
+
### Redistribution
|
|
45
|
+
|
|
46
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
|
|
47
|
+
If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
|
|
48
|
+
|
|
49
|
+
### Disclaimer
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
52
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
53
|
+
|
|
54
|
+
### Trademarks
|
|
55
|
+
|
|
56
|
+
Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
|
|
57
|
+
|
|
58
|
+
## Grant of Future License
|
|
59
|
+
|
|
60
|
+
We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
|
|
61
|
+
|
|
62
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
|
63
|
+
You may obtain a copy of the License at
|
|
64
|
+
|
|
65
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
66
|
+
|
|
67
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alerts-index.js","sourceRoot":"","sources":["../../src/alerts/alerts-index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as errors from '../errors/errors-index.js';
|
|
2
|
+
export type Primitive = string | number | boolean;
|
|
3
|
+
export type CaptureOptions = {
|
|
4
|
+
level?: errors.ErrorSeverity;
|
|
5
|
+
tags?: Record<string, Primitive | undefined>;
|
|
6
|
+
metadata?: Record<string, Primitive | undefined>;
|
|
7
|
+
};
|
|
8
|
+
export type CaptureErrorFunction = (error: any, options?: CaptureOptions) => void;
|
|
9
|
+
export type CaptureMessageFunction = (message: string, options?: CaptureOptions) => void;
|
|
10
|
+
export type ErrorReporter = {
|
|
11
|
+
captureException: CaptureErrorFunction;
|
|
12
|
+
captureMessage: CaptureMessageFunction;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/alerts/definitions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-op-reporter.js","sourceRoot":"","sources":["../../src/alerts/no-op-reporter.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAkB;IACzC,gBAAgB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC1B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-index.js","sourceRoot":"","sources":["../../src/codec/codec-index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import * as t from 'ts-codec';
|
|
3
|
+
import * as bson from 'bson';
|
|
4
|
+
export declare const buffer: t.Codec<Buffer, string, string, t.CodecProps>;
|
|
5
|
+
export declare const date: t.Codec<Date, string, string, t.CodecProps>;
|
|
6
|
+
export declare const ObjectId: t.Codec<bson.ObjectId, string, string, t.CodecProps>;
|
|
7
|
+
export declare const ResourceId: t.Codec<{
|
|
8
|
+
_id: bson.ObjectId;
|
|
9
|
+
}, {
|
|
10
|
+
id: string;
|
|
11
|
+
}, string, t.CodecProps>;
|
|
12
|
+
export declare const Timestamps: t.ObjectCodec<{
|
|
13
|
+
created_at: t.Codec<Date, string, string, t.CodecProps>;
|
|
14
|
+
updated_at: t.Codec<Date, string, string, t.CodecProps>;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const Resource: t.Intersection<t.Codec<{
|
|
17
|
+
_id: bson.ObjectId;
|
|
18
|
+
}, {
|
|
19
|
+
id: string;
|
|
20
|
+
}, string, t.CodecProps>, t.ObjectCodec<{
|
|
21
|
+
created_at: t.Codec<Date, string, string, t.CodecProps>;
|
|
22
|
+
updated_at: t.Codec<Date, string, string, t.CodecProps>;
|
|
23
|
+
}>>;
|
|
24
|
+
export declare const QueryFilter: t.ObjectCodec<{
|
|
25
|
+
exists: t.IdentityCodec<t.CodecType.Boolean>;
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as t from 'ts-codec';
|
|
2
|
+
import * as bson from 'bson';
|
|
3
|
+
export const buffer = t.codec('Buffer', (buffer) => {
|
|
4
|
+
if (!Buffer.isBuffer(buffer)) {
|
|
5
|
+
throw new t.TransformError([`Expected buffer but got ${typeof buffer}`]);
|
|
6
|
+
}
|
|
7
|
+
return buffer.toString('base64');
|
|
8
|
+
}, (buffer) => Buffer.from(buffer, 'base64'));
|
|
9
|
+
export const date = t.codec('Date', (date) => {
|
|
10
|
+
if (!(date instanceof Date)) {
|
|
11
|
+
throw new t.TransformError([`Expected Date but got ${typeof date}`]);
|
|
12
|
+
}
|
|
13
|
+
return date.toISOString();
|
|
14
|
+
}, (date) => {
|
|
15
|
+
const parsed = new Date(date);
|
|
16
|
+
if (isNaN(parsed.getTime())) {
|
|
17
|
+
throw new t.TransformError([`Invalid date`]);
|
|
18
|
+
}
|
|
19
|
+
return parsed;
|
|
20
|
+
});
|
|
21
|
+
const assertObjectId = (value) => {
|
|
22
|
+
if (!bson.ObjectId.isValid(value)) {
|
|
23
|
+
throw new t.TransformError([`Expected an ObjectId but got ${typeof value}`]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const ObjectId = t.codec('ObjectId', (id) => {
|
|
27
|
+
assertObjectId(id);
|
|
28
|
+
return id.toHexString();
|
|
29
|
+
}, (id) => {
|
|
30
|
+
assertObjectId(id);
|
|
31
|
+
return new bson.ObjectId(id);
|
|
32
|
+
});
|
|
33
|
+
const assertObjectWithField = (field, data) => {
|
|
34
|
+
if (typeof data !== 'object') {
|
|
35
|
+
throw new t.TransformError([`Expected an object but got ${typeof data}`]);
|
|
36
|
+
}
|
|
37
|
+
if (!(field in data)) {
|
|
38
|
+
throw new t.TransformError([`Expected ${field} to be a member of object`]);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export const ResourceId = t.codec('ResourceId', (data) => {
|
|
42
|
+
assertObjectWithField('_id', data);
|
|
43
|
+
return {
|
|
44
|
+
id: ObjectId.encode(data._id)
|
|
45
|
+
};
|
|
46
|
+
}, (data) => {
|
|
47
|
+
assertObjectWithField('id', data);
|
|
48
|
+
return {
|
|
49
|
+
_id: ObjectId.decode(data.id)
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
export const Timestamps = t.object({
|
|
53
|
+
created_at: date,
|
|
54
|
+
updated_at: date
|
|
55
|
+
});
|
|
56
|
+
export const Resource = ResourceId.and(Timestamps);
|
|
57
|
+
export const QueryFilter = t.object({
|
|
58
|
+
exists: t.boolean
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=codecs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs.js","sourceRoot":"","sources":["../../src/codec/codecs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAC3B,QAAQ,EACR,CAAC,MAAM,EAAE,EAAE;IACT,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC5B,MAAM,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,2BAA2B,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC;KAC1E;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC,EACD,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CACzB,MAAM,EACN,CAAC,IAAI,EAAE,EAAE;IACP,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,EAAE;QAC3B,MAAM,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,yBAAyB,OAAO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AAc,CAAC,CAAC,YAAY,KAAK,2BAA2B,CAAC,CAAC,CAAC;KAC5E;AACH,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAC/B,YAAY,EACZ,CAAC,IAAI,EAAE,EAAE;IACP,qBAAqB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KAC9B,CAAC;AACJ,CAAC,EACD,CAAC,IAAI,EAAE,EAAE;IACP,qBAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO;QACL,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;KAC9B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,MAAM,EAAE,CAAC,CAAC,OAAO;CAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import * as t from 'ts-codec';
|
|
3
|
+
export declare const ObjectIdParser: t.Parser<string, t.Codec<import("bson").ObjectId, string, string, t.CodecProps>>;
|
|
4
|
+
export declare const ResourceIdParser: t.Parser<string, t.Codec<{
|
|
5
|
+
_id: import("bson").ObjectId;
|
|
6
|
+
}, {
|
|
7
|
+
id: string;
|
|
8
|
+
}, string, t.CodecProps>>;
|
|
9
|
+
export declare const DateParser: t.Parser<string, t.Codec<Date, string, string, t.CodecProps>>;
|
|
10
|
+
export declare const BufferParser: t.Parser<string, t.Codec<Buffer, string, string, t.CodecProps>>;
|
|
11
|
+
export declare const parsers: (t.Parser<string, t.Codec<import("bson").ObjectId, string, string, t.CodecProps>> | t.Parser<string, t.Codec<{
|
|
12
|
+
_id: import("bson").ObjectId;
|
|
13
|
+
}, {
|
|
14
|
+
id: string;
|
|
15
|
+
}, string, t.CodecProps>> | t.Parser<string, t.Codec<Date, string, string, t.CodecProps>> | t.Parser<string, t.Codec<Buffer, string, string, t.CodecProps>>)[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as t from 'ts-codec';
|
|
2
|
+
import * as codecs from './codecs.js';
|
|
3
|
+
export const ObjectIdParser = t.createParser(codecs.ObjectId._tag, (_, { target }) => {
|
|
4
|
+
switch (target) {
|
|
5
|
+
case t.TransformTarget.Encoded: {
|
|
6
|
+
return { type: 'string' };
|
|
7
|
+
}
|
|
8
|
+
case t.TransformTarget.Decoded: {
|
|
9
|
+
return { bsonType: 'ObjectId' };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
export const ResourceIdParser = t.createParser(codecs.ResourceId._tag, (_, { target }) => {
|
|
14
|
+
switch (target) {
|
|
15
|
+
case t.TransformTarget.Encoded: {
|
|
16
|
+
return {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
id: { type: 'string' }
|
|
20
|
+
},
|
|
21
|
+
required: ['id']
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
case t.TransformTarget.Decoded: {
|
|
25
|
+
return {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
_id: { bsonType: 'ObjectId' }
|
|
29
|
+
},
|
|
30
|
+
required: ['_id']
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export const DateParser = t.createParser(codecs.date._tag, (_, { target }) => {
|
|
36
|
+
switch (target) {
|
|
37
|
+
case t.TransformTarget.Encoded: {
|
|
38
|
+
return { type: 'string' };
|
|
39
|
+
}
|
|
40
|
+
case t.TransformTarget.Decoded: {
|
|
41
|
+
return { nodeType: 'date' };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export const BufferParser = t.createParser(codecs.buffer._tag, (_, { target }) => {
|
|
46
|
+
switch (target) {
|
|
47
|
+
case t.TransformTarget.Encoded: {
|
|
48
|
+
return { type: 'string' };
|
|
49
|
+
}
|
|
50
|
+
case t.TransformTarget.Decoded: {
|
|
51
|
+
return { nodeType: 'buffer' };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export const parsers = [ObjectIdParser, ResourceIdParser, DateParser, BufferParser];
|
|
56
|
+
//# sourceMappingURL=parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../src/codec/parsers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,YAAY,CAAyB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3G,QAAQ,MAAM,EAAE;QACd,KAAK,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAC9B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;SAC3B;QACD,KAAK,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAC9B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;SACjC;KACF;AACH,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,YAAY,CAA2B,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,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eAAe,CAAC,OAAO,CAAC,CAAC;YAC9B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;SAC/B;KACF;AACH,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ErrorReporter } from './alerts/definitions.js';
|
|
2
|
+
import { ProbeModule, TerminationHandler } from './signals/signals-index.js';
|
|
3
|
+
export declare enum ContainerImplementation {
|
|
4
|
+
REPORTER = "reporter",
|
|
5
|
+
PROBES = "probes",
|
|
6
|
+
TERMINATION_HANDLER = "termination-handler"
|
|
7
|
+
}
|
|
8
|
+
export type ContainerImplementationTypes = {
|
|
9
|
+
[ContainerImplementation.REPORTER]: ErrorReporter;
|
|
10
|
+
[ContainerImplementation.PROBES]: ProbeModule;
|
|
11
|
+
[ContainerImplementation.TERMINATION_HANDLER]: TerminationHandler;
|
|
12
|
+
};
|
|
13
|
+
export type RegisterDefaultsOptions = {
|
|
14
|
+
skip?: ContainerImplementation[];
|
|
15
|
+
};
|
|
16
|
+
export type ContainerImplementationDefaultGenerators = {
|
|
17
|
+
[type in ContainerImplementation]: () => ContainerImplementationTypes[type];
|
|
18
|
+
};
|
|
19
|
+
export declare class Container {
|
|
20
|
+
protected implementations: Partial<ContainerImplementationTypes>;
|
|
21
|
+
/**
|
|
22
|
+
* Manager for system health probes
|
|
23
|
+
*/
|
|
24
|
+
get probes(): ProbeModule;
|
|
25
|
+
/**
|
|
26
|
+
* Error reporter. Defaults to a no-op reporter
|
|
27
|
+
*/
|
|
28
|
+
get reporter(): ErrorReporter;
|
|
29
|
+
/**
|
|
30
|
+
* Handler for termination of the Node process
|
|
31
|
+
*/
|
|
32
|
+
get terminationHandler(): {
|
|
33
|
+
handleTerminationSignal: (handler: import("./signals/termination-handler.js").Handler) => void;
|
|
34
|
+
handleTerminationSignalLast: (handler: import("./signals/termination-handler.js").Handler) => void;
|
|
35
|
+
gracefully: <T>(exec: () => T | Promise<T>, handler: (component: T, signal: import("./signals/termination-handler.js").Signal) => void | Promise<void>) => Promise<T>;
|
|
36
|
+
};
|
|
37
|
+
constructor();
|
|
38
|
+
getImplementation<Type extends ContainerImplementation>(type: Type): NonNullable<Partial<ContainerImplementationTypes>[Type]>;
|
|
39
|
+
/**
|
|
40
|
+
* Registers default implementations
|
|
41
|
+
*/
|
|
42
|
+
registerDefaults(options?: RegisterDefaultsOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Allows for overriding a default implementation
|
|
45
|
+
*/
|
|
46
|
+
register<Type extends ContainerImplementation>(type: Type, implementation: ContainerImplementationTypes[Type]): void;
|
|
47
|
+
}
|
|
48
|
+
export declare const container: Container;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { NoOpReporter } from './alerts/no-op-reporter.js';
|
|
3
|
+
import { createFSProbe, createTerminationHandler } from './signals/signals-index.js';
|
|
4
|
+
export var ContainerImplementation;
|
|
5
|
+
(function (ContainerImplementation) {
|
|
6
|
+
ContainerImplementation["REPORTER"] = "reporter";
|
|
7
|
+
ContainerImplementation["PROBES"] = "probes";
|
|
8
|
+
ContainerImplementation["TERMINATION_HANDLER"] = "termination-handler";
|
|
9
|
+
})(ContainerImplementation || (ContainerImplementation = {}));
|
|
10
|
+
const DEFAULT_GENERATORS = {
|
|
11
|
+
[ContainerImplementation.REPORTER]: () => NoOpReporter,
|
|
12
|
+
[ContainerImplementation.PROBES]: () => createFSProbe(),
|
|
13
|
+
[ContainerImplementation.TERMINATION_HANDLER]: () => createTerminationHandler()
|
|
14
|
+
};
|
|
15
|
+
export class Container {
|
|
16
|
+
/**
|
|
17
|
+
* Manager for system health probes
|
|
18
|
+
*/
|
|
19
|
+
get probes() {
|
|
20
|
+
return this.getImplementation(ContainerImplementation.PROBES);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error reporter. Defaults to a no-op reporter
|
|
24
|
+
*/
|
|
25
|
+
get reporter() {
|
|
26
|
+
return this.getImplementation(ContainerImplementation.REPORTER);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Handler for termination of the Node process
|
|
30
|
+
*/
|
|
31
|
+
get terminationHandler() {
|
|
32
|
+
return this.getImplementation(ContainerImplementation.TERMINATION_HANDLER);
|
|
33
|
+
}
|
|
34
|
+
constructor() {
|
|
35
|
+
this.implementations = {};
|
|
36
|
+
}
|
|
37
|
+
getImplementation(type) {
|
|
38
|
+
const implementation = this.implementations[type];
|
|
39
|
+
if (!implementation) {
|
|
40
|
+
throw new Error(`Implementation for ${type} has not been registered.`);
|
|
41
|
+
}
|
|
42
|
+
return implementation;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Registers default implementations
|
|
46
|
+
*/
|
|
47
|
+
registerDefaults(options) {
|
|
48
|
+
_.difference(Object.values(ContainerImplementation), options?.skip ?? []).forEach((type) => {
|
|
49
|
+
const generator = DEFAULT_GENERATORS[type];
|
|
50
|
+
this.implementations[type] = generator(); // :(
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Allows for overriding a default implementation
|
|
55
|
+
*/
|
|
56
|
+
register(type, implementation) {
|
|
57
|
+
this.implementations[type] = implementation;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export const container = new Container();
|
|
61
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAmC,aAAa,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtH,MAAM,CAAN,IAAY,uBAIX;AAJD,WAAY,uBAAuB;IAC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,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,SAAS,EAAS,CAAC,CAAC,KAAK;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,QAAQ,CAAuC,IAAU,EAAE,cAAkD;QAC3G,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;IAC9C,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-index.js","sourceRoot":"","sources":["../../src/errors/errors-index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare enum ErrorSeverity {
|
|
2
|
+
INFO = "info",
|
|
3
|
+
WARNING = "warning",
|
|
4
|
+
ERROR = "error"
|
|
5
|
+
}
|
|
6
|
+
export type ErrorData = {
|
|
7
|
+
name?: string;
|
|
8
|
+
code: string;
|
|
9
|
+
description: string;
|
|
10
|
+
severity?: ErrorSeverity;
|
|
11
|
+
details?: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
stack?: string;
|
|
14
|
+
origin?: string;
|
|
15
|
+
trace_id?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare class JourneyError extends Error {
|
|
18
|
+
is_journey_error: boolean;
|
|
19
|
+
errorData: ErrorData;
|
|
20
|
+
static isJourneyError(input: any): input is JourneyError;
|
|
21
|
+
constructor(data: ErrorData);
|
|
22
|
+
toString(): string | undefined;
|
|
23
|
+
toJSON(): ErrorData;
|
|
24
|
+
setTraceId(id: string): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class ValidationError extends JourneyError {
|
|
27
|
+
static CODE: string;
|
|
28
|
+
constructor(errors: any);
|
|
29
|
+
}
|
|
30
|
+
export declare class AuthorizationError extends JourneyError {
|
|
31
|
+
static CODE: string;
|
|
32
|
+
constructor(errors: any);
|
|
33
|
+
}
|
|
34
|
+
export declare class InternalServerError extends JourneyError {
|
|
35
|
+
static CODE: string;
|
|
36
|
+
constructor(err: Error);
|
|
37
|
+
}
|
|
38
|
+
export declare class ResourceNotFound extends JourneyError {
|
|
39
|
+
static CODE: string;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use the (resource, id) constructor instead.
|
|
42
|
+
* @param id
|
|
43
|
+
*/
|
|
44
|
+
constructor(id: string);
|
|
45
|
+
constructor(resource: string, id: string);
|
|
46
|
+
}
|
|
47
|
+
export declare class ResourceConflict extends JourneyError {
|
|
48
|
+
static CODE: string;
|
|
49
|
+
constructor(details: string);
|
|
50
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export var ErrorSeverity;
|
|
2
|
+
(function (ErrorSeverity) {
|
|
3
|
+
ErrorSeverity["INFO"] = "info";
|
|
4
|
+
ErrorSeverity["WARNING"] = "warning";
|
|
5
|
+
ErrorSeverity["ERROR"] = "error";
|
|
6
|
+
})(ErrorSeverity || (ErrorSeverity = {}));
|
|
7
|
+
// Maybe this could be renamed to ServiceError or something similar
|
|
8
|
+
export class JourneyError extends Error {
|
|
9
|
+
static isJourneyError(input) {
|
|
10
|
+
return input instanceof JourneyError || input?.is_journey_error == true;
|
|
11
|
+
}
|
|
12
|
+
constructor(data) {
|
|
13
|
+
super(`[${data.code}] ${data.description}\n ${data.details}`);
|
|
14
|
+
this.is_journey_error = true;
|
|
15
|
+
this.errorData = data;
|
|
16
|
+
if (data.stack) {
|
|
17
|
+
this.stack = data.stack;
|
|
18
|
+
}
|
|
19
|
+
this.name = data.name || this.constructor.name;
|
|
20
|
+
this.errorData.name = this.name;
|
|
21
|
+
}
|
|
22
|
+
toString() {
|
|
23
|
+
return this.stack;
|
|
24
|
+
}
|
|
25
|
+
toJSON() {
|
|
26
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
27
|
+
return this.errorData;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
name: this.errorData.name,
|
|
31
|
+
code: this.errorData.code,
|
|
32
|
+
status: this.errorData.status,
|
|
33
|
+
description: this.errorData.description,
|
|
34
|
+
details: this.errorData.details,
|
|
35
|
+
trace_id: this.errorData.trace_id,
|
|
36
|
+
severity: this.errorData.severity,
|
|
37
|
+
origin: this.errorData.origin
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
setTraceId(id) {
|
|
41
|
+
this.errorData.trace_id = id;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class ValidationError extends JourneyError {
|
|
45
|
+
constructor(errors) {
|
|
46
|
+
super({
|
|
47
|
+
code: ValidationError.CODE,
|
|
48
|
+
status: 400,
|
|
49
|
+
description: 'Validation failed',
|
|
50
|
+
details: JSON.stringify(errors)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
ValidationError.CODE = 'VALIDATION_ERROR';
|
|
55
|
+
export class AuthorizationError extends JourneyError {
|
|
56
|
+
constructor(errors) {
|
|
57
|
+
super({
|
|
58
|
+
code: AuthorizationError.CODE,
|
|
59
|
+
status: 401,
|
|
60
|
+
description: 'Authorization failed',
|
|
61
|
+
details: errors
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
AuthorizationError.CODE = 'AUTHORIZATION';
|
|
66
|
+
export class InternalServerError extends JourneyError {
|
|
67
|
+
constructor(err) {
|
|
68
|
+
super({
|
|
69
|
+
code: InternalServerError.CODE,
|
|
70
|
+
severity: ErrorSeverity.ERROR,
|
|
71
|
+
status: 500,
|
|
72
|
+
description: 'Something went wrong',
|
|
73
|
+
details: err.message,
|
|
74
|
+
stack: process.env.NODE_ENV !== 'production' ? err.stack : undefined
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
InternalServerError.CODE = 'INTERNAL_SERVER_ERROR';
|
|
79
|
+
export class ResourceNotFound extends JourneyError {
|
|
80
|
+
constructor(resource, id) {
|
|
81
|
+
const combinedId = id ? `${resource}/${id}` : resource;
|
|
82
|
+
super({
|
|
83
|
+
code: ResourceNotFound.CODE,
|
|
84
|
+
status: 404,
|
|
85
|
+
description: 'The requested resource does not exist on this server',
|
|
86
|
+
details: `The resource ${combinedId} does not exist on this server`,
|
|
87
|
+
severity: ErrorSeverity.INFO
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
ResourceNotFound.CODE = 'RESOURCE_NOT_FOUND';
|
|
92
|
+
export class ResourceConflict extends JourneyError {
|
|
93
|
+
constructor(details) {
|
|
94
|
+
super({
|
|
95
|
+
code: ResourceConflict.CODE,
|
|
96
|
+
status: 409,
|
|
97
|
+
description: 'The specified resource already exists on this server',
|
|
98
|
+
details: details,
|
|
99
|
+
severity: ErrorSeverity.INFO
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
ResourceConflict.CODE = 'RESOURCE_CONFLICT';
|
|
104
|
+
//# sourceMappingURL=framework-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-errors.js","sourceRoot":"","sources":["../../src/errors/framework-errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,oCAAmB,CAAA;IACnB,gCAAe,CAAA;AACjB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAkBD,mEAAmE;AACnE,MAAM,OAAO,YAAa,SAAQ,KAAK;IAKrC,MAAM,CAAC,cAAc,CAAC,KAAU;QAC9B,OAAO,KAAK,YAAY,YAAY,IAAI,KAAK,EAAE,gBAAgB,IAAI,IAAI,CAAC;IAC1E,CAAC;IAED,YAAY,IAAe;QACzB,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,WAAW,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,C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Q,YAAY;IAGhD,YAAY,OAAe;QACzB,KAAK,CAAC;YACJ,IAAI,EAAE,gBAAgB,CAAC,IAAI;YAC3B,MAAM,EAAE,GAAG;YACX,WAAW,EAAE,sDAAsD;YACnE,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,aAAa,CAAC,IAAI;SAC7B,CAAC,CAAC;IACL,CAAC;;AAVM,qBAAI,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ErrorData, JourneyError } from './framework-errors.js';
|
|
2
|
+
export declare const isJourneyError: (err: any) => err is JourneyError;
|
|
3
|
+
export declare const getErrorData: (err: Error | any) => ErrorData | undefined;
|
|
4
|
+
export declare const matchesErrorCode: (err: Error | any, code: string) => boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JourneyError } from './framework-errors.js';
|
|
2
|
+
export const isJourneyError = (err) => {
|
|
3
|
+
const matches = JourneyError.isJourneyError(err);
|
|
4
|
+
return !!matches;
|
|
5
|
+
};
|
|
6
|
+
export const getErrorData = (err) => {
|
|
7
|
+
if (!isJourneyError(err)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return err.toJSON();
|
|
11
|
+
};
|
|
12
|
+
export const matchesErrorCode = (err, code) => {
|
|
13
|
+
if (isJourneyError(err)) {
|
|
14
|
+
return err.errorData.code === code;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/errors/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAuB,EAAE;IAC9D,MAAM,OAAO,GAAG,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACjD,OAAO,CAAC,CAAC,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAgB,EAAyB,EAAE;IACtE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO;KACR;IACD,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAgB,EAAE,IAAY,EAAE,EAAE;IACjE,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE;QACvB,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC;KACpC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './alerts/alerts-index.js';
|
|
2
|
+
export * as alerts from './alerts/alerts-index.js';
|
|
3
|
+
export * from './codec/codec-index.js';
|
|
4
|
+
export * as codecs from './codec/codec-index.js';
|
|
5
|
+
export * from './container.js';
|
|
6
|
+
export * from './errors/errors-index.js';
|
|
7
|
+
export * as errors from './errors/errors-index.js';
|
|
8
|
+
export * from './logger/Logger.js';
|
|
9
|
+
export * from './schema/schema-index.js';
|
|
10
|
+
export * as schema from './schema/schema-index.js';
|
|
11
|
+
export * from './signals/signals-index.js';
|
|
12
|
+
export * as signals from './signals/signals-index.js';
|
|
13
|
+
export * from './router/router-index.js';
|
|
14
|
+
export * as router from './router/router-index.js';
|
|
15
|
+
export * from './system/LifeCycledSystem.js';
|
|
16
|
+
export * as system from './system/system-index.js';
|
|
17
|
+
export * from './utils/utils-index.js';
|
|
18
|
+
export * as utils from './utils/utils-index.js';
|