@m1cro/server-sdk 0.1.1-beta.2 → 0.1.1-beta.21
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/globals.d.ts +3 -6
- package/dist/globals.js +0 -2
- package/dist/index.d.ts +164 -241
- package/dist/index.js +1 -2
- package/dist/log-BiuB_mLm.d.ts +405 -0
- package/package.json +2 -18
- package/dist/globals.js.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/globals.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { B as Bridge, L as LogLevel } from './log-BiuB_mLm.js';
|
|
1
2
|
import * as console from 'node:console';
|
|
2
|
-
|
|
3
|
-
declare const logLevels: readonly ["trace", "debug", "info", "warn", "error", "none"];
|
|
4
|
-
type LogLevel = (typeof logLevels)[number];
|
|
3
|
+
import 'cookie';
|
|
5
4
|
|
|
6
5
|
declare global {
|
|
6
|
+
var Bridge: Bridge;
|
|
7
7
|
interface Console extends console.Console {
|
|
8
8
|
logLevel: LogLevel;
|
|
9
9
|
}
|
|
10
|
-
interface Request {
|
|
11
|
-
artifacts?: any;
|
|
12
|
-
}
|
|
13
10
|
}
|
package/dist/globals.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,264 +1,187 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { E as EntitySchema, G as GeneratedFields, C as CompiledSchema, F as Filter, a as FindQuery, H as HydratedDocument, b as FindOneQuery, I as InsertDocument, c as InsertQuery, d as InsertOneQuery, U as UpdateQuery, e as InferInterface, f as UpdateOneQuery, R as RemoveQuery, g as RemoveOneQuery, h as Router, i as HookEventMap, A as AppRole, j as EventHandler } from './log-BiuB_mLm.js';
|
|
2
|
+
export { k as AppId, l as Artifacts, m as Auth, B as Bridge, n as Entity, o as InferSchema, L as LogLevel, M as Method, p as Middleware, N as Namespace, P as Provider, q as Providers, r as Request, s as RequestBuilder, t as RequestHandler, u as Response, v as ResponseBuilder, w as RouteOptions, S as Sorting, x as StatusCode, y as Subject, T as Tenant, V as Visibility, z as entitySchema } from './log-BiuB_mLm.js';
|
|
3
|
+
import 'cookie';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
declare function entityModel<S extends EntitySchema<any>>(name: string, schemaDef: S, options?: EntityModelOptions<S>): EntityModel<S>;
|
|
6
|
+
interface EntityModelRegistration {
|
|
7
|
+
get name(): string;
|
|
8
|
+
get schema(): {
|
|
9
|
+
get shape(): unknown;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
declare class EntityModel<S extends EntitySchema<any>> implements EntityModelRegistration {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly schemaDef: S;
|
|
15
|
+
readonly options?: EntityModelOptions<S> | undefined;
|
|
16
|
+
schema: CompiledSchema;
|
|
17
|
+
constructor(name: string, schemaDef: S, options?: EntityModelOptions<S> | undefined);
|
|
18
|
+
private entity;
|
|
19
|
+
find(filter?: Filter): FindQuery<HydratedDocument<S>>;
|
|
20
|
+
findOne(filter?: Filter): FindOneQuery<HydratedDocument<S>>;
|
|
21
|
+
insert(docs: InsertDocument<S>[]): InsertQuery<InsertDocument<S>, 'insertedIds'>;
|
|
22
|
+
insertOne(doc: InsertDocument<S>): InsertOneQuery<InsertDocument<S>, 'insertedId'>;
|
|
23
|
+
update(filter: Filter, update: Record<string, unknown>): UpdateQuery<InferInterface<S>, 'affectedRows'>;
|
|
24
|
+
updateOne(filter: Filter, update: Record<string, unknown>): UpdateOneQuery<InferInterface<S>, 'success'>;
|
|
25
|
+
remove(filter: Filter): RemoveQuery<InferInterface<S>, 'affectedRows'>;
|
|
26
|
+
removeOne(filter: Filter): RemoveOneQuery<InferInterface<S>, 'success'>;
|
|
27
|
+
}
|
|
28
|
+
interface EntityModelOptions<S extends EntitySchema<any>> {
|
|
29
|
+
indexes?: EntityIndexManifest<S>[];
|
|
30
|
+
}
|
|
31
|
+
interface EntityIndexManifest<S extends EntitySchema<any>> {
|
|
32
|
+
fields: Array<keyof GeneratedFields | keyof S['definition']>;
|
|
33
|
+
unique?: boolean | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type EntryPoint = (app: App) => unknown;
|
|
37
|
+
interface App {
|
|
38
|
+
get router(): Router;
|
|
39
|
+
on<K extends keyof HookEventMap>(type: K, listener: (...args: HookEventMap[K]) => unknown): App;
|
|
40
|
+
role(role: AppRole): App;
|
|
41
|
+
capability(app: string, permissions: string[]): App;
|
|
42
|
+
capabilities(capabilities: {
|
|
43
|
+
[app: string]: string[];
|
|
44
|
+
}): App;
|
|
45
|
+
entity(model: EntityModelRegistration): App;
|
|
46
|
+
subscribe(pattern: string, handler: EventHandler): App;
|
|
16
47
|
}
|
|
17
48
|
|
|
18
|
-
|
|
19
|
-
|
|
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>(this: App, 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
|
-
namespace: string;
|
|
36
|
-
app: string;
|
|
37
|
-
}
|
|
38
|
-
type AppRole = Variant<"type", AppRoleData>;
|
|
39
|
-
type AppRoleData = {
|
|
40
|
-
provider: {
|
|
41
|
-
group: string;
|
|
42
|
-
};
|
|
43
|
-
test: void;
|
|
49
|
+
declare const _default: {
|
|
50
|
+
encode<T>(data: T): Uint8Array;
|
|
51
|
+
decode<T>(data: Uint8Array): T;
|
|
44
52
|
};
|
|
45
|
-
interface HookEventMap {
|
|
46
|
-
"start": [];
|
|
47
|
-
"install": [];
|
|
48
|
-
}
|
|
49
53
|
|
|
50
|
-
interface
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
exec(): Promise<T[]>;
|
|
54
|
+
interface ErrorPayload {
|
|
55
|
+
status: number;
|
|
56
|
+
code: string;
|
|
57
|
+
msg?: string | undefined;
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
declare class BaseError extends Error {
|
|
60
|
+
protected payload: ErrorPayload;
|
|
61
|
+
constructor(payload: ErrorPayload);
|
|
62
|
+
status(status: number): this;
|
|
63
|
+
code(code: string): this;
|
|
64
|
+
msg(msg: string): this;
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
type InsertReturnType<T extends Record$1, R extends InsertReturnMode> = R extends 'insertedIds' ? string[] : R extends 'documents' ? T[] : never;
|
|
64
|
-
interface InsertQuery<T extends Record$1 = Record$1, R extends InsertReturnMode = 'insertedIds'> {
|
|
65
|
-
return(mode: 'insertedIds'): InsertQuery<T, 'insertedIds'>;
|
|
66
|
-
return(mode: 'documents'): InsertQuery<T, 'documents'>;
|
|
67
|
-
return(mode: InsertReturnMode): InsertQuery<T, typeof mode>;
|
|
68
|
-
exec(): Promise<InsertReturnType<T, R>>;
|
|
69
|
-
}
|
|
70
|
-
type InsertOneReturnMode = 'insertedId' | 'document';
|
|
71
|
-
type InsertOneReturnType<T extends Record$1, R extends InsertOneReturnMode> = R extends 'insertedId' ? string : R extends 'document' ? T : never;
|
|
72
|
-
interface InsertOneQuery<T extends Record$1 = Record$1, R extends InsertOneReturnMode = 'insertedId'> {
|
|
73
|
-
return(mode: 'insertedId'): InsertOneQuery<T, 'insertedId'>;
|
|
74
|
-
return(mode: 'document'): InsertOneQuery<T, 'document'>;
|
|
75
|
-
return(mode: InsertOneReturnMode): InsertOneQuery<T, typeof mode>;
|
|
76
|
-
exec(): Promise<InsertOneReturnType<T, R>>;
|
|
66
|
+
declare class BadRequestError extends BaseError {
|
|
67
|
+
constructor(msg?: string);
|
|
77
68
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
type UpdateReturnType<T, R extends UpdateReturnMode> = R extends 'affectedRows' ? bigint : R extends 'oldDocuments' | 'newDocuments' ? T[] : never;
|
|
81
|
-
interface UpdateQuery<T extends Record$1 = Record$1, R extends UpdateReturnMode = 'affectedRows'> {
|
|
82
|
-
limit(limit: number): this;
|
|
83
|
-
offset(offset: number): this;
|
|
84
|
-
sort(sort: Sorting): this;
|
|
85
|
-
return(mode: 'affectedRows'): UpdateQuery<T, 'affectedRows'>;
|
|
86
|
-
return(mode: 'oldDocuments'): UpdateQuery<T, 'oldDocuments'>;
|
|
87
|
-
return(mode: 'newDocuments'): UpdateQuery<T, 'newDocuments'>;
|
|
88
|
-
return(mode: UpdateReturnMode): UpdateQuery<T, typeof mode>;
|
|
89
|
-
exec(): Promise<UpdateReturnType<T, R>>;
|
|
90
|
-
}
|
|
91
|
-
type UpdateOneReturnMode = 'success' | 'oldDocument' | 'newDocument';
|
|
92
|
-
type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success' ? boolean : R extends 'oldDocument' | 'newDocument' ? (T | undefined) : never;
|
|
93
|
-
interface UpdateOneQuery<T extends Record$1 = Record$1, R extends UpdateOneReturnMode = 'success'> {
|
|
94
|
-
offset(offset: number): this;
|
|
95
|
-
sort(sort: Sorting): this;
|
|
96
|
-
return(mode: 'success'): UpdateOneQuery<T, 'success'>;
|
|
97
|
-
return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
|
|
98
|
-
return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
|
|
99
|
-
return(mode: UpdateOneReturnMode): UpdateOneQuery<T, typeof mode>;
|
|
100
|
-
exec(): Promise<UpdateOneReturnType<T, R>>;
|
|
69
|
+
declare class UnauthorizedError extends BaseError {
|
|
70
|
+
constructor(msg?: string);
|
|
101
71
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
type RemoveReturnType<T, R extends RemoveReturnMode> = R extends 'affectedRows' ? bigint : R extends 'documents' ? T[] : never;
|
|
105
|
-
interface RemoveQuery<T extends Record$1 = Record$1, R extends RemoveReturnMode = 'affectedRows'> {
|
|
106
|
-
limit(limit: number): this;
|
|
107
|
-
offset(offset: number): this;
|
|
108
|
-
sort(sort: Sorting): this;
|
|
109
|
-
return(mode: 'affectedRows'): RemoveQuery<T, 'affectedRows'>;
|
|
110
|
-
return(mode: 'documents'): RemoveQuery<T, 'documents'>;
|
|
111
|
-
return(mode: RemoveReturnMode): RemoveQuery<T, typeof mode>;
|
|
112
|
-
exec(): Promise<RemoveReturnType<T, R>>;
|
|
113
|
-
}
|
|
114
|
-
type RemoveOneReturnMode = 'success' | 'document';
|
|
115
|
-
type RemoveOneReturnType<T, R extends RemoveOneReturnMode> = R extends 'success' ? boolean : R extends 'document' ? (T | undefined) : never;
|
|
116
|
-
interface RemoveOneQuery<T extends Record$1 = Record$1, R extends RemoveOneReturnMode = 'success'> {
|
|
117
|
-
offset(offset: number): this;
|
|
118
|
-
sort(sort: Sorting): this;
|
|
119
|
-
return(mode: 'success'): RemoveOneQuery<T, 'success'>;
|
|
120
|
-
return(mode: 'document'): RemoveOneQuery<T, 'document'>;
|
|
121
|
-
return(mode: RemoveOneReturnMode): RemoveOneQuery<T, typeof mode>;
|
|
122
|
-
exec(): Promise<RemoveOneReturnType<T, R>>;
|
|
72
|
+
declare class PaymentRequiredError extends BaseError {
|
|
73
|
+
constructor(msg?: string);
|
|
123
74
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
get name(): string;
|
|
127
|
-
find(query?: Record$1): FindQuery<T>;
|
|
128
|
-
findOne(query?: Record$1): FindOneQuery<T>;
|
|
129
|
-
insert(docs: T[]): InsertQuery<T>;
|
|
130
|
-
insertOne(doc: T): InsertOneQuery<T>;
|
|
131
|
-
update(query: Record$1, update: Record$1): UpdateQuery<T>;
|
|
132
|
-
updateOne(query: Record$1, update: Record$1): UpdateOneQuery<T>;
|
|
133
|
-
remove(query: Record$1): RemoveQuery<T>;
|
|
134
|
-
removeOne(query: Record$1): RemoveOneQuery<T>;
|
|
135
|
-
}
|
|
136
|
-
interface Sorting {
|
|
137
|
-
[field: string]: 'asc' | 'desc';
|
|
75
|
+
declare class ForbiddenError extends BaseError {
|
|
76
|
+
constructor(msg?: string);
|
|
138
77
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
ttl?: number;
|
|
142
|
-
existenceCheck?: "nx" | "xx";
|
|
78
|
+
declare class NotFoundError extends BaseError {
|
|
79
|
+
constructor(msg?: string);
|
|
143
80
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
getDel<T>(key: string): Promise<T>;
|
|
147
|
-
set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
|
|
148
|
-
delete(key: string): Promise<void>;
|
|
81
|
+
declare class MethodNotAllowedError extends BaseError {
|
|
82
|
+
constructor(msg?: string);
|
|
149
83
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
list(group: string): Provider[];
|
|
84
|
+
declare class NotAcceptableError extends BaseError {
|
|
85
|
+
constructor(msg?: string);
|
|
153
86
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
app: AppId;
|
|
87
|
+
declare class ProxyAuthenticationRequiredError extends BaseError {
|
|
88
|
+
constructor(msg?: string);
|
|
157
89
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
get<T>(key: string): T | undefined;
|
|
161
|
-
set<T>(key: string, value: T): void;
|
|
162
|
-
delete(key: string): void;
|
|
90
|
+
declare class RequestTimeoutError extends BaseError {
|
|
91
|
+
constructor(msg?: string);
|
|
163
92
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
type RequestHandler = (this: App, req: Request, res: ResponseBuilder) => void | Promise<void>;
|
|
167
|
-
interface Router {
|
|
168
|
-
scope(path: string): Router;
|
|
169
|
-
route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
170
|
-
get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
171
|
-
post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
172
|
-
put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
173
|
-
patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
174
|
-
delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
175
|
-
}
|
|
176
|
-
interface RouteOptions {
|
|
177
|
-
timeoutMs?: number;
|
|
178
|
-
permissions?: string[];
|
|
179
|
-
authenticated?: boolean;
|
|
180
|
-
visibility?: Visibility;
|
|
181
|
-
}
|
|
182
|
-
interface Request {
|
|
183
|
-
get artifacts(): Artifacts;
|
|
184
|
-
get method(): Method;
|
|
185
|
-
get url(): URL;
|
|
186
|
-
get params(): Record<string, string>;
|
|
187
|
-
get headers(): Headers;
|
|
188
|
-
body(): Promise<Uint8Array>;
|
|
189
|
-
text(): Promise<string>;
|
|
190
|
-
json<T>(): Promise<T>;
|
|
191
|
-
}
|
|
192
|
-
interface RequestBuilder {
|
|
193
|
-
method(method: Method): RequestBuilder;
|
|
194
|
-
url(url: string | URL): RequestBuilder;
|
|
195
|
-
header(name: string, value: string): RequestBuilder;
|
|
196
|
-
headers(headers: HeadersInit): RequestBuilder;
|
|
197
|
-
body(bytes: Uint8Array): RequestBuilder;
|
|
198
|
-
text(text: string): RequestBuilder;
|
|
199
|
-
json<T>(json: T): RequestBuilder;
|
|
200
|
-
}
|
|
201
|
-
interface Response {
|
|
202
|
-
get status(): number;
|
|
203
|
-
get headers(): Headers;
|
|
204
|
-
body(): Promise<Uint8Array>;
|
|
205
|
-
text(): Promise<string>;
|
|
206
|
-
json<T>(): Promise<T>;
|
|
207
|
-
}
|
|
208
|
-
interface ResponseBuilder {
|
|
209
|
-
status(status: number): ResponseBuilder;
|
|
210
|
-
header(name: string, value: string): ResponseBuilder;
|
|
211
|
-
headers(headers: HeadersInit): ResponseBuilder;
|
|
212
|
-
body(bytes: Uint8Array): ResponseBuilder;
|
|
213
|
-
text(text: string): ResponseBuilder;
|
|
214
|
-
json<T>(json: T): ResponseBuilder;
|
|
93
|
+
declare class ConflictError extends BaseError {
|
|
94
|
+
constructor(msg?: string);
|
|
215
95
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
call(url: string, method: Method): Call;
|
|
219
|
-
get(url: string): Call;
|
|
220
|
-
post(url: string): Call;
|
|
221
|
-
put(url: string): Call;
|
|
222
|
-
patch(url: string): Call;
|
|
223
|
-
delete(url: string): Call;
|
|
96
|
+
declare class GoneError extends BaseError {
|
|
97
|
+
constructor(msg?: string);
|
|
224
98
|
}
|
|
225
|
-
|
|
226
|
-
|
|
99
|
+
declare class LengthRequiredError extends BaseError {
|
|
100
|
+
constructor(msg?: string);
|
|
227
101
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
push<T>(event: T, targets: string[]): Promise<void>;
|
|
102
|
+
declare class PreconditionFailedError extends BaseError {
|
|
103
|
+
constructor(msg?: string);
|
|
231
104
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
get tenant(): Tenant;
|
|
235
|
-
get providers(): Providers;
|
|
236
|
-
settings<T>(): T | undefined;
|
|
237
|
-
crd<T>(key: string): T | undefined;
|
|
238
|
-
get rpc(): RPC;
|
|
239
|
-
get kv(): KeyValueStore;
|
|
240
|
-
get sse(): SSE;
|
|
241
|
-
get crypto(): Crypto;
|
|
242
|
-
entity<T extends object>(name: string): Entity<T>;
|
|
243
|
-
publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
|
|
105
|
+
declare class ContentTooLargeError extends BaseError {
|
|
106
|
+
constructor(msg?: string);
|
|
244
107
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
108
|
+
declare class URITooLongError extends BaseError {
|
|
109
|
+
constructor(msg?: string);
|
|
110
|
+
}
|
|
111
|
+
declare class UnsupportedMediaTypeError extends BaseError {
|
|
112
|
+
constructor(msg?: string);
|
|
113
|
+
}
|
|
114
|
+
declare class RangeNotSatisfiableError extends BaseError {
|
|
115
|
+
constructor(msg?: string);
|
|
116
|
+
}
|
|
117
|
+
declare class ExpectationFailedError extends BaseError {
|
|
118
|
+
constructor(msg?: string);
|
|
119
|
+
}
|
|
120
|
+
declare class ImATeapotError extends BaseError {
|
|
121
|
+
constructor(msg?: string);
|
|
122
|
+
}
|
|
123
|
+
declare class MisdirectedRequestError extends BaseError {
|
|
124
|
+
constructor(msg?: string);
|
|
125
|
+
}
|
|
126
|
+
declare class UnprocessableEntityError extends BaseError {
|
|
127
|
+
constructor(msg?: string);
|
|
128
|
+
}
|
|
129
|
+
declare class LockedError extends BaseError {
|
|
130
|
+
constructor(msg?: string);
|
|
131
|
+
}
|
|
132
|
+
declare class FailedDependencyError extends BaseError {
|
|
133
|
+
constructor(msg?: string);
|
|
134
|
+
}
|
|
135
|
+
declare class TooEarlyError extends BaseError {
|
|
136
|
+
constructor(msg?: string);
|
|
137
|
+
}
|
|
138
|
+
declare class UpgradeRequiredError extends BaseError {
|
|
139
|
+
constructor(msg?: string);
|
|
140
|
+
}
|
|
141
|
+
declare class PreconditionRequiredError extends BaseError {
|
|
142
|
+
constructor(msg?: string);
|
|
143
|
+
}
|
|
144
|
+
declare class TooManyRequestsError extends BaseError {
|
|
145
|
+
constructor(msg?: string);
|
|
146
|
+
}
|
|
147
|
+
declare class RequestHeaderFieldsTooLargeError extends BaseError {
|
|
148
|
+
constructor(msg?: string);
|
|
149
|
+
}
|
|
150
|
+
declare class UnavailableForLegalReasonsError extends BaseError {
|
|
151
|
+
constructor(msg?: string);
|
|
152
|
+
}
|
|
153
|
+
declare class InternalServerError extends BaseError {
|
|
154
|
+
constructor(msg?: string);
|
|
155
|
+
}
|
|
156
|
+
declare class NotImplementedError extends BaseError {
|
|
157
|
+
constructor(msg?: string);
|
|
158
|
+
}
|
|
159
|
+
declare class BadGatewayError extends BaseError {
|
|
160
|
+
constructor(msg?: string);
|
|
161
|
+
}
|
|
162
|
+
declare class ServiceUnavailableError extends BaseError {
|
|
163
|
+
constructor(msg?: string);
|
|
164
|
+
}
|
|
165
|
+
declare class GatewayTimeoutError extends BaseError {
|
|
166
|
+
constructor(msg?: string);
|
|
167
|
+
}
|
|
168
|
+
declare class HTTPVersionNotSupportedError extends BaseError {
|
|
169
|
+
constructor(msg?: string);
|
|
170
|
+
}
|
|
171
|
+
declare class VariantAlsoNegotiatesError extends BaseError {
|
|
172
|
+
constructor(msg?: string);
|
|
173
|
+
}
|
|
174
|
+
declare class InsufficientStorageError extends BaseError {
|
|
175
|
+
constructor(msg?: string);
|
|
176
|
+
}
|
|
177
|
+
declare class LoopDetectedError extends BaseError {
|
|
178
|
+
constructor(msg?: string);
|
|
179
|
+
}
|
|
180
|
+
declare class NotExtendedError extends BaseError {
|
|
181
|
+
constructor(msg?: string);
|
|
182
|
+
}
|
|
183
|
+
declare class NetworkAuthenticationRequiredError extends BaseError {
|
|
184
|
+
constructor(msg?: string);
|
|
262
185
|
}
|
|
263
186
|
|
|
264
|
-
export { type App, type
|
|
187
|
+
export { type App, AppRole, BadGatewayError, BadRequestError, BaseError, ConflictError, ContentTooLargeError, type EntityIndexManifest, EntityModel, type EntityModelOptions, EntitySchema, type EntryPoint, EventHandler, ExpectationFailedError, FailedDependencyError, Filter, ForbiddenError, GatewayTimeoutError, GoneError, HTTPVersionNotSupportedError, HydratedDocument, ImATeapotError, InferInterface, InsertDocument, InsufficientStorageError, InternalServerError, LengthRequiredError, LockedError, LoopDetectedError, MethodNotAllowedError, MisdirectedRequestError, NetworkAuthenticationRequiredError, NotAcceptableError, NotExtendedError, NotFoundError, NotImplementedError, PaymentRequiredError, PreconditionFailedError, PreconditionRequiredError, ProxyAuthenticationRequiredError, RangeNotSatisfiableError, RequestHeaderFieldsTooLargeError, RequestTimeoutError, Router, ServiceUnavailableError, TooEarlyError, TooManyRequestsError, URITooLongError, UnauthorizedError, UnavailableForLegalReasonsError, UnprocessableEntityError, UnsupportedMediaTypeError, UpgradeRequiredError, VariantAlsoNegotiatesError, _default as cbor, entityModel };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import*as o from'cbor2';var $={encode(r){return o.encode(r)},decode(r){return o.decode(r)}};function S(r){return new i(r)}var i=class{constructor(t){this.definition=t;}},p=class{constructor(t){}get shape(){return {}}};function C(r,t,s){return new a(r,t,s)}var a=class{constructor(t,s,re){this.name=t;this.schemaDef=s;this.options=re;this.schema=new p(s);}schema;entity(){return globalThis.Bridge.entity(this.name)}find(t){return this.entity().find(t)}findOne(t){return this.entity().findOne(t)}insert(t){return this.entity().insert(t)}insertOne(t){return this.entity().insertOne(t)}update(t,s){return this.entity().update(t,s)}updateOne(t,s){return this.entity().updateOne(t,s)}remove(t){return this.entity().remove(t)}removeOne(t){return this.entity().removeOne(t)}};var d=(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))(d||{});var n=class extends Error{constructor(s){super(s.msg);this.payload=s;}status(s){return this.payload.status=s,this}code(s){return this.payload.code=s,this}msg(s){return this.payload.msg=s,this}},l=class extends n{constructor(t){super({status:400,code:"bad_request",msg:t});}},u=class extends n{constructor(t){super({status:401,code:"unauthorized",msg:t});}},m=class extends n{constructor(t){super({status:402,code:"payment_required",msg:t});}},y=class extends n{constructor(t){super({status:403,code:"forbidden",msg:t});}},g=class extends n{constructor(t){super({status:404,code:"not_found",msg:t});}},x=class extends n{constructor(t){super({status:405,code:"method_not_allowed",msg:t});}},f=class extends n{constructor(t){super({status:406,code:"not_acceptable",msg:t});}},h=class extends n{constructor(t){super({status:407,code:"proxy_authentication_required",msg:t});}},R=class extends n{constructor(t){super({status:408,code:"request_timeout",msg:t});}},I=class extends n{constructor(t){super({status:409,code:"conflict",msg:t});}},b=class extends n{constructor(t){super({status:410,code:"gone",msg:t});}},v=class extends n{constructor(t){super({status:411,code:"length_required",msg:t});}},_=class extends n{constructor(t){super({status:412,code:"precondition_failed",msg:t});}},q=class extends n{constructor(t){super({status:413,code:"content_too_large",msg:t});}},T=class extends n{constructor(t){super({status:414,code:"uri_too_long",msg:t});}},A=class extends n{constructor(t){super({status:415,code:"unsupported_media_type",msg:t});}},P=class extends n{constructor(t){super({status:416,code:"range_not_satisfiable",msg:t});}},M=class extends n{constructor(t){super({status:417,code:"expectation_failed",msg:t});}},E=class extends n{constructor(t){super({status:418,code:"im_a_teapot",msg:t});}},O=class extends n{constructor(t){super({status:421,code:"misdirected_request",msg:t});}},F=class extends n{constructor(t){super({status:422,code:"unprocessable_entity",msg:t});}},U=class extends n{constructor(t){super({status:423,code:"locked",msg:t});}},D=class extends n{constructor(t){super({status:424,code:"failed_dependency",msg:t});}},w=class extends n{constructor(t){super({status:425,code:"too_early",msg:t});}},k=class extends n{constructor(t){super({status:426,code:"upgrade_required",msg:t});}},H=class extends n{constructor(t){super({status:428,code:"precondition_required",msg:t});}},N=class extends n{constructor(t){super({status:429,code:"too_many_requests",msg:t});}},Q=class extends n{constructor(t){super({status:431,code:"request_header_fields_too_large",msg:t});}},L=class extends n{constructor(t){super({status:451,code:"unavailable_for_legal_reasons",msg:t});}},j=class extends n{constructor(t){super({status:500,code:"internal_server_error",msg:t});}},B=class extends n{constructor(t){super({status:501,code:"not_implemented",msg:t});}},V=class extends n{constructor(t){super({status:502,code:"bad_gateway",msg:t});}},G=class extends n{constructor(t){super({status:503,code:"service_unavailable",msg:t});}},K=class extends n{constructor(t){super({status:504,code:"gateway_timeout",msg:t});}},z=class extends n{constructor(t){super({status:505,code:"http_version_not_supported",msg:t});}},J=class extends n{constructor(t){super({status:506,code:"variant_also_negotiates",msg:t});}},W=class extends n{constructor(t){super({status:507,code:"insufficient_storage",msg:t});}},X=class extends n{constructor(t){super({status:508,code:"loop_detected",msg:t});}},Y=class extends n{constructor(t){super({status:510,code:"not_extended",msg:t});}},Z=class extends n{constructor(t){super({status:511,code:"network_authentication_required",msg:t});}};var c={get instance(){return globalThis.__M1CRO__.internals}};var ee={fromId(r){return c.instance.providerFromId(r)}};var te={parse(r){return c.instance.parseAppId(r)}};export{te as AppId,V as BadGatewayError,l as BadRequestError,n as BaseError,I as ConflictError,q as ContentTooLargeError,a as EntityModel,i as EntitySchema,M as ExpectationFailedError,D as FailedDependencyError,y as ForbiddenError,K as GatewayTimeoutError,b as GoneError,z as HTTPVersionNotSupportedError,E as ImATeapotError,W as InsufficientStorageError,j as InternalServerError,v as LengthRequiredError,U as LockedError,X as LoopDetectedError,x as MethodNotAllowedError,O as MisdirectedRequestError,Z as NetworkAuthenticationRequiredError,f as NotAcceptableError,Y as NotExtendedError,g as NotFoundError,B as NotImplementedError,m as PaymentRequiredError,_ as PreconditionFailedError,H as PreconditionRequiredError,ee as Provider,h as ProxyAuthenticationRequiredError,P as RangeNotSatisfiableError,Q as RequestHeaderFieldsTooLargeError,R as RequestTimeoutError,G as ServiceUnavailableError,d as StatusCode,w as TooEarlyError,N as TooManyRequestsError,T as URITooLongError,u as UnauthorizedError,L as UnavailableForLegalReasonsError,F as UnprocessableEntityError,A as UnsupportedMediaTypeError,k as UpgradeRequiredError,J as VariantAlsoNegotiatesError,$ as cbor,C as entityModel,S as entitySchema};
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { SetCookie } from 'cookie';
|
|
2
|
+
|
|
3
|
+
type Filter = Record<string, unknown>;
|
|
4
|
+
type Sorting$1 = Record<string, 'asc' | 'desc'>;
|
|
5
|
+
type GeneratedFields = {
|
|
6
|
+
id: string;
|
|
7
|
+
createdAt: number;
|
|
8
|
+
updatedAt: number;
|
|
9
|
+
};
|
|
10
|
+
type ReservedKeys = keyof GeneratedFields;
|
|
11
|
+
type HydratedDocument<S extends EntitySchema<any>> = Omit<InferInterface<S>, ReservedKeys> & GeneratedFields;
|
|
12
|
+
type InsertDocument<S extends EntitySchema<any>> = Omit<InferInterface<S>, ReservedKeys> & Partial<GeneratedFields>;
|
|
13
|
+
type ScalarConstructor = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor | ObjectConstructor;
|
|
14
|
+
type ArraySpec = readonly [FieldSpec];
|
|
15
|
+
type InnerSpec = ScalarConstructor | ArraySpec | SchemaDefinition;
|
|
16
|
+
type FieldSpec = InnerSpec | {
|
|
17
|
+
type: InnerSpec;
|
|
18
|
+
required?: boolean;
|
|
19
|
+
};
|
|
20
|
+
interface SchemaDefinition {
|
|
21
|
+
[key: string]: FieldSpec;
|
|
22
|
+
}
|
|
23
|
+
type ConstructorToType<T> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends DateConstructor ? number : T extends ObjectConstructor ? Record<string, unknown> : never;
|
|
24
|
+
type IsOptional<F> = F extends {
|
|
25
|
+
required: false;
|
|
26
|
+
} ? true : false;
|
|
27
|
+
type RequiredKeys<Def extends SchemaDefinition> = {
|
|
28
|
+
[K in keyof Def]-?: IsOptional<Def[K]> extends false ? K : never;
|
|
29
|
+
}[keyof Def];
|
|
30
|
+
type OptionalKeys<Def extends SchemaDefinition> = Exclude<keyof Def, RequiredKeys<Def>>;
|
|
31
|
+
type InferInterface<S extends EntitySchema<any>> = InferSchema<S['definition']>;
|
|
32
|
+
type AssertNoReservedKeys<Def extends SchemaDefinition> = Extract<keyof Def, ReservedKeys> extends never ? Def : never;
|
|
33
|
+
type Unwrap<F> = F extends {
|
|
34
|
+
type: infer I;
|
|
35
|
+
} ? I : F;
|
|
36
|
+
type InferInner<I> = I extends ScalarConstructor ? ConstructorToType<I> : I extends readonly [infer U] ? U extends FieldSpec ? Array<InferField<U>> : never : I extends SchemaDefinition ? InferSchema<I> : never;
|
|
37
|
+
type InferField<F extends FieldSpec> = InferInner<Unwrap<F>>;
|
|
38
|
+
type InferSchema<Def extends SchemaDefinition> = {
|
|
39
|
+
[K in OptionalKeys<Def>]?: InferField<Def[K]> | undefined;
|
|
40
|
+
} & {
|
|
41
|
+
[K in RequiredKeys<Def>]: InferField<Def[K]>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
declare function entitySchema<const Def extends SchemaDefinition>(def: AssertNoReservedKeys<Def>): EntitySchema<Def>;
|
|
45
|
+
declare class EntitySchema<Def extends SchemaDefinition = SchemaDefinition> {
|
|
46
|
+
readonly definition: Def;
|
|
47
|
+
constructor(definition: Def);
|
|
48
|
+
}
|
|
49
|
+
declare class CompiledSchema {
|
|
50
|
+
constructor(schema: EntitySchema);
|
|
51
|
+
get shape(): unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type InsertReturnMode = 'insertedIds' | 'documents';
|
|
55
|
+
type InsertReturnType<T extends object = Record<string, unknown>, R extends InsertReturnMode = 'insertedIds'> = R extends 'insertedIds' ? string[] : R extends 'documents' ? T[] : never;
|
|
56
|
+
interface InsertQuery<T extends object = Record<string, unknown>, R extends InsertReturnMode = 'insertedIds'> extends PromiseLike<InsertReturnType<T, R>> {
|
|
57
|
+
return(mode: 'insertedIds'): InsertQuery<T, 'insertedIds'>;
|
|
58
|
+
return(mode: 'documents'): InsertQuery<T, 'documents'>;
|
|
59
|
+
return(mode: InsertReturnMode): InsertQuery<T, typeof mode>;
|
|
60
|
+
}
|
|
61
|
+
type InsertOneReturnMode = 'insertedId' | 'document';
|
|
62
|
+
type InsertOneReturnType<T extends object = Record<string, unknown>, R extends InsertOneReturnMode = 'insertedId'> = R extends 'insertedId' ? string : R extends 'document' ? T : never;
|
|
63
|
+
interface InsertOneQuery<T extends object = Record<string, unknown>, R extends InsertOneReturnMode = 'insertedId'> extends PromiseLike<InsertOneReturnType<T, R>> {
|
|
64
|
+
return(mode: 'insertedId'): InsertOneQuery<T, 'insertedId'>;
|
|
65
|
+
return(mode: 'document'): InsertOneQuery<T, 'document'>;
|
|
66
|
+
return(mode: InsertOneReturnMode): InsertOneQuery<T, typeof mode>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type UpdateReturnMode = 'affectedRows' | 'oldDocuments' | 'newDocuments';
|
|
70
|
+
type UpdateReturnType<T, R extends UpdateReturnMode> = R extends 'affectedRows' ? bigint : R extends 'oldDocuments' | 'newDocuments' ? T[] : never;
|
|
71
|
+
interface UpdateQuery<T extends object = Record<string, unknown>, R extends UpdateReturnMode = 'affectedRows'> extends PromiseLike<UpdateReturnType<T, R>> {
|
|
72
|
+
limit(limit: number): this;
|
|
73
|
+
offset(offset: number): this;
|
|
74
|
+
sort(sort: Sorting): this;
|
|
75
|
+
return(mode: 'affectedRows'): UpdateQuery<T, 'affectedRows'>;
|
|
76
|
+
return(mode: 'oldDocuments'): UpdateQuery<T, 'oldDocuments'>;
|
|
77
|
+
return(mode: 'newDocuments'): UpdateQuery<T, 'newDocuments'>;
|
|
78
|
+
return(mode: UpdateReturnMode): UpdateQuery<T, typeof mode>;
|
|
79
|
+
}
|
|
80
|
+
type UpdateOneReturnMode = 'success' | 'oldDocument' | 'newDocument';
|
|
81
|
+
type UpdateOneReturnType<T, R extends UpdateOneReturnMode> = R extends 'success' ? boolean : R extends 'oldDocument' | 'newDocument' ? T | undefined : never;
|
|
82
|
+
interface UpdateOneQuery<T extends object = Record<string, unknown>, R extends UpdateOneReturnMode = 'success'> extends PromiseLike<UpdateOneReturnType<T, R>> {
|
|
83
|
+
offset(offset: number): this;
|
|
84
|
+
sort(sort: Sorting): this;
|
|
85
|
+
upsert(upsert: boolean): this;
|
|
86
|
+
return(mode: 'success'): UpdateOneQuery<T, 'success'>;
|
|
87
|
+
return(mode: 'oldDocument'): UpdateOneQuery<T, 'oldDocument'>;
|
|
88
|
+
return(mode: 'newDocument'): UpdateOneQuery<T, 'newDocument'>;
|
|
89
|
+
return(mode: UpdateOneReturnMode): UpdateOneQuery<T, typeof mode>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type RemoveReturnMode = 'affectedRows' | 'documents';
|
|
93
|
+
type RemoveReturnType<T, R extends RemoveReturnMode> = R extends 'affectedRows' ? bigint : R extends 'documents' ? T[] : never;
|
|
94
|
+
interface RemoveQuery<T extends object = Record<string, unknown>, R extends RemoveReturnMode = 'affectedRows'> extends PromiseLike<RemoveReturnType<T, R>> {
|
|
95
|
+
limit(limit: number): this;
|
|
96
|
+
offset(offset: number): this;
|
|
97
|
+
sort(sort: Sorting): this;
|
|
98
|
+
return(mode: 'affectedRows'): RemoveQuery<T, 'affectedRows'>;
|
|
99
|
+
return(mode: 'documents'): RemoveQuery<T, 'documents'>;
|
|
100
|
+
return(mode: RemoveReturnMode): RemoveQuery<T, typeof mode>;
|
|
101
|
+
}
|
|
102
|
+
type RemoveOneReturnMode = 'success' | 'document';
|
|
103
|
+
type RemoveOneReturnType<T, R extends RemoveOneReturnMode> = R extends 'success' ? boolean : R extends 'document' ? T | undefined : never;
|
|
104
|
+
interface RemoveOneQuery<T extends object = Record<string, unknown>, R extends RemoveOneReturnMode = 'success'> extends PromiseLike<RemoveOneReturnType<T, R>> {
|
|
105
|
+
offset(offset: number): this;
|
|
106
|
+
sort(sort: Sorting): this;
|
|
107
|
+
return(mode: 'success'): RemoveOneQuery<T, 'success'>;
|
|
108
|
+
return(mode: 'document'): RemoveOneQuery<T, 'document'>;
|
|
109
|
+
return(mode: RemoveOneReturnMode): RemoveOneQuery<T, typeof mode>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface Entity<T extends object = Record<string, unknown>> {
|
|
113
|
+
get name(): string;
|
|
114
|
+
find(filter?: Filter): FindQuery<T>;
|
|
115
|
+
findOne(filter?: Filter): FindOneQuery<T>;
|
|
116
|
+
insert(docs: T[]): InsertQuery<T>;
|
|
117
|
+
insertOne(doc: T): InsertOneQuery<T>;
|
|
118
|
+
update(filter: Filter, update: Record<string, unknown>): UpdateQuery<T>;
|
|
119
|
+
updateOne(filter: Filter, update: Record<string, unknown>): UpdateOneQuery<T>;
|
|
120
|
+
remove(filter: Filter): RemoveQuery<T>;
|
|
121
|
+
removeOne(filter: Filter): RemoveOneQuery<T>;
|
|
122
|
+
}
|
|
123
|
+
interface Sorting {
|
|
124
|
+
[field: string]: 'asc' | 'desc';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface FindQuery<T extends object = Record<string, unknown>> extends PromiseLike<T[]> {
|
|
128
|
+
limit(limit: number): this;
|
|
129
|
+
offset(offset: number): this;
|
|
130
|
+
sort(sort: Sorting): this;
|
|
131
|
+
}
|
|
132
|
+
interface FindOneQuery<T extends object = Record<string, unknown>> extends PromiseLike<T | undefined> {
|
|
133
|
+
offset(offset: number): this;
|
|
134
|
+
sort(sort: Sorting): this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type Variant<K extends PropertyKey, T extends object> = {
|
|
138
|
+
[P in keyof T]: {
|
|
139
|
+
[Q in K]: P;
|
|
140
|
+
} & T[P] extends infer U ? {
|
|
141
|
+
[Q in keyof U]: U[Q];
|
|
142
|
+
} : never;
|
|
143
|
+
}[keyof T];
|
|
144
|
+
type EventHandler = <T>(event: string, data: T) => void | Promise<void>;
|
|
145
|
+
type Visibility = 'private' | 'platform' | 'vendor' | 'public';
|
|
146
|
+
interface Tenant {
|
|
147
|
+
id: string;
|
|
148
|
+
host: string;
|
|
149
|
+
}
|
|
150
|
+
interface AppId {
|
|
151
|
+
get name(): string;
|
|
152
|
+
get namespace(): Namespace;
|
|
153
|
+
toString(separator?: string): string;
|
|
154
|
+
}
|
|
155
|
+
declare const AppId: {
|
|
156
|
+
parse(input: string): AppId;
|
|
157
|
+
};
|
|
158
|
+
type Namespace = 'system' | 'platform' | {
|
|
159
|
+
vendor: string;
|
|
160
|
+
};
|
|
161
|
+
type AppRole = Variant<'type', AppRoleData>;
|
|
162
|
+
type AppRoleData = {
|
|
163
|
+
provider: {
|
|
164
|
+
group: string;
|
|
165
|
+
};
|
|
166
|
+
test: void;
|
|
167
|
+
};
|
|
168
|
+
interface Auth {
|
|
169
|
+
subject: Subject;
|
|
170
|
+
permissions: Permissions;
|
|
171
|
+
}
|
|
172
|
+
interface Subject {
|
|
173
|
+
id: string;
|
|
174
|
+
email: string;
|
|
175
|
+
roles: string[];
|
|
176
|
+
}
|
|
177
|
+
interface Permissions {
|
|
178
|
+
[key: string]: string[];
|
|
179
|
+
}
|
|
180
|
+
interface HookEventMap {
|
|
181
|
+
start: [];
|
|
182
|
+
install: [];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
interface Artifacts {
|
|
186
|
+
get<T>(key: string): T | undefined;
|
|
187
|
+
set<T>(key: string, value: T): void;
|
|
188
|
+
delete(key: string): void;
|
|
189
|
+
get auth(): Auth | undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
193
|
+
declare enum StatusCode {
|
|
194
|
+
Continue = 100,
|
|
195
|
+
SwitchingProtocols = 101,
|
|
196
|
+
Processing = 102,
|
|
197
|
+
EarlyHints = 103,
|
|
198
|
+
OK = 200,
|
|
199
|
+
Created = 201,
|
|
200
|
+
Accepted = 202,
|
|
201
|
+
NonAuthoritativeInformation = 203,
|
|
202
|
+
NoContent = 204,
|
|
203
|
+
ResetContent = 205,
|
|
204
|
+
PartialContent = 206,
|
|
205
|
+
MultiStatus = 207,
|
|
206
|
+
AlreadyReported = 208,
|
|
207
|
+
IMUsed = 226,
|
|
208
|
+
MultipleChoices = 300,
|
|
209
|
+
MovedPermanently = 301,
|
|
210
|
+
Found = 302,
|
|
211
|
+
SeeOther = 303,
|
|
212
|
+
NotModified = 304,
|
|
213
|
+
UseProxy = 305,
|
|
214
|
+
TemporaryRedirect = 307,
|
|
215
|
+
PermanentRedirect = 308,
|
|
216
|
+
BadRequest = 400,
|
|
217
|
+
Unauthorized = 401,
|
|
218
|
+
PaymentRequired = 402,
|
|
219
|
+
Forbidden = 403,
|
|
220
|
+
NotFound = 404,
|
|
221
|
+
MethodNotAllowed = 405,
|
|
222
|
+
NotAcceptable = 406,
|
|
223
|
+
ProxyAuthenticationRequired = 407,
|
|
224
|
+
RequestTimeout = 408,
|
|
225
|
+
Conflict = 409,
|
|
226
|
+
Gone = 410,
|
|
227
|
+
LengthRequired = 411,
|
|
228
|
+
PreconditionFailed = 412,
|
|
229
|
+
ContentTooLarge = 413,
|
|
230
|
+
URITooLong = 414,
|
|
231
|
+
UnsupportedMediaType = 415,
|
|
232
|
+
RangeNotSatisfiable = 416,
|
|
233
|
+
ExpectationFailed = 417,
|
|
234
|
+
ImATeapot = 418,
|
|
235
|
+
MisdirectedRequest = 421,
|
|
236
|
+
UnprocessableEntity = 422,
|
|
237
|
+
Locked = 423,
|
|
238
|
+
FailedDependency = 424,
|
|
239
|
+
TooEarly = 425,
|
|
240
|
+
UpgradeRequired = 426,
|
|
241
|
+
PreconditionRequired = 428,
|
|
242
|
+
TooManyRequests = 429,
|
|
243
|
+
RequestHeaderFieldsTooLarge = 431,
|
|
244
|
+
UnavailableForLegalReasons = 451,
|
|
245
|
+
InternalServerError = 500,
|
|
246
|
+
NotImplemented = 501,
|
|
247
|
+
BadGateway = 502,
|
|
248
|
+
ServiceUnavailable = 503,
|
|
249
|
+
GatewayTimeout = 504,
|
|
250
|
+
HTTPVersionNotSupported = 505,
|
|
251
|
+
VariantAlsoNegotiates = 506,
|
|
252
|
+
InsufficientStorage = 507,
|
|
253
|
+
LoopDetected = 508,
|
|
254
|
+
NotExtended = 510,
|
|
255
|
+
NetworkAuthenticationRequired = 511
|
|
256
|
+
}
|
|
257
|
+
type RequestHandler = (req: Request, res: ResponseBuilder) => void | Promise<void>;
|
|
258
|
+
type Middleware = (req: Request, res: ResponseBuilder, next: () => Promise<void>) => void | Promise<void>;
|
|
259
|
+
interface Router {
|
|
260
|
+
scope(path: string): Router;
|
|
261
|
+
route(method: Method, path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
262
|
+
middleware(handler: Middleware, options?: MiddlewareOptions): Router;
|
|
263
|
+
get(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
264
|
+
post(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
265
|
+
put(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
266
|
+
patch(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
267
|
+
delete(path: string, handler: RequestHandler, options?: RouteOptions): Router;
|
|
268
|
+
}
|
|
269
|
+
interface RouteOptions {
|
|
270
|
+
timeoutMs?: number;
|
|
271
|
+
permissions?: string[];
|
|
272
|
+
authenticated?: boolean;
|
|
273
|
+
visibility?: Visibility;
|
|
274
|
+
}
|
|
275
|
+
interface MiddlewareOptions {
|
|
276
|
+
path?: string;
|
|
277
|
+
priority?: number;
|
|
278
|
+
}
|
|
279
|
+
interface Request {
|
|
280
|
+
get artifacts(): Artifacts;
|
|
281
|
+
get method(): Method;
|
|
282
|
+
get url(): URL;
|
|
283
|
+
get params(): Record<string, string>;
|
|
284
|
+
get headers(): Headers;
|
|
285
|
+
cookie(name: string): string | undefined;
|
|
286
|
+
body(): Promise<Uint8Array>;
|
|
287
|
+
text(): Promise<string>;
|
|
288
|
+
json<T>(): Promise<T>;
|
|
289
|
+
}
|
|
290
|
+
interface RequestBuilder {
|
|
291
|
+
method(method: Method): this;
|
|
292
|
+
url(url: string | URL): this;
|
|
293
|
+
header(name: string, value: string): this;
|
|
294
|
+
headers(headers: HeadersInit): this;
|
|
295
|
+
cookie(name: string, value: string): this;
|
|
296
|
+
body(bytes: Uint8Array): this;
|
|
297
|
+
text(text: string): this;
|
|
298
|
+
json<T>(json: T): this;
|
|
299
|
+
}
|
|
300
|
+
interface Response {
|
|
301
|
+
get status(): number;
|
|
302
|
+
get headers(): Headers;
|
|
303
|
+
cookie(name: string): SetCookie | undefined;
|
|
304
|
+
body(): Promise<Uint8Array>;
|
|
305
|
+
text(): Promise<string>;
|
|
306
|
+
json<T>(): Promise<T>;
|
|
307
|
+
}
|
|
308
|
+
interface ResponseBuilder {
|
|
309
|
+
status(status: number): this;
|
|
310
|
+
header(name: string, value: string): this;
|
|
311
|
+
headers(headers: HeadersInit): this;
|
|
312
|
+
cookie(name: string, value?: string, options?: SetCookieOptions): this;
|
|
313
|
+
body(bytes: Uint8Array): this;
|
|
314
|
+
text(text: string): this;
|
|
315
|
+
json<T>(json: T): this;
|
|
316
|
+
}
|
|
317
|
+
interface SetCookieOptions {
|
|
318
|
+
encode?: (s: string) => string;
|
|
319
|
+
maxAge?: number;
|
|
320
|
+
expires?: Date;
|
|
321
|
+
domain?: string;
|
|
322
|
+
path?: string;
|
|
323
|
+
httpOnly?: boolean;
|
|
324
|
+
secure?: boolean;
|
|
325
|
+
partitioned?: boolean;
|
|
326
|
+
priority?: 'low' | 'medium' | 'high';
|
|
327
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
interface Crypto {
|
|
331
|
+
deriveKey(seed: string, length: number): Uint8Array;
|
|
332
|
+
aesGcmEncrypt<T>(data: T): Uint8Array;
|
|
333
|
+
aesGcmDecrypt<T>(data: Uint8Array): T;
|
|
334
|
+
argon2Hash(algorithm: Argon2Algorithm, password: string, options?: Argon2Options): string;
|
|
335
|
+
argon2Verify(algorithm: Argon2Algorithm, password: string, hash: string, options?: Argon2Options): boolean;
|
|
336
|
+
}
|
|
337
|
+
type Argon2Algorithm = 'argon2d' | 'argon2i' | 'argon2id';
|
|
338
|
+
interface Argon2Options {
|
|
339
|
+
mCost?: number;
|
|
340
|
+
tCost?: number;
|
|
341
|
+
pCost?: number;
|
|
342
|
+
outputLen?: number;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
interface SetOptions {
|
|
346
|
+
ttl?: number;
|
|
347
|
+
existenceCheck?: 'nx' | 'xx';
|
|
348
|
+
}
|
|
349
|
+
interface KeyValueStore {
|
|
350
|
+
get<T>(key: string): Promise<T>;
|
|
351
|
+
getDel<T>(key: string): Promise<T>;
|
|
352
|
+
set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
|
|
353
|
+
delete(key: string): Promise<void>;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
interface RPC {
|
|
357
|
+
call(url: string, method: Method): Call;
|
|
358
|
+
get(url: string): Call;
|
|
359
|
+
post(url: string): Call;
|
|
360
|
+
put(url: string): Call;
|
|
361
|
+
patch(url: string): Call;
|
|
362
|
+
delete(url: string): Call;
|
|
363
|
+
}
|
|
364
|
+
interface Call extends RequestBuilder, PromiseLike<Response> {
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
interface Providers {
|
|
368
|
+
list(group: string): Provider[];
|
|
369
|
+
}
|
|
370
|
+
interface Provider {
|
|
371
|
+
get app(): AppId;
|
|
372
|
+
get group(): string;
|
|
373
|
+
get id(): string;
|
|
374
|
+
call(path: string, method: Method): Call;
|
|
375
|
+
get(path: string): Call;
|
|
376
|
+
post(path: string): Call;
|
|
377
|
+
put(path: string): Call;
|
|
378
|
+
patch(path: string): Call;
|
|
379
|
+
delete(path: string): Call;
|
|
380
|
+
}
|
|
381
|
+
declare const Provider: {
|
|
382
|
+
fromId(id: string): Provider;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
interface SSE {
|
|
386
|
+
push<T>(event: T, targets: string[]): Promise<void>;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
interface Bridge {
|
|
390
|
+
get tenant(): Tenant;
|
|
391
|
+
get providers(): Providers;
|
|
392
|
+
settings<T>(): T | undefined;
|
|
393
|
+
crd<T>(key: string): T | undefined;
|
|
394
|
+
get rpc(): RPC;
|
|
395
|
+
get kv(): KeyValueStore;
|
|
396
|
+
get sse(): SSE;
|
|
397
|
+
get crypto(): Crypto;
|
|
398
|
+
entity<T extends object>(name: string): Entity<T>;
|
|
399
|
+
publish<T extends object>(event: string, payload: T, visibility?: Visibility[]): void;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
declare const logLevels: readonly ["trace", "debug", "info", "warn", "error", "none"];
|
|
403
|
+
type LogLevel = (typeof logLevels)[number];
|
|
404
|
+
|
|
405
|
+
export { type AppRole as A, type Bridge as B, CompiledSchema as C, EntitySchema as E, type Filter as F, type GeneratedFields as G, type HydratedDocument as H, type InsertDocument as I, type LogLevel as L, type Method as M, type Namespace as N, Provider as P, type RemoveQuery as R, type Sorting$1 as S, type Tenant as T, type UpdateQuery as U, type Visibility as V, type FindQuery as a, type FindOneQuery as b, type InsertQuery as c, type InsertOneQuery as d, type InferInterface as e, type UpdateOneQuery as f, type RemoveOneQuery as g, type Router as h, type HookEventMap as i, type EventHandler as j, AppId as k, type Artifacts as l, type Auth as m, type Entity as n, type InferSchema as o, type Middleware as p, type Providers as q, type Request as r, type RequestBuilder as s, type RequestHandler as t, type Response as u, type ResponseBuilder as v, type RouteOptions as w, StatusCode as x, type Subject as y, entitySchema as z };
|
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.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -12,29 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"./globals": {
|
|
14
14
|
"types": "./dist/globals.d.ts"
|
|
15
|
-
},
|
|
16
|
-
"./entity": {
|
|
17
|
-
"types": "./dist/entity.d.ts",
|
|
18
|
-
"import": "./dist/entity.js"
|
|
19
|
-
},
|
|
20
|
-
"./http": {
|
|
21
|
-
"types": "./dist/http.d.ts",
|
|
22
|
-
"import": "./dist/http.js"
|
|
23
|
-
},
|
|
24
|
-
"./rpc": {
|
|
25
|
-
"types": "./dist/rpc.d.ts",
|
|
26
|
-
"import": "./dist/rpc.js"
|
|
27
|
-
},
|
|
28
|
-
"./types": {
|
|
29
|
-
"types": "./dist/types.d.ts",
|
|
30
|
-
"import": "./dist/types.js"
|
|
31
15
|
}
|
|
32
16
|
},
|
|
33
17
|
"publishConfig": {
|
|
34
18
|
"access": "public"
|
|
35
19
|
},
|
|
36
20
|
"scripts": {
|
|
37
|
-
"build": "yarn
|
|
21
|
+
"build": "yarn && yarn typecheck && yarn bundle",
|
|
38
22
|
"typecheck": "tsc --noEmit",
|
|
39
23
|
"bundle": "tsup --minify --treeshake smallest",
|
|
40
24
|
"versioning": "yarn version --new-version",
|
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"],"names":["cbor_default","data"],"mappings":"wBAEA,IAAOA,CAAAA,CAAQ,CACX,MAAA,CAAUC,CAAAA,CAAqB,CAC3B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC5B,CAAA,CACA,OAAUA,CAAAA,CAAqB,CAC3B,OAAa,CAAA,CAAA,MAAA,CAAOA,CAAI,CAC5B,CACJ","file":"index.js","sourcesContent":["import * as cbor2 from \"cbor2\";\n\nexport 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"]}
|