@m1cro/server-sdk 0.1.1-beta.7 → 0.1.1-beta.9
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/bridge-BD4H31JR.d.ts +354 -0
- package/dist/globals.d.ts +6 -0
- package/dist/globals.js +0 -2
- package/dist/index.d.ts +16 -362
- package/dist/index.js +1 -2
- package/package.json +1 -4
- package/dist/globals.js.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { SetCookie } from 'cookie';
|
|
2
|
+
|
|
3
|
+
interface Crypto {
|
|
4
|
+
deriveKey(seed: string, length: number): Uint8Array;
|
|
5
|
+
aesGcmEncrypt<T>(data: T): Uint8Array;
|
|
6
|
+
aesGcmDecrypt<T>(data: Uint8Array): T;
|
|
7
|
+
argon2Hash(algorithm: Argon2Algorithm, password: string, options?: Argon2Options): string;
|
|
8
|
+
argon2Verify(algorithm: Argon2Algorithm, password: string, hash: string, options?: Argon2Options): boolean;
|
|
9
|
+
}
|
|
10
|
+
type Argon2Algorithm = 'argon2d' | 'argon2i' | 'argon2id';
|
|
11
|
+
interface Argon2Options {
|
|
12
|
+
mCost?: number;
|
|
13
|
+
tCost?: number;
|
|
14
|
+
pCost?: number;
|
|
15
|
+
outputLen?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Record$1<K extends string | number | symbol = string, V = any> = {
|
|
19
|
+
[key in K]: V;
|
|
20
|
+
};
|
|
21
|
+
type Variant<K extends PropertyKey, T extends object> = {
|
|
22
|
+
[P in keyof T]: {
|
|
23
|
+
[Q in K]: P;
|
|
24
|
+
} & T[P] extends infer U ? {
|
|
25
|
+
[Q in keyof U]: U[Q];
|
|
26
|
+
} : never;
|
|
27
|
+
}[keyof T];
|
|
28
|
+
type EventHandler = <T>(event: string, data: T) => void | Promise<void>;
|
|
29
|
+
type Visibility = 'private' | 'platform' | 'vendor' | 'public';
|
|
30
|
+
interface Tenant {
|
|
31
|
+
id: string;
|
|
32
|
+
host: string;
|
|
33
|
+
}
|
|
34
|
+
interface AppId {
|
|
35
|
+
get name(): string;
|
|
36
|
+
get namespace(): Namespace;
|
|
37
|
+
toString(separator?: string): string;
|
|
38
|
+
}
|
|
39
|
+
declare const AppId: {
|
|
40
|
+
parse(input: string): AppId;
|
|
41
|
+
};
|
|
42
|
+
type Namespace = 'system' | 'platform' | {
|
|
43
|
+
vendor: string;
|
|
44
|
+
};
|
|
45
|
+
type AppRole = Variant<'type', AppRoleData>;
|
|
46
|
+
type AppRoleData = {
|
|
47
|
+
provider: {
|
|
48
|
+
group: string;
|
|
49
|
+
};
|
|
50
|
+
test: void;
|
|
51
|
+
};
|
|
52
|
+
interface Auth {
|
|
53
|
+
subject: Subject;
|
|
54
|
+
permissions: Permissions;
|
|
55
|
+
}
|
|
56
|
+
interface Subject {
|
|
57
|
+
id: string;
|
|
58
|
+
email: string;
|
|
59
|
+
roles: string[];
|
|
60
|
+
}
|
|
61
|
+
interface Permissions {
|
|
62
|
+
[key: string]: string[];
|
|
63
|
+
}
|
|
64
|
+
interface HookEventMap {
|
|
65
|
+
start: [];
|
|
66
|
+
install: [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface FindQuery<T extends Record$1 = Record$1> extends PromiseLike<T[]> {
|
|
70
|
+
limit(limit: number): this;
|
|
71
|
+
offset(offset: number): this;
|
|
72
|
+
sort(sort: Sorting): this;
|
|
73
|
+
}
|
|
74
|
+
interface FindOneQuery<T extends Record$1 = Record$1> extends PromiseLike<T | undefined> {
|
|
75
|
+
offset(offset: number): this;
|
|
76
|
+
sort(sort: Sorting): this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type InsertReturnMode = 'insertedIds' | 'documents';
|
|
80
|
+
type InsertReturnType<T extends Record$1, R extends InsertReturnMode> = R extends 'insertedIds' ? string[] : R extends 'documents' ? T[] : never;
|
|
81
|
+
interface InsertQuery<T extends Record$1 = Record$1, R extends InsertReturnMode = 'insertedIds'> extends PromiseLike<InsertReturnType<T, R>> {
|
|
82
|
+
return(mode: 'insertedIds'): InsertQuery<T, 'insertedIds'>;
|
|
83
|
+
return(mode: 'documents'): InsertQuery<T, 'documents'>;
|
|
84
|
+
return(mode: InsertReturnMode): InsertQuery<T, typeof mode>;
|
|
85
|
+
}
|
|
86
|
+
type InsertOneReturnMode = 'insertedId' | 'document';
|
|
87
|
+
type InsertOneReturnType<T extends Record$1, R extends InsertOneReturnMode> = R extends 'insertedId' ? string : R extends 'document' ? T : never;
|
|
88
|
+
interface InsertOneQuery<T extends Record$1 = Record$1, R extends InsertOneReturnMode = 'insertedId'> extends PromiseLike<InsertOneReturnType<T, R>> {
|
|
89
|
+
return(mode: 'insertedId'): InsertOneQuery<T, 'insertedId'>;
|
|
90
|
+
return(mode: 'document'): InsertOneQuery<T, 'document'>;
|
|
91
|
+
return(mode: InsertOneReturnMode): InsertOneQuery<T, typeof mode>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type UpdateReturnMode = 'affectedRows' | 'oldDocuments' | 'newDocuments';
|
|
95
|
+
type UpdateReturnType<T, R extends UpdateReturnMode> = R extends 'affectedRows' ? bigint : R extends 'oldDocuments' | 'newDocuments' ? T[] : never;
|
|
96
|
+
interface UpdateQuery<T extends Record$1 = Record$1, R extends UpdateReturnMode = 'affectedRows'> extends PromiseLike<UpdateReturnType<T, R>> {
|
|
97
|
+
limit(limit: number): this;
|
|
98
|
+
offset(offset: number): this;
|
|
99
|
+
sort(sort: Sorting): this;
|
|
100
|
+
return(mode: 'affectedRows'): UpdateQuery<T, 'affectedRows'>;
|
|
101
|
+
return(mode: 'oldDocuments'): UpdateQuery<T, 'oldDocuments'>;
|
|
102
|
+
return(mode: 'newDocuments'): UpdateQuery<T, 'newDocuments'>;
|
|
103
|
+
return(mode: UpdateReturnMode): UpdateQuery<T, typeof mode>;
|
|
104
|
+
}
|
|
105
|
+
type UpdateOneReturnMode = 'success' | 'oldDocument' | 'newDocument';
|
|
106
|
+
type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success' ? boolean : R extends 'oldDocument' | 'newDocument' ? T | undefined : never;
|
|
107
|
+
interface UpdateOneQuery<T extends Record$1 = Record$1, R extends UpdateOneReturnMode = 'success'> extends PromiseLike<UpdateOneReturnType<T, R>> {
|
|
108
|
+
offset(offset: number): this;
|
|
109
|
+
sort(sort: Sorting): this;
|
|
110
|
+
upsert(upsert: boolean): this;
|
|
111
|
+
return(mode: 'success'): UpdateOneQuery<T, 'success'>;
|
|
112
|
+
return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
|
|
113
|
+
return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
|
|
114
|
+
return(mode: UpdateOneReturnMode): UpdateOneQuery<T, typeof mode>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type RemoveReturnMode = 'affectedRows' | 'documents';
|
|
118
|
+
type RemoveReturnType<T, R extends RemoveReturnMode> = R extends 'affectedRows' ? bigint : R extends 'documents' ? T[] : never;
|
|
119
|
+
interface RemoveQuery<T extends Record$1 = Record$1, R extends RemoveReturnMode = 'affectedRows'> extends PromiseLike<RemoveReturnType<T, R>> {
|
|
120
|
+
limit(limit: number): this;
|
|
121
|
+
offset(offset: number): this;
|
|
122
|
+
sort(sort: Sorting): this;
|
|
123
|
+
return(mode: 'affectedRows'): RemoveQuery<T, 'affectedRows'>;
|
|
124
|
+
return(mode: 'documents'): RemoveQuery<T, 'documents'>;
|
|
125
|
+
return(mode: RemoveReturnMode): RemoveQuery<T, typeof mode>;
|
|
126
|
+
}
|
|
127
|
+
type RemoveOneReturnMode = 'success' | 'document';
|
|
128
|
+
type RemoveOneReturnType<T, R extends RemoveOneReturnMode> = R extends 'success' ? boolean : R extends 'document' ? T | undefined : never;
|
|
129
|
+
interface RemoveOneQuery<T extends Record$1 = Record$1, R extends RemoveOneReturnMode = 'success'> extends PromiseLike<RemoveOneReturnType<T, R>> {
|
|
130
|
+
offset(offset: number): this;
|
|
131
|
+
sort(sort: Sorting): this;
|
|
132
|
+
return(mode: 'success'): RemoveOneQuery<T, 'success'>;
|
|
133
|
+
return(mode: 'document'): RemoveOneQuery<T, 'document'>;
|
|
134
|
+
return(mode: RemoveOneReturnMode): RemoveOneQuery<T, typeof mode>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface Entity<T extends object = Record$1<string, unknown>> {
|
|
138
|
+
get name(): string;
|
|
139
|
+
find(query?: Record$1): FindQuery<T>;
|
|
140
|
+
findOne(query?: Record$1): FindOneQuery<T>;
|
|
141
|
+
insert(docs: T[]): InsertQuery<T>;
|
|
142
|
+
insertOne(doc: T): InsertOneQuery<T>;
|
|
143
|
+
update(query: Record$1, update: Record$1): UpdateQuery<T>;
|
|
144
|
+
updateOne(query: Record$1, update: Record$1): UpdateOneQuery<T>;
|
|
145
|
+
remove(query: Record$1): RemoveQuery<T>;
|
|
146
|
+
removeOne(query: Record$1): RemoveOneQuery<T>;
|
|
147
|
+
}
|
|
148
|
+
interface Sorting {
|
|
149
|
+
[field: string]: 'asc' | 'desc';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
interface SetOptions {
|
|
153
|
+
ttl?: number;
|
|
154
|
+
existenceCheck?: 'nx' | 'xx';
|
|
155
|
+
}
|
|
156
|
+
interface KeyValueStore {
|
|
157
|
+
get<T>(key: string): Promise<T>;
|
|
158
|
+
getDel<T>(key: string): Promise<T>;
|
|
159
|
+
set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
|
|
160
|
+
delete(key: string): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface Artifacts {
|
|
164
|
+
get<T>(key: string): T | undefined;
|
|
165
|
+
set<T>(key: string, value: T): void;
|
|
166
|
+
delete(key: string): void;
|
|
167
|
+
get auth(): Auth | undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
171
|
+
declare enum StatusCode {
|
|
172
|
+
Continue = 100,
|
|
173
|
+
SwitchingProtocols = 101,
|
|
174
|
+
Processing = 102,
|
|
175
|
+
EarlyHints = 103,
|
|
176
|
+
OK = 200,
|
|
177
|
+
Created = 201,
|
|
178
|
+
Accepted = 202,
|
|
179
|
+
NonAuthoritativeInformation = 203,
|
|
180
|
+
NoContent = 204,
|
|
181
|
+
ResetContent = 205,
|
|
182
|
+
PartialContent = 206,
|
|
183
|
+
MultiStatus = 207,
|
|
184
|
+
AlreadyReported = 208,
|
|
185
|
+
IMUsed = 226,
|
|
186
|
+
MultipleChoices = 300,
|
|
187
|
+
MovedPermanently = 301,
|
|
188
|
+
Found = 302,
|
|
189
|
+
SeeOther = 303,
|
|
190
|
+
NotModified = 304,
|
|
191
|
+
UseProxy = 305,
|
|
192
|
+
TemporaryRedirect = 307,
|
|
193
|
+
PermanentRedirect = 308,
|
|
194
|
+
BadRequest = 400,
|
|
195
|
+
Unauthorized = 401,
|
|
196
|
+
PaymentRequired = 402,
|
|
197
|
+
Forbidden = 403,
|
|
198
|
+
NotFound = 404,
|
|
199
|
+
MethodNotAllowed = 405,
|
|
200
|
+
NotAcceptable = 406,
|
|
201
|
+
ProxyAuthenticationRequired = 407,
|
|
202
|
+
RequestTimeout = 408,
|
|
203
|
+
Conflict = 409,
|
|
204
|
+
Gone = 410,
|
|
205
|
+
LengthRequired = 411,
|
|
206
|
+
PreconditionFailed = 412,
|
|
207
|
+
ContentTooLarge = 413,
|
|
208
|
+
URITooLong = 414,
|
|
209
|
+
UnsupportedMediaType = 415,
|
|
210
|
+
RangeNotSatisfiable = 416,
|
|
211
|
+
ExpectationFailed = 417,
|
|
212
|
+
ImATeapot = 418,
|
|
213
|
+
MisdirectedRequest = 421,
|
|
214
|
+
UnprocessableEntity = 422,
|
|
215
|
+
Locked = 423,
|
|
216
|
+
FailedDependency = 424,
|
|
217
|
+
TooEarly = 425,
|
|
218
|
+
UpgradeRequired = 426,
|
|
219
|
+
PreconditionRequired = 428,
|
|
220
|
+
TooManyRequests = 429,
|
|
221
|
+
RequestHeaderFieldsTooLarge = 431,
|
|
222
|
+
UnavailableForLegalReasons = 451,
|
|
223
|
+
InternalServerError = 500,
|
|
224
|
+
NotImplemented = 501,
|
|
225
|
+
BadGateway = 502,
|
|
226
|
+
ServiceUnavailable = 503,
|
|
227
|
+
GatewayTimeout = 504,
|
|
228
|
+
HTTPVersionNotSupported = 505,
|
|
229
|
+
VariantAlsoNegotiates = 506,
|
|
230
|
+
InsufficientStorage = 507,
|
|
231
|
+
LoopDetected = 508,
|
|
232
|
+
NotExtended = 510,
|
|
233
|
+
NetworkAuthenticationRequired = 511
|
|
234
|
+
}
|
|
235
|
+
type RequestHandler = (req: Request, res: ResponseBuilder) => void | Promise<void>;
|
|
236
|
+
type Middleware = (req: Request, res: ResponseBuilder, next: () => Promise<void>) => void | Promise<void>;
|
|
237
|
+
interface Router {
|
|
238
|
+
scope(path: string): Router;
|
|
239
|
+
route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
240
|
+
middleware(handler: Middleware, options?: MiddlewareOptions): Router;
|
|
241
|
+
get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
242
|
+
post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
243
|
+
put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
244
|
+
patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
245
|
+
delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
246
|
+
}
|
|
247
|
+
interface RouteOptions {
|
|
248
|
+
timeoutMs?: number;
|
|
249
|
+
permissions?: string[];
|
|
250
|
+
authenticated?: boolean;
|
|
251
|
+
visibility?: Visibility;
|
|
252
|
+
}
|
|
253
|
+
interface MiddlewareOptions {
|
|
254
|
+
path?: string;
|
|
255
|
+
priority?: number;
|
|
256
|
+
}
|
|
257
|
+
interface Request {
|
|
258
|
+
get artifacts(): Artifacts;
|
|
259
|
+
get method(): Method;
|
|
260
|
+
get url(): URL;
|
|
261
|
+
get params(): Record<string, string>;
|
|
262
|
+
get headers(): Headers;
|
|
263
|
+
cookie(name: string): string | undefined;
|
|
264
|
+
body(): Promise<Uint8Array>;
|
|
265
|
+
text(): Promise<string>;
|
|
266
|
+
json<T>(): Promise<T>;
|
|
267
|
+
}
|
|
268
|
+
interface RequestBuilder {
|
|
269
|
+
method(method: Method): this;
|
|
270
|
+
url(url: string | URL): this;
|
|
271
|
+
header(name: string, value: string): this;
|
|
272
|
+
headers(headers: HeadersInit): this;
|
|
273
|
+
cookie(name: string, value: string): this;
|
|
274
|
+
body(bytes: Uint8Array): this;
|
|
275
|
+
text(text: string): this;
|
|
276
|
+
json<T>(json: T): this;
|
|
277
|
+
}
|
|
278
|
+
interface Response {
|
|
279
|
+
get status(): number;
|
|
280
|
+
get headers(): Headers;
|
|
281
|
+
cookie(name: string): SetCookie | undefined;
|
|
282
|
+
body(): Promise<Uint8Array>;
|
|
283
|
+
text(): Promise<string>;
|
|
284
|
+
json<T>(): Promise<T>;
|
|
285
|
+
}
|
|
286
|
+
interface ResponseBuilder {
|
|
287
|
+
status(status: number): this;
|
|
288
|
+
header(name: string, value: string): this;
|
|
289
|
+
headers(headers: HeadersInit): this;
|
|
290
|
+
cookie(name: string, value?: string, options?: SetCookieOptions): this;
|
|
291
|
+
body(bytes: Uint8Array): this;
|
|
292
|
+
text(text: string): this;
|
|
293
|
+
json<T>(json: T): this;
|
|
294
|
+
}
|
|
295
|
+
interface SetCookieOptions {
|
|
296
|
+
encode?: (s: string) => string;
|
|
297
|
+
maxAge?: number;
|
|
298
|
+
expires?: Date;
|
|
299
|
+
domain?: string;
|
|
300
|
+
path?: string;
|
|
301
|
+
httpOnly?: boolean;
|
|
302
|
+
secure?: boolean;
|
|
303
|
+
partitioned?: boolean;
|
|
304
|
+
priority?: 'low' | 'medium' | 'high';
|
|
305
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface RPC {
|
|
309
|
+
call(url: string, method: Method): Call;
|
|
310
|
+
get(url: string): Call;
|
|
311
|
+
post(url: string): Call;
|
|
312
|
+
put(url: string): Call;
|
|
313
|
+
patch(url: string): Call;
|
|
314
|
+
delete(url: string): Call;
|
|
315
|
+
}
|
|
316
|
+
interface Call extends RequestBuilder, PromiseLike<Response> {
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
interface Providers {
|
|
320
|
+
list(group: string): Provider[];
|
|
321
|
+
}
|
|
322
|
+
interface Provider {
|
|
323
|
+
get app(): AppId;
|
|
324
|
+
get group(): string;
|
|
325
|
+
get id(): string;
|
|
326
|
+
call(path: string, method: Method): Call;
|
|
327
|
+
get(path: string): Call;
|
|
328
|
+
post(path: string): Call;
|
|
329
|
+
put(path: string): Call;
|
|
330
|
+
patch(path: string): Call;
|
|
331
|
+
delete(path: string): Call;
|
|
332
|
+
}
|
|
333
|
+
declare const Provider: {
|
|
334
|
+
fromId(id: string): Provider;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
interface SSE {
|
|
338
|
+
push<T>(event: T, targets: string[]): Promise<void>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
interface Bridge {
|
|
342
|
+
get tenant(): Tenant;
|
|
343
|
+
get providers(): Providers;
|
|
344
|
+
settings<T>(): T | undefined;
|
|
345
|
+
crd<T>(key: string): T | undefined;
|
|
346
|
+
get rpc(): RPC;
|
|
347
|
+
get kv(): KeyValueStore;
|
|
348
|
+
get sse(): SSE;
|
|
349
|
+
get crypto(): Crypto;
|
|
350
|
+
entity<T extends object>(name: string): Entity<T>;
|
|
351
|
+
publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export { type AppRole as A, type Bridge as B, type EventHandler as E, type HookEventMap as H, type Method as M, type Namespace as N, Provider as P, type Router as R, StatusCode as S, type Tenant as T, type Visibility as V, AppId as a, type Artifacts as b, type Auth as c, type Entity as d, type Middleware as e, type Providers as f, type Request as g, type RequestBuilder as h, type RequestHandler as i, type Response as j, type ResponseBuilder as k, type RouteOptions as l, type Subject as m };
|
package/dist/globals.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import * as console from 'node:console';
|
|
2
|
+
import { B as Bridge } from './bridge-BD4H31JR.js';
|
|
3
|
+
import 'cookie';
|
|
2
4
|
|
|
3
5
|
declare const logLevels: readonly ["trace", "debug", "info", "warn", "error", "none"];
|
|
4
6
|
type LogLevel = (typeof logLevels)[number];
|
|
5
7
|
|
|
8
|
+
interface M1cro {
|
|
9
|
+
bridge: Bridge;
|
|
10
|
+
}
|
|
6
11
|
declare global {
|
|
12
|
+
var __M1CRO__: M1cro;
|
|
7
13
|
interface Console extends console.Console {
|
|
8
14
|
logLevel: LogLevel;
|
|
9
15
|
}
|
package/dist/globals.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,342 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as Router, H as HookEventMap, A as AppRole, E as EventHandler, B as Bridge$1 } from './bridge-BD4H31JR.js';
|
|
2
|
+
export { a as AppId, b as Artifacts, c as Auth, d as Entity, M as Method, e as Middleware, N as Namespace, P as Provider, f as Providers, g as Request, h as RequestBuilder, i as RequestHandler, j as Response, k as ResponseBuilder, l as RouteOptions, S as StatusCode, m as Subject, T as Tenant, V as Visibility } from './bridge-BD4H31JR.js';
|
|
2
3
|
import { JSONSchema4 } from 'json-schema';
|
|
4
|
+
import 'cookie';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
pCost?: number;
|
|
16
|
-
outputLen?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type Record$1<K extends string | number | symbol = string, V = any> = {
|
|
20
|
-
[key in K]: V;
|
|
21
|
-
};
|
|
22
|
-
type Variant<K extends PropertyKey, T extends object> = {
|
|
23
|
-
[P in keyof T]: {
|
|
24
|
-
[Q in K]: P;
|
|
25
|
-
} & T[P] extends infer U ? {
|
|
26
|
-
[Q in keyof U]: U[Q];
|
|
27
|
-
} : never;
|
|
28
|
-
}[keyof T];
|
|
29
|
-
type EventHandler = <T>(this: App, event: string, data: T) => void | Promise<void>;
|
|
30
|
-
type Visibility = 'private' | 'platform' | 'vendor' | 'public';
|
|
31
|
-
interface Tenant {
|
|
32
|
-
id: string;
|
|
33
|
-
host: string;
|
|
34
|
-
}
|
|
35
|
-
interface AppId {
|
|
36
|
-
get name(): string;
|
|
37
|
-
get namespace(): Namespace;
|
|
38
|
-
toString(separator?: string): string;
|
|
39
|
-
}
|
|
40
|
-
declare const AppId: {
|
|
41
|
-
parse(input: string): AppId;
|
|
42
|
-
};
|
|
43
|
-
type Namespace = 'system' | 'platform' | {
|
|
44
|
-
vendor: string;
|
|
45
|
-
};
|
|
46
|
-
type AppRole = Variant<'type', AppRoleData>;
|
|
47
|
-
type AppRoleData = {
|
|
48
|
-
provider: {
|
|
49
|
-
group: string;
|
|
50
|
-
};
|
|
51
|
-
test: void;
|
|
52
|
-
};
|
|
53
|
-
interface Auth {
|
|
54
|
-
subject: Subject;
|
|
55
|
-
permissions: Permissions;
|
|
56
|
-
}
|
|
57
|
-
interface Subject {
|
|
58
|
-
id: string;
|
|
59
|
-
email: string;
|
|
60
|
-
roles: string[];
|
|
61
|
-
}
|
|
62
|
-
interface Permissions {
|
|
63
|
-
[key: string]: string[];
|
|
64
|
-
}
|
|
65
|
-
interface HookEventMap {
|
|
66
|
-
start: [];
|
|
67
|
-
install: [];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface FindQuery<T extends Record$1 = Record$1> extends PromiseLike<T[]> {
|
|
71
|
-
limit(limit: number): this;
|
|
72
|
-
offset(offset: number): this;
|
|
73
|
-
sort(sort: Sorting): this;
|
|
74
|
-
}
|
|
75
|
-
interface FindOneQuery<T extends Record$1 = Record$1> extends PromiseLike<T | undefined> {
|
|
76
|
-
offset(offset: number): this;
|
|
77
|
-
sort(sort: Sorting): this;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
type InsertReturnMode = 'insertedIds' | 'documents';
|
|
81
|
-
type InsertReturnType<T extends Record$1, R extends InsertReturnMode> = R extends 'insertedIds' ? string[] : R extends 'documents' ? T[] : never;
|
|
82
|
-
interface InsertQuery<T extends Record$1 = Record$1, R extends InsertReturnMode = 'insertedIds'> extends PromiseLike<InsertReturnType<T, R>> {
|
|
83
|
-
return(mode: 'insertedIds'): InsertQuery<T, 'insertedIds'>;
|
|
84
|
-
return(mode: 'documents'): InsertQuery<T, 'documents'>;
|
|
85
|
-
return(mode: InsertReturnMode): InsertQuery<T, typeof mode>;
|
|
86
|
-
}
|
|
87
|
-
type InsertOneReturnMode = 'insertedId' | 'document';
|
|
88
|
-
type InsertOneReturnType<T extends Record$1, R extends InsertOneReturnMode> = R extends 'insertedId' ? string : R extends 'document' ? T : never;
|
|
89
|
-
interface InsertOneQuery<T extends Record$1 = Record$1, R extends InsertOneReturnMode = 'insertedId'> extends PromiseLike<InsertOneReturnType<T, R>> {
|
|
90
|
-
return(mode: 'insertedId'): InsertOneQuery<T, 'insertedId'>;
|
|
91
|
-
return(mode: 'document'): InsertOneQuery<T, 'document'>;
|
|
92
|
-
return(mode: InsertOneReturnMode): InsertOneQuery<T, typeof mode>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
type UpdateReturnMode = 'affectedRows' | 'oldDocuments' | 'newDocuments';
|
|
96
|
-
type UpdateReturnType<T, R extends UpdateReturnMode> = R extends 'affectedRows' ? bigint : R extends 'oldDocuments' | 'newDocuments' ? T[] : never;
|
|
97
|
-
interface UpdateQuery<T extends Record$1 = Record$1, R extends UpdateReturnMode = 'affectedRows'> extends PromiseLike<UpdateReturnType<T, R>> {
|
|
98
|
-
limit(limit: number): this;
|
|
99
|
-
offset(offset: number): this;
|
|
100
|
-
sort(sort: Sorting): this;
|
|
101
|
-
return(mode: 'affectedRows'): UpdateQuery<T, 'affectedRows'>;
|
|
102
|
-
return(mode: 'oldDocuments'): UpdateQuery<T, 'oldDocuments'>;
|
|
103
|
-
return(mode: 'newDocuments'): UpdateQuery<T, 'newDocuments'>;
|
|
104
|
-
return(mode: UpdateReturnMode): UpdateQuery<T, typeof mode>;
|
|
105
|
-
}
|
|
106
|
-
type UpdateOneReturnMode = 'success' | 'oldDocument' | 'newDocument';
|
|
107
|
-
type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success' ? boolean : R extends 'oldDocument' | 'newDocument' ? T | undefined : never;
|
|
108
|
-
interface UpdateOneQuery<T extends Record$1 = Record$1, R extends UpdateOneReturnMode = 'success'> extends PromiseLike<UpdateOneReturnType<T, R>> {
|
|
109
|
-
offset(offset: number): this;
|
|
110
|
-
sort(sort: Sorting): this;
|
|
111
|
-
upsert(upsert: boolean): this;
|
|
112
|
-
return(mode: 'success'): UpdateOneQuery<T, 'success'>;
|
|
113
|
-
return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
|
|
114
|
-
return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
|
|
115
|
-
return(mode: UpdateOneReturnMode): UpdateOneQuery<T, typeof mode>;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
type RemoveReturnMode = 'affectedRows' | 'documents';
|
|
119
|
-
type RemoveReturnType<T, R extends RemoveReturnMode> = R extends 'affectedRows' ? bigint : R extends 'documents' ? T[] : never;
|
|
120
|
-
interface RemoveQuery<T extends Record$1 = Record$1, R extends RemoveReturnMode = 'affectedRows'> extends PromiseLike<RemoveReturnType<T, R>> {
|
|
121
|
-
limit(limit: number): this;
|
|
122
|
-
offset(offset: number): this;
|
|
123
|
-
sort(sort: Sorting): this;
|
|
124
|
-
return(mode: 'affectedRows'): RemoveQuery<T, 'affectedRows'>;
|
|
125
|
-
return(mode: 'documents'): RemoveQuery<T, 'documents'>;
|
|
126
|
-
return(mode: RemoveReturnMode): RemoveQuery<T, typeof mode>;
|
|
127
|
-
}
|
|
128
|
-
type RemoveOneReturnMode = 'success' | 'document';
|
|
129
|
-
type RemoveOneReturnType<T, R extends RemoveOneReturnMode> = R extends 'success' ? boolean : R extends 'document' ? T | undefined : never;
|
|
130
|
-
interface RemoveOneQuery<T extends Record$1 = Record$1, R extends RemoveOneReturnMode = 'success'> extends PromiseLike<RemoveOneReturnType<T, R>> {
|
|
131
|
-
offset(offset: number): this;
|
|
132
|
-
sort(sort: Sorting): this;
|
|
133
|
-
return(mode: 'success'): RemoveOneQuery<T, 'success'>;
|
|
134
|
-
return(mode: 'document'): RemoveOneQuery<T, 'document'>;
|
|
135
|
-
return(mode: RemoveOneReturnMode): RemoveOneQuery<T, typeof mode>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
interface Entity<T extends object = Record$1<string, unknown>> {
|
|
139
|
-
get name(): string;
|
|
140
|
-
find(query?: Record$1): FindQuery<T>;
|
|
141
|
-
findOne(query?: Record$1): FindOneQuery<T>;
|
|
142
|
-
insert(docs: T[]): InsertQuery<T>;
|
|
143
|
-
insertOne(doc: T): InsertOneQuery<T>;
|
|
144
|
-
update(query: Record$1, update: Record$1): UpdateQuery<T>;
|
|
145
|
-
updateOne(query: Record$1, update: Record$1): UpdateOneQuery<T>;
|
|
146
|
-
remove(query: Record$1): RemoveQuery<T>;
|
|
147
|
-
removeOne(query: Record$1): RemoveOneQuery<T>;
|
|
148
|
-
}
|
|
149
|
-
interface Sorting {
|
|
150
|
-
[field: string]: 'asc' | 'desc';
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
interface Artifacts {
|
|
154
|
-
get<T>(key: string): T | undefined;
|
|
155
|
-
set<T>(key: string, value: T): void;
|
|
156
|
-
delete(key: string): void;
|
|
157
|
-
get auth(): Auth | undefined;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
161
|
-
declare enum StatusCode {
|
|
162
|
-
Continue = 100,
|
|
163
|
-
SwitchingProtocols = 101,
|
|
164
|
-
Processing = 102,
|
|
165
|
-
EarlyHints = 103,
|
|
166
|
-
OK = 200,
|
|
167
|
-
Created = 201,
|
|
168
|
-
Accepted = 202,
|
|
169
|
-
NonAuthoritativeInformation = 203,
|
|
170
|
-
NoContent = 204,
|
|
171
|
-
ResetContent = 205,
|
|
172
|
-
PartialContent = 206,
|
|
173
|
-
MultiStatus = 207,
|
|
174
|
-
AlreadyReported = 208,
|
|
175
|
-
IMUsed = 226,
|
|
176
|
-
MultipleChoices = 300,
|
|
177
|
-
MovedPermanently = 301,
|
|
178
|
-
Found = 302,
|
|
179
|
-
SeeOther = 303,
|
|
180
|
-
NotModified = 304,
|
|
181
|
-
UseProxy = 305,
|
|
182
|
-
TemporaryRedirect = 307,
|
|
183
|
-
PermanentRedirect = 308,
|
|
184
|
-
BadRequest = 400,
|
|
185
|
-
Unauthorized = 401,
|
|
186
|
-
PaymentRequired = 402,
|
|
187
|
-
Forbidden = 403,
|
|
188
|
-
NotFound = 404,
|
|
189
|
-
MethodNotAllowed = 405,
|
|
190
|
-
NotAcceptable = 406,
|
|
191
|
-
ProxyAuthenticationRequired = 407,
|
|
192
|
-
RequestTimeout = 408,
|
|
193
|
-
Conflict = 409,
|
|
194
|
-
Gone = 410,
|
|
195
|
-
LengthRequired = 411,
|
|
196
|
-
PreconditionFailed = 412,
|
|
197
|
-
ContentTooLarge = 413,
|
|
198
|
-
URITooLong = 414,
|
|
199
|
-
UnsupportedMediaType = 415,
|
|
200
|
-
RangeNotSatisfiable = 416,
|
|
201
|
-
ExpectationFailed = 417,
|
|
202
|
-
ImATeapot = 418,
|
|
203
|
-
MisdirectedRequest = 421,
|
|
204
|
-
UnprocessableEntity = 422,
|
|
205
|
-
Locked = 423,
|
|
206
|
-
FailedDependency = 424,
|
|
207
|
-
TooEarly = 425,
|
|
208
|
-
UpgradeRequired = 426,
|
|
209
|
-
PreconditionRequired = 428,
|
|
210
|
-
TooManyRequests = 429,
|
|
211
|
-
RequestHeaderFieldsTooLarge = 431,
|
|
212
|
-
UnavailableForLegalReasons = 451,
|
|
213
|
-
InternalServerError = 500,
|
|
214
|
-
NotImplemented = 501,
|
|
215
|
-
BadGateway = 502,
|
|
216
|
-
ServiceUnavailable = 503,
|
|
217
|
-
GatewayTimeout = 504,
|
|
218
|
-
HTTPVersionNotSupported = 505,
|
|
219
|
-
VariantAlsoNegotiates = 506,
|
|
220
|
-
InsufficientStorage = 507,
|
|
221
|
-
LoopDetected = 508,
|
|
222
|
-
NotExtended = 510,
|
|
223
|
-
NetworkAuthenticationRequired = 511
|
|
224
|
-
}
|
|
225
|
-
type RequestHandler = (this: App, req: Request, res: ResponseBuilder) => void | Promise<void>;
|
|
226
|
-
type Middleware = (this: App, req: Request, res: ResponseBuilder, next: () => Promise<void>) => void | Promise<void>;
|
|
227
|
-
interface Router {
|
|
228
|
-
scope(path: string): Router;
|
|
229
|
-
route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
230
|
-
middleware(handler: Middleware, options?: MiddlewareOptions): Router;
|
|
231
|
-
get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
232
|
-
post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
233
|
-
put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
234
|
-
patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
235
|
-
delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
236
|
-
}
|
|
237
|
-
interface RouteOptions {
|
|
238
|
-
timeoutMs?: number;
|
|
239
|
-
permissions?: string[];
|
|
240
|
-
authenticated?: boolean;
|
|
241
|
-
visibility?: Visibility;
|
|
242
|
-
}
|
|
243
|
-
interface MiddlewareOptions {
|
|
244
|
-
path?: string;
|
|
245
|
-
priority?: number;
|
|
246
|
-
}
|
|
247
|
-
interface Request {
|
|
248
|
-
get artifacts(): Artifacts;
|
|
249
|
-
get method(): Method;
|
|
250
|
-
get url(): URL;
|
|
251
|
-
get params(): Record<string, string>;
|
|
252
|
-
get headers(): Headers;
|
|
253
|
-
cookie(name: string): string | undefined;
|
|
254
|
-
body(): Promise<Uint8Array>;
|
|
255
|
-
text(): Promise<string>;
|
|
256
|
-
json<T>(): Promise<T>;
|
|
257
|
-
}
|
|
258
|
-
interface RequestBuilder {
|
|
259
|
-
method(method: Method): RequestBuilder;
|
|
260
|
-
url(url: string | URL): RequestBuilder;
|
|
261
|
-
header(name: string, value: string): RequestBuilder;
|
|
262
|
-
headers(headers: HeadersInit): RequestBuilder;
|
|
263
|
-
cookie(name: string, value: string): RequestBuilder;
|
|
264
|
-
body(bytes: Uint8Array): RequestBuilder;
|
|
265
|
-
text(text: string): RequestBuilder;
|
|
266
|
-
json<T>(json: T): RequestBuilder;
|
|
267
|
-
}
|
|
268
|
-
interface Response {
|
|
269
|
-
get status(): number;
|
|
270
|
-
get headers(): Headers;
|
|
271
|
-
cookie(name: string): SetCookie | undefined;
|
|
272
|
-
body(): Promise<Uint8Array>;
|
|
273
|
-
text(): Promise<string>;
|
|
274
|
-
json<T>(): Promise<T>;
|
|
275
|
-
}
|
|
276
|
-
interface ResponseBuilder {
|
|
277
|
-
status(status: number): ResponseBuilder;
|
|
278
|
-
header(name: string, value: string): ResponseBuilder;
|
|
279
|
-
headers(headers: HeadersInit): ResponseBuilder;
|
|
280
|
-
cookie(name: string, value?: string, options?: SetCookieOptions): ResponseBuilder;
|
|
281
|
-
body(bytes: Uint8Array): ResponseBuilder;
|
|
282
|
-
text(text: string): ResponseBuilder;
|
|
283
|
-
json<T>(json: T): ResponseBuilder;
|
|
284
|
-
}
|
|
285
|
-
interface SetCookieOptions {
|
|
286
|
-
encode?: (s: string) => string;
|
|
287
|
-
maxAge?: number;
|
|
288
|
-
expires?: Date;
|
|
289
|
-
domain?: string;
|
|
290
|
-
path?: string;
|
|
291
|
-
httpOnly?: boolean;
|
|
292
|
-
secure?: boolean;
|
|
293
|
-
partitioned?: boolean;
|
|
294
|
-
priority?: "low" | "medium" | "high";
|
|
295
|
-
sameSite?: boolean | "lax" | "strict" | "none";
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
interface SetOptions {
|
|
299
|
-
ttl?: number;
|
|
300
|
-
existenceCheck?: 'nx' | 'xx';
|
|
301
|
-
}
|
|
302
|
-
interface KeyValueStore {
|
|
303
|
-
get<T>(key: string): Promise<T>;
|
|
304
|
-
getDel<T>(key: string): Promise<T>;
|
|
305
|
-
set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
|
|
306
|
-
delete(key: string): Promise<void>;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
interface RPC {
|
|
310
|
-
call(url: string, method: Method): Call;
|
|
311
|
-
get(url: string): Call;
|
|
312
|
-
post(url: string): Call;
|
|
313
|
-
put(url: string): Call;
|
|
314
|
-
patch(url: string): Call;
|
|
315
|
-
delete(url: string): Call;
|
|
316
|
-
}
|
|
317
|
-
interface Call extends RequestBuilder, PromiseLike<Response> {
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
interface Providers {
|
|
321
|
-
list(group: string): Provider[];
|
|
322
|
-
}
|
|
323
|
-
interface Provider {
|
|
324
|
-
get app(): AppId;
|
|
325
|
-
get group(): string;
|
|
326
|
-
get id(): string;
|
|
327
|
-
call(path: string, method: Method): Call;
|
|
328
|
-
get(path: string): Call;
|
|
329
|
-
post(path: string): Call;
|
|
330
|
-
put(path: string): Call;
|
|
331
|
-
patch(path: string): Call;
|
|
332
|
-
delete(path: string): Call;
|
|
333
|
-
}
|
|
334
|
-
declare const Provider: {
|
|
335
|
-
fromId(id: string): Provider;
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
interface SSE {
|
|
339
|
-
push<T>(event: T, targets: string[]): Promise<void>;
|
|
6
|
+
type EntryPoint = (app: App) => unknown;
|
|
7
|
+
interface App {
|
|
8
|
+
get router(): Router;
|
|
9
|
+
on<K extends keyof HookEventMap>(type: K, listener: (...args: HookEventMap[K]) => unknown): App;
|
|
10
|
+
role(role: AppRole): App;
|
|
11
|
+
capability(app: string, permissions: string[]): App;
|
|
12
|
+
capabilities(capabilities: {
|
|
13
|
+
[app: string]: string[];
|
|
14
|
+
}): App;
|
|
15
|
+
entity(name: string, schema: JSONSchema4): App;
|
|
16
|
+
subscribe(pattern: string, handler: EventHandler): App;
|
|
340
17
|
}
|
|
341
18
|
|
|
342
19
|
declare const _default: {
|
|
@@ -344,29 +21,6 @@ declare const _default: {
|
|
|
344
21
|
decode<T>(data: Uint8Array): T;
|
|
345
22
|
};
|
|
346
23
|
|
|
347
|
-
|
|
348
|
-
interface App {
|
|
349
|
-
get tenant(): Tenant;
|
|
350
|
-
get providers(): Providers;
|
|
351
|
-
settings<T>(): T | undefined;
|
|
352
|
-
crd<T>(key: string): T | undefined;
|
|
353
|
-
get rpc(): RPC;
|
|
354
|
-
get kv(): KeyValueStore;
|
|
355
|
-
get sse(): SSE;
|
|
356
|
-
get crypto(): Crypto;
|
|
357
|
-
entity<T extends object>(name: string): Entity<T>;
|
|
358
|
-
publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
|
|
359
|
-
}
|
|
360
|
-
interface AppBuilder {
|
|
361
|
-
get router(): Router;
|
|
362
|
-
on<K extends keyof HookEventMap>(type: K, listener: (this: App, ...args: HookEventMap[K]) => unknown): AppBuilder;
|
|
363
|
-
role(role: AppRole): AppBuilder;
|
|
364
|
-
capability(app: string, permissions: string[]): AppBuilder;
|
|
365
|
-
capabilities(capabilities: {
|
|
366
|
-
[app: string]: string[];
|
|
367
|
-
}): AppBuilder;
|
|
368
|
-
entity(name: string, schema: JSONSchema4): AppBuilder;
|
|
369
|
-
subscribe(pattern: string, handler: EventHandler): AppBuilder;
|
|
370
|
-
}
|
|
24
|
+
declare const Bridge: Bridge$1;
|
|
371
25
|
|
|
372
|
-
export { type App,
|
|
26
|
+
export { type App, AppRole, Bridge, type EntryPoint, EventHandler, Router, _default as cbor };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import*as i from'cbor2';var
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import*as i from'cbor2';var o={encode(r){return i.encode(r)},decode(r){return i.decode(r)}};var t=(e=>(e[e.Continue=100]="Continue",e[e.SwitchingProtocols=101]="SwitchingProtocols",e[e.Processing=102]="Processing",e[e.EarlyHints=103]="EarlyHints",e[e.OK=200]="OK",e[e.Created=201]="Created",e[e.Accepted=202]="Accepted",e[e.NonAuthoritativeInformation=203]="NonAuthoritativeInformation",e[e.NoContent=204]="NoContent",e[e.ResetContent=205]="ResetContent",e[e.PartialContent=206]="PartialContent",e[e.MultiStatus=207]="MultiStatus",e[e.AlreadyReported=208]="AlreadyReported",e[e.IMUsed=226]="IMUsed",e[e.MultipleChoices=300]="MultipleChoices",e[e.MovedPermanently=301]="MovedPermanently",e[e.Found=302]="Found",e[e.SeeOther=303]="SeeOther",e[e.NotModified=304]="NotModified",e[e.UseProxy=305]="UseProxy",e[e.TemporaryRedirect=307]="TemporaryRedirect",e[e.PermanentRedirect=308]="PermanentRedirect",e[e.BadRequest=400]="BadRequest",e[e.Unauthorized=401]="Unauthorized",e[e.PaymentRequired=402]="PaymentRequired",e[e.Forbidden=403]="Forbidden",e[e.NotFound=404]="NotFound",e[e.MethodNotAllowed=405]="MethodNotAllowed",e[e.NotAcceptable=406]="NotAcceptable",e[e.ProxyAuthenticationRequired=407]="ProxyAuthenticationRequired",e[e.RequestTimeout=408]="RequestTimeout",e[e.Conflict=409]="Conflict",e[e.Gone=410]="Gone",e[e.LengthRequired=411]="LengthRequired",e[e.PreconditionFailed=412]="PreconditionFailed",e[e.ContentTooLarge=413]="ContentTooLarge",e[e.URITooLong=414]="URITooLong",e[e.UnsupportedMediaType=415]="UnsupportedMediaType",e[e.RangeNotSatisfiable=416]="RangeNotSatisfiable",e[e.ExpectationFailed=417]="ExpectationFailed",e[e.ImATeapot=418]="ImATeapot",e[e.MisdirectedRequest=421]="MisdirectedRequest",e[e.UnprocessableEntity=422]="UnprocessableEntity",e[e.Locked=423]="Locked",e[e.FailedDependency=424]="FailedDependency",e[e.TooEarly=425]="TooEarly",e[e.UpgradeRequired=426]="UpgradeRequired",e[e.PreconditionRequired=428]="PreconditionRequired",e[e.TooManyRequests=429]="TooManyRequests",e[e.RequestHeaderFieldsTooLarge=431]="RequestHeaderFieldsTooLarge",e[e.UnavailableForLegalReasons=451]="UnavailableForLegalReasons",e[e.InternalServerError=500]="InternalServerError",e[e.NotImplemented=501]="NotImplemented",e[e.BadGateway=502]="BadGateway",e[e.ServiceUnavailable=503]="ServiceUnavailable",e[e.GatewayTimeout=504]="GatewayTimeout",e[e.HTTPVersionNotSupported=505]="HTTPVersionNotSupported",e[e.VariantAlsoNegotiates=506]="VariantAlsoNegotiates",e[e.InsufficientStorage=507]="InsufficientStorage",e[e.LoopDetected=508]="LoopDetected",e[e.NotExtended=510]="NotExtended",e[e.NetworkAuthenticationRequired=511]="NetworkAuthenticationRequired",e))(t||{});var n={get instance(){return globalThis.__M1CRO__.internals}};var p={fromId(r){return n.instance.providerFromId(r)}};var s={parse(r){return n.instance.parseAppId(r)}};var x=globalThis.__M1CRO__.bridge;export{s as AppId,x as Bridge,p as Provider,t as StatusCode,o as cbor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m1cro/server-sdk",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,9 +9,6 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
-
},
|
|
13
|
-
"./globals": {
|
|
14
|
-
"types": "./dist/globals.d.ts"
|
|
15
12
|
}
|
|
16
13
|
},
|
|
17
14
|
"publishConfig": {
|
package/dist/globals.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"globals.js","sourcesContent":[]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cbor.ts","../src/http.ts","../src/internals.ts","../src/provider.ts","../src/types.ts"],"names":["cbor_default","data","StatusCode","internals_default","Provider","id","AppId","input"],"mappings":"wBAEA,IAAOA,CAAAA,CAAQ,CACb,MAAA,CAAUC,CAAAA,CAAqB,CAC7B,OAAa,SAAOA,CAAI,CAC1B,CAAA,CACA,MAAA,CAAUA,EAAqB,CAC7B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC1B,CACF,ECFO,IAAKC,CAAAA,CAAAA,CAAAA,CAAAA,GAEVA,IAAA,QAAA,CAAW,GAAA,CAAA,CAAX,UAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,mBAAqB,GAAA,CAAA,CAArB,oBAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,UAAA,CAAa,KAAb,YAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,UAAA,CAAa,GAAA,CAAA,CAAb,aAGAA,CAAAA,CAAAA,CAAAA,CAAA,EAAA,CAAK,GAAA,CAAA,CAAL,IAAA,CACAA,IAAA,OAAA,CAAU,GAAA,CAAA,CAAV,SAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,SAAW,GAAA,CAAA,CAAX,UAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,2BAAA,CAA8B,KAA9B,6BAAA,CACAA,CAAAA,CAAAA,CAAAA,CAAA,SAAA,CAAY,GAAA,CAAA,CAAZ,YACAA,CAAAA,CAAAA,CAAAA,CAAA,YAAA,CAAe,GAAA,CAAA,CAAf,cAAA,CACAA,IAAA,cAAA,CAAiB,GAAA,CAAA,CAAjB,gBAAA,CACAA,CAAAA,CAA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default {\n encode<T>(data: T): Uint8Array {\n return cbor2.encode(data);\n },\n decode<T>(data: Uint8Array): T {\n return cbor2.decode(data);\n },\n};\n","import type { SetCookie } from 'cookie';\nimport type { App } from '.';\nimport type { Artifacts } from './artifact';\nimport type * as types from './types';\n\nexport type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';\n\nexport enum StatusCode {\n // 1xx\n Continue = 100,\n SwitchingProtocols = 101,\n Processing = 102,\n EarlyHints = 103,\n\n // 2xx\n OK = 200,\n Created = 201,\n Accepted = 202,\n NonAuthoritativeInformation = 203,\n NoContent = 204,\n ResetContent = 205,\n PartialContent = 206,\n MultiStatus = 207,\n AlreadyReported = 208,\n IMUsed = 226,\n\n // 3xx\n MultipleChoices = 300,\n MovedPermanently = 301,\n Found = 302,\n SeeOther = 303,\n NotModified = 304,\n UseProxy = 305,\n // SwitchProxy = 306, // Deprecated\n TemporaryRedirect = 307,\n PermanentRedirect = 308,\n\n // 4xx\n BadRequest = 400,\n Unauthorized = 401,\n PaymentRequired = 402,\n Forbidden = 403,\n NotFound = 404,\n MethodNotAllowed = 405,\n NotAcceptable = 406,\n ProxyAuthenticationRequired = 407,\n RequestTimeout = 408,\n Conflict = 409,\n Gone = 410,\n LengthRequired = 411,\n PreconditionFailed = 412,\n ContentTooLarge = 413,\n URITooLong = 414,\n UnsupportedMediaType = 415,\n RangeNotSatisfiable = 416,\n ExpectationFailed = 417,\n ImATeapot = 418,\n MisdirectedRequest = 421,\n UnprocessableEntity = 422,\n Locked = 423,\n FailedDependency = 424,\n TooEarly = 425,\n UpgradeRequired = 426,\n PreconditionRequired = 428,\n TooManyRequests = 429,\n RequestHeaderFieldsTooLarge = 431,\n UnavailableForLegalReasons = 451,\n\n // 5xx\n InternalServerError = 500,\n NotImplemented = 501,\n BadGateway = 502,\n ServiceUnavailable = 503,\n GatewayTimeout = 504,\n HTTPVersionNotSupported = 505,\n VariantAlsoNegotiates = 506,\n InsufficientStorage = 507,\n LoopDetected = 508,\n NotExtended = 510,\n NetworkAuthenticationRequired = 511,\n}\n\nexport type RequestHandler = (\n this: App,\n req: Request,\n res: ResponseBuilder\n) => void | Promise<void>;\n\nexport type Middleware = (\n this: App,\n req: Request,\n res: ResponseBuilder,\n next: () => Promise<void>\n) => void | Promise<void>;\n\nexport interface Router {\n scope(path: string): Router;\n\n route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n middleware(handler: Middleware, options?: MiddlewareOptions): Router;\n\n get(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n post(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n put(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n\n delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;\n}\n\nexport interface RouteOptions {\n timeoutMs?: number;\n permissions?: string[];\n authenticated?: boolean;\n visibility?: types.Visibility;\n}\n\nexport interface MiddlewareOptions {\n path?: string;\n priority?: number;\n}\n\nexport interface Request {\n get artifacts(): Artifacts;\n get method(): Method;\n get url(): URL;\n get params(): Record<string, string>;\n get headers(): Headers;\n cookie(name: string): string | undefined;\n body(): Promise<Uint8Array>;\n text(): Promise<string>;\n json<T>(): Promise<T>;\n}\n\nexport interface RequestBuilder {\n method(method: Method): RequestBuilder;\n url(url: string | URL): RequestBuilder;\n header(name: string, value: string): RequestBuilder;\n headers(headers: HeadersInit): RequestBuilder;\n cookie(name: string, value: string): RequestBuilder;\n body(bytes: Uint8Array): RequestBuilder;\n text(text: string): RequestBuilder;\n json<T>(json: T): RequestBuilder;\n}\n\nexport interface Response {\n get status(): number;\n get headers(): Headers;\n cookie(name: string): SetCookie | undefined;\n body(): Promise<Uint8Array>;\n text(): Promise<string>;\n json<T>(): Promise<T>;\n}\n\nexport interface ResponseBuilder {\n status(status: number): ResponseBuilder;\n header(name: string, value: string): ResponseBuilder;\n headers(headers: HeadersInit): ResponseBuilder;\n cookie(name: string, value?: string, options?: SetCookieOptions): ResponseBuilder;\n body(bytes: Uint8Array): ResponseBuilder;\n text(text: string): ResponseBuilder;\n json<T>(json: T): ResponseBuilder;\n}\n\nexport interface SetCookieOptions {\n encode?: (s: string) => string;\n maxAge?: number;\n expires?: Date;\n domain?: string;\n path?: string;\n httpOnly?: boolean;\n secure?: boolean;\n partitioned?: boolean;\n priority?: \"low\" | \"medium\" | \"high\";\n sameSite?: boolean | \"lax\" | \"strict\" | \"none\";\n}\n\nexport type { SetCookie } from 'cookie';\n","import { Provider } from \"./provider\";\nimport type { AppId } from \"./types\";\n\nexport interface Internals {\n parseAppId(input: string): AppId;\n providerFromId(id: string): Provider;\n}\n\nexport default {\n get instance() {\n return (globalThis as any)[\"__M1CRO__\"][\"internals\"] as Internals;\n }\n}\n\n","import type { Method } from './http';\nimport internals from './internals';\nimport type { Call } from './rpc';\nimport type { AppId } from './types';\n\nexport interface Providers {\n list(group: string): Provider[];\n}\n\nexport interface Provider {\n get app(): AppId;\n get group(): string;\n get id(): string;\n call(path: string, method: Method): Call;\n get(path: string): Call;\n post(path: string): Call;\n put(path: string): Call;\n patch(path: string): Call;\n delete(path: string): Call;\n}\n\nexport const Provider = {\n fromId(id: string): Provider {\n return internals.instance.providerFromId(id);\n },\n};","import internals from './internals';\nimport type { App } from '.';\n\nexport type Record<K extends string | number | symbol = string, V = any> = {\n [key in K]: V;\n};\n\nexport type Variant<K extends PropertyKey, T extends object> = {\n [P in keyof T]: { [Q in K]: P } & T[P] extends infer U ? { [Q in keyof U]: U[Q] } : never;\n}[keyof T];\n\nexport type EventHandler = <T>(this: App, event: string, data: T) => void | Promise<void>;\n\nexport type Visibility = 'private' | 'platform' | 'vendor' | 'public';\n\nexport interface Tenant {\n id: string;\n host: string;\n}\n\nexport interface AppId {\n get name(): string;\n get namespace(): Namespace;\n toString(separator?: string): string;\n}\n\nexport const AppId = {\n parse(input: string): AppId {\n return internals.instance.parseAppId(input);\n },\n};\n\nexport type Namespace = 'system' | 'platform' | { vendor: string };\n\nexport type AppRole = Variant<'type', AppRoleData>;\n\nexport type AppRoleData = {\n provider: { group: string };\n test: void;\n};\n\nexport interface Auth {\n subject: Subject;\n permissions: Permissions;\n}\n\nexport interface Subject {\n id: string;\n email: string;\n roles: string[];\n}\n\nexport interface Permissions {\n [key: string]: string[];\n}\n\nexport interface HookEventMap {\n start: [];\n install: [];\n}\n"]}
|