aeria-sdk 0.0.0
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 +19 -0
- package/README.md +13 -0
- package/bin/index.js +3 -0
- package/dist/auth.d.ts +15 -0
- package/dist/auth.js +22 -0
- package/dist/auth.mjs +169 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +16 -0
- package/dist/cli.mjs +148 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +24 -0
- package/dist/http.mjs +160 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +23 -0
- package/dist/index.mjs +5 -0
- package/dist/mirror.d.ts +4 -0
- package/dist/mirror.js +106 -0
- package/dist/mirror.mjs +193 -0
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.mjs +5 -0
- package/dist/storage.d.ts +9 -0
- package/dist/storage.js +51 -0
- package/dist/storage.mjs +42 -0
- package/dist/topLevel.d.ts +19 -0
- package/dist/topLevel.js +43 -0
- package/dist/topLevel.mjs +188 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.js +2 -0
- package/dist/types.mjs +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +12 -0
- package/dist/utils.mjs +6 -0
- package/package.json +51 -0
package/dist/mirror.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mirror = exports.runtimeEsm = exports.runtimeCjs = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const common_1 = require("@aeriajs/common");
|
|
9
|
+
const promises_1 = require("fs/promises");
|
|
10
|
+
const topLevel_js_1 = require("./topLevel.js");
|
|
11
|
+
const utils_js_1 = require("./utils.js");
|
|
12
|
+
const mirrorDts = (mirrorObj) => {
|
|
13
|
+
const collections = mirrorObj.descriptions;
|
|
14
|
+
return `import type {
|
|
15
|
+
InferProperty,
|
|
16
|
+
InferResponse,
|
|
17
|
+
SchemaWithId,
|
|
18
|
+
MakeEndpoint,
|
|
19
|
+
RequestMethod,
|
|
20
|
+
CollectionFunctions
|
|
21
|
+
|
|
22
|
+
} from '@aeriajs/types'
|
|
23
|
+
|
|
24
|
+
declare type MirrorDescriptions = ${JSON.stringify(collections, null, 2)}\n
|
|
25
|
+
|
|
26
|
+
declare type MirrorRouter = ${JSON.stringify(mirrorObj.router, null, 2)}\n
|
|
27
|
+
|
|
28
|
+
declare global {
|
|
29
|
+
type Collections = {
|
|
30
|
+
[K in keyof MirrorDescriptions]: {
|
|
31
|
+
item: SchemaWithId<MirrorDescriptions[K]>
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare module 'aeria-sdk' {
|
|
37
|
+
import { TopLevelObject, TLOFunctions } from 'aeria-sdk'
|
|
38
|
+
|
|
39
|
+
type UnionToIntersection<T> = (T extends any ? ((x: T) => 0) : never) extends ((x: infer R) => 0)
|
|
40
|
+
? R
|
|
41
|
+
: never
|
|
42
|
+
|
|
43
|
+
type Endpoints = {
|
|
44
|
+
[Route in keyof MirrorRouter]: {
|
|
45
|
+
[Method in keyof MirrorRouter[Route]]: Method extends RequestMethod
|
|
46
|
+
? MirrorRouter[Route][Method] extends infer Contract
|
|
47
|
+
? Contract extends
|
|
48
|
+
| { response: infer RouteResponse }
|
|
49
|
+
| { payload: infer RoutePayload }
|
|
50
|
+
| { query: infer RoutePayload }
|
|
51
|
+
? MakeEndpoint<Route, Method, InferResponse<RouteResponse>, InferProperty<RoutePayload>>
|
|
52
|
+
: MakeEndpoint<Route, Method>
|
|
53
|
+
: never
|
|
54
|
+
: never
|
|
55
|
+
} extends infer Methods
|
|
56
|
+
? Methods[keyof Methods]
|
|
57
|
+
: never
|
|
58
|
+
} extends infer Endpoints
|
|
59
|
+
? UnionToIntersection<Endpoints[keyof Endpoints]>
|
|
60
|
+
: never
|
|
61
|
+
|
|
62
|
+
type StrongelyTypedTLO = TopLevelObject & Endpoints & {
|
|
63
|
+
[K in keyof MirrorDescriptions]: SchemaWithId<MirrorDescriptions[K]> extends infer Document
|
|
64
|
+
? CollectionFunctions<Document> extends infer Functions
|
|
65
|
+
? Omit<TLOFunctions, keyof Functions> & {
|
|
66
|
+
[P in keyof Functions]: {
|
|
67
|
+
POST: Functions[P]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
: never
|
|
71
|
+
: never
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const url: string
|
|
75
|
+
export const aeria: StrongelyTypedTLO
|
|
76
|
+
}\n
|
|
77
|
+
`;
|
|
78
|
+
};
|
|
79
|
+
const runtimeCjs = (config) => `const config = ${JSON.stringify(config)}
|
|
80
|
+
exports.config = config
|
|
81
|
+
exports.url = '${(0, utils_js_1.apiUrl)(config)}'
|
|
82
|
+
exports.aeria = require('aeria-sdk/topLevel').topLevel(config)
|
|
83
|
+
exports.storage = require('aeria-sdk/storage').getStorage(config)
|
|
84
|
+
\n`;
|
|
85
|
+
exports.runtimeCjs = runtimeCjs;
|
|
86
|
+
const runtimeEsm = (config) => `import { Aeria, getStorage } from 'aeria-sdk'
|
|
87
|
+
export const config = ${JSON.stringify(config)}
|
|
88
|
+
export const url = '${(0, utils_js_1.apiUrl)(config)}'
|
|
89
|
+
export const aeria = Aeria(config)
|
|
90
|
+
export const storage = getStorage(config)
|
|
91
|
+
\n`;
|
|
92
|
+
exports.runtimeEsm = runtimeEsm;
|
|
93
|
+
const mirror = async (config) => {
|
|
94
|
+
const api = (0, topLevel_js_1.topLevel)(config);
|
|
95
|
+
const runtimeBase = path_1.default.dirname(require.resolve('aeria-sdk'));
|
|
96
|
+
const mirror = (0, common_1.deserialize)(await api.describe.POST({
|
|
97
|
+
router: true,
|
|
98
|
+
}));
|
|
99
|
+
await (0, promises_1.mkdir)(runtimeBase, {
|
|
100
|
+
recursive: true,
|
|
101
|
+
});
|
|
102
|
+
await (0, promises_1.writeFile)(path_1.default.join(process.cwd(), 'aeria-sdk.d.ts'), mirrorDts(mirror));
|
|
103
|
+
await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, 'runtime.js'), (0, exports.runtimeCjs)(config));
|
|
104
|
+
await (0, promises_1.writeFile)(path_1.default.join(runtimeBase, 'runtime.mjs'), (0, exports.runtimeEsm)(config));
|
|
105
|
+
};
|
|
106
|
+
exports.mirror = mirror;
|
package/dist/mirror.mjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g;
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
import path from "path";
|
|
126
|
+
import { deserialize } from "@aeriajs/common";
|
|
127
|
+
import { writeFile, mkdir } from "fs/promises";
|
|
128
|
+
import { topLevel } from "./topLevel.mjs";
|
|
129
|
+
import { apiUrl } from "./utils.mjs";
|
|
130
|
+
var mirrorDts = function(mirrorObj) {
|
|
131
|
+
var collections = mirrorObj.descriptions;
|
|
132
|
+
return "import type {\n InferProperty,\n InferResponse,\n SchemaWithId,\n MakeEndpoint,\n RequestMethod,\n CollectionFunctions\n\n} from '@aeriajs/types'\n\ndeclare type MirrorDescriptions = ".concat(JSON.stringify(collections, null, 2), "\n\n\ndeclare type MirrorRouter = ").concat(JSON.stringify(mirrorObj.router, null, 2), "\n\n\ndeclare global {\n type Collections = {\n [K in keyof MirrorDescriptions]: {\n item: SchemaWithId<MirrorDescriptions[K]>\n }\n }\n}\n\ndeclare module 'aeria-sdk' {\n import { TopLevelObject, TLOFunctions } from 'aeria-sdk'\n\n type UnionToIntersection<T> = (T extends any ? ((x: T) => 0) : never) extends ((x: infer R) => 0)\n ? R\n : never\n\n type Endpoints = {\n [Route in keyof MirrorRouter]: {\n [Method in keyof MirrorRouter[Route]]: Method extends RequestMethod\n ? MirrorRouter[Route][Method] extends infer Contract\n ? Contract extends\n | { response: infer RouteResponse }\n | { payload: infer RoutePayload }\n | { query: infer RoutePayload }\n ? MakeEndpoint<Route, Method, InferResponse<RouteResponse>, InferProperty<RoutePayload>>\n : MakeEndpoint<Route, Method>\n : never\n : never\n } extends infer Methods\n ? Methods[keyof Methods]\n : never\n } extends infer Endpoints\n ? UnionToIntersection<Endpoints[keyof Endpoints]>\n : never\n\n type StrongelyTypedTLO = TopLevelObject & Endpoints & {\n [K in keyof MirrorDescriptions]: SchemaWithId<MirrorDescriptions[K]> extends infer Document\n ? CollectionFunctions<Document> extends infer Functions\n ? Omit<TLOFunctions, keyof Functions> & {\n [P in keyof Functions]: {\n POST: Functions[P]\n }\n }\n : never\n : never\n }\n\n export const url: string\n export const aeria: StrongelyTypedTLO\n}\n\n ");
|
|
133
|
+
};
|
|
134
|
+
export var runtimeCjs = function(config) {
|
|
135
|
+
return "const config = ".concat(JSON.stringify(config), "\nexports.config = config\nexports.url = '").concat(apiUrl(config), "'\nexports.aeria = require('aeria-sdk/topLevel').topLevel(config)\nexports.storage = require('aeria-sdk/storage').getStorage(config)\n\n");
|
|
136
|
+
};
|
|
137
|
+
export var runtimeEsm = function(config) {
|
|
138
|
+
return "import { Aeria, getStorage } from 'aeria-sdk'\nexport const config = ".concat(JSON.stringify(config), "\nexport const url = '").concat(apiUrl(config), "'\nexport const aeria = Aeria(config)\nexport const storage = getStorage(config)\n\n");
|
|
139
|
+
};
|
|
140
|
+
export var mirror = function() {
|
|
141
|
+
var _ref = _async_to_generator(function(config) {
|
|
142
|
+
var api, runtimeBase, mirror;
|
|
143
|
+
return _ts_generator(this, function(_state) {
|
|
144
|
+
switch(_state.label){
|
|
145
|
+
case 0:
|
|
146
|
+
api = topLevel(config);
|
|
147
|
+
runtimeBase = path.dirname(require.resolve("aeria-sdk"));
|
|
148
|
+
return [
|
|
149
|
+
4,
|
|
150
|
+
api.describe.POST({
|
|
151
|
+
router: true
|
|
152
|
+
})
|
|
153
|
+
];
|
|
154
|
+
case 1:
|
|
155
|
+
mirror = deserialize.apply(void 0, [
|
|
156
|
+
_state.sent()
|
|
157
|
+
]);
|
|
158
|
+
return [
|
|
159
|
+
4,
|
|
160
|
+
mkdir(runtimeBase, {
|
|
161
|
+
recursive: true
|
|
162
|
+
})
|
|
163
|
+
];
|
|
164
|
+
case 2:
|
|
165
|
+
_state.sent();
|
|
166
|
+
return [
|
|
167
|
+
4,
|
|
168
|
+
writeFile(path.join(process.cwd(), "aeria-sdk.d.ts"), mirrorDts(mirror))
|
|
169
|
+
];
|
|
170
|
+
case 3:
|
|
171
|
+
_state.sent();
|
|
172
|
+
return [
|
|
173
|
+
4,
|
|
174
|
+
writeFile(path.join(runtimeBase, "runtime.mjs"), runtimeCjs(config))
|
|
175
|
+
];
|
|
176
|
+
case 4:
|
|
177
|
+
_state.sent();
|
|
178
|
+
return [
|
|
179
|
+
4,
|
|
180
|
+
writeFile(path.join(runtimeBase, "runtime.mjs"), runtimeEsm(config))
|
|
181
|
+
];
|
|
182
|
+
case 5:
|
|
183
|
+
_state.sent();
|
|
184
|
+
return [
|
|
185
|
+
2
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
return function mirror(config) {
|
|
191
|
+
return _ref.apply(this, arguments);
|
|
192
|
+
};
|
|
193
|
+
}();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InstanceConfig } from './types.js';
|
|
2
|
+
export declare const instanceConfig: InstanceConfig;
|
|
3
|
+
export declare const url = "";
|
|
4
|
+
export declare const aeria: {};
|
|
5
|
+
export declare const storage: {
|
|
6
|
+
get: (key: "auth") => import("./auth.js").AuthenticationResult | null;
|
|
7
|
+
remove: (key: string) => void;
|
|
8
|
+
set: (key: string, value: any) => void;
|
|
9
|
+
};
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.storage = exports.aeria = exports.url = exports.instanceConfig = void 0;
|
|
4
|
+
exports.instanceConfig = {};
|
|
5
|
+
exports.url = '';
|
|
6
|
+
exports.aeria = {};
|
|
7
|
+
exports.storage = {};
|
|
8
|
+
throw new Error('Runtime files werent generated. Run the "aeria-sdk" script first.');
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InstanceConfig } from './types.js';
|
|
2
|
+
import type { AuthenticationResult } from './auth.js';
|
|
3
|
+
export declare const storageMemo: Record<string, string>;
|
|
4
|
+
export declare const storageKey: (key: string, config: InstanceConfig) => string;
|
|
5
|
+
export declare const getStorage: (config: InstanceConfig) => {
|
|
6
|
+
get: (key: 'auth') => AuthenticationResult | null;
|
|
7
|
+
remove: (key: string) => void;
|
|
8
|
+
set: (key: string, value: any) => void;
|
|
9
|
+
};
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStorage = exports.storageKey = exports.storageMemo = void 0;
|
|
4
|
+
exports.storageMemo = {};
|
|
5
|
+
const storageKey = (key, config) => {
|
|
6
|
+
const namespace = config.storage?.namespace || 'aeriaSdk';
|
|
7
|
+
return `${namespace}:${key}`;
|
|
8
|
+
};
|
|
9
|
+
exports.storageKey = storageKey;
|
|
10
|
+
const getStorage = (config) => {
|
|
11
|
+
const strategy = !config.storage?.strategy
|
|
12
|
+
? 'memo'
|
|
13
|
+
: config.storage.strategy === 'localStorage' && !('localStorage' in globalThis)
|
|
14
|
+
? 'memo'
|
|
15
|
+
: config.storage.strategy;
|
|
16
|
+
function get(key) {
|
|
17
|
+
switch (strategy) {
|
|
18
|
+
case 'memo':
|
|
19
|
+
return exports.storageMemo[key] || null;
|
|
20
|
+
case 'localStorage':
|
|
21
|
+
const value = localStorage.getItem((0, exports.storageKey)(key, config));
|
|
22
|
+
return value
|
|
23
|
+
? JSON.parse(value)
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
get,
|
|
29
|
+
remove: (key) => {
|
|
30
|
+
switch (strategy) {
|
|
31
|
+
case 'memo':
|
|
32
|
+
delete exports.storageMemo[key];
|
|
33
|
+
break;
|
|
34
|
+
case 'localStorage':
|
|
35
|
+
localStorage.removeItem((0, exports.storageKey)(key, config));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
set: (key, value) => {
|
|
40
|
+
switch (strategy) {
|
|
41
|
+
case 'memo':
|
|
42
|
+
exports.storageMemo[key] = value;
|
|
43
|
+
break;
|
|
44
|
+
case 'localStorage':
|
|
45
|
+
const serialized = JSON.stringify(value);
|
|
46
|
+
return localStorage.setItem((0, exports.storageKey)(key, config), serialized);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.getStorage = getStorage;
|
package/dist/storage.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export var storageMemo = {};
|
|
2
|
+
export var storageKey = function(key, config) {
|
|
3
|
+
var _config_storage;
|
|
4
|
+
var namespace = ((_config_storage = config.storage) === null || _config_storage === void 0 ? void 0 : _config_storage.namespace) || "aeriaSdk";
|
|
5
|
+
return "".concat(namespace, ":").concat(key);
|
|
6
|
+
};
|
|
7
|
+
export var getStorage = function(config) {
|
|
8
|
+
var get = function get(key) {
|
|
9
|
+
switch(strategy){
|
|
10
|
+
case "memo":
|
|
11
|
+
return storageMemo[key] || null;
|
|
12
|
+
case "localStorage":
|
|
13
|
+
var value = localStorage.getItem(storageKey(key, config));
|
|
14
|
+
return value ? JSON.parse(value) : null;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var _config_storage;
|
|
18
|
+
var strategy = !((_config_storage = config.storage) === null || _config_storage === void 0 ? void 0 : _config_storage.strategy) ? "memo" : config.storage.strategy === "localStorage" && !("localStorage" in globalThis) ? "memo" : config.storage.strategy;
|
|
19
|
+
return {
|
|
20
|
+
get: get,
|
|
21
|
+
remove: function(key) {
|
|
22
|
+
switch(strategy){
|
|
23
|
+
case "memo":
|
|
24
|
+
delete storageMemo[key];
|
|
25
|
+
break;
|
|
26
|
+
case "localStorage":
|
|
27
|
+
localStorage.removeItem(storageKey(key, config));
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
set: function(key, value) {
|
|
32
|
+
switch(strategy){
|
|
33
|
+
case "memo":
|
|
34
|
+
storageMemo[key] = value;
|
|
35
|
+
break;
|
|
36
|
+
case "localStorage":
|
|
37
|
+
var serialized = JSON.stringify(value);
|
|
38
|
+
return localStorage.setItem(storageKey(key, config), serialized);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RequestMethod } from '@aeriajs/types';
|
|
2
|
+
import type { InstanceConfig } from './types.js';
|
|
3
|
+
import { type AuthenticationPayload } from './auth.js';
|
|
4
|
+
type UserFunctions = {
|
|
5
|
+
user: TLOFunctions & {
|
|
6
|
+
authenticate: (payload: AuthenticationPayload) => Promise<any>;
|
|
7
|
+
signout: () => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type TLOFunctions = {
|
|
11
|
+
[P: string]: Record<RequestMethod, ((payload?: any) => Promise<any>) & TLOFunctions>;
|
|
12
|
+
};
|
|
13
|
+
export type TopLevelObject = UserFunctions & {
|
|
14
|
+
describe: {
|
|
15
|
+
POST: (...args: any) => Promise<any>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const topLevel: (config: InstanceConfig) => TopLevelObject;
|
|
19
|
+
export {};
|
package/dist/topLevel.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.topLevel = void 0;
|
|
4
|
+
const auth_js_1 = require("./auth.js");
|
|
5
|
+
const http_js_1 = require("./http.js");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
const topLevel = (config) => {
|
|
8
|
+
const proxify = (target, parent) => new Proxy(target, {
|
|
9
|
+
get: (_, key) => {
|
|
10
|
+
if (typeof key === 'symbol') {
|
|
11
|
+
return target[key];
|
|
12
|
+
}
|
|
13
|
+
switch (`${parent}/${key}`) {
|
|
14
|
+
case 'user/authenticate': return (0, auth_js_1.authenticate)(config);
|
|
15
|
+
case 'user/signout': return (0, auth_js_1.signout)(config);
|
|
16
|
+
}
|
|
17
|
+
const endpoint = parent;
|
|
18
|
+
const fn = async (payload) => {
|
|
19
|
+
const method = key;
|
|
20
|
+
const requestConfig = {
|
|
21
|
+
params: {
|
|
22
|
+
method,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
26
|
+
if (payload) {
|
|
27
|
+
requestConfig.params.headers = {
|
|
28
|
+
'content-type': 'application/json',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const response = await (0, http_js_1.request)(config, `${(0, utils_js_1.apiUrl)(config)}/${endpoint}`, payload, requestConfig);
|
|
33
|
+
return response.data;
|
|
34
|
+
};
|
|
35
|
+
const path = parent
|
|
36
|
+
? `${parent}/${key}`
|
|
37
|
+
: key;
|
|
38
|
+
return proxify(fn, path);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return proxify({});
|
|
42
|
+
};
|
|
43
|
+
exports.topLevel = topLevel;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _type_of(obj) {
|
|
31
|
+
"@swc/helpers - typeof";
|
|
32
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
33
|
+
}
|
|
34
|
+
function _ts_generator(thisArg, body) {
|
|
35
|
+
var f, y, t, g, _ = {
|
|
36
|
+
label: 0,
|
|
37
|
+
sent: function() {
|
|
38
|
+
if (t[0] & 1) throw t[1];
|
|
39
|
+
return t[1];
|
|
40
|
+
},
|
|
41
|
+
trys: [],
|
|
42
|
+
ops: []
|
|
43
|
+
};
|
|
44
|
+
return g = {
|
|
45
|
+
next: verb(0),
|
|
46
|
+
"throw": verb(1),
|
|
47
|
+
"return": verb(2)
|
|
48
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
49
|
+
return this;
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function(v) {
|
|
53
|
+
return step([
|
|
54
|
+
n,
|
|
55
|
+
v
|
|
56
|
+
]);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function step(op) {
|
|
60
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
+
while(_)try {
|
|
62
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
+
if (y = 0, t) op = [
|
|
64
|
+
op[0] & 2,
|
|
65
|
+
t.value
|
|
66
|
+
];
|
|
67
|
+
switch(op[0]){
|
|
68
|
+
case 0:
|
|
69
|
+
case 1:
|
|
70
|
+
t = op;
|
|
71
|
+
break;
|
|
72
|
+
case 4:
|
|
73
|
+
_.label++;
|
|
74
|
+
return {
|
|
75
|
+
value: op[1],
|
|
76
|
+
done: false
|
|
77
|
+
};
|
|
78
|
+
case 5:
|
|
79
|
+
_.label++;
|
|
80
|
+
y = op[1];
|
|
81
|
+
op = [
|
|
82
|
+
0
|
|
83
|
+
];
|
|
84
|
+
continue;
|
|
85
|
+
case 7:
|
|
86
|
+
op = _.ops.pop();
|
|
87
|
+
_.trys.pop();
|
|
88
|
+
continue;
|
|
89
|
+
default:
|
|
90
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
91
|
+
_ = 0;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
95
|
+
_.label = op[1];
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
99
|
+
_.label = t[1];
|
|
100
|
+
t = op;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (t && _.label < t[2]) {
|
|
104
|
+
_.label = t[2];
|
|
105
|
+
_.ops.push(op);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (t[2]) _.ops.pop();
|
|
109
|
+
_.trys.pop();
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
op = body.call(thisArg, _);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
op = [
|
|
115
|
+
6,
|
|
116
|
+
e
|
|
117
|
+
];
|
|
118
|
+
y = 0;
|
|
119
|
+
} finally{
|
|
120
|
+
f = t = 0;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] & 5) throw op[1];
|
|
123
|
+
return {
|
|
124
|
+
value: op[0] ? op[1] : void 0,
|
|
125
|
+
done: true
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
import { authenticate, signout } from "./auth.mjs";
|
|
130
|
+
import { request } from "./http.mjs";
|
|
131
|
+
import { apiUrl } from "./utils.mjs";
|
|
132
|
+
export var topLevel = function(config) {
|
|
133
|
+
var proxify = function(target, parent) {
|
|
134
|
+
return new Proxy(target, {
|
|
135
|
+
get: function(_, key) {
|
|
136
|
+
if ((typeof key === "undefined" ? "undefined" : _type_of(key)) === "symbol") {
|
|
137
|
+
return target[key];
|
|
138
|
+
}
|
|
139
|
+
switch("".concat(parent, "/").concat(key)){
|
|
140
|
+
case "user/authenticate":
|
|
141
|
+
return authenticate(config);
|
|
142
|
+
case "user/signout":
|
|
143
|
+
return signout(config);
|
|
144
|
+
}
|
|
145
|
+
var endpoint = parent;
|
|
146
|
+
var fn = function() {
|
|
147
|
+
var _ref = _async_to_generator(function(payload) {
|
|
148
|
+
var method, requestConfig, response;
|
|
149
|
+
return _ts_generator(this, function(_state) {
|
|
150
|
+
switch(_state.label){
|
|
151
|
+
case 0:
|
|
152
|
+
method = key;
|
|
153
|
+
requestConfig = {
|
|
154
|
+
params: {
|
|
155
|
+
method: method
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
159
|
+
if (payload) {
|
|
160
|
+
requestConfig.params.headers = {
|
|
161
|
+
"content-type": "application/json"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return [
|
|
166
|
+
4,
|
|
167
|
+
request(config, "".concat(apiUrl(config), "/").concat(endpoint), payload, requestConfig)
|
|
168
|
+
];
|
|
169
|
+
case 1:
|
|
170
|
+
response = _state.sent();
|
|
171
|
+
return [
|
|
172
|
+
2,
|
|
173
|
+
response.data
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
return function fn(payload) {
|
|
179
|
+
return _ref.apply(this, arguments);
|
|
180
|
+
};
|
|
181
|
+
}();
|
|
182
|
+
var path = parent ? "".concat(parent, "/").concat(key) : key;
|
|
183
|
+
return proxify(fn, path);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
return proxify({});
|
|
188
|
+
};
|