sporades 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile.base +19 -0
- package/LICENSE +21 -0
- package/README.md +289 -0
- package/bin/sporades-host-helper.js +4001 -0
- package/bin/sporades.js +14198 -0
- package/dist/base-image.d.ts +43 -0
- package/dist/base-image.d.ts.map +1 -0
- package/dist/base-image.js +53 -0
- package/dist/base-image.js.map +1 -0
- package/dist/bundle-pipeline.d.ts +110 -0
- package/dist/bundle-pipeline.d.ts.map +1 -0
- package/dist/bundle-pipeline.js +369 -0
- package/dist/bundle-pipeline.js.map +1 -0
- package/dist/capsule-services.d.ts +94 -0
- package/dist/capsule-services.d.ts.map +1 -0
- package/dist/capsule-services.js +310 -0
- package/dist/capsule-services.js.map +1 -0
- package/dist/cli/cli-help.d.ts +16 -0
- package/dist/cli/cli-help.d.ts.map +1 -0
- package/dist/cli/cli-help.js +202 -0
- package/dist/cli/cli-help.js.map +1 -0
- package/dist/cli/cli-support.d.ts +17 -0
- package/dist/cli/cli-support.d.ts.map +1 -0
- package/dist/cli/cli-support.js +46 -0
- package/dist/cli/cli-support.js.map +1 -0
- package/dist/cli/github-autodeploy-workflow.d.ts +7 -0
- package/dist/cli/github-autodeploy-workflow.d.ts.map +1 -0
- package/dist/cli/github-autodeploy-workflow.js +185 -0
- package/dist/cli/github-autodeploy-workflow.js.map +1 -0
- package/dist/cli/host-helper-archive.d.ts +9 -0
- package/dist/cli/host-helper-archive.d.ts.map +1 -0
- package/dist/cli/host-helper-archive.js +74 -0
- package/dist/cli/host-helper-archive.js.map +1 -0
- package/dist/cli/host-helper-config.d.ts +15 -0
- package/dist/cli/host-helper-config.d.ts.map +1 -0
- package/dist/cli/host-helper-config.js +111 -0
- package/dist/cli/host-helper-config.js.map +1 -0
- package/dist/cli/host-helper-contract.d.ts +5 -0
- package/dist/cli/host-helper-contract.d.ts.map +1 -0
- package/dist/cli/host-helper-contract.js +5 -0
- package/dist/cli/host-helper-contract.js.map +1 -0
- package/dist/cli/host-helper-docker-types.d.ts +27 -0
- package/dist/cli/host-helper-docker-types.d.ts.map +1 -0
- package/dist/cli/host-helper-docker-types.js +2 -0
- package/dist/cli/host-helper-docker-types.js.map +1 -0
- package/dist/cli/host-helper-json.d.ts +6 -0
- package/dist/cli/host-helper-json.d.ts.map +1 -0
- package/dist/cli/host-helper-json.js +2 -0
- package/dist/cli/host-helper-json.js.map +1 -0
- package/dist/cli/host-helper-release-files.d.ts +4 -0
- package/dist/cli/host-helper-release-files.d.ts.map +1 -0
- package/dist/cli/host-helper-release-files.js +21 -0
- package/dist/cli/host-helper-release-files.js.map +1 -0
- package/dist/cli/host-helper-requests.d.ts +163 -0
- package/dist/cli/host-helper-requests.d.ts.map +1 -0
- package/dist/cli/host-helper-requests.js +2 -0
- package/dist/cli/host-helper-requests.js.map +1 -0
- package/dist/cli/host-helper-validation.d.ts +27 -0
- package/dist/cli/host-helper-validation.d.ts.map +1 -0
- package/dist/cli/host-helper-validation.js +256 -0
- package/dist/cli/host-helper-validation.js.map +1 -0
- package/dist/cli/host-request-builders.d.ts +143 -0
- package/dist/cli/host-request-builders.d.ts.map +1 -0
- package/dist/cli/host-request-builders.js +266 -0
- package/dist/cli/host-request-builders.js.map +1 -0
- package/dist/cli/hosted-capsule-contract.d.ts +128 -0
- package/dist/cli/hosted-capsule-contract.d.ts.map +1 -0
- package/dist/cli/hosted-capsule-contract.js +2 -0
- package/dist/cli/hosted-capsule-contract.js.map +1 -0
- package/dist/cli/sporades-host-helper.d.ts +3 -0
- package/dist/cli/sporades-host-helper.d.ts.map +1 -0
- package/dist/cli/sporades-host-helper.js +3120 -0
- package/dist/cli/sporades-host-helper.js.map +1 -0
- package/dist/cli/sporades.d.ts +3 -0
- package/dist/cli/sporades.d.ts.map +1 -0
- package/dist/cli/sporades.js +4066 -0
- package/dist/cli/sporades.js.map +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +9 -0
- package/dist/client.js.map +1 -0
- package/dist/runtime-restart-policy.d.ts +29 -0
- package/dist/runtime-restart-policy.d.ts.map +1 -0
- package/dist/runtime-restart-policy.js +53 -0
- package/dist/runtime-restart-policy.js.map +1 -0
- package/dist/sealed-server-env.d.ts +56 -0
- package/dist/sealed-server-env.d.ts.map +1 -0
- package/dist/sealed-server-env.js +170 -0
- package/dist/sealed-server-env.js.map +1 -0
- package/dist/server-runtime-source.d.ts +1262 -0
- package/dist/server-runtime-source.d.ts.map +1 -0
- package/dist/server-runtime-source.js +6397 -0
- package/dist/server-runtime-source.js.map +1 -0
- package/dist/server.d.ts +58 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +183 -0
- package/dist/server.js.map +1 -0
- package/dist/templates/client-runtime-template.d.ts +2 -0
- package/dist/templates/client-runtime-template.d.ts.map +1 -0
- package/dist/templates/client-runtime-template.js +438 -0
- package/dist/templates/client-runtime-template.js.map +1 -0
- package/dist/templates/scaffold-template.d.ts +19 -0
- package/dist/templates/scaffold-template.d.ts.map +1 -0
- package/dist/templates/scaffold-template.js +1201 -0
- package/dist/templates/scaffold-template.js.map +1 -0
- package/dist/templates/server-bundle-template.d.ts +8 -0
- package/dist/templates/server-bundle-template.d.ts.map +1 -0
- package/dist/templates/server-bundle-template.js +162 -0
- package/dist/templates/server-bundle-template.js.map +1 -0
- package/package.json +44 -0
- package/src/types/client.d.ts +161 -0
- package/src/types/server.d.ts +300 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
export type FieldKind = "String" | "Boolean" | "Number" | "Date" | "Json" | "Reference";
|
|
2
|
+
|
|
3
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };
|
|
4
|
+
|
|
5
|
+
export type MaybePromise<Value> = Value | Promise<Value>;
|
|
6
|
+
|
|
7
|
+
export type FieldBuilder<Value> = {
|
|
8
|
+
kind: FieldKind;
|
|
9
|
+
default(defaultValue: Value): FieldDefinition<Value>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type FieldDefinition<Value> = {
|
|
13
|
+
kind: FieldKind;
|
|
14
|
+
defaultValue?: Value;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ReferenceFieldBuilder = {
|
|
18
|
+
kind: "Reference";
|
|
19
|
+
targetTable: string;
|
|
20
|
+
default(defaultValue: string | null): ReferenceFieldDefinition;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ReferenceFieldDefinition = {
|
|
24
|
+
kind: "Reference";
|
|
25
|
+
targetTable: string;
|
|
26
|
+
defaultValue?: string | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type AnyFieldDefinition =
|
|
30
|
+
| FieldBuilder<unknown>
|
|
31
|
+
| FieldDefinition<unknown>
|
|
32
|
+
| ReferenceFieldBuilder
|
|
33
|
+
| ReferenceFieldDefinition;
|
|
34
|
+
|
|
35
|
+
export type TableAclOperation = "read" | "write" | "insert" | "update" | "delete";
|
|
36
|
+
|
|
37
|
+
export type AclStorageFileMetadata = {
|
|
38
|
+
id: string;
|
|
39
|
+
path: string;
|
|
40
|
+
bucket: string;
|
|
41
|
+
owner: string;
|
|
42
|
+
ownerId: string;
|
|
43
|
+
status: string;
|
|
44
|
+
size: number;
|
|
45
|
+
type: string;
|
|
46
|
+
name: string;
|
|
47
|
+
originalName: string;
|
|
48
|
+
version: string;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
deletedAt: string | null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type AclDatabaseHelpers = {
|
|
55
|
+
get(tableName: string, id: string): Record<string, unknown> | null;
|
|
56
|
+
exists(tableName: string, id: string): boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type AclStorageHelpers = {
|
|
60
|
+
get(resourceName: "files", reference: string): AclStorageFileMetadata | null;
|
|
61
|
+
exists(resourceName: "files", reference: string): boolean;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type AclHelpers = {
|
|
65
|
+
db: AclDatabaseHelpers;
|
|
66
|
+
storage: AclStorageHelpers;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type TableAclContext = {
|
|
70
|
+
auth: AuthContext;
|
|
71
|
+
acl: AclHelpers;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type TableAclRuleInput<Row extends Record<string, unknown> = Record<string, unknown>> = {
|
|
76
|
+
ctx: TableAclContext;
|
|
77
|
+
operation: TableAclOperation;
|
|
78
|
+
table: string;
|
|
79
|
+
row?: Row | null;
|
|
80
|
+
previous?: Row | null;
|
|
81
|
+
next?: Row | null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type TableAclRule<Row extends Record<string, unknown> = Record<string, unknown>> = (
|
|
85
|
+
input: TableAclRuleInput<Row>,
|
|
86
|
+
) => MaybePromise<boolean>;
|
|
87
|
+
|
|
88
|
+
export type TableAclRules<Row extends Record<string, unknown> = Record<string, unknown>> = Partial<
|
|
89
|
+
Record<TableAclOperation, TableAclRule<Row>>
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
export type TableDefinition<Fields extends Record<string, AnyFieldDefinition> = Record<string, AnyFieldDefinition>> = {
|
|
93
|
+
kind: "table";
|
|
94
|
+
fields: Fields;
|
|
95
|
+
aclRules?: TableAclRules;
|
|
96
|
+
acl(rules: TableAclRules<RowFromFields<Fields>>): TableDefinition<Fields>;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type SchemaDefinition = Record<string, TableDefinition>;
|
|
100
|
+
|
|
101
|
+
export type AutoFields = {
|
|
102
|
+
id: string;
|
|
103
|
+
createdAt: string;
|
|
104
|
+
updatedAt: string;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type FieldValue<Field> = Field extends FieldBuilder<infer Value>
|
|
108
|
+
? Value | null
|
|
109
|
+
: Field extends FieldDefinition<infer Value>
|
|
110
|
+
? Value
|
|
111
|
+
: Field extends ReferenceFieldBuilder | ReferenceFieldDefinition
|
|
112
|
+
? string | null
|
|
113
|
+
: unknown;
|
|
114
|
+
|
|
115
|
+
export type RowFromFields<Fields extends Record<string, AnyFieldDefinition>> = AutoFields & {
|
|
116
|
+
[Key in keyof Fields]: FieldValue<Fields[Key]>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type InsertValues<Row> = Partial<Omit<Row, keyof AutoFields>>;
|
|
120
|
+
export type UpdateValues<Row> = Partial<Omit<Row, keyof AutoFields>>;
|
|
121
|
+
export type OrderDirection = "asc" | "desc" | "ASC" | "DESC";
|
|
122
|
+
|
|
123
|
+
export type TableApi<Row extends Record<string, unknown> = Record<string, unknown>> = {
|
|
124
|
+
insert(values: InsertValues<Row>): Row;
|
|
125
|
+
update(id: string, values: UpdateValues<Row>): Row | null;
|
|
126
|
+
delete(id: string): boolean;
|
|
127
|
+
where<FieldName extends keyof Row & string>(fieldName: FieldName, value: Row[FieldName]): TableApi<Row>;
|
|
128
|
+
orderBy(fieldName: keyof Row & string, direction?: OrderDirection): TableApi<Row>;
|
|
129
|
+
limit(count: number): TableApi<Row>;
|
|
130
|
+
get(): Row | null;
|
|
131
|
+
all(): Row[];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type DatabaseFromSchema<Schema extends SchemaDefinition> = {
|
|
135
|
+
[TableName in keyof Schema]: Schema[TableName] extends TableDefinition<infer Fields> ? TableApi<RowFromFields<Fields>> : TableApi;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type AuthContext = {
|
|
139
|
+
userId: string;
|
|
140
|
+
displayName: string;
|
|
141
|
+
email: string | null;
|
|
142
|
+
picture: string | null;
|
|
143
|
+
isAuthenticated: boolean;
|
|
144
|
+
isGuest: boolean;
|
|
145
|
+
provider: string;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export type Logger = {
|
|
149
|
+
info(...args: unknown[]): void;
|
|
150
|
+
warn(...args: unknown[]): void;
|
|
151
|
+
error(...args: unknown[]): void;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type MessageScope =
|
|
155
|
+
| "currentUser"
|
|
156
|
+
| "all"
|
|
157
|
+
| {
|
|
158
|
+
userId?: string;
|
|
159
|
+
userIds?: string[];
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export type MessageApi = {
|
|
163
|
+
send(message: { type: string; data?: unknown; scope?: MessageScope }): number;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export type CapsuleContext<Schema extends SchemaDefinition = SchemaDefinition> = {
|
|
167
|
+
db: DatabaseFromSchema<Schema>;
|
|
168
|
+
auth: AuthContext;
|
|
169
|
+
env: Record<string, string>;
|
|
170
|
+
log: Logger;
|
|
171
|
+
messages: MessageApi;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export type EndpointRequest = {
|
|
175
|
+
method: string;
|
|
176
|
+
path: string;
|
|
177
|
+
query: Record<string, string>;
|
|
178
|
+
headers: Record<string, string>;
|
|
179
|
+
body?: unknown;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export type EndpointContext<Schema extends SchemaDefinition = SchemaDefinition> = CapsuleContext<Schema> & {
|
|
183
|
+
request: EndpointRequest;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type QueryHandler<Schema extends SchemaDefinition = SchemaDefinition, Result = unknown> = (
|
|
187
|
+
ctx: CapsuleContext<Schema>,
|
|
188
|
+
) => MaybePromise<Result>;
|
|
189
|
+
|
|
190
|
+
export type MutationHandler<
|
|
191
|
+
Schema extends SchemaDefinition = SchemaDefinition,
|
|
192
|
+
Args extends unknown[] = string[],
|
|
193
|
+
Result = unknown,
|
|
194
|
+
> = (
|
|
195
|
+
ctx: CapsuleContext<Schema>,
|
|
196
|
+
...args: Args
|
|
197
|
+
) => MaybePromise<Result>;
|
|
198
|
+
|
|
199
|
+
export type EndpointHandler<Schema extends SchemaDefinition = SchemaDefinition, Result = unknown> = (
|
|
200
|
+
ctx: EndpointContext<Schema>,
|
|
201
|
+
) => MaybePromise<Result>;
|
|
202
|
+
|
|
203
|
+
export type MessageHandler<Schema extends SchemaDefinition = SchemaDefinition, Result = unknown> = (
|
|
204
|
+
ctx: CapsuleContext<Schema>,
|
|
205
|
+
data: unknown,
|
|
206
|
+
) => MaybePromise<Result>;
|
|
207
|
+
|
|
208
|
+
export type ContextKind = "query" | "mutation" | "endpoint" | "message";
|
|
209
|
+
|
|
210
|
+
export type MiddlewareContext<Schema extends SchemaDefinition = SchemaDefinition> = CapsuleContext<Schema> &
|
|
211
|
+
Partial<Pick<EndpointContext<Schema>, "request">> & {
|
|
212
|
+
kind: ContextKind;
|
|
213
|
+
[key: string]: unknown;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export type ContextMiddleware<Schema extends SchemaDefinition = SchemaDefinition> = (
|
|
217
|
+
ctx: MiddlewareContext<Schema>,
|
|
218
|
+
) => MaybePromise<MiddlewareContext<Schema> | void>;
|
|
219
|
+
|
|
220
|
+
export type MutationResult<Result = unknown> = {
|
|
221
|
+
ok: boolean;
|
|
222
|
+
data?: Result | null;
|
|
223
|
+
error?: { message: string; hint?: string } | null;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export type MutationHookEvent<Schema extends SchemaDefinition = SchemaDefinition, Result = unknown> = {
|
|
227
|
+
name: string;
|
|
228
|
+
args: unknown[];
|
|
229
|
+
ctx: MiddlewareContext<Schema>;
|
|
230
|
+
result?: MutationResult<Result>;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export type MutationHook<Schema extends SchemaDefinition = SchemaDefinition, Result = unknown> = (
|
|
234
|
+
event: MutationHookEvent<Schema, Result>,
|
|
235
|
+
) => MaybePromise<void>;
|
|
236
|
+
|
|
237
|
+
export type CapsuleHooks<Schema extends SchemaDefinition = SchemaDefinition> = {
|
|
238
|
+
beforeMutation?: MutationHook<Schema>[];
|
|
239
|
+
afterMutation?: MutationHook<Schema>[];
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export type QueryDefinition<Handler = QueryHandler> = {
|
|
243
|
+
kind: "query";
|
|
244
|
+
handler: Handler;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export type MutationDefinition<Handler = MutationHandler> = {
|
|
248
|
+
kind: "mutation";
|
|
249
|
+
handler: Handler;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export type EndpointOptions = {
|
|
253
|
+
method: string;
|
|
254
|
+
path: string;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export type EndpointDefinition<Handler = EndpointHandler> = {
|
|
258
|
+
kind: "endpoint";
|
|
259
|
+
options: EndpointOptions;
|
|
260
|
+
handler: Handler;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export type MessageDefinition<Handler = MessageHandler> = {
|
|
264
|
+
kind: "message";
|
|
265
|
+
handler: Handler;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
export type CapsuleDefinition<Schema extends SchemaDefinition = SchemaDefinition> = {
|
|
269
|
+
name: string;
|
|
270
|
+
schema?: Schema;
|
|
271
|
+
queries?: Record<string, QueryDefinition<QueryHandler<Schema>>>;
|
|
272
|
+
mutations?: Record<string, MutationDefinition>;
|
|
273
|
+
endpoints?: Record<string, EndpointDefinition<EndpointHandler<Schema>>>;
|
|
274
|
+
messages?: Record<string, MessageDefinition<MessageHandler<Schema>>>;
|
|
275
|
+
middleware?: ContextMiddleware<Schema>[];
|
|
276
|
+
hooks?: CapsuleHooks<Schema>;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
export type Capsule<Definition extends object = CapsuleDefinition> = Definition & {
|
|
280
|
+
kind: "capsule";
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export function capsule<const Schema extends SchemaDefinition, const Definition extends CapsuleDefinition<Schema>>(
|
|
284
|
+
definition: Definition & { schema?: Schema },
|
|
285
|
+
): Capsule<Definition>;
|
|
286
|
+
|
|
287
|
+
export function endpoint<Handler extends EndpointHandler>(options: EndpointOptions, handler: Handler): EndpointDefinition<Handler>;
|
|
288
|
+
export function query<Handler extends QueryHandler>(handler: Handler): QueryDefinition<Handler>;
|
|
289
|
+
export function mutation<const Args extends unknown[] = string[], Result = unknown>(
|
|
290
|
+
handler: (ctx: CapsuleContext, ...args: Args) => MaybePromise<Result>,
|
|
291
|
+
): MutationDefinition<(ctx: CapsuleContext, ...args: Args) => MaybePromise<Result>>;
|
|
292
|
+
export function message<Handler extends MessageHandler>(handler: Handler): MessageDefinition<Handler>;
|
|
293
|
+
export function table<const Fields extends Record<string, AnyFieldDefinition>>(fields: Fields): TableDefinition<Fields>;
|
|
294
|
+
|
|
295
|
+
export function String(): FieldBuilder<string>;
|
|
296
|
+
export function Boolean(): FieldBuilder<boolean>;
|
|
297
|
+
export function Number(): FieldBuilder<number>;
|
|
298
|
+
export function Date(): FieldBuilder<string | globalThis.Date | null>;
|
|
299
|
+
export function Json<Value extends JsonValue = JsonValue>(): FieldBuilder<Value>;
|
|
300
|
+
export function Reference(targetTable: string): ReferenceFieldBuilder;
|