ignotum 0.0.6 → 0.0.8
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/README.md +85 -101
- package/dist/cli/bin.mjs +1487 -168
- package/dist/cli/bin.mjs.map +1 -1
- package/dist/runtime/{api-DtX8qPrq.js → api-BTeMI5tx.js} +27 -3
- package/dist/runtime/api-BTeMI5tx.js.map +1 -0
- package/dist/runtime/{api-D2bsAz4T.d.ts → api-D9lV-5av.d.ts} +7 -10
- package/dist/runtime/client.d.ts +27 -3
- package/dist/runtime/client.js +468 -68
- package/dist/runtime/client.js.map +1 -1
- package/dist/runtime/{descriptor-t6BOEGw9-BTHR-ZMv.js → descriptor-C5VA9qRl-C338iC6l.js} +63 -5
- package/dist/runtime/descriptor-C5VA9qRl-C338iC6l.js.map +1 -0
- package/dist/runtime/file-BXf63ulU.js +166 -0
- package/dist/runtime/file-BXf63ulU.js.map +1 -0
- package/dist/runtime/{result-BgcHn25t.d.ts → id-Btwac71X-DGj0DQuu.d.ts} +56 -4
- package/dist/runtime/{index-Dl_VQGmA.d.ts → index-CF04_Dps.d.ts} +96 -86
- package/dist/runtime/internal/api.d.ts +2 -2
- package/dist/runtime/internal/api.js +1 -1
- package/dist/runtime/internal/host.d.ts +25 -8
- package/dist/runtime/internal/host.js +209 -15
- package/dist/runtime/internal/host.js.map +1 -1
- package/dist/runtime/internal/server.d.ts +1 -1
- package/dist/runtime/internal/server.js +1 -1
- package/dist/runtime/internal/types.d.ts +1 -1
- package/dist/runtime/internal/types.js +1 -1
- package/dist/runtime/pagination-BNFhAjns.d.ts +1 -0
- package/dist/runtime/pagination-DrOowBve-Bnipd34u.d.ts +84 -0
- package/dist/runtime/{schema-B-jMZEbs.js → schema-DJfwfq87.js} +108 -30
- package/dist/runtime/schema-DJfwfq87.js.map +1 -0
- package/dist/runtime/server.d.ts +3 -3
- package/dist/runtime/server.js +2 -2
- package/dist/runtime/server.js.map +1 -1
- package/dist/runtime/sync-mIXn9eKv.d.ts +8 -0
- package/package.json +2 -2
- package/src/cli/agent-files.ts +56 -13
- package/src/cli/app-configuration.ts +4 -1
- package/src/cli/build/server.ts +83 -6
- package/src/cli/new-app.ts +15 -0
- package/src/client/files.ts +168 -0
- package/src/client/hooks.ts +166 -17
- package/src/client/index.ts +9 -1
- package/src/client/sync.ts +137 -21
- package/src/dev-runtime/database.ts +621 -78
- package/src/dev-runtime/files.ts +338 -0
- package/src/dev-runtime/functions.ts +14 -6
- package/src/dev-runtime/migrations.ts +44 -0
- package/src/dev-runtime/sync.ts +123 -5
- package/src/internal/api.ts +16 -1
- package/src/server/index.ts +8 -1
- package/dist/runtime/api-DtX8qPrq.js.map +0 -1
- package/dist/runtime/descriptor-t6BOEGw9-BTHR-ZMv.js.map +0 -1
- package/dist/runtime/id-Btwac71X-B9OeBzvq.d.ts +0 -9
- package/dist/runtime/id-D570vudg.js +0 -26
- package/dist/runtime/id-D570vudg.js.map +0 -1
- package/dist/runtime/schema-B-jMZEbs.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { i as getFunctionSchema, t as SchemaDefinitionTypeId } from "../schema-
|
|
4
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { g as runtimeFileOccurrencesOf, y as GeneratedId } from "../file-BXf63ulU.js";
|
|
2
|
+
import { _ as TransportValueSchema, a as PaginationCursor, f as documentNotFound, g as resultFromEffect, o as PaginationPageSize, u as ErrorValueSchema, v as datePathsOf, y as datePathsOfObject } from "../descriptor-C5VA9qRl-C338iC6l.js";
|
|
3
|
+
import { i as getFunctionSchema, t as SchemaDefinitionTypeId } from "../schema-DJfwfq87.js";
|
|
4
|
+
import { Effect, Predicate, Schema } from "effect";
|
|
5
5
|
//#region ../contracts/dist/runtime/host.js
|
|
6
6
|
const HostDocument = Schema.Struct({
|
|
7
7
|
id: GeneratedId,
|
|
@@ -13,6 +13,40 @@ const HostCollect = Schema.Struct({
|
|
|
13
13
|
type: Schema.Literal("Collect"),
|
|
14
14
|
table: Schema.String
|
|
15
15
|
});
|
|
16
|
+
const HostIndexComparison = Schema.Struct({
|
|
17
|
+
field: Schema.String,
|
|
18
|
+
value: Schema.Json
|
|
19
|
+
});
|
|
20
|
+
const HostIndexRange = Schema.Struct({
|
|
21
|
+
equal: Schema.Array(HostIndexComparison),
|
|
22
|
+
lower: Schema.optional(Schema.Struct({
|
|
23
|
+
...HostIndexComparison.fields,
|
|
24
|
+
inclusive: Schema.Boolean
|
|
25
|
+
})),
|
|
26
|
+
upper: Schema.optional(Schema.Struct({
|
|
27
|
+
...HostIndexComparison.fields,
|
|
28
|
+
inclusive: Schema.Boolean
|
|
29
|
+
}))
|
|
30
|
+
});
|
|
31
|
+
const HostQuery = Schema.Struct({
|
|
32
|
+
type: Schema.Literal("Query"),
|
|
33
|
+
table: Schema.String,
|
|
34
|
+
index: Schema.optional(Schema.String),
|
|
35
|
+
range: Schema.optional(HostIndexRange),
|
|
36
|
+
order: Schema.Literals(["Asc", "Desc"]),
|
|
37
|
+
limit: Schema.optional(Schema.Natural)
|
|
38
|
+
});
|
|
39
|
+
const HostPaginate = Schema.Struct({
|
|
40
|
+
type: Schema.Literal("Paginate"),
|
|
41
|
+
table: Schema.String,
|
|
42
|
+
index: Schema.optional(Schema.String),
|
|
43
|
+
range: Schema.optional(HostIndexRange),
|
|
44
|
+
order: Schema.Literals(["Asc", "Desc"]),
|
|
45
|
+
pagination: Schema.Struct({
|
|
46
|
+
cursor: Schema.NullOr(PaginationCursor),
|
|
47
|
+
pageSize: PaginationPageSize
|
|
48
|
+
})
|
|
49
|
+
});
|
|
16
50
|
const HostFind = Schema.Struct({
|
|
17
51
|
type: Schema.Literal("Find"),
|
|
18
52
|
table: Schema.String,
|
|
@@ -42,6 +76,8 @@ const HostReplace = Schema.Struct({
|
|
|
42
76
|
});
|
|
43
77
|
const QuickJsHostRequest = Schema.Union([
|
|
44
78
|
HostCollect,
|
|
79
|
+
HostQuery,
|
|
80
|
+
HostPaginate,
|
|
45
81
|
HostFind,
|
|
46
82
|
HostInsert,
|
|
47
83
|
HostDelete,
|
|
@@ -52,6 +88,11 @@ const HostDocuments = Schema.Struct({
|
|
|
52
88
|
type: Schema.Literal("Documents"),
|
|
53
89
|
documents: Schema.Array(HostDocument)
|
|
54
90
|
});
|
|
91
|
+
const HostPage = Schema.Struct({
|
|
92
|
+
type: Schema.Literal("Page"),
|
|
93
|
+
documents: Schema.Array(HostDocument),
|
|
94
|
+
nextCursor: Schema.NullOr(PaginationCursor)
|
|
95
|
+
});
|
|
55
96
|
const HostFound = Schema.Struct({
|
|
56
97
|
type: Schema.Literal("Found"),
|
|
57
98
|
document: Schema.NullOr(HostDocument)
|
|
@@ -60,9 +101,13 @@ const HostInserted = Schema.Struct({
|
|
|
60
101
|
type: Schema.Literal("Inserted"),
|
|
61
102
|
id: GeneratedId
|
|
62
103
|
});
|
|
63
|
-
const HostCompleted = Schema.Struct({
|
|
104
|
+
const HostCompleted = Schema.Struct({
|
|
105
|
+
type: Schema.Literal("Completed"),
|
|
106
|
+
found: Schema.Boolean
|
|
107
|
+
});
|
|
64
108
|
Schema.Union([
|
|
65
109
|
HostDocuments,
|
|
110
|
+
HostPage,
|
|
66
111
|
HostFound,
|
|
67
112
|
HostInserted,
|
|
68
113
|
HostCompleted
|
|
@@ -71,6 +116,7 @@ Schema.Union([
|
|
|
71
116
|
//#region ../runtime/dist/guest.js
|
|
72
117
|
const decodeHostResponse = Schema.decodeEffect(Schema.fromJsonString(Schema.Union([
|
|
73
118
|
HostDocuments,
|
|
119
|
+
HostPage,
|
|
74
120
|
HostFound,
|
|
75
121
|
HostInserted,
|
|
76
122
|
HostCompleted
|
|
@@ -119,21 +165,163 @@ const makeReader = (schema, call) => {
|
|
|
119
165
|
table,
|
|
120
166
|
id: GeneratedId.make(id)
|
|
121
167
|
}).pipe(Effect.map((response) => expectResponse(response, "Found")), Effect.map(({ document }) => document === null ? void 0 : decodeDocument(schema, table, document)));
|
|
168
|
+
const query = (table, selectedIndex, selectedRange, order = "Asc") => {
|
|
169
|
+
const definition = tableFor(schema, table);
|
|
170
|
+
const encodeIndexValue = (field, value) => {
|
|
171
|
+
const codec = field === "createdAt" ? Schema.DateFromMillis : field === "id" ? GeneratedId : definition.fields[field];
|
|
172
|
+
if (codec === void 0) throw new Error(`Unknown index field '${field}'.`);
|
|
173
|
+
return Schema.decodeUnknownSync(Schema.Json)(Schema.encodeUnknownSync(guestCodec(codec))(value));
|
|
174
|
+
};
|
|
175
|
+
const execute = (limit) => {
|
|
176
|
+
const request = selectedIndex === void 0 ? {
|
|
177
|
+
type: "Query",
|
|
178
|
+
table,
|
|
179
|
+
order
|
|
180
|
+
} : selectedRange === void 0 ? {
|
|
181
|
+
type: "Query",
|
|
182
|
+
table,
|
|
183
|
+
index: selectedIndex,
|
|
184
|
+
order
|
|
185
|
+
} : {
|
|
186
|
+
type: "Query",
|
|
187
|
+
table,
|
|
188
|
+
index: selectedIndex,
|
|
189
|
+
range: selectedRange,
|
|
190
|
+
order
|
|
191
|
+
};
|
|
192
|
+
return callHost(call, limit === void 0 ? request : {
|
|
193
|
+
...request,
|
|
194
|
+
limit
|
|
195
|
+
}).pipe(Effect.map((response) => expectResponse(response, "Documents")), Effect.map(({ documents }) => documents.map((document) => decodeDocument(schema, table, document))));
|
|
196
|
+
};
|
|
197
|
+
const executePage = (pagination) => {
|
|
198
|
+
return callHost(call, selectedIndex === void 0 ? {
|
|
199
|
+
type: "Paginate",
|
|
200
|
+
table,
|
|
201
|
+
order,
|
|
202
|
+
pagination
|
|
203
|
+
} : selectedRange === void 0 ? {
|
|
204
|
+
type: "Paginate",
|
|
205
|
+
table,
|
|
206
|
+
index: selectedIndex,
|
|
207
|
+
order,
|
|
208
|
+
pagination
|
|
209
|
+
} : {
|
|
210
|
+
type: "Paginate",
|
|
211
|
+
table,
|
|
212
|
+
index: selectedIndex,
|
|
213
|
+
range: selectedRange,
|
|
214
|
+
order,
|
|
215
|
+
pagination
|
|
216
|
+
}).pipe(Effect.map((response) => expectResponse(response, "Page")), Effect.map(({ documents, nextCursor }) => ({
|
|
217
|
+
items: documents.map((document) => decodeDocument(schema, table, document)),
|
|
218
|
+
nextCursor
|
|
219
|
+
})));
|
|
220
|
+
};
|
|
221
|
+
const validateLimit = (count) => {
|
|
222
|
+
if (!Number.isInteger(count) || count < 0 || count > 1e3) throw new Error("Query limits must be integers between 0 and 1000.");
|
|
223
|
+
return count;
|
|
224
|
+
};
|
|
225
|
+
return Object.freeze({
|
|
226
|
+
index: (name, buildRange) => {
|
|
227
|
+
if (selectedIndex !== void 0) throw new Error("A query can select only one index.");
|
|
228
|
+
const index = definition.indexes[name];
|
|
229
|
+
if (index === void 0) throw new Error(`Unknown index '${name}' on table '${table}'.`);
|
|
230
|
+
if (buildRange === void 0) return query(table, name, void 0, order);
|
|
231
|
+
const fields = [
|
|
232
|
+
...index.fields,
|
|
233
|
+
"createdAt",
|
|
234
|
+
"id"
|
|
235
|
+
];
|
|
236
|
+
const range = { equal: [] };
|
|
237
|
+
let position = 0;
|
|
238
|
+
let boundedField;
|
|
239
|
+
const expectField = (field) => {
|
|
240
|
+
const expected = fields[position];
|
|
241
|
+
if (field !== expected) throw new Error(`Expected index field '${expected}', received '${field}'.`);
|
|
242
|
+
};
|
|
243
|
+
const builder = {
|
|
244
|
+
eq: (field, value) => {
|
|
245
|
+
if (boundedField !== void 0) throw new Error("Equality cannot follow an index bound.");
|
|
246
|
+
expectField(field);
|
|
247
|
+
range.equal.push({
|
|
248
|
+
field,
|
|
249
|
+
value: encodeIndexValue(field, value)
|
|
250
|
+
});
|
|
251
|
+
position += 1;
|
|
252
|
+
return builder;
|
|
253
|
+
},
|
|
254
|
+
gt: (field, value) => {
|
|
255
|
+
expectField(field);
|
|
256
|
+
if (range.lower !== void 0) throw new Error("An index range has only one lower bound.");
|
|
257
|
+
boundedField = field;
|
|
258
|
+
range.lower = {
|
|
259
|
+
field,
|
|
260
|
+
value: encodeIndexValue(field, value),
|
|
261
|
+
inclusive: false
|
|
262
|
+
};
|
|
263
|
+
return builder;
|
|
264
|
+
},
|
|
265
|
+
gte: (field, value) => {
|
|
266
|
+
expectField(field);
|
|
267
|
+
if (range.lower !== void 0) throw new Error("An index range has only one lower bound.");
|
|
268
|
+
boundedField = field;
|
|
269
|
+
range.lower = {
|
|
270
|
+
field,
|
|
271
|
+
value: encodeIndexValue(field, value),
|
|
272
|
+
inclusive: true
|
|
273
|
+
};
|
|
274
|
+
return builder;
|
|
275
|
+
},
|
|
276
|
+
lt: (field, value) => {
|
|
277
|
+
expectField(field);
|
|
278
|
+
if (range.upper !== void 0) throw new Error("An index range has only one upper bound.");
|
|
279
|
+
boundedField = field;
|
|
280
|
+
range.upper = {
|
|
281
|
+
field,
|
|
282
|
+
value: encodeIndexValue(field, value),
|
|
283
|
+
inclusive: false
|
|
284
|
+
};
|
|
285
|
+
return builder;
|
|
286
|
+
},
|
|
287
|
+
lte: (field, value) => {
|
|
288
|
+
expectField(field);
|
|
289
|
+
if (range.upper !== void 0) throw new Error("An index range has only one upper bound.");
|
|
290
|
+
boundedField = field;
|
|
291
|
+
range.upper = {
|
|
292
|
+
field,
|
|
293
|
+
value: encodeIndexValue(field, value),
|
|
294
|
+
inclusive: true
|
|
295
|
+
};
|
|
296
|
+
return builder;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const built = buildRange(builder);
|
|
300
|
+
if (!Predicate.isObject(built)) throw new Error("An index range callback must return its builder.");
|
|
301
|
+
return query(table, name, range, order);
|
|
302
|
+
},
|
|
303
|
+
order: (direction) => query(table, selectedIndex, selectedRange, direction === "asc" ? "Asc" : "Desc"),
|
|
304
|
+
collect: () => resultFromEffect(execute()),
|
|
305
|
+
take: (count) => resultFromEffect(execute(validateLimit(count))),
|
|
306
|
+
first: () => resultFromEffect(execute(1).pipe(Effect.map((documents) => documents[0]))),
|
|
307
|
+
unique: () => resultFromEffect(execute(2).pipe(Effect.flatMap((documents) => documents.length > 1 ? Effect.die(/* @__PURE__ */ new Error("A unique database query matched more than one document.")) : Effect.succeed(documents[0])))),
|
|
308
|
+
paginate: (options) => resultFromEffect(executePage(options))
|
|
309
|
+
});
|
|
310
|
+
};
|
|
122
311
|
return Object.freeze({
|
|
123
312
|
find: (table, id) => resultFromEffect(findEffect(table, id)),
|
|
124
313
|
get: (table, id) => resultFromEffect(findEffect(table, id).pipe(Effect.flatMap((document) => document === void 0 ? Effect.fail(documentNotFound(table, id)) : Effect.succeed(document)))),
|
|
125
|
-
query: (table) => (
|
|
126
|
-
type: "Collect",
|
|
127
|
-
table
|
|
128
|
-
}).pipe(Effect.map((response) => expectResponse(response, "Documents")), Effect.map(({ documents }) => documents.map((document) => decodeDocument(schema, table, document))))) })
|
|
314
|
+
query: (table) => query(table)
|
|
129
315
|
});
|
|
130
316
|
};
|
|
131
317
|
const makeWriter = (schema, call) => {
|
|
132
318
|
const reader = makeReader(schema, call);
|
|
133
|
-
const complete =
|
|
319
|
+
const complete = Effect.fn("Guest.completeWrite")(function* (table, id, request) {
|
|
320
|
+
if (expectResponse(yield* callHost(call, request), "Completed").found === false) return yield* Effect.fail(documentNotFound(table, id));
|
|
321
|
+
});
|
|
134
322
|
const writer = {
|
|
135
323
|
...reader,
|
|
136
|
-
delete: (table, id) => resultFromEffect(complete({
|
|
324
|
+
delete: (table, id) => resultFromEffect(complete(table, id, {
|
|
137
325
|
type: "Delete",
|
|
138
326
|
table,
|
|
139
327
|
id: GeneratedId.make(id)
|
|
@@ -143,13 +331,13 @@ const makeWriter = (schema, call) => {
|
|
|
143
331
|
table,
|
|
144
332
|
fields: encodeFields(schema, table, value)
|
|
145
333
|
}).pipe(Effect.map((response) => expectResponse(response, "Inserted").id))),
|
|
146
|
-
patch: (table, id, value) => resultFromEffect(complete({
|
|
334
|
+
patch: (table, id, value) => resultFromEffect(complete(table, id, {
|
|
147
335
|
type: "Patch",
|
|
148
336
|
table,
|
|
149
337
|
id: GeneratedId.make(id),
|
|
150
338
|
fields: encodePatchFields(schema, table, value)
|
|
151
339
|
})),
|
|
152
|
-
replace: (table, id, value) => resultFromEffect(complete({
|
|
340
|
+
replace: (table, id, value) => resultFromEffect(complete(table, id, {
|
|
153
341
|
type: "Replace",
|
|
154
342
|
table,
|
|
155
343
|
id: GeneratedId.make(id),
|
|
@@ -163,9 +351,15 @@ const encodeSuccess = Effect.fn("Guest.encodeSuccess")(function* (definition, va
|
|
|
163
351
|
yield* Schema.encodeUnknownEffect(Schema.Undefined)(value);
|
|
164
352
|
return { type: "Success" };
|
|
165
353
|
}
|
|
166
|
-
const
|
|
354
|
+
const encoded = yield* Schema.encodeUnknownEffect(Schema.toCodecJson(definition.returns))(value);
|
|
355
|
+
const files = runtimeFileOccurrencesOf(value);
|
|
356
|
+
const result = files.length === 0 ? {
|
|
357
|
+
type: "Success",
|
|
358
|
+
value: encoded
|
|
359
|
+
} : {
|
|
167
360
|
type: "Success",
|
|
168
|
-
value:
|
|
361
|
+
value: encoded,
|
|
362
|
+
files
|
|
169
363
|
};
|
|
170
364
|
const dates = datePathsOf(value);
|
|
171
365
|
return dates.length === 0 ? result : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":[],"sources":["../../../../contracts/dist/runtime/host.js","../../../../runtime/dist/guest.js"],"sourcesContent":["import { GeneratedId } from \"./id.js\";\nimport { Schema } from \"effect\";\n//#region src/runtime/host.ts\nconst HostDocument = Schema.Struct({\n\tid: GeneratedId,\n\tcreatedAt: Schema.Int,\n\tupdatedAt: Schema.Int,\n\tfields: Schema.JsonObject\n});\nconst HostCollect = Schema.Struct({\n\ttype: Schema.Literal(\"Collect\"),\n\ttable: Schema.String\n});\nconst HostFind = Schema.Struct({\n\ttype: Schema.Literal(\"Find\"),\n\ttable: Schema.String,\n\tid: GeneratedId\n});\nconst HostInsert = Schema.Struct({\n\ttype: Schema.Literal(\"Insert\"),\n\ttable: Schema.String,\n\tfields: Schema.JsonObject\n});\nconst HostDelete = Schema.Struct({\n\ttype: Schema.Literal(\"Delete\"),\n\ttable: Schema.String,\n\tid: GeneratedId\n});\nconst HostPatch = Schema.Struct({\n\ttype: Schema.Literal(\"Patch\"),\n\ttable: Schema.String,\n\tid: GeneratedId,\n\tfields: Schema.JsonObject\n});\nconst HostReplace = Schema.Struct({\n\ttype: Schema.Literal(\"Replace\"),\n\ttable: Schema.String,\n\tid: GeneratedId,\n\tfields: Schema.JsonObject\n});\nconst QuickJsHostRequest = Schema.Union([\n\tHostCollect,\n\tHostFind,\n\tHostInsert,\n\tHostDelete,\n\tHostPatch,\n\tHostReplace\n]);\nconst HostDocuments = Schema.Struct({\n\ttype: Schema.Literal(\"Documents\"),\n\tdocuments: Schema.Array(HostDocument)\n});\nconst HostFound = Schema.Struct({\n\ttype: Schema.Literal(\"Found\"),\n\tdocument: Schema.NullOr(HostDocument)\n});\nconst HostInserted = Schema.Struct({\n\ttype: Schema.Literal(\"Inserted\"),\n\tid: GeneratedId\n});\nconst HostCompleted = Schema.Struct({ type: Schema.Literal(\"Completed\") });\nconst QuickJsHostResponse = Schema.Union([\n\tHostDocuments,\n\tHostFound,\n\tHostInserted,\n\tHostCompleted\n]);\n//#endregion\nexport { HostCollect, HostCompleted, HostDelete, HostDocument, HostDocuments, HostFind, HostFound, HostInsert, HostInserted, HostPatch, HostReplace, QuickJsHostRequest, QuickJsHostResponse };\n\n//# sourceMappingURL=host.js.map","import { HostCompleted, HostDocuments, HostFound, HostInserted, QuickJsHostRequest } from \"@ignotum/contracts/runtime/host\";\nimport { GeneratedId } from \"@ignotum/contracts/runtime/id\";\nimport { Effect, Schema } from \"effect\";\nimport { ErrorValueSchema, documentNotFound, resultFromEffect } from \"@ignotum/contracts/runtime/result\";\nimport { getFunctionSchema } from \"@ignotum/contracts/runtime/schema\";\nimport { TransportValueSchema, datePathsOf, datePathsOfObject } from \"@ignotum/contracts/runtime/value\";\nimport { SchemaDefinitionTypeId } from \"@ignotum/contracts/schema\";\n//#region src/guest.ts\nconst decodeHostResponse = Schema.decodeEffect(Schema.fromJsonString(Schema.Union([\n\tHostDocuments,\n\tHostFound,\n\tHostInserted,\n\tHostCompleted\n])));\nconst encodeHostRequest = Schema.encodeSync(Schema.fromJsonString(QuickJsHostRequest));\nconst callHost = Effect.fn(\"Guest.callHost\")(function* (call, request) {\n\treturn yield* Effect.tryPromise(() => call(encodeHostRequest(request))).pipe(Effect.flatMap(decodeHostResponse), Effect.orDie);\n});\nconst tableFor = (schema, table) => {\n\tconst definition = schema[SchemaDefinitionTypeId][table];\n\tif (definition === void 0) throw new Error(`Unknown database table '${table}'.`);\n\treturn definition;\n};\nconst guestCodec = (schema) => schema;\nconst encodeFields = (schema, table, fields) => {\n\tconst definition = tableFor(schema, table);\n\treturn Schema.decodeUnknownSync(Schema.JsonObject)(Schema.encodeUnknownSync(Schema.toCodecJson(guestCodec(definition.schema)), { onExcessProperty: \"error\" })(fields));\n};\nconst encodePatchFields = (schema, table, fields) => {\n\tconst definition = tableFor(schema, table);\n\treturn Schema.decodeSync(Schema.JsonObject)(Object.fromEntries(Object.entries(fields).map(([name, value]) => {\n\t\tconst field = definition.fields[name];\n\t\tif (field === void 0) throw new Error(`Unknown field '${name}' on table '${table}'.`);\n\t\treturn [name, Schema.encodeUnknownSync(Schema.toCodecJson(guestCodec(field)))(value)];\n\t})));\n};\nconst documentCodec = (schema, table) => guestCodec(Schema.Struct({\n\t...tableFor(schema, table).fields,\n\tid: Schema.String,\n\tcreatedAt: Schema.DateFromMillis,\n\tupdatedAt: Schema.DateFromMillis\n}));\nconst decodeDocument = (schema, table, document) => Schema.decodeUnknownSync(Schema.Record(Schema.String, Schema.UndefinedOr(TransportValueSchema)))(Schema.decodeSync(Schema.toCodecJson(documentCodec(schema, table)))({\n\t...document.fields,\n\tid: document.id,\n\tcreatedAt: document.createdAt,\n\tupdatedAt: document.updatedAt\n}));\nconst expectResponse = (response, tag) => {\n\tif (response.type !== tag) throw new Error(`Unexpected host response '${response.type}'.`);\n\treturn response;\n};\nconst makeReader = (schema, call) => {\n\tconst findEffect = (table, id) => callHost(call, {\n\t\ttype: \"Find\",\n\t\ttable,\n\t\tid: GeneratedId.make(id)\n\t}).pipe(Effect.map((response) => expectResponse(response, \"Found\")), Effect.map(({ document }) => document === null ? void 0 : decodeDocument(schema, table, document)));\n\treturn Object.freeze({\n\t\tfind: (table, id) => resultFromEffect(findEffect(table, id)),\n\t\tget: (table, id) => resultFromEffect(findEffect(table, id).pipe(Effect.flatMap((document) => document === void 0 ? Effect.fail(documentNotFound(table, id)) : Effect.succeed(document)))),\n\t\tquery: (table) => ({ collect: () => resultFromEffect(callHost(call, {\n\t\t\ttype: \"Collect\",\n\t\t\ttable\n\t\t}).pipe(Effect.map((response) => expectResponse(response, \"Documents\")), Effect.map(({ documents }) => documents.map((document) => decodeDocument(schema, table, document))))) })\n\t});\n};\nconst makeWriter = (schema, call) => {\n\tconst reader = makeReader(schema, call);\n\tconst complete = (request) => callHost(call, request).pipe(Effect.map((response) => expectResponse(response, \"Completed\")), Effect.asVoid);\n\tconst writer = {\n\t\t...reader,\n\t\tdelete: (table, id) => resultFromEffect(complete({\n\t\t\ttype: \"Delete\",\n\t\t\ttable,\n\t\t\tid: GeneratedId.make(id)\n\t\t})),\n\t\tinsert: (table, value) => resultFromEffect(callHost(call, {\n\t\t\ttype: \"Insert\",\n\t\t\ttable,\n\t\t\tfields: encodeFields(schema, table, value)\n\t\t}).pipe(Effect.map((response) => expectResponse(response, \"Inserted\").id))),\n\t\tpatch: (table, id, value) => resultFromEffect(complete({\n\t\t\ttype: \"Patch\",\n\t\t\ttable,\n\t\t\tid: GeneratedId.make(id),\n\t\t\tfields: encodePatchFields(schema, table, value)\n\t\t})),\n\t\treplace: (table, id, value) => resultFromEffect(complete({\n\t\t\ttype: \"Replace\",\n\t\t\ttable,\n\t\t\tid: GeneratedId.make(id),\n\t\t\tfields: encodeFields(schema, table, value)\n\t\t}))\n\t};\n\treturn Object.freeze(writer);\n};\nconst encodeSuccess = Effect.fn(\"Guest.encodeSuccess\")(function* (definition, value) {\n\tif (definition.returns === void 0) {\n\t\tyield* Schema.encodeUnknownEffect(Schema.Undefined)(value);\n\t\treturn { type: \"Success\" };\n\t}\n\tconst result = {\n\t\ttype: \"Success\",\n\t\tvalue: yield* Schema.encodeUnknownEffect(Schema.toCodecJson(definition.returns))(value)\n\t};\n\tconst dates = datePathsOf(value);\n\treturn dates.length === 0 ? result : {\n\t\t...result,\n\t\tdates\n\t};\n});\nconst encodeFailure = Effect.fn(\"Guest.encodeFailure\")(function* (definition, error) {\n\tconst result = {\n\t\ttype: \"Failure\",\n\t\terror: yield* Schema.encodeUnknownEffect(Schema.toCodecJson(definition.errors ?? ErrorValueSchema))(error)\n\t};\n\tconst dates = datePathsOfObject(error);\n\treturn dates.length === 0 ? result : {\n\t\t...result,\n\t\tdates\n\t};\n});\nconst runGuest = Effect.fn(\"Guest.invoke\")(function* (definition, encodedArgs, call) {\n\tconst schema = getFunctionSchema(definition);\n\tif (schema === void 0) return yield* Effect.die(\"The function has no bound schema.\");\n\tconst decodedArgs = yield* Schema.decodeEffect(Schema.toCodecJson(guestCodec(Schema.Struct(definition.args ?? {}))))(encodedArgs).pipe(Effect.match({\n\t\tonFailure: () => ({ valid: false }),\n\t\tonSuccess: (value) => ({\n\t\t\tvalid: true,\n\t\t\tvalue\n\t\t})\n\t}));\n\tif (!decodedArgs.valid) return {\n\t\ttype: \"InvocationRejected\",\n\t\tcode: \"InvalidArguments\",\n\t\tmessage: \"The invocation arguments do not match the function definition.\"\n\t};\n\tconst args = yield* Schema.decodeUnknownEffect(Schema.ObjectKeyword)(decodedArgs.value);\n\tconst context = Object.freeze({ db: definition._tag === \"Query\" ? makeReader(schema, call) : makeWriter(schema, call) });\n\treturn yield* Effect.gen(() => definition.handler(context, args)).pipe(Effect.matchEffect({\n\t\tonFailure: (error) => encodeFailure(definition, error),\n\t\tonSuccess: (value) => encodeSuccess(definition, value)\n\t}));\n});\nconst invoke = (definition, encodedArgs, call) => Effect.runPromise(runGuest(definition, encodedArgs, call)).then((result) => Schema.encodeSync(Schema.fromJsonString(Schema.Json))(result));\n//#endregion\nexport { invoke };\n\n//# sourceMappingURL=guest.js.map"],"mappings":";;;;;AAGA,MAAM,eAAe,OAAO,OAAO;CAClC,IAAI;CACJ,WAAW,OAAO;CAClB,WAAW,OAAO;CAClB,QAAQ,OAAO;AAChB,CAAC;AACD,MAAM,cAAc,OAAO,OAAO;CACjC,MAAM,OAAO,QAAQ,SAAS;CAC9B,OAAO,OAAO;AACf,CAAC;AACD,MAAM,WAAW,OAAO,OAAO;CAC9B,MAAM,OAAO,QAAQ,MAAM;CAC3B,OAAO,OAAO;CACd,IAAI;AACL,CAAC;AACD,MAAM,aAAa,OAAO,OAAO;CAChC,MAAM,OAAO,QAAQ,QAAQ;CAC7B,OAAO,OAAO;CACd,QAAQ,OAAO;AAChB,CAAC;AACD,MAAM,aAAa,OAAO,OAAO;CAChC,MAAM,OAAO,QAAQ,QAAQ;CAC7B,OAAO,OAAO;CACd,IAAI;AACL,CAAC;AACD,MAAM,YAAY,OAAO,OAAO;CAC/B,MAAM,OAAO,QAAQ,OAAO;CAC5B,OAAO,OAAO;CACd,IAAI;CACJ,QAAQ,OAAO;AAChB,CAAC;AACD,MAAM,cAAc,OAAO,OAAO;CACjC,MAAM,OAAO,QAAQ,SAAS;CAC9B,OAAO,OAAO;CACd,IAAI;CACJ,QAAQ,OAAO;AAChB,CAAC;AACD,MAAM,qBAAqB,OAAO,MAAM;CACvC;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;AACD,MAAM,gBAAgB,OAAO,OAAO;CACnC,MAAM,OAAO,QAAQ,WAAW;CAChC,WAAW,OAAO,MAAM,YAAY;AACrC,CAAC;AACD,MAAM,YAAY,OAAO,OAAO;CAC/B,MAAM,OAAO,QAAQ,OAAO;CAC5B,UAAU,OAAO,OAAO,YAAY;AACrC,CAAC;AACD,MAAM,eAAe,OAAO,OAAO;CAClC,MAAM,OAAO,QAAQ,UAAU;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AAS,UAAU,WAAW,QAAQ,IAAI,IAAI,WAAW,QAAQ,IAAI,EAAE,CAAC;CACvH,OAAO,OAAO,OAAO,UAAU,WAAW,QAAQ,SAAS,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,YAAY;EACzF,YAAY,UAAU,cAAc,YAAY,KAAK;EACrD,YAAY,UAAU,cAAc,YAAY,KAAK;CACtD,CAAC,CAAC;AACH,CAAC;AACD,MAAM,UAAU,YAAY,aAAa,SAAS,OAAO,WAAW,SAAS,YAAY,aAAa,IAAI,CAAC,CAAC,CAAC,MAAM,WAAW,OAAO,WAAW,OAAO,eAAe,OAAO,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../../../../contracts/dist/runtime/host.js","../../../../runtime/dist/guest.js"],"sourcesContent":["import { GeneratedId } from \"./id.js\";\nimport { PaginationCursor, PaginationPageSize } from \"./pagination.js\";\nimport { Schema } from \"effect\";\n//#region src/runtime/host.ts\nconst HostDocument = Schema.Struct({\n\tid: GeneratedId,\n\tcreatedAt: Schema.Int,\n\tupdatedAt: Schema.Int,\n\tfields: Schema.JsonObject\n});\nconst HostCollect = Schema.Struct({\n\ttype: Schema.Literal(\"Collect\"),\n\ttable: Schema.String\n});\nconst HostIndexComparison = Schema.Struct({\n\tfield: Schema.String,\n\tvalue: Schema.Json\n});\nconst HostIndexRange = Schema.Struct({\n\tequal: Schema.Array(HostIndexComparison),\n\tlower: Schema.optional(Schema.Struct({\n\t\t...HostIndexComparison.fields,\n\t\tinclusive: Schema.Boolean\n\t})),\n\tupper: Schema.optional(Schema.Struct({\n\t\t...HostIndexComparison.fields,\n\t\tinclusive: Schema.Boolean\n\t}))\n});\nconst HostQuery = Schema.Struct({\n\ttype: Schema.Literal(\"Query\"),\n\ttable: Schema.String,\n\tindex: Schema.optional(Schema.String),\n\trange: Schema.optional(HostIndexRange),\n\torder: Schema.Literals([\"Asc\", \"Desc\"]),\n\tlimit: Schema.optional(Schema.Natural)\n});\nconst HostPaginate = Schema.Struct({\n\ttype: Schema.Literal(\"Paginate\"),\n\ttable: Schema.String,\n\tindex: Schema.optional(Schema.String),\n\trange: Schema.optional(HostIndexRange),\n\torder: Schema.Literals([\"Asc\", \"Desc\"]),\n\tpagination: Schema.Struct({\n\t\tcursor: Schema.NullOr(PaginationCursor),\n\t\tpageSize: PaginationPageSize\n\t})\n});\nconst HostFind = Schema.Struct({\n\ttype: Schema.Literal(\"Find\"),\n\ttable: Schema.String,\n\tid: GeneratedId\n});\nconst HostInsert = Schema.Struct({\n\ttype: Schema.Literal(\"Insert\"),\n\ttable: Schema.String,\n\tfields: Schema.JsonObject\n});\nconst HostDelete = Schema.Struct({\n\ttype: Schema.Literal(\"Delete\"),\n\ttable: Schema.String,\n\tid: GeneratedId\n});\nconst HostPatch = Schema.Struct({\n\ttype: Schema.Literal(\"Patch\"),\n\ttable: Schema.String,\n\tid: GeneratedId,\n\tfields: Schema.JsonObject\n});\nconst HostReplace = Schema.Struct({\n\ttype: Schema.Literal(\"Replace\"),\n\ttable: Schema.String,\n\tid: GeneratedId,\n\tfields: Schema.JsonObject\n});\nconst QuickJsHostRequest = Schema.Union([\n\tHostCollect,\n\tHostQuery,\n\tHostPaginate,\n\tHostFind,\n\tHostInsert,\n\tHostDelete,\n\tHostPatch,\n\tHostReplace\n]);\nconst HostDocuments = Schema.Struct({\n\ttype: Schema.Literal(\"Documents\"),\n\tdocuments: Schema.Array(HostDocument)\n});\nconst HostPage = Schema.Struct({\n\ttype: Schema.Literal(\"Page\"),\n\tdocuments: Schema.Array(HostDocument),\n\tnextCursor: Schema.NullOr(PaginationCursor)\n});\nconst HostFound = Schema.Struct({\n\ttype: Schema.Literal(\"Found\"),\n\tdocument: Schema.NullOr(HostDocument)\n});\nconst HostInserted = Schema.Struct({\n\ttype: Schema.Literal(\"Inserted\"),\n\tid: GeneratedId\n});\nconst HostCompleted = Schema.Struct({\n\ttype: Schema.Literal(\"Completed\"),\n\tfound: Schema.Boolean\n});\nconst QuickJsHostResponse = Schema.Union([\n\tHostDocuments,\n\tHostPage,\n\tHostFound,\n\tHostInserted,\n\tHostCompleted\n]);\n//#endregion\nexport { HostCollect, HostCompleted, HostDelete, HostDocument, HostDocuments, HostFind, HostFound, HostIndexComparison, HostIndexRange, HostInsert, HostInserted, HostPage, HostPaginate, HostPatch, HostQuery, HostReplace, QuickJsHostRequest, QuickJsHostResponse };\n\n//# sourceMappingURL=host.js.map","import { HostCompleted, HostDocuments, HostFound, HostInserted, HostPage, QuickJsHostRequest } from \"@ignotum/contracts/runtime/host\";\nimport { runtimeFileOccurrencesOf } from \"@ignotum/contracts/schema/file\";\nimport { GeneratedId } from \"@ignotum/contracts/runtime/id\";\nimport { Effect, Predicate, Schema } from \"effect\";\nimport { ErrorValueSchema, documentNotFound, resultFromEffect } from \"@ignotum/contracts/runtime/result\";\nimport { getFunctionSchema } from \"@ignotum/contracts/runtime/schema\";\nimport { TransportValueSchema, datePathsOf, datePathsOfObject } from \"@ignotum/contracts/runtime/value\";\nimport { SchemaDefinitionTypeId } from \"@ignotum/contracts/schema\";\n//#region src/guest.ts\nconst decodeHostResponse = Schema.decodeEffect(Schema.fromJsonString(Schema.Union([\n\tHostDocuments,\n\tHostPage,\n\tHostFound,\n\tHostInserted,\n\tHostCompleted\n])));\nconst encodeHostRequest = Schema.encodeSync(Schema.fromJsonString(QuickJsHostRequest));\nconst callHost = Effect.fn(\"Guest.callHost\")(function* (call, request) {\n\treturn yield* Effect.tryPromise(() => call(encodeHostRequest(request))).pipe(Effect.flatMap(decodeHostResponse), Effect.orDie);\n});\nconst tableFor = (schema, table) => {\n\tconst definition = schema[SchemaDefinitionTypeId][table];\n\tif (definition === void 0) throw new Error(`Unknown database table '${table}'.`);\n\treturn definition;\n};\nconst guestCodec = (schema) => schema;\nconst encodeFields = (schema, table, fields) => {\n\tconst definition = tableFor(schema, table);\n\treturn Schema.decodeUnknownSync(Schema.JsonObject)(Schema.encodeUnknownSync(Schema.toCodecJson(guestCodec(definition.schema)), { onExcessProperty: \"error\" })(fields));\n};\nconst encodePatchFields = (schema, table, fields) => {\n\tconst definition = tableFor(schema, table);\n\treturn Schema.decodeSync(Schema.JsonObject)(Object.fromEntries(Object.entries(fields).map(([name, value]) => {\n\t\tconst field = definition.fields[name];\n\t\tif (field === void 0) throw new Error(`Unknown field '${name}' on table '${table}'.`);\n\t\treturn [name, Schema.encodeUnknownSync(Schema.toCodecJson(guestCodec(field)))(value)];\n\t})));\n};\nconst documentCodec = (schema, table) => guestCodec(Schema.Struct({\n\t...tableFor(schema, table).fields,\n\tid: Schema.String,\n\tcreatedAt: Schema.DateFromMillis,\n\tupdatedAt: Schema.DateFromMillis\n}));\nconst decodeDocument = (schema, table, document) => Schema.decodeUnknownSync(Schema.Record(Schema.String, Schema.UndefinedOr(TransportValueSchema)))(Schema.decodeSync(Schema.toCodecJson(documentCodec(schema, table)))({\n\t...document.fields,\n\tid: document.id,\n\tcreatedAt: document.createdAt,\n\tupdatedAt: document.updatedAt\n}));\nconst expectResponse = (response, tag) => {\n\tif (response.type !== tag) throw new Error(`Unexpected host response '${response.type}'.`);\n\treturn response;\n};\nconst makeReader = (schema, call) => {\n\tconst findEffect = (table, id) => callHost(call, {\n\t\ttype: \"Find\",\n\t\ttable,\n\t\tid: GeneratedId.make(id)\n\t}).pipe(Effect.map((response) => expectResponse(response, \"Found\")), Effect.map(({ document }) => document === null ? void 0 : decodeDocument(schema, table, document)));\n\tconst query = (table, selectedIndex, selectedRange, order = \"Asc\") => {\n\t\tconst definition = tableFor(schema, table);\n\t\tconst encodeIndexValue = (field, value) => {\n\t\t\tconst codec = field === \"createdAt\" ? Schema.DateFromMillis : field === \"id\" ? GeneratedId : definition.fields[field];\n\t\t\tif (codec === void 0) throw new Error(`Unknown index field '${field}'.`);\n\t\t\treturn Schema.decodeUnknownSync(Schema.Json)(Schema.encodeUnknownSync(guestCodec(codec))(value));\n\t\t};\n\t\tconst execute = (limit) => {\n\t\t\tconst request = selectedIndex === void 0 ? {\n\t\t\t\ttype: \"Query\",\n\t\t\t\ttable,\n\t\t\t\torder\n\t\t\t} : selectedRange === void 0 ? {\n\t\t\t\ttype: \"Query\",\n\t\t\t\ttable,\n\t\t\t\tindex: selectedIndex,\n\t\t\t\torder\n\t\t\t} : {\n\t\t\t\ttype: \"Query\",\n\t\t\t\ttable,\n\t\t\t\tindex: selectedIndex,\n\t\t\t\trange: selectedRange,\n\t\t\t\torder\n\t\t\t};\n\t\t\treturn callHost(call, limit === void 0 ? request : {\n\t\t\t\t...request,\n\t\t\t\tlimit\n\t\t\t}).pipe(Effect.map((response) => expectResponse(response, \"Documents\")), Effect.map(({ documents }) => documents.map((document) => decodeDocument(schema, table, document))));\n\t\t};\n\t\tconst executePage = (pagination) => {\n\t\t\treturn callHost(call, selectedIndex === void 0 ? {\n\t\t\t\ttype: \"Paginate\",\n\t\t\t\ttable,\n\t\t\t\torder,\n\t\t\t\tpagination\n\t\t\t} : selectedRange === void 0 ? {\n\t\t\t\ttype: \"Paginate\",\n\t\t\t\ttable,\n\t\t\t\tindex: selectedIndex,\n\t\t\t\torder,\n\t\t\t\tpagination\n\t\t\t} : {\n\t\t\t\ttype: \"Paginate\",\n\t\t\t\ttable,\n\t\t\t\tindex: selectedIndex,\n\t\t\t\trange: selectedRange,\n\t\t\t\torder,\n\t\t\t\tpagination\n\t\t\t}).pipe(Effect.map((response) => expectResponse(response, \"Page\")), Effect.map(({ documents, nextCursor }) => ({\n\t\t\t\titems: documents.map((document) => decodeDocument(schema, table, document)),\n\t\t\t\tnextCursor\n\t\t\t})));\n\t\t};\n\t\tconst validateLimit = (count) => {\n\t\t\tif (!Number.isInteger(count) || count < 0 || count > 1e3) throw new Error(\"Query limits must be integers between 0 and 1000.\");\n\t\t\treturn count;\n\t\t};\n\t\treturn Object.freeze({\n\t\t\tindex: (name, buildRange) => {\n\t\t\t\tif (selectedIndex !== void 0) throw new Error(\"A query can select only one index.\");\n\t\t\t\tconst index = definition.indexes[name];\n\t\t\t\tif (index === void 0) throw new Error(`Unknown index '${name}' on table '${table}'.`);\n\t\t\t\tif (buildRange === void 0) return query(table, name, void 0, order);\n\t\t\t\tconst fields = [\n\t\t\t\t\t...index.fields,\n\t\t\t\t\t\"createdAt\",\n\t\t\t\t\t\"id\"\n\t\t\t\t];\n\t\t\t\tconst range = { equal: [] };\n\t\t\t\tlet position = 0;\n\t\t\t\tlet boundedField;\n\t\t\t\tconst expectField = (field) => {\n\t\t\t\t\tconst expected = fields[position];\n\t\t\t\t\tif (field !== expected) throw new Error(`Expected index field '${expected}', received '${field}'.`);\n\t\t\t\t};\n\t\t\t\tconst builder = {\n\t\t\t\t\teq: (field, value) => {\n\t\t\t\t\t\tif (boundedField !== void 0) throw new Error(\"Equality cannot follow an index bound.\");\n\t\t\t\t\t\texpectField(field);\n\t\t\t\t\t\trange.equal.push({\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalue: encodeIndexValue(field, value)\n\t\t\t\t\t\t});\n\t\t\t\t\t\tposition += 1;\n\t\t\t\t\t\treturn builder;\n\t\t\t\t\t},\n\t\t\t\t\tgt: (field, value) => {\n\t\t\t\t\t\texpectField(field);\n\t\t\t\t\t\tif (range.lower !== void 0) throw new Error(\"An index range has only one lower bound.\");\n\t\t\t\t\t\tboundedField = field;\n\t\t\t\t\t\trange.lower = {\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalue: encodeIndexValue(field, value),\n\t\t\t\t\t\t\tinclusive: false\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn builder;\n\t\t\t\t\t},\n\t\t\t\t\tgte: (field, value) => {\n\t\t\t\t\t\texpectField(field);\n\t\t\t\t\t\tif (range.lower !== void 0) throw new Error(\"An index range has only one lower bound.\");\n\t\t\t\t\t\tboundedField = field;\n\t\t\t\t\t\trange.lower = {\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalue: encodeIndexValue(field, value),\n\t\t\t\t\t\t\tinclusive: true\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn builder;\n\t\t\t\t\t},\n\t\t\t\t\tlt: (field, value) => {\n\t\t\t\t\t\texpectField(field);\n\t\t\t\t\t\tif (range.upper !== void 0) throw new Error(\"An index range has only one upper bound.\");\n\t\t\t\t\t\tboundedField = field;\n\t\t\t\t\t\trange.upper = {\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalue: encodeIndexValue(field, value),\n\t\t\t\t\t\t\tinclusive: false\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn builder;\n\t\t\t\t\t},\n\t\t\t\t\tlte: (field, value) => {\n\t\t\t\t\t\texpectField(field);\n\t\t\t\t\t\tif (range.upper !== void 0) throw new Error(\"An index range has only one upper bound.\");\n\t\t\t\t\t\tboundedField = field;\n\t\t\t\t\t\trange.upper = {\n\t\t\t\t\t\t\tfield,\n\t\t\t\t\t\t\tvalue: encodeIndexValue(field, value),\n\t\t\t\t\t\t\tinclusive: true\n\t\t\t\t\t\t};\n\t\t\t\t\t\treturn builder;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst built = buildRange(builder);\n\t\t\t\tif (!Predicate.isObject(built)) throw new Error(\"An index range callback must return its builder.\");\n\t\t\t\treturn query(table, name, range, order);\n\t\t\t},\n\t\t\torder: (direction) => query(table, selectedIndex, selectedRange, direction === \"asc\" ? \"Asc\" : \"Desc\"),\n\t\t\tcollect: () => resultFromEffect(execute()),\n\t\t\ttake: (count) => resultFromEffect(execute(validateLimit(count))),\n\t\t\tfirst: () => resultFromEffect(execute(1).pipe(Effect.map((documents) => documents[0]))),\n\t\t\tunique: () => resultFromEffect(execute(2).pipe(Effect.flatMap((documents) => documents.length > 1 ? Effect.die(/* @__PURE__ */ new Error(\"A unique database query matched more than one document.\")) : Effect.succeed(documents[0])))),\n\t\t\tpaginate: (options) => resultFromEffect(executePage(options))\n\t\t});\n\t};\n\treturn Object.freeze({\n\t\tfind: (table, id) => resultFromEffect(findEffect(table, id)),\n\t\tget: (table, id) => resultFromEffect(findEffect(table, id).pipe(Effect.flatMap((document) => document === void 0 ? Effect.fail(documentNotFound(table, id)) : Effect.succeed(document)))),\n\t\tquery: (table) => query(table)\n\t});\n};\nconst makeWriter = (schema, call) => {\n\tconst reader = makeReader(schema, call);\n\tconst complete = Effect.fn(\"Guest.completeWrite\")(function* (table, id, request) {\n\t\tif (expectResponse(yield* callHost(call, request), \"Completed\").found === false) return yield* Effect.fail(documentNotFound(table, id));\n\t});\n\tconst writer = {\n\t\t...reader,\n\t\tdelete: (table, id) => resultFromEffect(complete(table, id, {\n\t\t\ttype: \"Delete\",\n\t\t\ttable,\n\t\t\tid: GeneratedId.make(id)\n\t\t})),\n\t\tinsert: (table, value) => resultFromEffect(callHost(call, {\n\t\t\ttype: \"Insert\",\n\t\t\ttable,\n\t\t\tfields: encodeFields(schema, table, value)\n\t\t}).pipe(Effect.map((response) => expectResponse(response, \"Inserted\").id))),\n\t\tpatch: (table, id, value) => resultFromEffect(complete(table, id, {\n\t\t\ttype: \"Patch\",\n\t\t\ttable,\n\t\t\tid: GeneratedId.make(id),\n\t\t\tfields: encodePatchFields(schema, table, value)\n\t\t})),\n\t\treplace: (table, id, value) => resultFromEffect(complete(table, id, {\n\t\t\ttype: \"Replace\",\n\t\t\ttable,\n\t\t\tid: GeneratedId.make(id),\n\t\t\tfields: encodeFields(schema, table, value)\n\t\t}))\n\t};\n\treturn Object.freeze(writer);\n};\nconst encodeSuccess = Effect.fn(\"Guest.encodeSuccess\")(function* (definition, value) {\n\tif (definition.returns === void 0) {\n\t\tyield* Schema.encodeUnknownEffect(Schema.Undefined)(value);\n\t\treturn { type: \"Success\" };\n\t}\n\tconst encoded = yield* Schema.encodeUnknownEffect(Schema.toCodecJson(definition.returns))(value);\n\tconst files = runtimeFileOccurrencesOf(value);\n\tconst result = files.length === 0 ? {\n\t\ttype: \"Success\",\n\t\tvalue: encoded\n\t} : {\n\t\ttype: \"Success\",\n\t\tvalue: encoded,\n\t\tfiles\n\t};\n\tconst dates = datePathsOf(value);\n\treturn dates.length === 0 ? result : {\n\t\t...result,\n\t\tdates\n\t};\n});\nconst encodeFailure = Effect.fn(\"Guest.encodeFailure\")(function* (definition, error) {\n\tconst result = {\n\t\ttype: \"Failure\",\n\t\terror: yield* Schema.encodeUnknownEffect(Schema.toCodecJson(definition.errors ?? ErrorValueSchema))(error)\n\t};\n\tconst dates = datePathsOfObject(error);\n\treturn dates.length === 0 ? result : {\n\t\t...result,\n\t\tdates\n\t};\n});\nconst runGuest = Effect.fn(\"Guest.invoke\")(function* (definition, encodedArgs, call) {\n\tconst schema = getFunctionSchema(definition);\n\tif (schema === void 0) return yield* Effect.die(\"The function has no bound schema.\");\n\tconst decodedArgs = yield* Schema.decodeEffect(Schema.toCodecJson(guestCodec(Schema.Struct(definition.args ?? {}))))(encodedArgs).pipe(Effect.match({\n\t\tonFailure: () => ({ valid: false }),\n\t\tonSuccess: (value) => ({\n\t\t\tvalid: true,\n\t\t\tvalue\n\t\t})\n\t}));\n\tif (!decodedArgs.valid) return {\n\t\ttype: \"InvocationRejected\",\n\t\tcode: \"InvalidArguments\",\n\t\tmessage: \"The invocation arguments do not match the function definition.\"\n\t};\n\tconst args = yield* Schema.decodeUnknownEffect(Schema.ObjectKeyword)(decodedArgs.value);\n\tconst context = Object.freeze({ db: definition._tag === \"Query\" ? makeReader(schema, call) : makeWriter(schema, call) });\n\treturn yield* Effect.gen(() => definition.handler(context, args)).pipe(Effect.matchEffect({\n\t\tonFailure: (error) => encodeFailure(definition, error),\n\t\tonSuccess: (value) => encodeSuccess(definition, value)\n\t}));\n});\nconst invoke = (definition, encodedArgs, call) => Effect.runPromise(runGuest(definition, encodedArgs, call)).then((result) => Schema.encodeSync(Schema.fromJsonString(Schema.Json))(result));\n//#endregion\nexport { invoke };\n\n//# sourceMappingURL=guest.js.map"],"mappings":";;;;;AAIA,MAAM,eAAe,OAAO,OAAO;CAClC,IAAI;CACJ,WAAW,OAAO;CAClB,WAAW,OAA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|
-
import { a as Document, c as SchemaDefinitionTypeId, o as Id, s as SchemaDefinitionOf } from "../index-
|
|
1
|
+
import { a as Document, c as SchemaDefinitionTypeId, o as Id, s as SchemaDefinitionOf } from "../index-CF04_Dps.js";
|
|
2
2
|
export { type Document, type Id, type SchemaDefinitionOf, SchemaDefinitionTypeId };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as SchemaDefinitionTypeId } from "../schema-
|
|
1
|
+
import { t as SchemaDefinitionTypeId } from "../schema-DJfwfq87.js";
|
|
2
2
|
export { SchemaDefinitionTypeId };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./pagination-DrOowBve-Bnipd34u.js";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import "./id-Btwac71X-DGj0DQuu.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
//#region ../contracts/dist/descriptor-CEi5Jjiv.d.ts
|
|
4
|
+
//#region src/schema/descriptor.d.ts
|
|
5
|
+
interface DescriptorField {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly value: ValueDescriptor;
|
|
8
|
+
}
|
|
9
|
+
type ValueDescriptor = {
|
|
10
|
+
readonly type: "array";
|
|
11
|
+
readonly value: ValueDescriptor;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "boolean";
|
|
14
|
+
} | {
|
|
15
|
+
readonly type: "date";
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "file";
|
|
18
|
+
readonly formats: ReadonlyArray<"jpeg" | "png" | "webp" | "avif" | "gif">;
|
|
19
|
+
readonly maxBytes: number;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "error";
|
|
22
|
+
readonly tag: string;
|
|
23
|
+
readonly fields: ReadonlyArray<DescriptorField>;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "id";
|
|
26
|
+
readonly table: string;
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "integer";
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "literal";
|
|
31
|
+
readonly value: string | number | boolean;
|
|
32
|
+
} | {
|
|
33
|
+
readonly type: "literals";
|
|
34
|
+
readonly values: ReadonlyArray<string | number | boolean>;
|
|
35
|
+
} | {
|
|
36
|
+
readonly type: "never";
|
|
37
|
+
} | {
|
|
38
|
+
readonly type: "null";
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "nullable";
|
|
41
|
+
readonly value: ValueDescriptor;
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "number";
|
|
44
|
+
} | {
|
|
45
|
+
readonly type: "object";
|
|
46
|
+
readonly fields: ReadonlyArray<DescriptorField>;
|
|
47
|
+
} | {
|
|
48
|
+
readonly type: "optional";
|
|
49
|
+
readonly value: ValueDescriptor;
|
|
50
|
+
} | {
|
|
51
|
+
readonly type: "record";
|
|
52
|
+
readonly value: ValueDescriptor;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "string";
|
|
55
|
+
} | {
|
|
56
|
+
readonly type: "union";
|
|
57
|
+
readonly members: ReadonlyArray<ValueDescriptor>;
|
|
58
|
+
};
|
|
59
|
+
declare const ValueDescriptor: Schema.Codec<ValueDescriptor>;
|
|
60
|
+
declare const ValueDescriptorTypeId: unique symbol;
|
|
61
|
+
interface ValueDescriptorCarrier {
|
|
62
|
+
readonly [ValueDescriptorTypeId]: ValueDescriptor;
|
|
63
|
+
}
|
|
64
|
+
type DescribedValue<Value extends Schema.Constraint = Schema.Constraint> = Value & ValueDescriptorCarrier;
|
|
65
|
+
type ValueFields = {
|
|
66
|
+
readonly [fieldName: PropertyKey]: DescribedValue;
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region ../contracts/dist/pagination-DrOowBve.d.ts
|
|
70
|
+
//#region src/runtime/pagination.d.ts
|
|
71
|
+
declare const PaginationCursor: Schema.brand<Schema.String, "ignotum/runtime/PaginationCursor">;
|
|
72
|
+
type PaginationCursor = typeof PaginationCursor.Type;
|
|
73
|
+
declare const PaginationOptions: Schema.Struct<{
|
|
74
|
+
readonly cursor: Schema.NullOr<Schema.brand<Schema.String, "ignotum/runtime/PaginationCursor">>;
|
|
75
|
+
readonly pageSize: Schema.brand<Schema.Int, "ignotum/runtime/PaginationPageSize">;
|
|
76
|
+
}>;
|
|
77
|
+
type PaginationOptions = typeof PaginationOptions.Type;
|
|
78
|
+
interface PaginationPage<Item> {
|
|
79
|
+
readonly items: ReadonlyArray<Item>;
|
|
80
|
+
readonly nextCursor: PaginationCursor | null;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { ValueDescriptorCarrier as a, ValueDescriptor as i, PaginationPage as n, ValueFields as o, DescribedValue as r, PaginationOptions as t };
|
|
84
|
+
//# sourceMappingURL=pagination-DrOowBve-Bnipd34u.d.ts.map
|