@octostar/platform-api 0.0.2
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 +21 -0
- package/README.md +1 -0
- package/dist/platform-api.d.ts +73 -0
- package/lib/apis.d.ts +6 -0
- package/lib/apis.d.ts.map +1 -0
- package/lib/apis.js +21 -0
- package/lib/apis.js.map +1 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +16 -0
- package/lib/constants.js.map +1 -0
- package/lib/factory.d.ts +4 -0
- package/lib/factory.d.ts.map +1 -0
- package/lib/factory.js +69 -0
- package/lib/factory.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/lib/AsyncServiceLocator.d.ts +21 -0
- package/lib/lib/AsyncServiceLocator.d.ts.map +1 -0
- package/lib/lib/AsyncServiceLocator.js +73 -0
- package/lib/lib/AsyncServiceLocator.js.map +1 -0
- package/lib/types.d.ts +37 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +17 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +30 -0
- package/lib/utils.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Oleksandr Korzhov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Octostar platform API
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Desktop } from '@octostar/platform-types';
|
|
2
|
+
import { Ontology } from '@octostar/platform-types';
|
|
3
|
+
|
|
4
|
+
export declare const apiNames: Record<"desktop", "octostar:api-names:desktop"> & Record<"ontology", "octostar:api-names:ontology"> & Record<"context", "octostar:api-names:context">;
|
|
5
|
+
|
|
6
|
+
declare type BasePostResponsePayload<D, E> = {
|
|
7
|
+
data: D;
|
|
8
|
+
error: E;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export declare type ContextApi<T> = {
|
|
12
|
+
getContext: () => T;
|
|
13
|
+
subscribeToChanges: (id: string, callback: (context: T) => void) => void;
|
|
14
|
+
unsubscribeFromChanges: (id: string) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export declare const contextApi: () => EnsureMethodsReturnPromise<ContextApi<unknown>>;
|
|
18
|
+
|
|
19
|
+
declare type CreateMessageNamesResult<N, M> = M extends readonly [infer F, ...infer R] ? Record<F & string, MessageValue<N, F>> & CreateMessageNamesResult<N, R> : {};
|
|
20
|
+
|
|
21
|
+
export declare const createPrefixesConstants: <N extends string, M extends readonly [string, ...string[]]>(namespace: N, messages: M) => CreateMessageNamesResult<N, M>;
|
|
22
|
+
|
|
23
|
+
export declare const desktopApi: () => EnsureMethodsReturnPromise<Desktop>;
|
|
24
|
+
|
|
25
|
+
export declare type EnsureMethodsReturnPromise<T> = {
|
|
26
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? (...args: Parameters<T[K]>) => Promise<Awaited<ReturnType<T[K]>>> : T[K];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export declare type ErrorPostResponsePayload = BasePostResponsePayload<null, {
|
|
30
|
+
code: string;
|
|
31
|
+
message: string;
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
export declare type GetRemoteApiParams = {
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
declare type MessageValue<N, M> = `${N & string}:${M & string}`;
|
|
39
|
+
|
|
40
|
+
export declare const ontologyApi: () => EnsureMethodsReturnPromise<Ontology>;
|
|
41
|
+
|
|
42
|
+
export declare const postMessageNames: Record<"get_api", "octostar:post-messages:get_api">;
|
|
43
|
+
|
|
44
|
+
export declare type PostRequest<T extends object> = {
|
|
45
|
+
source: Window | null;
|
|
46
|
+
origin: string;
|
|
47
|
+
data: T;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export declare type PostResponse<T extends object> = {
|
|
51
|
+
source: Window | null;
|
|
52
|
+
origin: string;
|
|
53
|
+
data: T;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export declare type PostResponsePayload<T> = ErrorPostResponsePayload | SuccessPostResponsePayload<T>;
|
|
57
|
+
|
|
58
|
+
export declare type PostResponseWithPayload<T> = PostResponse<PostResponsePayload<T>>;
|
|
59
|
+
|
|
60
|
+
export declare type RemoteApiError = Error & {
|
|
61
|
+
originalError: Error;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export declare const retry: <T>(fn: (...args: any) => T | Promise<T>, options?: RetryOptions) => Promise<T>;
|
|
65
|
+
|
|
66
|
+
declare type RetryOptions = {
|
|
67
|
+
maxAttempts?: number;
|
|
68
|
+
retryInterval?: number;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export declare type SuccessPostResponsePayload<T> = BasePostResponsePayload<T, null>;
|
|
72
|
+
|
|
73
|
+
export { }
|
package/lib/apis.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Desktop, Ontology } from '@octostar/platform-types';
|
|
2
|
+
import { ContextApi, EnsureMethodsReturnPromise } from './types';
|
|
3
|
+
export declare const desktopApi: () => EnsureMethodsReturnPromise<Desktop>;
|
|
4
|
+
export declare const ontologyApi: () => EnsureMethodsReturnPromise<Ontology>;
|
|
5
|
+
export declare const contextApi: () => EnsureMethodsReturnPromise<ContextApi<unknown>>;
|
|
6
|
+
//# sourceMappingURL=apis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apis.d.ts","sourceRoot":"","sources":["../src/apis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAuBjE,eAAO,MAAM,UAAU,2CACwC,CAAC;AAEhE,eAAO,MAAM,WAAW,4CACwC,CAAC;AAEjE,eAAO,MAAM,UAAU,uDACwC,CAAC"}
|
package/lib/apis.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AsyncServiceLocator } from './lib/AsyncServiceLocator';
|
|
2
|
+
import { forwardCallsToFutureObject, createRemoteApiHandle } from './factory';
|
|
3
|
+
import { apiNames } from './constants';
|
|
4
|
+
const apisLocator = AsyncServiceLocator.getInstance('platform-api', {
|
|
5
|
+
cache: false,
|
|
6
|
+
})
|
|
7
|
+
.registerService('desktop', () => createRemoteApiHandle({
|
|
8
|
+
name: apiNames.desktop,
|
|
9
|
+
}))
|
|
10
|
+
.registerService('ontology', () => createRemoteApiHandle({
|
|
11
|
+
name: apiNames.ontology,
|
|
12
|
+
}))
|
|
13
|
+
.registerService('context', () =>
|
|
14
|
+
// TODO: clarify about the context type
|
|
15
|
+
createRemoteApiHandle({
|
|
16
|
+
name: apiNames.context,
|
|
17
|
+
}));
|
|
18
|
+
export const desktopApi = () => forwardCallsToFutureObject(apisLocator.getService('desktop'));
|
|
19
|
+
export const ontologyApi = () => forwardCallsToFutureObject(apisLocator.getService('ontology'));
|
|
20
|
+
export const contextApi = () => forwardCallsToFutureObject(apisLocator.getService('context'));
|
|
21
|
+
//# sourceMappingURL=apis.js.map
|
package/lib/apis.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apis.js","sourceRoot":"","sources":["../src/apis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC,cAAc,EAAE;IAClE,KAAK,EAAE,KAAK;CACb,CAAC;KACC,eAAe,CAAC,SAAS,EAAE,GAAG,EAAE,CAC/B,qBAAqB,CAAsC;IACzD,IAAI,EAAE,QAAQ,CAAC,OAAO;CACvB,CAAC,CACH;KACA,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,CAChC,qBAAqB,CAAuC;IAC1D,IAAI,EAAE,QAAQ,CAAC,QAAQ;CACxB,CAAC,CACH;KACA,eAAe,CAAC,SAAS,EAAE,GAAG,EAAE;AAC/B,uCAAuC;AACvC,qBAAqB,CAAkD;IACrE,IAAI,EAAE,QAAQ,CAAC,OAAO;CACvB,CAAC,CACH,CAAC;AAEJ,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE,CAC7B,0BAA0B,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAC9B,0BAA0B,CAAC,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE,CAC7B,0BAA0B,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type MessageValue<N, M> = `${N & string}:${M & string}`;
|
|
2
|
+
type CreateMessageNamesResult<N, M> = M extends readonly [infer F, ...infer R] ? Record<F & string, MessageValue<N, F>> & CreateMessageNamesResult<N, R> : {};
|
|
3
|
+
export declare const createPrefixesConstants: <N extends string, M extends readonly [string, ...string[]]>(namespace: N, messages: M) => CreateMessageNamesResult<N, M>;
|
|
4
|
+
export declare const postMessageNames: Record<"get_api", "octostar:post-messages:get_api">;
|
|
5
|
+
export declare const apiNames: Record<"desktop", "octostar:api-names:desktop"> & Record<"ontology", "octostar:api-names:ontology"> & Record<"context", "octostar:api-names:context">;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;AAExD,KAAK,wBAAwB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAC1E,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvE,EAAE,CAAC;AAEP,eAAO,MAAM,uBAAuB,2HAcnC,CAAC;AAEF,eAAO,MAAM,gBAAgB,qDAG5B,CAAC;AAEF,eAAO,MAAM,QAAQ,uJAIV,CAAC"}
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const createPrefixesConstants = (namespace, messages) => {
|
|
2
|
+
const result = {};
|
|
3
|
+
messages.forEach(message => {
|
|
4
|
+
result[message] = `${namespace}:${message}`;
|
|
5
|
+
});
|
|
6
|
+
return result;
|
|
7
|
+
};
|
|
8
|
+
export const postMessageNames = createPrefixesConstants('octostar:post-messages', ['get_api']);
|
|
9
|
+
export const apiNames = createPrefixesConstants('octostar:api-names', [
|
|
10
|
+
'desktop',
|
|
11
|
+
'ontology',
|
|
12
|
+
'context',
|
|
13
|
+
]);
|
|
14
|
+
// test
|
|
15
|
+
// const v = messages.get_api;
|
|
16
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAIrC,SAAY,EACZ,QAAW,EACqB,EAAE;IAClC,MAAM,MAAM,GAA+C,EAAE,CAAC;IAE9D,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACzB,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,SAAS,IAAI,OAAO,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,OAAO,MAAwC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CACrD,wBAAwB,EACxB,CAAC,SAAS,CAAU,CACrB,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,oBAAoB,EAAE;IACpE,SAAS;IACT,UAAU;IACV,SAAS;CACD,CAAC,CAAC;AAEZ,OAAO;AACP,8BAA8B"}
|
package/lib/factory.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AA+DjB,eAAO,MAAM,qBAAqB,6BACxB,kBAAkB,eAgB3B,CAAC;AAEF,eAAO,MAAM,0BAA0B,6BAS/B,CAAC"}
|
package/lib/factory.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import postRobot from 'post-robot';
|
|
11
|
+
import { retry } from './utils';
|
|
12
|
+
import { postMessageNames } from './constants';
|
|
13
|
+
const hasParent = (window) => window.parent !== window;
|
|
14
|
+
const getTopWindow = (window) => {
|
|
15
|
+
let w = window;
|
|
16
|
+
while (hasParent(w)) {
|
|
17
|
+
w = w.parent;
|
|
18
|
+
}
|
|
19
|
+
return w;
|
|
20
|
+
};
|
|
21
|
+
const handlePostResponse = (response) => {
|
|
22
|
+
if (response.data.error) {
|
|
23
|
+
throw new Error(response.data.error.message);
|
|
24
|
+
}
|
|
25
|
+
return response.data.data;
|
|
26
|
+
};
|
|
27
|
+
const createObjectProxy = (value, options) => new Proxy(value, {
|
|
28
|
+
get: (target, prop) => {
|
|
29
|
+
// This construction does not support nested objects
|
|
30
|
+
if (typeof target[prop] === 'function') {
|
|
31
|
+
return new Proxy(target[prop], {
|
|
32
|
+
apply: (methodTarget, _, args) => {
|
|
33
|
+
const callResult = methodTarget(...args);
|
|
34
|
+
const isPromise = callResult instanceof Promise;
|
|
35
|
+
const isPromiseLike = typeof (callResult === null || callResult === void 0 ? void 0 : callResult.then) === 'function' &&
|
|
36
|
+
typeof (callResult === null || callResult === void 0 ? void 0 : callResult.catch) === 'function';
|
|
37
|
+
if (isPromise || isPromiseLike) {
|
|
38
|
+
return callResult.catch((e) => {
|
|
39
|
+
const methodFullPath = `${options.name}.${prop}()`;
|
|
40
|
+
const error = new Error(`Error calling ${methodFullPath}: ${e.message}`);
|
|
41
|
+
error.stack = `at ${methodFullPath}: ${e.stack}`;
|
|
42
|
+
error.originalError = e;
|
|
43
|
+
throw error;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return callResult;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return target[prop];
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
export const createRemoteApiHandle = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const topWindow = getTopWindow(window);
|
|
55
|
+
const response = yield retry(() => postRobot.send(topWindow, postMessageNames.get_api, params), {
|
|
56
|
+
maxAttempts: 5,
|
|
57
|
+
retryInterval: 2000,
|
|
58
|
+
});
|
|
59
|
+
const api = handlePostResponse(response);
|
|
60
|
+
return createObjectProxy(api, {
|
|
61
|
+
name: params.name,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
export const forwardCallsToFutureObject = (chain) => new Proxy({}, {
|
|
65
|
+
get: (target, prop) => new Proxy(() => { }, {
|
|
66
|
+
apply: (__, _, args) => chain.then((obj) => obj[prop](...args)),
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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ClB,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAI,KAAiB,EAAK,EAAE,CACpE,IAAI,KAAK,CACP,EAAE,EACF;IACE,GAAG,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CACpB,IAAI,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE;QAClB,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;KACrE,CAAC;CACL,CACG,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type DependencyFactoryGeneral = (locator: unknown) => Promise<any>;
|
|
2
|
+
type DependencyFactory<T, S extends Record<string, DependencyFactoryGeneral>> = (locator: AsyncServiceLocator<S>) => Promise<T>;
|
|
3
|
+
type GetServiceResult<T> = Promise<T extends (...args: any) => infer R ? Awaited<R> : never>;
|
|
4
|
+
export type ReadOnlyAsyncServiceLocator<T, I = T extends AsyncServiceLocator<infer S> ? S : never> = {
|
|
5
|
+
getService<K extends keyof I>(name: K): GetServiceResult<I[K]>;
|
|
6
|
+
};
|
|
7
|
+
type AsyncServiceLocatorOptions = {
|
|
8
|
+
cache: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare class AsyncServiceLocator<S extends Record<string, DependencyFactory<any, Record<string, DependencyFactoryGeneral>>>> {
|
|
11
|
+
private readonly services;
|
|
12
|
+
private readonly cache;
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(services: S, cache: Record<keyof S, any>, options: AsyncServiceLocatorOptions);
|
|
15
|
+
static instances: Record<string, AsyncServiceLocator<{}>>;
|
|
16
|
+
static getInstance(key: string, options: AsyncServiceLocatorOptions): AsyncServiceLocator<{}>;
|
|
17
|
+
registerService<K extends string, V extends DependencyFactory<any, S>>(name: K, serviceFactory: V): AsyncServiceLocator<S & Record<K, V>>;
|
|
18
|
+
getService<K extends keyof S>(name: K): GetServiceResult<S[K]>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=AsyncServiceLocator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncServiceLocator.d.ts","sourceRoot":"","sources":["../../src/lib/AsyncServiceLocator.ts"],"names":[],"mappings":"AAAA,KAAK,wBAAwB,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEnE,KAAK,iBAAiB,CACpB,CAAC,EACD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,IAChD,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAEpD,KAAK,gBAAgB,CAAC,CAAC,IAAI,OAAO,CAChC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CACzD,CAAC;AAEF,MAAM,MAAM,2BAA2B,CACrC,CAAC,EACD,CAAC,GAAG,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awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export class AsyncServiceLocator {
|
|
11
|
+
constructor(services, cache, options) {
|
|
12
|
+
this.services = services;
|
|
13
|
+
this.cache = cache;
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
static getInstance(key, options) {
|
|
17
|
+
const serializedOptions = JSON.stringify(options);
|
|
18
|
+
const instanceKey = `${key}-${serializedOptions}`;
|
|
19
|
+
if (!this.instances[instanceKey]) {
|
|
20
|
+
this.instances[instanceKey] = new AsyncServiceLocator({}, {}, options);
|
|
21
|
+
}
|
|
22
|
+
return this.instances[instanceKey];
|
|
23
|
+
}
|
|
24
|
+
registerService(name, serviceFactory) {
|
|
25
|
+
return new AsyncServiceLocator(Object.assign(Object.assign({}, this.services), { [name]: serviceFactory }), Object.assign(Object.assign({}, this.cache), { [name]: undefined }), this.options);
|
|
26
|
+
}
|
|
27
|
+
getService(name) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const service = this.services[name];
|
|
30
|
+
if (!service) {
|
|
31
|
+
throw new Error(`Service ${String(name)} not found`);
|
|
32
|
+
}
|
|
33
|
+
if (!this.cache[name] || !this.options.cache) {
|
|
34
|
+
this.cache[name] = yield service(this);
|
|
35
|
+
}
|
|
36
|
+
return this.cache[name];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
AsyncServiceLocator.instances = {};
|
|
41
|
+
// class Test {
|
|
42
|
+
// // constructor(name: string, age: number) {}
|
|
43
|
+
//
|
|
44
|
+
// public test() {
|
|
45
|
+
// return 'test';
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
//
|
|
49
|
+
// class Test2 {
|
|
50
|
+
// constructor(private testDependency: Test) {}
|
|
51
|
+
//
|
|
52
|
+
// public getName() {
|
|
53
|
+
// return 'test2';
|
|
54
|
+
// }
|
|
55
|
+
//
|
|
56
|
+
// public test() {
|
|
57
|
+
// return 'test2';
|
|
58
|
+
// }
|
|
59
|
+
// }
|
|
60
|
+
//
|
|
61
|
+
// const testLocator = AsyncServiceLocator.getInstance('default')
|
|
62
|
+
// .registerService('test', async () => new Test())
|
|
63
|
+
// .registerService('test3', async () => Test)
|
|
64
|
+
// .registerService(
|
|
65
|
+
// 'test2',
|
|
66
|
+
// async locator => new Test2(await locator.getService('test')),
|
|
67
|
+
// );
|
|
68
|
+
// const testService = await testLocator.getService('test');
|
|
69
|
+
// const test2Service = await testLocator.getService('test2');
|
|
70
|
+
//
|
|
71
|
+
// testService.test();
|
|
72
|
+
// test2Service.getName();
|
|
73
|
+
//# sourceMappingURL=AsyncServiceLocator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncServiceLocator.js","sourceRoot":"","sources":["../../src/lib/AsyncServiceLocator.ts"],"names":[],"mappings":";;;;;;;;;AAsBA,MAAM,OAAO,mBAAmB;IAY9B,YACE,QAAW,EACX,KAA2B,EAC3B,OAAmC;QAEnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAID,MAAM,CAAC,WAAW,CAAC,GAAW,EAAE,OAAmC;QACjE,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,WA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BAAoB;AACpB,sBAAsB;AACtB,MAAM;AACN,IAAI;AACJ,EAAE;AACF,iEAAiE;AACjE,qDAAqD;AACrD,gDAAgD;AAChD,sBAAsB;AACtB,eAAe;AACf,oEAAoE;AACpE,OAAO;AACP,4DAA4D;AAC5D,8DAA8D;AAC9D,EAAE;AACF,sBAAsB;AACtB,0BAA0B"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type GetRemoteApiParams = {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
4
|
+
export type PostRequest<T extends object> = {
|
|
5
|
+
source: Window | null;
|
|
6
|
+
origin: string;
|
|
7
|
+
data: T;
|
|
8
|
+
};
|
|
9
|
+
export type PostResponse<T extends object> = {
|
|
10
|
+
source: Window | null;
|
|
11
|
+
origin: string;
|
|
12
|
+
data: T;
|
|
13
|
+
};
|
|
14
|
+
export type PostResponseWithPayload<T> = PostResponse<PostResponsePayload<T>>;
|
|
15
|
+
type BasePostResponsePayload<D, E> = {
|
|
16
|
+
data: D;
|
|
17
|
+
error: E;
|
|
18
|
+
};
|
|
19
|
+
export type ErrorPostResponsePayload = BasePostResponsePayload<null, {
|
|
20
|
+
code: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}>;
|
|
23
|
+
export type SuccessPostResponsePayload<T> = BasePostResponsePayload<T, null>;
|
|
24
|
+
export type PostResponsePayload<T> = ErrorPostResponsePayload | SuccessPostResponsePayload<T>;
|
|
25
|
+
export type RemoteApiError = Error & {
|
|
26
|
+
originalError: Error;
|
|
27
|
+
};
|
|
28
|
+
export type EnsureMethodsReturnPromise<T> = {
|
|
29
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? (...args: Parameters<T[K]>) => Promise<Awaited<ReturnType<T[K]>>> : T[K];
|
|
30
|
+
};
|
|
31
|
+
export type ContextApi<T> = {
|
|
32
|
+
getContext: () => T;
|
|
33
|
+
subscribeToChanges: (id: string, callback: (context: T) => void) => void;
|
|
34
|
+
unsubscribeFromChanges: (id: string) => void;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI;IAC1C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI;IAC3C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9E,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI;IACnC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,CAC5D,IAAI,EACJ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAClC,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI,uBAAuB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAE7E,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC7B,wBAAwB,GACxB,0BAA0B,CAAC,CAAC,CAAC,CAAC;AAElC,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG;IAAE,aAAa,EAAE,KAAK,CAAA;CAAE,CAAC;AAE9D,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAChD,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACjE,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,UAAU,EAAE,MAAM,CAAC,CAAC;IACpB,kBAAkB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,KAAK,IAAI,CAAC;IACzE,sBAAsB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
// type ET = EnsureMethodsReturnPromise<{
|
|
3
|
+
// value: number;
|
|
4
|
+
// foo: (a: string) => string;
|
|
5
|
+
// bar: (a: string) => Promise<string>;
|
|
6
|
+
// nested: {
|
|
7
|
+
// value: number;
|
|
8
|
+
// foo: (a: string) => string;
|
|
9
|
+
// bar: (a: string) => Promise<string>;
|
|
10
|
+
// };
|
|
11
|
+
// }>;
|
|
12
|
+
// const a = {} as ET;
|
|
13
|
+
//
|
|
14
|
+
// const v: number = a.value;
|
|
15
|
+
// const f = a.foo('a');
|
|
16
|
+
// const b = a.bar('s');
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAgDA,yCAAyC;AACzC,mBAAmB;AACnB,gCAAgC;AAChC,yCAAyC;AACzC,cAAc;AACd,qBAAqB;AACrB,kCAAkC;AAClC,2CAA2C;AAC3C,OAAO;AACP,MAAM;AAEN,sBAAsB;AACtB,EAAE;AACF,6BAA6B;AAC7B,wBAAwB;AACxB,wBAAwB"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,KAAK,oBACF,GAAG,+BACP,YAAY,eAsBvB,CAAC"}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const retry = (fn, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
let attempts = 0;
|
|
13
|
+
const maxAttempts = (_a = options === null || options === void 0 ? void 0 : options.maxAttempts) !== null && _a !== void 0 ? _a : 3;
|
|
14
|
+
const retryInterval = (_b = options === null || options === void 0 ? void 0 : options.retryInterval) !== null && _b !== void 0 ? _b : 1000;
|
|
15
|
+
while (true) {
|
|
16
|
+
attempts += 1;
|
|
17
|
+
try {
|
|
18
|
+
// eslint-disable-next-line no-await-in-loop
|
|
19
|
+
return yield fn();
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (attempts < maxAttempts) {
|
|
23
|
+
// eslint-disable-next-line no-await-in-loop
|
|
24
|
+
yield new Promise(resolve => setTimeout(resolve, retryInterval));
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;AAKA,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,EAAoC,EACpC,OAAsB,EACV,EAAE;;IACd,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,MAAM,WAAW,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,IAAI,CAAC;IAErD,OAAO,IAAI,EAAE;QACX,QAAQ,IAAI,CAAC,CAAC;QAEd,IAAI;YACF,4CAA4C;YAC5C,OAAO,MAAM,EAAE,EAAE,CAAC;SACnB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,QAAQ,GAAG,WAAW,EAAE;gBAC1B,4CAA4C;gBAC5C,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;aAClE;YAED,MAAM,CAAC,CAAC;SACT;KACF;AACH,CAAC,CAAA,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octostar/platform-api",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Provides access to the API exposed by Octostar platform to an application run in an iframe",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"octostar",
|
|
7
|
+
"api"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "",
|
|
12
|
+
"directory": "superset-frontend/packages/octostar-platform-api"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "",
|
|
16
|
+
"main": "lib/index.js",
|
|
17
|
+
"types": "dist/platform-api.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/platform-api.d.ts",
|
|
20
|
+
"lib/**/*"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "npm run clear && npm run compile && npm run run:api-extractor",
|
|
24
|
+
"clear": "rimraf ./lib ./dist ./temp tsconfig.tsbuildinfo",
|
|
25
|
+
"compile": "tsc",
|
|
26
|
+
"dev": "tsc -b -w",
|
|
27
|
+
"run:api-extractor": "api-extractor run --local --verbose"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@octostar/platform-types": "0.0.1",
|
|
31
|
+
"post-robot": "^10.0.46"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@microsoft/api-extractor": "^7.42.3",
|
|
35
|
+
"rimraf": "^5.0.5"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "0b301a354cbacd253d138bcb828888ac4df82120"
|
|
41
|
+
}
|