@nkzw/fate 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +810 -129
- package/docs/api/classes/FateClient.md +832 -0
- package/docs/api/functions/clientRoot.md +27 -0
- package/docs/api/functions/createClient.md +21 -0
- package/docs/api/functions/createHTTPTransport.md +51 -0
- package/docs/api/functions/createTRPCTransport.md +46 -0
- package/docs/api/functions/getListEntries.md +15 -0
- package/docs/api/functions/getSelectionPlan.md +36 -0
- package/docs/api/functions/isRecord.md +15 -0
- package/docs/api/functions/isViewTag.md +17 -0
- package/docs/api/functions/liveConnectionTopic.md +19 -0
- package/docs/api/functions/liveEntityTopic.md +19 -0
- package/docs/api/functions/liveGlobalConnectionTopic.md +15 -0
- package/docs/api/functions/mutation.md +32 -0
- package/docs/api/functions/toEntityId.md +21 -0
- package/docs/api/functions/view.md +26 -0
- package/docs/api/index.md +81 -0
- package/docs/api/interfaces/FateThenable.md +31 -0
- package/docs/api/interfaces/Transport.md +199 -0
- package/docs/api/server/classes/FateRequestError.md +67 -0
- package/docs/api/server/drizzle/functions/createDrizzleFate.md +431 -0
- package/docs/api/server/drizzle/functions/createDrizzleSourceAdapter.md +21 -0
- package/docs/api/server/drizzle/functions/createDrizzleSourceRegistry.md +21 -0
- package/docs/api/server/drizzle/index.md +23 -0
- package/docs/api/server/drizzle/type-aliases/DrizzleManyToManyConfig.md +15 -0
- package/docs/api/server/drizzle/type-aliases/DrizzleManyToManyInput.md +5 -0
- package/docs/api/server/drizzle/type-aliases/DrizzleQueryExtra.md +21 -0
- package/docs/api/server/drizzle/type-aliases/DrizzleSourceAdapter.md +337 -0
- package/docs/api/server/drizzle/type-aliases/DrizzleViewConfig.md +29 -0
- package/docs/api/server/functions/bindSourceProcedures.md +32 -0
- package/docs/api/server/functions/computed.md +43 -0
- package/docs/api/server/functions/count.md +21 -0
- package/docs/api/server/functions/createFateFetchHandler.md +21 -0
- package/docs/api/server/functions/createFateServer.md +41 -0
- package/docs/api/server/functions/createHonoFateHandler.md +21 -0
- package/docs/api/server/functions/createLiveEventBus.md +17 -0
- package/docs/api/server/functions/createNestedSourcePlan.md +103 -0
- package/docs/api/server/functions/createResolver.md +74 -0
- package/docs/api/server/functions/createSourcePlan.md +95 -0
- package/docs/api/server/functions/createSourceProcedures.md +46 -0
- package/docs/api/server/functions/dataView.md +32 -0
- package/docs/api/server/functions/field.md +15 -0
- package/docs/api/server/functions/getNestedSelection.md +19 -0
- package/docs/api/server/functions/getScopedArgs.md +21 -0
- package/docs/api/server/functions/hasNestedSelection.md +19 -0
- package/docs/api/server/functions/list.md +28 -0
- package/docs/api/server/functions/refetchSourceById.md +55 -0
- package/docs/api/server/functions/resolveSourceById.md +55 -0
- package/docs/api/server/functions/resolveSourceByIds.md +55 -0
- package/docs/api/server/functions/resolveSourceConnection.md +67 -0
- package/docs/api/server/functions/resolver.md +42 -0
- package/docs/api/server/functions/toPrismaSelect.md +25 -0
- package/docs/api/server/functions/withConnection.md +24 -0
- package/docs/api/server/index.md +109 -0
- package/docs/api/server/prisma/functions/createPrismaFate.md +435 -0
- package/docs/api/server/prisma/functions/createPrismaSourceAdapter.md +21 -0
- package/docs/api/server/prisma/functions/createPrismaSourceRegistry.md +21 -0
- package/docs/api/server/prisma/functions/prismaConnectionArgs.md +57 -0
- package/docs/api/server/prisma/index.md +23 -0
- package/docs/api/server/prisma/type-aliases/PrismaDelegate.md +59 -0
- package/docs/api/server/prisma/type-aliases/PrismaQueryExtra.md +5 -0
- package/docs/api/server/prisma/type-aliases/PrismaSourceAdapter.md +343 -0
- package/docs/api/server/prisma/type-aliases/PrismaViewConfig.md +31 -0
- package/docs/api/server/type-aliases/ComputedField.md +55 -0
- package/docs/api/server/type-aliases/ComputedSelection.md +5 -0
- package/docs/api/server/type-aliases/ConnectionItem.md +29 -0
- package/docs/api/server/type-aliases/ConnectionPagination.md +39 -0
- package/docs/api/server/type-aliases/ConnectionResult.md +29 -0
- package/docs/api/server/type-aliases/CountSelection.md +29 -0
- package/docs/api/server/type-aliases/CountWhere.md +5 -0
- package/docs/api/server/type-aliases/DataViewListOptions.md +13 -0
- package/docs/api/server/type-aliases/DataViewOrderBy.md +5 -0
- package/docs/api/server/type-aliases/DataViewOrderDirection.md +5 -0
- package/docs/api/server/type-aliases/DataViewResult.md +11 -0
- package/docs/api/server/type-aliases/Entity.md +21 -0
- package/docs/api/server/type-aliases/FateServer.md +75 -0
- package/docs/api/server/type-aliases/FateServerManifest.md +5 -0
- package/docs/api/server/type-aliases/FieldSelection.md +21 -0
- package/docs/api/server/type-aliases/LiveConnectionEventType.md +5 -0
- package/docs/api/server/type-aliases/LiveConnectionSourceEvent.md +5 -0
- package/docs/api/server/type-aliases/LiveEventBus.md +5 -0
- package/docs/api/server/type-aliases/LiveEventType.md +5 -0
- package/docs/api/server/type-aliases/LiveSourceEvent.md +5 -0
- package/docs/api/server/type-aliases/NativeFateAPI.md +47 -0
- package/docs/api/server/type-aliases/OrderDirection.md +5 -0
- package/docs/api/server/type-aliases/SourceConfig.md +55 -0
- package/docs/api/server/type-aliases/SourceDefinition.md +55 -0
- package/docs/api/server/type-aliases/SourceOrder.md +5 -0
- package/docs/api/server/type-aliases/SourceOrderField.md +21 -0
- package/docs/api/server/type-aliases/SourcePlan.md +29 -0
- package/docs/api/server/type-aliases/SourcePlanNode.md +29 -0
- package/docs/api/server/type-aliases/SourceRegistry.md +11 -0
- package/docs/api/server/type-aliases/SourceRelation.md +15 -0
- package/docs/api/server/type-aliases/SourceRelationConfig.md +23 -0
- package/docs/api/server/variables/byIdInput.md +5 -0
- package/docs/api/server/variables/connectionArgs.md +7 -0
- package/docs/api/type-aliases/ConnectionMetadata.md +7 -0
- package/docs/api/type-aliases/ConnectionRef.md +13 -0
- package/docs/api/type-aliases/Entity.md +15 -0
- package/docs/api/type-aliases/EntityId.md +7 -0
- package/docs/api/type-aliases/FateLiveConnectionEvent.md +5 -0
- package/docs/api/type-aliases/FateLiveEvent.md +5 -0
- package/docs/api/type-aliases/FateMutations.md +7 -0
- package/docs/api/type-aliases/FateOperation.md +5 -0
- package/docs/api/type-aliases/FateProtocolRequest.md +5 -0
- package/docs/api/type-aliases/FateProtocolResponse.md +5 -0
- package/docs/api/type-aliases/FateRecord.md +7 -0
- package/docs/api/type-aliases/FateRoots.md +7 -0
- package/docs/api/type-aliases/InferFateAPI.md +11 -0
- package/docs/api/type-aliases/List.md +5 -0
- package/docs/api/type-aliases/ListEntry.md +5 -0
- package/docs/api/type-aliases/ListItem.md +13 -0
- package/docs/api/type-aliases/Mask.md +15 -0
- package/docs/api/type-aliases/MutationDefinition.md +21 -0
- package/docs/api/type-aliases/MutationEntity.md +13 -0
- package/docs/api/type-aliases/MutationIdentifier.md +19 -0
- package/docs/api/type-aliases/MutationInput.md +13 -0
- package/docs/api/type-aliases/MutationResult.md +13 -0
- package/docs/api/type-aliases/NodesItem.md +13 -0
- package/docs/api/type-aliases/Pagination.md +39 -0
- package/docs/api/type-aliases/Request.md +7 -0
- package/docs/api/type-aliases/RequestMode.md +7 -0
- package/docs/api/type-aliases/RequestOptions.md +7 -0
- package/docs/api/type-aliases/RequestResult.md +18 -0
- package/docs/api/type-aliases/Selection.md +13 -0
- package/docs/api/type-aliases/Snapshot.md +7 -0
- package/docs/api/type-aliases/TypeConfig.md +41 -0
- package/docs/api/type-aliases/View.md +17 -0
- package/docs/api/type-aliases/ViewData.md +18 -0
- package/docs/api/type-aliases/ViewEntity.md +13 -0
- package/docs/api/type-aliases/ViewEntityName.md +13 -0
- package/docs/api/type-aliases/ViewRef.md +13 -0
- package/docs/api/type-aliases/ViewSelection.md +13 -0
- package/docs/api/type-aliases/ViewSnapshot.md +18 -0
- package/docs/api/type-aliases/ViewTag.md +7 -0
- package/docs/api/variables/ConnectionTag.md +7 -0
- package/docs/guide/actions.md +263 -0
- package/docs/guide/core-concepts.md +22 -0
- package/docs/guide/getting-started.md +57 -0
- package/docs/guide/list-views.md +86 -0
- package/docs/guide/live-views.md +245 -0
- package/docs/guide/requests.md +130 -0
- package/docs/guide/server-integration.md +630 -0
- package/docs/guide/views.md +278 -0
- package/docs/guide/void-integration.md +167 -0
- package/docs/index.md +4 -0
- package/lib/cli.mjs +17 -250
- package/lib/clientStub.d.mts +6 -0
- package/lib/clientStub.mjs +6 -0
- package/lib/executor-BqwHdN3n.d.mts +468 -0
- package/lib/index.d.mts +64 -2
- package/lib/index.mjs +1961 -555
- package/lib/list-4wRNSVgI.d.mts +10 -0
- package/lib/list-C_mi6GnE.mjs +16 -0
- package/lib/list.d.mts +2 -0
- package/lib/list.mjs +2 -0
- package/lib/liveTopics-DzNtJaBD.mjs +197 -0
- package/lib/{record-DnhZuvUe.mjs → record-AeZJC9fd.mjs} +1 -2
- package/lib/record-ENh92gyb.d.mts +315 -0
- package/lib/server/drizzle.d.mts +304 -0
- package/lib/server/drizzle.mjs +688 -0
- package/lib/server/prisma.d.mts +309 -0
- package/lib/server/prisma.mjs +345 -0
- package/lib/server.d.mts +82 -183
- package/lib/server.mjs +870 -416
- package/lib/sourceRouter-Bwpkr062.mjs +972 -0
- package/lib/{types-HECWvGpd.d.mts → types-Dz46PXr3.d.mts} +215 -63
- package/lib/vite.d.mts +17 -0
- package/lib/vite.mjs +593 -0
- package/package.json +44 -6
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { U as List, o as EntityId } from "./types-Dz46PXr3.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/list.d.ts
|
|
4
|
+
type ListEntry = Readonly<{
|
|
5
|
+
cursor?: string;
|
|
6
|
+
id: EntityId;
|
|
7
|
+
}>;
|
|
8
|
+
declare const getListEntries: (listState: List | undefined) => Array<ListEntry>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getListEntries as n, ListEntry as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/list.ts
|
|
2
|
+
const getListEntries = (listState) => {
|
|
3
|
+
if (!listState) return [];
|
|
4
|
+
const entries = [];
|
|
5
|
+
for (const id of listState.pendingBeforeIds ?? []) entries.push({ id });
|
|
6
|
+
listState.ids.forEach((id, index) => {
|
|
7
|
+
entries.push({
|
|
8
|
+
cursor: listState.cursors?.[index],
|
|
9
|
+
id
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
for (const id of listState.pendingAfterIds ?? []) entries.push({ id });
|
|
13
|
+
return entries;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getListEntries as t };
|
package/lib/list.d.mts
ADDED
package/lib/list.mjs
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { t as isRecord } from "./record-AeZJC9fd.mjs";
|
|
2
|
+
//#region src/args.ts
|
|
3
|
+
const ensureSerializable = (value, path) => {
|
|
4
|
+
const type = typeof value;
|
|
5
|
+
if (type === "function" || type === "symbol") throw new Error(`fate: Argument '${path}' must be serializable. Received '${type}'.`);
|
|
6
|
+
};
|
|
7
|
+
const cloneArgs = (value, path) => {
|
|
8
|
+
const cloneValue = (entry, currentPath) => {
|
|
9
|
+
if (Array.isArray(entry)) return entry.map((item, index) => cloneValue(item, `${currentPath}[${index}]`));
|
|
10
|
+
if (isRecord(entry)) {
|
|
11
|
+
const result = {};
|
|
12
|
+
for (const [key, child] of Object.entries(entry)) result[key] = cloneValue(child, `${currentPath}.${key}`);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
ensureSerializable(entry, currentPath);
|
|
16
|
+
return entry;
|
|
17
|
+
};
|
|
18
|
+
return cloneValue(value, path);
|
|
19
|
+
};
|
|
20
|
+
const paginationArgKeys = new Set([
|
|
21
|
+
"after",
|
|
22
|
+
"before",
|
|
23
|
+
"cursor",
|
|
24
|
+
"first",
|
|
25
|
+
"last"
|
|
26
|
+
]);
|
|
27
|
+
const stableSerialize = (value) => {
|
|
28
|
+
if (value === null) return "null";
|
|
29
|
+
const type = typeof value;
|
|
30
|
+
if (type === "number" || type === "boolean" || type === "bigint") return `${type}:${String(value)}`;
|
|
31
|
+
if (type === "string") return `string:${JSON.stringify(value)}`;
|
|
32
|
+
if (type === "undefined") return "undefined";
|
|
33
|
+
if (Array.isArray(value)) return `array:[${value.map(stableSerialize).join(",")}]`;
|
|
34
|
+
if (typeof value === "object") return `object:{${Object.entries(value).map(([key, entry]) => [key, entry]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([_key, entry]) => `${JSON.stringify(_key)}:${stableSerialize(entry)}`).join(",")}}`;
|
|
35
|
+
throw new Error(`fate: Unable to serialize argument value of type '${type}'.`);
|
|
36
|
+
};
|
|
37
|
+
const hashArgs = (argsValue, options = {}) => {
|
|
38
|
+
const keys = {};
|
|
39
|
+
for (const [key, value] of Object.entries(argsValue)) {
|
|
40
|
+
if (options.ignoreKeys && options.ignoreKeys.has(key)) continue;
|
|
41
|
+
keys[key] = value;
|
|
42
|
+
}
|
|
43
|
+
return stableSerialize(keys);
|
|
44
|
+
};
|
|
45
|
+
const filterConnectionArgs = (argsValue) => {
|
|
46
|
+
if (!argsValue) return;
|
|
47
|
+
const result = {};
|
|
48
|
+
for (const [key, value] of Object.entries(argsValue)) if (!paginationArgKeys.has(key)) result[key] = value;
|
|
49
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
50
|
+
};
|
|
51
|
+
const mergeArgs = (target, source) => {
|
|
52
|
+
for (const [key, value] of Object.entries(source)) {
|
|
53
|
+
if (isRecord(value)) {
|
|
54
|
+
const existing = target[key];
|
|
55
|
+
if (isRecord(existing)) mergeArgs(existing, value);
|
|
56
|
+
else target[key] = { ...value };
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
target[key] = value;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const resolvedArgsFromPlan = (plan) => {
|
|
63
|
+
if (!plan || plan.args.size === 0) return;
|
|
64
|
+
const result = {};
|
|
65
|
+
for (const [path, entry] of plan.args.entries()) {
|
|
66
|
+
if (path === "") {
|
|
67
|
+
mergeArgs(result, entry.value);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const segments = path.split(".");
|
|
71
|
+
let current = result;
|
|
72
|
+
segments.forEach((segment, index) => {
|
|
73
|
+
if (index === segments.length - 1) {
|
|
74
|
+
const existing = current[segment];
|
|
75
|
+
if (isRecord(existing)) mergeArgs(existing, entry.value);
|
|
76
|
+
else current[segment] = { ...entry.value };
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const existing = current[segment];
|
|
80
|
+
if (isRecord(existing)) {
|
|
81
|
+
current = existing;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const next = {};
|
|
85
|
+
current[segment] = next;
|
|
86
|
+
current = next;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
};
|
|
91
|
+
const hasEntries = (value) => Boolean(value && Object.keys(value).length > 0);
|
|
92
|
+
const combineArgsPayload = (base, scoped) => {
|
|
93
|
+
if (!hasEntries(base) && !hasEntries(scoped)) return;
|
|
94
|
+
const result = hasEntries(base) ? { ...base } : {};
|
|
95
|
+
if (hasEntries(scoped)) mergeArgs(result, scoped);
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
const getArgsAtPath = (payload, path) => {
|
|
99
|
+
if (!payload) return;
|
|
100
|
+
if (path === "") return payload;
|
|
101
|
+
const segments = path.split(".");
|
|
102
|
+
let current = payload;
|
|
103
|
+
for (const segment of segments) {
|
|
104
|
+
if (!isRecord(current)) return;
|
|
105
|
+
current = current[segment];
|
|
106
|
+
if (current === void 0) return;
|
|
107
|
+
}
|
|
108
|
+
return isRecord(current) ? current : void 0;
|
|
109
|
+
};
|
|
110
|
+
const applyArgsPayloadToPlan = (plan, payload) => {
|
|
111
|
+
for (const [path, entry] of plan.args.entries()) {
|
|
112
|
+
const actual = path === "" ? payload : getArgsAtPath(payload, path);
|
|
113
|
+
if (!actual) continue;
|
|
114
|
+
const cloned = cloneArgs(actual, path);
|
|
115
|
+
const hash = hashArgs(cloned, { ignoreKeys: entry.ignoreKeys });
|
|
116
|
+
plan.args.set(path, {
|
|
117
|
+
hash,
|
|
118
|
+
ignoreKeys: entry.ignoreKeys,
|
|
119
|
+
value: cloned
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const scopeArgsPayload = (args, scope) => {
|
|
124
|
+
const segments = scope.split(".");
|
|
125
|
+
const result = {};
|
|
126
|
+
let current = result;
|
|
127
|
+
segments.forEach((segment, index) => {
|
|
128
|
+
if (index === segments.length - 1) {
|
|
129
|
+
current[segment] = args;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const next = {};
|
|
133
|
+
current[segment] = next;
|
|
134
|
+
current = next;
|
|
135
|
+
});
|
|
136
|
+
return result;
|
|
137
|
+
};
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/protocol.ts
|
|
140
|
+
var FateRequestError = class extends Error {
|
|
141
|
+
constructor(code, message, options = {}) {
|
|
142
|
+
super(message);
|
|
143
|
+
this.name = "FateRequestError";
|
|
144
|
+
this.code = code;
|
|
145
|
+
this.issues = options.issues;
|
|
146
|
+
this.status = options.status ?? statusFromErrorCode(code);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const statusFromErrorCode = (code) => {
|
|
150
|
+
switch (code) {
|
|
151
|
+
case "BAD_REQUEST":
|
|
152
|
+
case "VALIDATION_ERROR": return 400;
|
|
153
|
+
case "UNAUTHORIZED": return 401;
|
|
154
|
+
case "FORBIDDEN": return 403;
|
|
155
|
+
case "NOT_FOUND": return 404;
|
|
156
|
+
case "INTERNAL_ERROR": return 500;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const errorCodeFromStatus = (status) => {
|
|
160
|
+
if (status === 400) return "BAD_REQUEST";
|
|
161
|
+
if (status === 401) return "UNAUTHORIZED";
|
|
162
|
+
if (status === 403) return "FORBIDDEN";
|
|
163
|
+
if (status === 404) return "NOT_FOUND";
|
|
164
|
+
return "INTERNAL_ERROR";
|
|
165
|
+
};
|
|
166
|
+
const toProtocolError = (error) => {
|
|
167
|
+
if (error instanceof FateRequestError) return {
|
|
168
|
+
code: error.code,
|
|
169
|
+
issues: error.issues,
|
|
170
|
+
message: error.message
|
|
171
|
+
};
|
|
172
|
+
if (error instanceof Error) return {
|
|
173
|
+
code: "INTERNAL_ERROR",
|
|
174
|
+
message: "Internal server error."
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
code: "INTERNAL_ERROR",
|
|
178
|
+
message: "Internal server error."
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/liveTopics.ts
|
|
183
|
+
const encodeTopicPart = (value) => encodeURIComponent(String(value));
|
|
184
|
+
const normalizeConnectionArgs = (args) => {
|
|
185
|
+
const filtered = filterConnectionArgs(args);
|
|
186
|
+
if (!filtered) return;
|
|
187
|
+
const id = filtered.id;
|
|
188
|
+
return typeof id === "string" || typeof id === "number" ? {
|
|
189
|
+
...filtered,
|
|
190
|
+
id: String(id)
|
|
191
|
+
} : filtered;
|
|
192
|
+
};
|
|
193
|
+
const liveEntityTopic = (type, id) => `entity:${encodeTopicPart(type)}:${encodeTopicPart(id)}`;
|
|
194
|
+
const liveConnectionTopic = (procedure, args) => `connection:${encodeTopicPart(procedure)}:${encodeTopicPart(hashArgs(normalizeConnectionArgs(args) ?? {}))}`;
|
|
195
|
+
const liveGlobalConnectionTopic = (procedure) => `connection:${encodeTopicPart(procedure)}:*`;
|
|
196
|
+
//#endregion
|
|
197
|
+
export { errorCodeFromStatus as a, cloneArgs as c, hashArgs as d, paginationArgKeys as f, FateRequestError as i, combineArgsPayload as l, scopeArgsPayload as m, liveEntityTopic as n, toProtocolError as o, resolvedArgsFromPlan as p, liveGlobalConnectionTopic as r, applyArgsPayloadToPlan as s, liveConnectionTopic as t, filterConnectionArgs as u };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { t as AnyRecord } from "./types-Dz46PXr3.mjs";
|
|
2
|
+
import { N as DataViewResult, S as ConnectionResult, k as DataView, l as SourceDefinition, t as SourceRegistry } from "./executor-BqwHdN3n.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/liveTopics.d.ts
|
|
5
|
+
declare const liveEntityTopic: (type: string, id: string | number) => string;
|
|
6
|
+
declare const liveConnectionTopic: (procedure: string, args?: Record<string, unknown>) => string;
|
|
7
|
+
declare const liveGlobalConnectionTopic: (procedure: string) => string;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/server/live.d.ts
|
|
10
|
+
type LiveEventType = 'delete' | 'update';
|
|
11
|
+
type LiveConnectionEventType = 'appendEdge' | 'appendNode' | 'deleteEdge' | 'insertEdgeAfter' | 'insertEdgeBefore' | 'invalidate' | 'prependEdge' | 'prependNode';
|
|
12
|
+
type LiveSourceEvent = Readonly<{
|
|
13
|
+
changed?: ReadonlyArray<string>;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
eventId?: string;
|
|
16
|
+
id: string | number;
|
|
17
|
+
type: LiveEventType;
|
|
18
|
+
}>;
|
|
19
|
+
type LiveConnectionSourceEvent = Readonly<{
|
|
20
|
+
cursor?: string;
|
|
21
|
+
eventId?: string;
|
|
22
|
+
id?: string | number;
|
|
23
|
+
node?: unknown;
|
|
24
|
+
nodeType?: string;
|
|
25
|
+
targetCursor?: string;
|
|
26
|
+
type: LiveConnectionEventType;
|
|
27
|
+
}>;
|
|
28
|
+
type LiveConnectionTarget = Readonly<{
|
|
29
|
+
args?: Record<string, unknown>;
|
|
30
|
+
procedure: string;
|
|
31
|
+
}>;
|
|
32
|
+
type LiveConnectionEmitOptions = Readonly<{
|
|
33
|
+
cursor?: string;
|
|
34
|
+
eventId?: string;
|
|
35
|
+
node?: unknown;
|
|
36
|
+
nodeType?: string;
|
|
37
|
+
targetCursor?: string;
|
|
38
|
+
}>;
|
|
39
|
+
type LiveConnectionHandle = Readonly<{
|
|
40
|
+
appendEdge: (nodeType: string, id: string | number, options?: LiveConnectionEmitOptions) => void;
|
|
41
|
+
appendNode: (nodeType: string, id: string | number, options?: LiveConnectionEmitOptions) => void;
|
|
42
|
+
deleteEdge: (nodeType: string, id: string | number, options?: {
|
|
43
|
+
eventId?: string;
|
|
44
|
+
}) => void;
|
|
45
|
+
emit: (type: LiveConnectionEventType, options?: LiveConnectionEmitOptions & {
|
|
46
|
+
id?: string | number;
|
|
47
|
+
}) => void;
|
|
48
|
+
insertEdgeAfter: (nodeType: string, id: string | number, targetCursor: string, options?: LiveConnectionEmitOptions) => void;
|
|
49
|
+
insertEdgeBefore: (nodeType: string, id: string | number, targetCursor: string, options?: LiveConnectionEmitOptions) => void;
|
|
50
|
+
invalidate: (options?: {
|
|
51
|
+
eventId?: string;
|
|
52
|
+
}) => void;
|
|
53
|
+
prependEdge: (nodeType: string, id: string | number, options?: LiveConnectionEmitOptions) => void;
|
|
54
|
+
prependNode: (nodeType: string, id: string | number, options?: LiveConnectionEmitOptions) => void;
|
|
55
|
+
}>;
|
|
56
|
+
type LiveEventBus = Readonly<{
|
|
57
|
+
connection: (procedure: string, args?: Record<string, unknown>) => LiveConnectionHandle;
|
|
58
|
+
delete: (type: string, id: string | number, options?: {
|
|
59
|
+
eventId?: string;
|
|
60
|
+
}) => void;
|
|
61
|
+
emit: (type: string, id: string | number, options?: {
|
|
62
|
+
changed?: ReadonlyArray<string>;
|
|
63
|
+
data?: unknown;
|
|
64
|
+
eventId?: string;
|
|
65
|
+
type?: LiveEventType;
|
|
66
|
+
}) => void;
|
|
67
|
+
listen?: (type: string, id: string | number, handler: (event: LiveSourceEvent) => void, options?: {
|
|
68
|
+
lastEventId?: string;
|
|
69
|
+
signal?: AbortSignal;
|
|
70
|
+
}) => () => void;
|
|
71
|
+
listenConnection?: (target: LiveConnectionTarget, handler: (event: LiveConnectionSourceEvent) => void, options?: {
|
|
72
|
+
lastEventId?: string;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
}) => () => void;
|
|
75
|
+
subscribe: (type: string, id: string | number, options?: {
|
|
76
|
+
lastEventId?: string;
|
|
77
|
+
signal?: AbortSignal;
|
|
78
|
+
}) => AsyncIterable<readonly [LiveSourceEvent]>;
|
|
79
|
+
subscribeConnection: (target: LiveConnectionTarget, options?: {
|
|
80
|
+
lastEventId?: string;
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
}) => AsyncIterable<readonly [LiveConnectionSourceEvent]>;
|
|
83
|
+
update: (type: string, id: string | number, options?: {
|
|
84
|
+
changed?: ReadonlyArray<string>;
|
|
85
|
+
data?: unknown;
|
|
86
|
+
eventId?: string;
|
|
87
|
+
}) => void;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a small in-memory event bus for Fate live view subscriptions.
|
|
91
|
+
*
|
|
92
|
+
* The bus signals that an entity changed and can optionally include changed
|
|
93
|
+
* field paths. The native live handler refetches the selected record, or only
|
|
94
|
+
* the changed selected fields when paths are provided, before sending it to
|
|
95
|
+
* clients. It does not persist events or replay events after reconnects; provide
|
|
96
|
+
* a durable custom bus for lossless `lastEventId` resume behavior.
|
|
97
|
+
*/
|
|
98
|
+
declare function createLiveEventBus(): LiveEventBus;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/server/http.d.ts
|
|
101
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
102
|
+
type SourceResolver<Context> = {
|
|
103
|
+
getSource: <Item extends AnyRecord = AnyRecord>(target: DataView<Item> | SourceDefinition<Item, unknown>) => SourceDefinition<Item, unknown>;
|
|
104
|
+
registry: SourceRegistry<Context>;
|
|
105
|
+
};
|
|
106
|
+
type RootConfig = DataView<AnyRecord> | {
|
|
107
|
+
procedure?: string;
|
|
108
|
+
view: DataView<AnyRecord>;
|
|
109
|
+
};
|
|
110
|
+
type RootMap = Record<string, RootConfig>;
|
|
111
|
+
type OperationInput = {
|
|
112
|
+
args?: Record<string, unknown>;
|
|
113
|
+
select: Array<string>;
|
|
114
|
+
};
|
|
115
|
+
type ResolverContext<Context, Input = unknown> = {
|
|
116
|
+
ctx: Context;
|
|
117
|
+
input: Input;
|
|
118
|
+
select: Array<string>;
|
|
119
|
+
};
|
|
120
|
+
type QueryResolver<Context, Args = Record<string, unknown> | undefined, Output = unknown> = (options: ResolverContext<Context, {
|
|
121
|
+
args?: Args;
|
|
122
|
+
}>) => MaybePromise<Output>;
|
|
123
|
+
type ListResolver<Context, Args = Record<string, unknown> | undefined, Output = unknown> = (options: ResolverContext<Context, {
|
|
124
|
+
args?: Args;
|
|
125
|
+
}>) => MaybePromise<ConnectionResult<Output>>;
|
|
126
|
+
type MutationResolver<Context, Input = unknown, Output = unknown> = (options: ResolverContext<Context, Input>) => MaybePromise<Output>;
|
|
127
|
+
type QueryDefinition<Context, Args = Record<string, unknown> | undefined, Output = unknown> = {
|
|
128
|
+
resolve: QueryResolver<Context, Args, Output>;
|
|
129
|
+
type?: string;
|
|
130
|
+
};
|
|
131
|
+
type ListDefinition<Context, Args = Record<string, unknown> | undefined, Output = unknown> = {
|
|
132
|
+
defaultSize?: number;
|
|
133
|
+
resolve: ListResolver<Context, Args, Output>;
|
|
134
|
+
type?: string;
|
|
135
|
+
};
|
|
136
|
+
type SchemaLike = {
|
|
137
|
+
'~standard'?: {
|
|
138
|
+
validate: (value: unknown) => unknown;
|
|
139
|
+
};
|
|
140
|
+
parse?: (value: unknown) => unknown;
|
|
141
|
+
};
|
|
142
|
+
type MutationDefinition<Context, Input = unknown, Output = unknown> = {
|
|
143
|
+
input?: SchemaLike;
|
|
144
|
+
resolve: MutationResolver<Context, Input, Output>;
|
|
145
|
+
type: string;
|
|
146
|
+
};
|
|
147
|
+
type LiveConfig = LiveEventBus | {
|
|
148
|
+
bus: LiveEventBus;
|
|
149
|
+
};
|
|
150
|
+
type ContextOptions<AdapterContext> = {
|
|
151
|
+
adapterContext?: AdapterContext;
|
|
152
|
+
request: Request;
|
|
153
|
+
};
|
|
154
|
+
type FateServerOptions<Context, Roots extends RootMap, Queries extends Record<string, QueryDefinition<Context, any, any>>, Lists extends Record<string, ListDefinition<Context, any, any>>, Mutations extends Record<string, MutationDefinition<Context, any, any>>, AdapterContext> = {
|
|
155
|
+
context?: (options: ContextOptions<AdapterContext>) => MaybePromise<Context>;
|
|
156
|
+
lists?: Lists;
|
|
157
|
+
live?: false | LiveConfig;
|
|
158
|
+
mutations?: Mutations;
|
|
159
|
+
queries?: Queries;
|
|
160
|
+
roots: Roots;
|
|
161
|
+
sources: SourceResolver<Context>;
|
|
162
|
+
};
|
|
163
|
+
type RootView<Root> = Root extends DataView<AnyRecord> ? Root : Root extends {
|
|
164
|
+
view: infer View extends DataView<AnyRecord>;
|
|
165
|
+
} ? View : never;
|
|
166
|
+
type RootProcedure<_Root, Name extends string> = Name;
|
|
167
|
+
type RootOutput<Root> = RootView<Root> extends infer View extends DataView<AnyRecord> ? View['kind'] extends 'list' ? ConnectionResult<DataViewResult<View>> : DataViewResult<View> | null : never;
|
|
168
|
+
type RootLists<Roots extends RootMap> = { [K in keyof Roots as RootView<Roots[K]>['kind'] extends 'list' ? RootProcedure<Roots[K], K & string> : never]: {
|
|
169
|
+
input: OperationInput;
|
|
170
|
+
output: RootOutput<Roots[K]>;
|
|
171
|
+
} };
|
|
172
|
+
type RootQueries<Roots extends RootMap> = { [K in keyof Roots as RootView<Roots[K]>['kind'] extends 'list' ? never : RootProcedure<Roots[K], K & string>]: {
|
|
173
|
+
input: OperationInput;
|
|
174
|
+
output: RootOutput<Roots[K]>;
|
|
175
|
+
} };
|
|
176
|
+
type QueryAPI<Queries extends Record<string, QueryDefinition<any, any, any>>> = { [K in keyof Queries]: Queries[K] extends QueryDefinition<any, infer Args, infer Output> ? {
|
|
177
|
+
input: {
|
|
178
|
+
args?: Args;
|
|
179
|
+
select: Array<string>;
|
|
180
|
+
};
|
|
181
|
+
output: Awaited<Output>;
|
|
182
|
+
} : never };
|
|
183
|
+
type ListAPI<Lists extends Record<string, ListDefinition<any, any, any>>> = { [K in keyof Lists]: Lists[K] extends ListDefinition<any, infer Args, infer Output> ? {
|
|
184
|
+
input: {
|
|
185
|
+
args?: Args;
|
|
186
|
+
select: Array<string>;
|
|
187
|
+
};
|
|
188
|
+
output: ConnectionResult<Awaited<Output>>;
|
|
189
|
+
} : never };
|
|
190
|
+
type MutationAPI<Mutations extends Record<string, MutationDefinition<any, any, any>>> = { [K in keyof Mutations]: Mutations[K] extends MutationDefinition<any, infer Input, infer Output> ? {
|
|
191
|
+
entity: Mutations[K]['type'];
|
|
192
|
+
input: Input;
|
|
193
|
+
output: Awaited<Output>;
|
|
194
|
+
} : never };
|
|
195
|
+
type NativeFateAPI<Roots extends RootMap, Queries extends Record<string, QueryDefinition<any, any, any>>, Lists extends Record<string, ListDefinition<any, any, any>>, Mutations extends Record<string, MutationDefinition<any, any, any>>> = {
|
|
196
|
+
lists: RootLists<Roots> & ListAPI<Lists>;
|
|
197
|
+
mutations: MutationAPI<Mutations>;
|
|
198
|
+
queries: RootQueries<Roots> & QueryAPI<Queries>;
|
|
199
|
+
};
|
|
200
|
+
type FateServer<API, AdapterContext = unknown> = {
|
|
201
|
+
readonly __api?: API;
|
|
202
|
+
handleLiveRequest(request: Request, adapterContext?: AdapterContext): Promise<Response>;
|
|
203
|
+
handleRequest(request: Request, adapterContext?: AdapterContext): Promise<Response>;
|
|
204
|
+
readonly manifest: FateServerManifest;
|
|
205
|
+
};
|
|
206
|
+
type InferFateAPI<Server> = Server extends {
|
|
207
|
+
readonly __api?: infer API;
|
|
208
|
+
} ? API : never;
|
|
209
|
+
type FateServerManifest = Readonly<{
|
|
210
|
+
lists: Record<string, {
|
|
211
|
+
type: string;
|
|
212
|
+
}>;
|
|
213
|
+
live: Record<string, true>;
|
|
214
|
+
mutations: Record<string, {
|
|
215
|
+
type: string;
|
|
216
|
+
}>;
|
|
217
|
+
queries: Record<string, {
|
|
218
|
+
type: string;
|
|
219
|
+
}>;
|
|
220
|
+
types: Record<string, true>;
|
|
221
|
+
}>;
|
|
222
|
+
declare function createFateServer<Context = unknown, Roots extends RootMap = RootMap, Queries extends Record<string, QueryDefinition<Context, any, any>> = Record<never, never>, Lists extends Record<string, ListDefinition<Context, any, any>> = Record<never, never>, Mutations extends Record<string, MutationDefinition<Context, any, any>> = Record<never, never>, AdapterContext = unknown>({
|
|
223
|
+
context,
|
|
224
|
+
lists,
|
|
225
|
+
live,
|
|
226
|
+
mutations,
|
|
227
|
+
queries,
|
|
228
|
+
roots,
|
|
229
|
+
sources
|
|
230
|
+
}: FateServerOptions<Context, Roots, Queries, Lists, Mutations, AdapterContext>): FateServer<NativeFateAPI<Roots, Queries, Lists, Mutations>, AdapterContext>;
|
|
231
|
+
declare function createFateFetchHandler<AdapterContext>(server: FateServer<unknown, AdapterContext>): (request: Request, adapterContext?: AdapterContext) => Promise<Response>;
|
|
232
|
+
declare function createHonoFateHandler<Context>(server: FateServer<unknown, Context>): (context: Context & {
|
|
233
|
+
req: {
|
|
234
|
+
raw: Request;
|
|
235
|
+
};
|
|
236
|
+
}) => Promise<Response>;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/protocol.d.ts
|
|
239
|
+
type FateProtocolVersion = 1;
|
|
240
|
+
type FateOperationKind = 'byId' | 'list' | 'mutation' | 'query';
|
|
241
|
+
type FateOperation = Readonly<{
|
|
242
|
+
args?: Record<string, unknown>;
|
|
243
|
+
id: string;
|
|
244
|
+
ids?: Array<string | number>;
|
|
245
|
+
input?: unknown;
|
|
246
|
+
kind: FateOperationKind;
|
|
247
|
+
name?: string;
|
|
248
|
+
select: Array<string>;
|
|
249
|
+
type?: string;
|
|
250
|
+
}>;
|
|
251
|
+
type FateOperationResult = Readonly<{
|
|
252
|
+
data: unknown;
|
|
253
|
+
id: string;
|
|
254
|
+
ok: true;
|
|
255
|
+
}> | Readonly<{
|
|
256
|
+
error: FateProtocolError;
|
|
257
|
+
id: string;
|
|
258
|
+
ok: false;
|
|
259
|
+
}>;
|
|
260
|
+
type FateProtocolRequest = Readonly<{
|
|
261
|
+
operations: Array<FateOperation>;
|
|
262
|
+
version: FateProtocolVersion;
|
|
263
|
+
}>;
|
|
264
|
+
type FateProtocolResponse = Readonly<{
|
|
265
|
+
results: Array<FateOperationResult>;
|
|
266
|
+
version: FateProtocolVersion;
|
|
267
|
+
}>;
|
|
268
|
+
type FateLiveDataEvent = Readonly<{
|
|
269
|
+
data: unknown;
|
|
270
|
+
delete?: false;
|
|
271
|
+
select?: Array<string>;
|
|
272
|
+
type?: 'data' | 'update';
|
|
273
|
+
}>;
|
|
274
|
+
type FateLiveDeleteEvent = Readonly<{
|
|
275
|
+
delete: true;
|
|
276
|
+
id?: string | number;
|
|
277
|
+
type?: 'delete';
|
|
278
|
+
}>;
|
|
279
|
+
type FateLiveEvent = FateLiveDataEvent | FateLiveDeleteEvent;
|
|
280
|
+
type FateLiveConnectionEvent = Readonly<{
|
|
281
|
+
edge: {
|
|
282
|
+
cursor?: string;
|
|
283
|
+
node: unknown;
|
|
284
|
+
};
|
|
285
|
+
nodeType: string;
|
|
286
|
+
targetCursor?: string;
|
|
287
|
+
type: 'appendEdge' | 'appendNode' | 'insertEdgeAfter' | 'insertEdgeBefore' | 'prependEdge' | 'prependNode';
|
|
288
|
+
}> | Readonly<{
|
|
289
|
+
id: string | number;
|
|
290
|
+
nodeType: string;
|
|
291
|
+
type: 'deleteEdge';
|
|
292
|
+
}> | Readonly<{
|
|
293
|
+
type: 'invalidate';
|
|
294
|
+
}>;
|
|
295
|
+
type FateProtocolErrorCode = 'BAD_REQUEST' | 'FORBIDDEN' | 'INTERNAL_ERROR' | 'NOT_FOUND' | 'UNAUTHORIZED' | 'VALIDATION_ERROR';
|
|
296
|
+
type FateProtocolError = Readonly<{
|
|
297
|
+
code: FateProtocolErrorCode;
|
|
298
|
+
issues?: unknown;
|
|
299
|
+
message: string;
|
|
300
|
+
path?: string;
|
|
301
|
+
}>;
|
|
302
|
+
declare class FateRequestError extends Error {
|
|
303
|
+
readonly code: FateProtocolErrorCode;
|
|
304
|
+
readonly issues?: unknown;
|
|
305
|
+
readonly status: number;
|
|
306
|
+
constructor(code: FateProtocolErrorCode, message: string, options?: {
|
|
307
|
+
issues?: unknown;
|
|
308
|
+
status?: number;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/record.d.ts
|
|
313
|
+
declare const isRecord: (value: unknown) => value is AnyRecord;
|
|
314
|
+
//#endregion
|
|
315
|
+
export { liveGlobalConnectionTopic as C, liveEntityTopic as S, LiveEventBus as _, FateProtocolRequest as a, createLiveEventBus as b, FateServer as c, NativeFateAPI as d, createFateFetchHandler as f, LiveConnectionSourceEvent as g, LiveConnectionEventType as h, FateOperation as i, FateServerManifest as l, createHonoFateHandler as m, FateLiveConnectionEvent as n, FateProtocolResponse as o, createFateServer as p, FateLiveEvent as r, FateRequestError as s, isRecord as t, InferFateAPI as u, LiveEventType as v, liveConnectionTopic as x, LiveSourceEvent as y };
|