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 CHANGED
@@ -1,3 +1,4 @@
1
1
  export { topLevel as Aeria } from './topLevel';
2
2
  export * from '@sonata-api/common';
3
+ export * from './topLevel';
3
4
  export * from '.aeria-sdk';
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) => `import type {
12
- Schema,
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(mirrorObj.descriptions, null, 2)}\n
29
+ declare type MirrorDescriptions = ${JSON.stringify(collections, null, 2)}\n
25
30
 
26
- declare type CollectionFunctions<
27
- TCollectionName extends keyof MirrorDescriptions
28
- > = Schema<MirrorDescriptions[TCollectionName]> extends infer Document
29
- ? Document extends CollectionDocument<any>
30
- ? {
31
- get: (payload: GetPayload<Document>) => Promise<Document>
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
- : never
40
- : never
38
+ }
39
+ }
41
40
 
42
41
  declare module 'aeria-sdk' {
43
- import {
44
- InstanceConfig,
45
- TopLevelObject,
46
- TLOFunctions
47
- } from 'aeria-sdk'
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 StrongelyTypedTLO = Omit<TopLevelObject, keyof MirrorDescriptions> & {
50
- [K in keyof MirrorDescriptions]: CollectionFunctions<K> extends infer Functions
51
- ? Functions & Omit<TLOFunctions, keyof Functions>
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));
@@ -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 = TLOFunctions & UserFunctions;
11
+ export type TopLevelObject = UserFunctions & {
12
+ describe: (...args: any) => Promise<any>;
13
+ };
12
14
  export declare const topLevel: (config: InstanceConfig) => TopLevelObject;
13
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aeria-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",