@powersync/lib-services-framework 0.0.0-dev-20240620165410 → 0.0.0-dev-20240718134716
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/dist/container.d.ts
CHANGED
|
@@ -16,8 +16,26 @@ export type RegisterDefaultsOptions = {
|
|
|
16
16
|
export type ContainerImplementationDefaultGenerators = {
|
|
17
17
|
[type in ContainerImplementation]: () => ContainerImplementationTypes[type];
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Helper for identifying constructors
|
|
21
|
+
*/
|
|
22
|
+
export interface Abstract<T> {
|
|
23
|
+
prototype: T;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A basic class constructor
|
|
27
|
+
*/
|
|
28
|
+
export type Newable<T> = new (...args: never[]) => T;
|
|
29
|
+
/**
|
|
30
|
+
* Identifier used to get and register implementations
|
|
31
|
+
*/
|
|
32
|
+
export type ServiceIdentifier<T = unknown> = string | symbol | Newable<T> | Abstract<T> | ContainerImplementation;
|
|
33
|
+
/**
|
|
34
|
+
* A container which provides means for registering and getting various
|
|
35
|
+
* function implementations.
|
|
36
|
+
*/
|
|
19
37
|
export declare class Container {
|
|
20
|
-
protected implementations:
|
|
38
|
+
protected implementations: Map<ServiceIdentifier<any>, any>;
|
|
21
39
|
/**
|
|
22
40
|
* Manager for system health probes
|
|
23
41
|
*/
|
|
@@ -35,14 +53,31 @@ export declare class Container {
|
|
|
35
53
|
gracefully: <T>(exec: () => T | Promise<T>, handler: (component: T, signal: import("./signals/termination-handler.js").Signal) => void | Promise<void>) => Promise<T>;
|
|
36
54
|
};
|
|
37
55
|
constructor();
|
|
38
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Gets an implementation given an identifier.
|
|
58
|
+
* An exception is thrown if the implementation has not been registered.
|
|
59
|
+
* Core [ContainerImplementation] identifiers are mapped to their respective implementation types.
|
|
60
|
+
* This also allows for getting generic implementations (unknown to the core framework) which have been registered.
|
|
61
|
+
*/
|
|
62
|
+
getImplementation<T>(identifier: Newable<T> | Abstract<T>): T;
|
|
63
|
+
getImplementation<T extends ContainerImplementation>(identifier: T): ContainerImplementationTypes[T];
|
|
64
|
+
getImplementation<T>(identifier: ServiceIdentifier<T>): T;
|
|
65
|
+
/**
|
|
66
|
+
* Gets an implementation given an identifier.
|
|
67
|
+
* Null is returned if the implementation has not been registered yet.
|
|
68
|
+
* Core [ContainerImplementation] identifiers are mapped to their respective implementation types.
|
|
69
|
+
* This also allows for getting generic implementations (unknown to the core framework) which have been registered.
|
|
70
|
+
*/
|
|
71
|
+
getOptional<T>(identifier: Newable<T> | Abstract<T>): T | null;
|
|
72
|
+
getOptional<T extends ContainerImplementation>(identifier: T): ContainerImplementationTypes[T] | null;
|
|
73
|
+
getOptional<T>(identifier: ServiceIdentifier<T>): T | null;
|
|
39
74
|
/**
|
|
40
75
|
* Registers default implementations
|
|
41
76
|
*/
|
|
42
77
|
registerDefaults(options?: RegisterDefaultsOptions): void;
|
|
43
78
|
/**
|
|
44
|
-
* Allows for
|
|
79
|
+
* Allows for registering core and generic implementations of services/helpers.
|
|
45
80
|
*/
|
|
46
|
-
register<
|
|
81
|
+
register<T>(identifier: ServiceIdentifier<T>, implementation: T): void;
|
|
47
82
|
}
|
|
48
83
|
export declare const container: Container;
|
package/dist/container.js
CHANGED
|
@@ -12,6 +12,10 @@ const DEFAULT_GENERATORS = {
|
|
|
12
12
|
[ContainerImplementation.PROBES]: () => createFSProbe(),
|
|
13
13
|
[ContainerImplementation.TERMINATION_HANDLER]: () => createTerminationHandler()
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* A container which provides means for registering and getting various
|
|
17
|
+
* function implementations.
|
|
18
|
+
*/
|
|
15
19
|
export class Container {
|
|
16
20
|
/**
|
|
17
21
|
* Manager for system health probes
|
|
@@ -32,12 +36,19 @@ export class Container {
|
|
|
32
36
|
return this.getImplementation(ContainerImplementation.TERMINATION_HANDLER);
|
|
33
37
|
}
|
|
34
38
|
constructor() {
|
|
35
|
-
this.implementations =
|
|
39
|
+
this.implementations = new Map();
|
|
36
40
|
}
|
|
37
|
-
getImplementation(
|
|
38
|
-
const implementation = this.implementations
|
|
41
|
+
getImplementation(identifier) {
|
|
42
|
+
const implementation = this.implementations.get(identifier);
|
|
39
43
|
if (!implementation) {
|
|
40
|
-
throw new Error(`Implementation for ${
|
|
44
|
+
throw new Error(`Implementation for ${String(identifier)} has not been registered.`);
|
|
45
|
+
}
|
|
46
|
+
return implementation;
|
|
47
|
+
}
|
|
48
|
+
getOptional(identifier) {
|
|
49
|
+
const implementation = this.implementations.get(identifier);
|
|
50
|
+
if (!implementation) {
|
|
51
|
+
return null;
|
|
41
52
|
}
|
|
42
53
|
return implementation;
|
|
43
54
|
}
|
|
@@ -47,14 +58,14 @@ export class Container {
|
|
|
47
58
|
registerDefaults(options) {
|
|
48
59
|
_.difference(Object.values(ContainerImplementation), options?.skip ?? []).forEach((type) => {
|
|
49
60
|
const generator = DEFAULT_GENERATORS[type];
|
|
50
|
-
this.
|
|
61
|
+
this.register(type, generator());
|
|
51
62
|
});
|
|
52
63
|
}
|
|
53
64
|
/**
|
|
54
|
-
* Allows for
|
|
65
|
+
* Allows for registering core and generic implementations of services/helpers.
|
|
55
66
|
*/
|
|
56
|
-
register(
|
|
57
|
-
this.implementations
|
|
67
|
+
register(identifier, implementation) {
|
|
68
|
+
this.implementations.set(identifier, implementation);
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
export const container = new Container();
|
package/dist/container.js.map
CHANGED
|
@@ -1 +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,u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;IACnC,CAAC;IAWD,iBAAiB,CAAI,UAAgC;QACnD,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC,cAAc,EAAE;YACnB,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;SACtF;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAWD,WAAW,CAAI,UAAgC;QAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5D,IAAI,CAAC,cAAc,EAAE;YACnB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,gBAAgB,CAAC,OAAiC;QAChD,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACzF,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,QAAQ,CAAI,UAAgC,EAAE,cAAiB;QAC7D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACvD,CAAC;CACF;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC"}
|
|
@@ -18,6 +18,7 @@ export declare class JourneyError extends Error {
|
|
|
18
18
|
is_journey_error: boolean;
|
|
19
19
|
errorData: ErrorData;
|
|
20
20
|
static isJourneyError(input: any): input is JourneyError;
|
|
21
|
+
private static errorMessage;
|
|
21
22
|
constructor(data: ErrorData);
|
|
22
23
|
toString(): string | undefined;
|
|
23
24
|
toJSON(): ErrorData;
|
|
@@ -9,8 +9,15 @@ export class JourneyError extends Error {
|
|
|
9
9
|
static isJourneyError(input) {
|
|
10
10
|
return input instanceof JourneyError || input?.is_journey_error == true;
|
|
11
11
|
}
|
|
12
|
+
static errorMessage(data) {
|
|
13
|
+
let message = `[${data.code}] ${data.description}`;
|
|
14
|
+
if (data.details) {
|
|
15
|
+
message += `\n ${data.details}`;
|
|
16
|
+
}
|
|
17
|
+
return message;
|
|
18
|
+
}
|
|
12
19
|
constructor(data) {
|
|
13
|
-
super(
|
|
20
|
+
super(JourneyError.errorMessage(data));
|
|
14
21
|
this.is_journey_error = true;
|
|
15
22
|
this.errorData = data;
|
|
16
23
|
if (data.stack) {
|
|
@@ -1 +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;
|
|
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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AE,EAAW;QACvC,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACvD,KAAK,CAAC;YACJ,IAAI,EAAE,gBAAgB,CAAC,IAAI;YAC3B,MAAM,EAAE,GAAG;YACX,WAAW,EAAE,sDAAsD;YACnE,OAAO,EAAE,gBAAgB,UAAU,gCAAgC;YACnE,QAAQ,EAAE,aAAa,CAAC,IAAI;SAC7B,CAAC,CAAC;IACL,CAAC;;AAlBM,qBAAI,GAAG,oBAAoB,CAAC;AAqBrC,MAAM,OAAO,gBAAiB,SAAQ,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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/lib-services-framework",
|
|
3
3
|
"repository": "https://github.com/powersync-ja/powersync-service",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-20240718134716",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "dist/index.d.ts",
|