aeria-sdk 0.0.1 → 0.0.3
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mirror.js +44 -30
- package/dist/topLevel.d.ts +4 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -18,5 +18,6 @@ exports.Aeria = void 0;
|
|
|
18
18
|
var topLevel_1 = require("./topLevel");
|
|
19
19
|
Object.defineProperty(exports, "Aeria", { enumerable: true, get: function () { return topLevel_1.topLevel; } });
|
|
20
20
|
__exportStar(require("@sonata-api/common"), exports);
|
|
21
|
+
__exportStar(require("./topLevel"), exports);
|
|
21
22
|
// @ts-ignore
|
|
22
23
|
__exportStar(require(".aeria-sdk"), exports);
|
package/dist/mirror.js
CHANGED
|
@@ -8,8 +8,12 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const common_1 = require("@sonata-api/common");
|
|
9
9
|
const promises_1 = require("fs/promises");
|
|
10
10
|
const topLevel_1 = require("./topLevel");
|
|
11
|
-
const mirrorDts = (mirrorObj) =>
|
|
12
|
-
|
|
11
|
+
const mirrorDts = (mirrorObj) => {
|
|
12
|
+
const collections = mirrorObj.descriptions;
|
|
13
|
+
return `import type {
|
|
14
|
+
InferSchema,
|
|
15
|
+
SchemaWithId,
|
|
16
|
+
MakeEndpoint,
|
|
13
17
|
CollectionDocument,
|
|
14
18
|
GetPayload,
|
|
15
19
|
GetAllPayload,
|
|
@@ -17,53 +21,63 @@ const mirrorDts = (mirrorObj) => `import type {
|
|
|
17
21
|
RemovePayload,
|
|
18
22
|
RemoveAllPayload,
|
|
19
23
|
UploadPayload,
|
|
20
|
-
RemoveFilePayload
|
|
24
|
+
RemoveFilePayload,
|
|
25
|
+
CollectionFunctions
|
|
21
26
|
|
|
22
27
|
} from '@sonata-api/types'
|
|
23
28
|
|
|
24
|
-
declare type MirrorDescriptions = ${JSON.stringify(
|
|
29
|
+
declare type MirrorDescriptions = ${JSON.stringify(collections, null, 2)}\n
|
|
25
30
|
|
|
26
|
-
declare type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
getAll: (payload?: GetAllPayload<Document>) => Promise<Document[]>
|
|
33
|
-
insert: (payload: InsertPayload<Document>) => Promise<Document>
|
|
34
|
-
upload: (payload: UploadPayload<Document>) => Promise<any>
|
|
35
|
-
remove: (payload: RemovePayload<Document>) => Promise<Document>
|
|
36
|
-
removeAll: (payload: RemoveAllPayload<Document>) => Promise<any>
|
|
37
|
-
removeFile: (payload: UploadPayload<Document>) => Promise<any>
|
|
31
|
+
declare type MirrorRouter = ${JSON.stringify(mirrorObj.router, null, 2)}\n
|
|
32
|
+
|
|
33
|
+
declare global {
|
|
34
|
+
type Collections = {
|
|
35
|
+
[K in keyof MirrorDescriptions]: {
|
|
36
|
+
item: SchemaWithId<MirrorDescriptions[K]>
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
}
|
|
39
|
+
}
|
|
41
40
|
|
|
42
41
|
declare module 'aeria-sdk' {
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
import { TopLevelObject, TLOFunctions } from 'aeria-sdk'
|
|
43
|
+
|
|
44
|
+
type UnionToIntersection<T> = (T extends any ? ((x: T) => 0) : never) extends ((x: infer R) => 0)
|
|
45
|
+
? R
|
|
46
|
+
: never
|
|
48
47
|
|
|
49
|
-
type
|
|
50
|
-
[
|
|
51
|
-
?
|
|
48
|
+
type Endpoints = {
|
|
49
|
+
[Route in keyof MirrorRouter]: MirrorRouter[Route] extends infer RouteContract
|
|
50
|
+
? RouteContract extends [infer RoutePayload, infer RouteResponse]
|
|
51
|
+
? RoutePayload extends null
|
|
52
|
+
? MakeEndpoint<Route, InferSchema<RouteResponse>, undefined>
|
|
53
|
+
: MakeEndpoint<Route, InferSchema<RouteResponse>, InferSchema<RoutePayload>>
|
|
54
|
+
: MakeEndpoint<Route>
|
|
55
|
+
: never
|
|
56
|
+
} extends infer Endpoints
|
|
57
|
+
? UnionToIntersection<Endpoints[keyof Endpoints]>
|
|
58
|
+
: never
|
|
59
|
+
|
|
60
|
+
type StrongelyTypedTLO = TopLevelObject & Endpoints & {
|
|
61
|
+
[K in keyof MirrorDescriptions]: SchemaWithId<MirrorDescriptions[K]> extends infer Document
|
|
62
|
+
? CollectionFunctions<Document> & Omit<TLOFunctions, keyof Functions>
|
|
52
63
|
: never
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
export const url: string
|
|
56
67
|
export const aeria: StrongelyTypedTLO
|
|
57
|
-
}
|
|
58
|
-
`;
|
|
68
|
+
}\n
|
|
69
|
+
`;
|
|
70
|
+
};
|
|
59
71
|
const runtimeJs = (config) => `exports.url = '${config.apiUrl}'
|
|
60
|
-
exports.aeria = require('aeria-sdk').Aeria(${JSON.stringify(config)})
|
|
72
|
+
exports.aeria = require('aeria-sdk').Aeria(${JSON.stringify(config)})\n
|
|
61
73
|
`;
|
|
62
74
|
exports.runtimeJs = runtimeJs;
|
|
63
75
|
const mirror = async (config) => {
|
|
64
76
|
const api = (0, topLevel_1.topLevel)(config);
|
|
65
77
|
const runtimeBase = path_1.default.join(process.cwd(), 'node_modules', '.aeria-sdk');
|
|
66
|
-
const mirror = (0, common_1.deserialize)(await api.describe(
|
|
78
|
+
const mirror = (0, common_1.deserialize)(await api.describe({
|
|
79
|
+
router: true
|
|
80
|
+
}));
|
|
67
81
|
await (0, promises_1.mkdir)(runtimeBase, { recursive: true });
|
|
68
82
|
await (0, promises_1.writeFile)(path_1.default.join(process.cwd(), 'aeria-sdk.d.ts'), mirrorDts(mirror));
|
|
69
83
|
await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, 'index.js'), (0, exports.runtimeJs)(config));
|
package/dist/topLevel.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ type UserFunctions = {
|
|
|
5
5
|
authenticate: (payload: AuthenticationPayload) => Promise<any>;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
|
-
type TLOFunctions = {
|
|
8
|
+
export type TLOFunctions = {
|
|
9
9
|
[P in string]: ((payload?: any) => Promise<any>) & TLOFunctions;
|
|
10
10
|
};
|
|
11
|
-
type TopLevelObject =
|
|
11
|
+
export type TopLevelObject = UserFunctions & {
|
|
12
|
+
describe: (...args: any) => Promise<any>;
|
|
13
|
+
};
|
|
12
14
|
export declare const topLevel: (config: InstanceConfig) => TopLevelObject;
|
|
13
15
|
export {};
|