@soda-gql/core 0.1.0 → 0.3.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 +108 -161
- package/dist/adapter.cjs +35 -0
- package/dist/adapter.cjs.map +1 -0
- package/dist/adapter.d.cts +35 -0
- package/dist/adapter.d.cts.map +1 -0
- package/dist/adapter.d.ts +35 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +34 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index-DH3lMepk.d.cts +569 -0
- package/dist/index-DH3lMepk.d.cts.map +1 -0
- package/dist/index-WU6aMZjg.d.ts +569 -0
- package/dist/index-WU6aMZjg.d.ts.map +1 -0
- package/dist/index.cjs +485 -470
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +97 -3
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +97 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +458 -443
- package/dist/index.js.map +1 -1
- package/dist/runtime.cjs +85 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +40 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.ts +40 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +82 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema-BElqa12z.d.cts +520 -0
- package/dist/schema-BElqa12z.d.cts.map +1 -0
- package/dist/schema-BbCrsNkQ.js +86 -0
- package/dist/schema-BbCrsNkQ.js.map +1 -0
- package/dist/schema-C7q047S0.d.ts +520 -0
- package/dist/schema-C7q047S0.d.ts.map +1 -0
- package/dist/schema-DuWaRhdp.cjs +122 -0
- package/dist/schema-DuWaRhdp.cjs.map +1 -0
- package/dist/schema-builder-DDfulXP3.d.cts +40 -0
- package/dist/schema-builder-DDfulXP3.d.cts.map +1 -0
- package/dist/schema-builder-DfyTaFMt.d.ts +40 -0
- package/dist/schema-builder-DfyTaFMt.d.ts.map +1 -0
- package/package.json +34 -14
- package/dist/index-DYwkqPzd.d.ts +0 -1015
- package/dist/index-DYwkqPzd.d.ts.map +0 -1
- package/dist/index-Db9ogofS.d.ts +0 -365
- package/dist/index-Db9ogofS.d.ts.map +0 -1
- package/dist/index-Dth0NSJt.d.cts +0 -1015
- package/dist/index-Dth0NSJt.d.cts.map +0 -1
- package/dist/index-zGZ61WLt.d.cts +0 -365
- package/dist/index-zGZ61WLt.d.cts.map +0 -1
- package/dist/merge-CeMx09is.js +0 -74
- package/dist/merge-CeMx09is.js.map +0 -1
- package/dist/merge-ZxKV1syS.cjs +0 -85
- package/dist/metadata/index.cjs +0 -62
- package/dist/metadata/index.d.cts +0 -71
- package/dist/metadata/index.d.cts.map +0 -1
- package/dist/metadata/index.d.ts +0 -71
- package/dist/metadata/index.d.ts.map +0 -1
- package/dist/metadata/index.js +0 -59
- package/dist/metadata/index.js.map +0 -1
- package/dist/runtime/index.cjs +0 -107
- package/dist/runtime/index.d.cts +0 -72
- package/dist/runtime/index.d.cts.map +0 -1
- package/dist/runtime/index.d.ts +0 -72
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js +0 -104
- package/dist/runtime/index.js.map +0 -1
- package/dist/slice-BuSNc8vw.js +0 -278
- package/dist/slice-BuSNc8vw.js.map +0 -1
- package/dist/slice-C-FIQK-f.cjs +0 -373
package/dist/slice-C-FIQK-f.cjs
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region packages/core/src/types/type-foundation/var-ref.ts
|
|
3
|
-
var VarRef = class {
|
|
4
|
-
constructor(inner) {
|
|
5
|
-
this.inner = inner;
|
|
6
|
-
}
|
|
7
|
-
static getInner(varRef) {
|
|
8
|
-
return varRef.inner;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
const isVarRef = (value) => {
|
|
12
|
-
return typeof value === "object" && value !== null && value instanceof VarRef;
|
|
13
|
-
};
|
|
14
|
-
const createVarRefFromVariable = (name) => {
|
|
15
|
-
return new VarRef({
|
|
16
|
-
type: "variable",
|
|
17
|
-
name
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
const createVarRefFromConstValue = (value) => {
|
|
21
|
-
return new VarRef({
|
|
22
|
-
type: "const-value",
|
|
23
|
-
value
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const getVarRefInner = (varRef) => {
|
|
27
|
-
return VarRef.getInner(varRef);
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Get the variable name from a VarRef.
|
|
31
|
-
* Throws if the VarRef contains a const-value instead of a variable reference.
|
|
32
|
-
*/
|
|
33
|
-
const getVarRefName = (varRef) => {
|
|
34
|
-
const inner = VarRef.getInner(varRef);
|
|
35
|
-
if (inner.type !== "variable") throw new Error("Expected variable reference, got const-value");
|
|
36
|
-
return inner.name;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Get the const value from a VarRef.
|
|
40
|
-
* Throws if the VarRef contains a variable reference instead of a const-value.
|
|
41
|
-
*/
|
|
42
|
-
const getVarRefValue = (varRef) => {
|
|
43
|
-
const inner = VarRef.getInner(varRef);
|
|
44
|
-
if (inner.type !== "const-value") throw new Error("Expected const-value, got variable reference");
|
|
45
|
-
return inner.value;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region packages/core/src/types/runtime/projection.ts
|
|
50
|
-
/**
|
|
51
|
-
* Nominal type representing any slice selection regardless of schema specifics.
|
|
52
|
-
* Encodes how individual slices map a concrete field path to a projection
|
|
53
|
-
* function. Multiple selections allow slices to expose several derived values.
|
|
54
|
-
*/
|
|
55
|
-
var Projection = class {
|
|
56
|
-
constructor(paths, projector) {
|
|
57
|
-
this.projector = projector;
|
|
58
|
-
this.paths = paths.map((path) => createProjectionPath(path));
|
|
59
|
-
}
|
|
60
|
-
paths;
|
|
61
|
-
};
|
|
62
|
-
function createProjectionPath(path) {
|
|
63
|
-
const segments = path.split(".");
|
|
64
|
-
if (path === "$" || segments.length <= 1) throw new Error("Field path must not be only $ or empty");
|
|
65
|
-
return {
|
|
66
|
-
full: path,
|
|
67
|
-
segments: segments.slice(1)
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region packages/core/src/types/runtime/sliced-execution-result.ts
|
|
73
|
-
/** Runtime guard interface shared by all slice result variants. */
|
|
74
|
-
var SlicedExecutionResultGuards = class {
|
|
75
|
-
isSuccess() {
|
|
76
|
-
return this.type === "success";
|
|
77
|
-
}
|
|
78
|
-
isError() {
|
|
79
|
-
return this.type === "error";
|
|
80
|
-
}
|
|
81
|
-
isEmpty() {
|
|
82
|
-
return this.type === "empty";
|
|
83
|
-
}
|
|
84
|
-
constructor(type) {
|
|
85
|
-
this.type = type;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
/** Variant representing an empty payload (no data, no error). */
|
|
89
|
-
var SlicedExecutionResultEmpty = class extends SlicedExecutionResultGuards {
|
|
90
|
-
constructor() {
|
|
91
|
-
super("empty");
|
|
92
|
-
}
|
|
93
|
-
unwrap() {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
safeUnwrap() {
|
|
97
|
-
return {
|
|
98
|
-
data: void 0,
|
|
99
|
-
error: void 0
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
/** Variant representing a successful payload. */
|
|
104
|
-
var SlicedExecutionResultSuccess = class extends SlicedExecutionResultGuards {
|
|
105
|
-
constructor(data, extensions) {
|
|
106
|
-
super("success");
|
|
107
|
-
this.data = data;
|
|
108
|
-
this.extensions = extensions;
|
|
109
|
-
}
|
|
110
|
-
unwrap() {
|
|
111
|
-
return this.data;
|
|
112
|
-
}
|
|
113
|
-
safeUnwrap(transform) {
|
|
114
|
-
return {
|
|
115
|
-
data: transform(this.data),
|
|
116
|
-
error: void 0
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
/** Variant representing an error payload created by the adapter. */
|
|
121
|
-
var SlicedExecutionResultError = class extends SlicedExecutionResultGuards {
|
|
122
|
-
constructor(error, extensions) {
|
|
123
|
-
super("error");
|
|
124
|
-
this.error = error;
|
|
125
|
-
this.extensions = extensions;
|
|
126
|
-
}
|
|
127
|
-
unwrap() {
|
|
128
|
-
throw this.error;
|
|
129
|
-
}
|
|
130
|
-
safeUnwrap() {
|
|
131
|
-
return {
|
|
132
|
-
data: void 0,
|
|
133
|
-
error: this.error
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region packages/core/src/runtime/parse-execution-result.ts
|
|
140
|
-
function* generateErrorMapEntries(errors, projectionPathGraph) {
|
|
141
|
-
for (const error of errors) {
|
|
142
|
-
const errorPath = error.path ?? [];
|
|
143
|
-
let stack = projectionPathGraph;
|
|
144
|
-
for (let i = 0; i <= errorPath.length; i++) {
|
|
145
|
-
const segment = errorPath[i];
|
|
146
|
-
if (segment == null || typeof segment === "number") {
|
|
147
|
-
yield* stack.matches.map(({ label, path }) => ({
|
|
148
|
-
label,
|
|
149
|
-
path,
|
|
150
|
-
error
|
|
151
|
-
}));
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
yield* stack.matches.filter(({ exact }) => exact).map(({ label, path }) => ({
|
|
155
|
-
label,
|
|
156
|
-
path,
|
|
157
|
-
error
|
|
158
|
-
}));
|
|
159
|
-
const next = stack.children[segment];
|
|
160
|
-
if (!next) break;
|
|
161
|
-
stack = next;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const createErrorMaps = (errors, projectionPathGraph) => {
|
|
166
|
-
const errorMaps = {};
|
|
167
|
-
for (const { label, path, error } of generateErrorMapEntries(errors ?? [], projectionPathGraph)) {
|
|
168
|
-
const mapPerLabel = errorMaps[label] || (errorMaps[label] = {});
|
|
169
|
-
(mapPerLabel[path] || (mapPerLabel[path] = [])).push({ error });
|
|
170
|
-
}
|
|
171
|
-
return errorMaps;
|
|
172
|
-
};
|
|
173
|
-
const accessDataByPathSegments = (data, pathSegments) => {
|
|
174
|
-
let current = data;
|
|
175
|
-
for (const segment of pathSegments) {
|
|
176
|
-
if (current == null) return { error: /* @__PURE__ */ new Error("No data") };
|
|
177
|
-
if (typeof current !== "object") return { error: /* @__PURE__ */ new Error("Incorrect data type") };
|
|
178
|
-
if (Array.isArray(current)) return { error: /* @__PURE__ */ new Error("Incorrect data type") };
|
|
179
|
-
current = current[segment];
|
|
180
|
-
}
|
|
181
|
-
return { data: current };
|
|
182
|
-
};
|
|
183
|
-
const createExecutionResultParser = ({ fragments, projectionPathGraph }) => {
|
|
184
|
-
const prepare = (result) => {
|
|
185
|
-
if (result.type === "graphql") {
|
|
186
|
-
const errorMaps = createErrorMaps(result.body.errors, projectionPathGraph);
|
|
187
|
-
return {
|
|
188
|
-
...result,
|
|
189
|
-
errorMaps
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
if (result.type === "non-graphql-error") return {
|
|
193
|
-
...result,
|
|
194
|
-
error: new SlicedExecutionResultError({
|
|
195
|
-
type: "non-graphql-error",
|
|
196
|
-
error: result.error
|
|
197
|
-
})
|
|
198
|
-
};
|
|
199
|
-
if (result.type === "empty") return {
|
|
200
|
-
...result,
|
|
201
|
-
error: new SlicedExecutionResultEmpty()
|
|
202
|
-
};
|
|
203
|
-
throw new Error("Invalid result type", { cause: result });
|
|
204
|
-
};
|
|
205
|
-
return (result) => {
|
|
206
|
-
const prepared = prepare(result);
|
|
207
|
-
const entries = Object.entries(fragments).map(([label, fragment]) => {
|
|
208
|
-
const { projection } = fragment;
|
|
209
|
-
if (prepared.type === "graphql") {
|
|
210
|
-
const matchedErrors = projection.paths.flatMap(({ full: raw }) => prepared.errorMaps[label]?.[raw] ?? []);
|
|
211
|
-
const uniqueErrors = Array.from(new Set(matchedErrors.map(({ error }) => error)).values());
|
|
212
|
-
if (uniqueErrors.length > 0) return [label, projection.projector(new SlicedExecutionResultError({
|
|
213
|
-
type: "graphql-error",
|
|
214
|
-
errors: uniqueErrors
|
|
215
|
-
}))];
|
|
216
|
-
const dataResults = projection.paths.map(({ segments }) => prepared.body.data ? accessDataByPathSegments(prepared.body.data, segments) : { error: /* @__PURE__ */ new Error("No data") });
|
|
217
|
-
if (dataResults.some(({ error }) => error)) {
|
|
218
|
-
const errors = dataResults.flatMap(({ error }) => error ? [error] : []);
|
|
219
|
-
return [label, projection.projector(new SlicedExecutionResultError({
|
|
220
|
-
type: "parse-error",
|
|
221
|
-
errors
|
|
222
|
-
}))];
|
|
223
|
-
}
|
|
224
|
-
const dataList = dataResults.map(({ data }) => data);
|
|
225
|
-
return [label, projection.projector(new SlicedExecutionResultSuccess(dataList))];
|
|
226
|
-
}
|
|
227
|
-
if (prepared.type === "non-graphql-error") return [label, projection.projector(prepared.error)];
|
|
228
|
-
if (prepared.type === "empty") return [label, projection.projector(prepared.error)];
|
|
229
|
-
throw new Error("Invalid result type", { cause: prepared });
|
|
230
|
-
});
|
|
231
|
-
return Object.fromEntries(entries);
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region packages/core/src/utils/map-values.ts
|
|
237
|
-
function mapValues(obj, fn) {
|
|
238
|
-
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value, key)]));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region packages/core/src/composer/input.ts
|
|
243
|
-
const mergeVarDefinitions = (definitions) => Object.assign({}, ...definitions);
|
|
244
|
-
const createVarAssignments = (definitions, providedValues) => {
|
|
245
|
-
return mapValues(definitions, (_definition, key) => {
|
|
246
|
-
const varName = key;
|
|
247
|
-
if (!providedValues || providedValues[varName] === void 0) return createVarRefFromConstValue(void 0);
|
|
248
|
-
const provided = providedValues[varName];
|
|
249
|
-
if (isVarRef(provided)) return provided;
|
|
250
|
-
return createVarRefFromConstValue(provided);
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
const createVarRefs = (definitions) => mapValues(definitions, (_ref, name) => createVarRefFromVariable(name));
|
|
254
|
-
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region packages/core/src/utils/hidden.ts
|
|
257
|
-
const _dummy = () => {
|
|
258
|
-
throw new Error("DO NOT CALL THIS FUNCTION -- we use function to safely transfer type information");
|
|
259
|
-
};
|
|
260
|
-
const hidden = () => _dummy;
|
|
261
|
-
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region packages/core/src/runtime/slice.ts
|
|
264
|
-
const handleProjectionBuilder = (projectionBuilder) => projectionBuilder({ select: (path, projector) => new Projection(path, projector) });
|
|
265
|
-
const createRuntimeSlice = (input) => {
|
|
266
|
-
const projection = handleProjectionBuilder(input.runtime.buildProjection);
|
|
267
|
-
return {
|
|
268
|
-
operationType: input.prebuild.operationType,
|
|
269
|
-
embed: (variables) => ({
|
|
270
|
-
variables,
|
|
271
|
-
getFields: hidden(),
|
|
272
|
-
projection
|
|
273
|
-
})
|
|
274
|
-
};
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
//#endregion
|
|
278
|
-
Object.defineProperty(exports, 'Projection', {
|
|
279
|
-
enumerable: true,
|
|
280
|
-
get: function () {
|
|
281
|
-
return Projection;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
Object.defineProperty(exports, 'SlicedExecutionResultEmpty', {
|
|
285
|
-
enumerable: true,
|
|
286
|
-
get: function () {
|
|
287
|
-
return SlicedExecutionResultEmpty;
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
Object.defineProperty(exports, 'SlicedExecutionResultError', {
|
|
291
|
-
enumerable: true,
|
|
292
|
-
get: function () {
|
|
293
|
-
return SlicedExecutionResultError;
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
Object.defineProperty(exports, 'SlicedExecutionResultSuccess', {
|
|
297
|
-
enumerable: true,
|
|
298
|
-
get: function () {
|
|
299
|
-
return SlicedExecutionResultSuccess;
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
Object.defineProperty(exports, 'VarRef', {
|
|
303
|
-
enumerable: true,
|
|
304
|
-
get: function () {
|
|
305
|
-
return VarRef;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
Object.defineProperty(exports, 'createExecutionResultParser', {
|
|
309
|
-
enumerable: true,
|
|
310
|
-
get: function () {
|
|
311
|
-
return createExecutionResultParser;
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
Object.defineProperty(exports, 'createRuntimeSlice', {
|
|
315
|
-
enumerable: true,
|
|
316
|
-
get: function () {
|
|
317
|
-
return createRuntimeSlice;
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
Object.defineProperty(exports, 'createVarAssignments', {
|
|
321
|
-
enumerable: true,
|
|
322
|
-
get: function () {
|
|
323
|
-
return createVarAssignments;
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
Object.defineProperty(exports, 'createVarRefs', {
|
|
327
|
-
enumerable: true,
|
|
328
|
-
get: function () {
|
|
329
|
-
return createVarRefs;
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
Object.defineProperty(exports, 'getVarRefInner', {
|
|
333
|
-
enumerable: true,
|
|
334
|
-
get: function () {
|
|
335
|
-
return getVarRefInner;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
Object.defineProperty(exports, 'getVarRefName', {
|
|
339
|
-
enumerable: true,
|
|
340
|
-
get: function () {
|
|
341
|
-
return getVarRefName;
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
Object.defineProperty(exports, 'getVarRefValue', {
|
|
345
|
-
enumerable: true,
|
|
346
|
-
get: function () {
|
|
347
|
-
return getVarRefValue;
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
Object.defineProperty(exports, 'handleProjectionBuilder', {
|
|
351
|
-
enumerable: true,
|
|
352
|
-
get: function () {
|
|
353
|
-
return handleProjectionBuilder;
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
Object.defineProperty(exports, 'hidden', {
|
|
357
|
-
enumerable: true,
|
|
358
|
-
get: function () {
|
|
359
|
-
return hidden;
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
Object.defineProperty(exports, 'mapValues', {
|
|
363
|
-
enumerable: true,
|
|
364
|
-
get: function () {
|
|
365
|
-
return mapValues;
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
Object.defineProperty(exports, 'mergeVarDefinitions', {
|
|
369
|
-
enumerable: true,
|
|
370
|
-
get: function () {
|
|
371
|
-
return mergeVarDefinitions;
|
|
372
|
-
}
|
|
373
|
-
});
|