@loozo/angular-launch 0.0.3 → 0.0.5
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 +290 -98
- package/builders/application.d.ts +4 -0
- package/builders/application.js +71 -0
- package/builders/options.d.ts +10 -0
- package/builders/options.js +64 -0
- package/builders/serve.d.ts +8 -0
- package/builders/serve.js +248 -0
- package/builders.json +15 -0
- package/client.d.ts +42 -21
- package/client.js +34 -16
- package/generation/context-file.d.ts +2 -0
- package/generation/context-file.js +3 -0
- package/generation/index.d.ts +8 -1
- package/generation/index.js +75 -38
- package/index.d.ts +1 -0
- package/input-issues.d.ts +56 -0
- package/input-issues.js +78 -0
- package/package.json +21 -3
- package/schemas/application.json +756 -0
- package/schemas/serve.json +153 -0
- package/server/backend.d.ts +3 -3
- package/server/backend.js +19 -8
- package/server/definitions.d.ts +347 -177
- package/server/definitions.js +82 -103
- package/server/dispatch.d.ts +45 -14
- package/server/dispatch.js +212 -73
- package/server/index.d.ts +4 -3
- package/server/index.js +2 -1
- package/server/outcomes.d.ts +26 -0
- package/server/outcomes.js +36 -0
- package/tanstack-query/README.md +164 -0
- package/tanstack-query/generated.d.ts +5 -0
- package/tanstack-query/generated.js +127 -0
- package/tanstack-query/hydration.d.ts +46 -0
- package/tanstack-query/hydration.js +70 -0
- package/tanstack-query/index.d.ts +2 -0
- package/tanstack-query/index.js +1 -0
- package/tanstack-query/queries.d.ts +124 -0
- package/tanstack-query/queries.js +1 -0
package/generation/index.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ export interface GenerationOptions {
|
|
|
6
6
|
scanDirectories: string[];
|
|
7
7
|
/** Where the application-wide generated files go, relative to the workspace. */
|
|
8
8
|
outDirectory: string;
|
|
9
|
+
/**
|
|
10
|
+
* Also writes `injectQueries()` and `type Queries` into each `rpc.generated.ts`: TanStack
|
|
11
|
+
* Query options and keys for the same groups as `injectRpc()`. Requires
|
|
12
|
+
* `@tanstack/angular-query` in the application and `provideLaunchQueries()` from
|
|
13
|
+
* `@loozo/angular-launch/tanstack-query` in its providers. Defaults to `false`.
|
|
14
|
+
*/
|
|
15
|
+
tanstackQuery?: boolean;
|
|
9
16
|
/**
|
|
10
17
|
* Verifies the generated files without writing them, failing when any is changed,
|
|
11
18
|
* missing or stale. Defaults to `false`.
|
|
@@ -113,4 +120,4 @@ export declare function generate(workspace: string, options: GenerationOptions,
|
|
|
113
120
|
* passed per call instead.
|
|
114
121
|
* @returns The session. Dispose it when done.
|
|
115
122
|
*/
|
|
116
|
-
export declare function createGenerationSession(workspace: string, { tsconfig, scanDirectories, outDirectory }: Omit<GenerationOptions, "check">): GenerationSession;
|
|
123
|
+
export declare function createGenerationSession(workspace: string, { tsconfig, scanDirectories, outDirectory, tanstackQuery }: Omit<GenerationOptions, "check">): GenerationSession;
|
package/generation/index.js
CHANGED
|
@@ -5,16 +5,46 @@ import { readFile, realpath } from "node:fs/promises";
|
|
|
5
5
|
import { dirname, resolve, relative, sep } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { prepareLaunchRoutes, createValidationProgram, validateRoutes, planOutputs, publish, walk, auditPath, launchMarkers, fail, properties, namedImport, genuineImport, specifier, CompilerState, AnchorState, } from "@loozo/angular-router/_generation";
|
|
8
|
+
import { contextFiles } from "./context-file.js";
|
|
8
9
|
function directCall(node, label) {
|
|
9
10
|
if (!ts.isCallExpression(node) || node.typeArguments?.length) {
|
|
10
11
|
fail(node, `${label} requires a direct nongeneric factory call`);
|
|
11
12
|
}
|
|
12
13
|
return node;
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const builderShape = "defineRpc requires an arrow function destructuring query and/or mutation, returning a parenthesized object of procedures";
|
|
16
|
+
// `({ query, mutation }) => ({ ... })`: the builder names it binds and its procedures.
|
|
17
|
+
function builderCallback(node) {
|
|
18
|
+
if (!ts.isArrowFunction(node) ||
|
|
19
|
+
node.modifiers?.length ||
|
|
20
|
+
node.typeParameters?.length ||
|
|
21
|
+
node.type ||
|
|
22
|
+
node.parameters.length !== 1) {
|
|
23
|
+
fail(node, builderShape);
|
|
24
|
+
}
|
|
25
|
+
const [parameter] = node.parameters;
|
|
26
|
+
if (!ts.isObjectBindingPattern(parameter.name) ||
|
|
27
|
+
parameter.type ||
|
|
28
|
+
parameter.initializer ||
|
|
29
|
+
parameter.dotDotDotToken) {
|
|
30
|
+
fail(parameter, builderShape);
|
|
31
|
+
}
|
|
32
|
+
const bound = new Set();
|
|
33
|
+
for (const element of parameter.name.elements) {
|
|
34
|
+
if (element.propertyName ||
|
|
35
|
+
element.initializer ||
|
|
36
|
+
element.dotDotDotToken ||
|
|
37
|
+
!ts.isIdentifier(element.name) ||
|
|
38
|
+
(element.name.text !== "query" && element.name.text !== "mutation") ||
|
|
39
|
+
bound.has(element.name.text)) {
|
|
40
|
+
fail(element, "defineRpc's callback may only destructure query and mutation, without renaming");
|
|
41
|
+
}
|
|
42
|
+
bound.add(element.name.text);
|
|
43
|
+
}
|
|
44
|
+
if (!ts.isParenthesizedExpression(node.body)) {
|
|
45
|
+
fail(node.body, builderShape);
|
|
46
|
+
}
|
|
47
|
+
return { bound, procedures: properties(node.body.expression, "RPC procedures") };
|
|
18
48
|
}
|
|
19
49
|
function onlyKeys(fields, allowed, node) {
|
|
20
50
|
for (const key of fields.keys()) {
|
|
@@ -93,14 +123,14 @@ async function groupsOf(sources) {
|
|
|
93
123
|
}
|
|
94
124
|
owners.add(owner);
|
|
95
125
|
const call = directCall(declaration.call, "defineRpc");
|
|
96
|
-
const [namespace,
|
|
126
|
+
const [namespace, build, options] = call.arguments;
|
|
97
127
|
if (call.arguments.length < 2 ||
|
|
98
128
|
call.arguments.length > 3 ||
|
|
99
129
|
!namespace ||
|
|
100
130
|
!ts.isStringLiteral(namespace) ||
|
|
101
131
|
!/^[A-Za-z_][A-Za-z0-9_]*$/.test(namespace.text) ||
|
|
102
|
-
!
|
|
103
|
-
fail(call, "defineRpc requires a literal identifier namespace,
|
|
132
|
+
!build) {
|
|
133
|
+
fail(call, "defineRpc requires a literal identifier namespace, a procedure callback and optional inline options");
|
|
104
134
|
}
|
|
105
135
|
if (namespace.text === "__proto__") {
|
|
106
136
|
fail(namespace, "RPC namespace '__proto__' is reserved");
|
|
@@ -112,11 +142,11 @@ async function groupsOf(sources) {
|
|
|
112
142
|
namespaces.set(namespace.text, declaration);
|
|
113
143
|
if (options) {
|
|
114
144
|
const fields = properties(options, "RPC group options");
|
|
115
|
-
onlyKeys(fields, ["
|
|
116
|
-
guards(fields.get("canActivate"));
|
|
145
|
+
onlyKeys(fields, ["use"], options);
|
|
117
146
|
}
|
|
147
|
+
const { bound, procedures } = builderCallback(build);
|
|
118
148
|
const methods = [];
|
|
119
|
-
for (const [name, value] of
|
|
149
|
+
for (const [name, value] of procedures) {
|
|
120
150
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
|
|
121
151
|
fail(value, "RPC methods must be identifier names");
|
|
122
152
|
}
|
|
@@ -124,38 +154,31 @@ async function groupsOf(sources) {
|
|
|
124
154
|
fail(value, "RPC procedure '__proto__' is reserved");
|
|
125
155
|
}
|
|
126
156
|
const procedure = directCall(value, "query/mutation");
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (imported && (await genuineImport(imported, launch.typeEntry, sources.parsed.options))) {
|
|
131
|
-
kind = candidate;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (!kind) {
|
|
135
|
-
fail(procedure, "Procedure must directly call a genuine named query import or mutation import");
|
|
157
|
+
// The callback's own binding: its body is an object literal, so nothing can shadow it.
|
|
158
|
+
if (!ts.isIdentifier(procedure.expression) || !bound.has(procedure.expression.text)) {
|
|
159
|
+
fail(procedure, "Procedure must directly call the callback's query or mutation");
|
|
136
160
|
}
|
|
161
|
+
const kind = procedure.expression.text;
|
|
137
162
|
if (procedure.arguments.length !== 1) {
|
|
138
163
|
fail(procedure, `${kind} requires one inline options object`);
|
|
139
164
|
}
|
|
140
165
|
const fields = properties(procedure.arguments[0], "Procedure options");
|
|
141
|
-
onlyKeys(fields, ["handler", "input", "
|
|
166
|
+
onlyKeys(fields, ["handler", "input", "use", "errors"], procedure);
|
|
142
167
|
if (!fields.has("handler")) {
|
|
143
168
|
fail(procedure, `${kind} requires handler`);
|
|
144
169
|
}
|
|
145
|
-
guards(fields.get("canActivate"));
|
|
146
170
|
methods.push({
|
|
147
171
|
name,
|
|
148
172
|
input: fields.has("input"),
|
|
149
173
|
kind,
|
|
150
174
|
errors: errorMetadata(fields.get("errors")),
|
|
151
|
-
call: procedure,
|
|
152
175
|
});
|
|
153
176
|
}
|
|
154
177
|
groups.push({ declaration, owner, namespace: namespace.text, methods });
|
|
155
178
|
}
|
|
156
179
|
return { context, groups };
|
|
157
180
|
}
|
|
158
|
-
function emitLaunch(sources, desired, context, groups, appId) {
|
|
181
|
+
function emitLaunch(sources, desired, context, groups, appId, tanstackQuery) {
|
|
159
182
|
const payloads = [];
|
|
160
183
|
function payloadImport(from, target, local, typeOnly = false) {
|
|
161
184
|
payloads.push({ from, target, local });
|
|
@@ -171,12 +194,13 @@ function emitLaunch(sources, desired, context, groups, appId) {
|
|
|
171
194
|
const server = [
|
|
172
195
|
launchMarkers["server.generated.ts"],
|
|
173
196
|
payloadImport(registry, context.file, "context"),
|
|
197
|
+
`import type { HandleOptions } from '@loozo/angular-launch/server';`,
|
|
174
198
|
`import { createRequestScope, handleRpc, provideLaunchServer } from '@loozo/angular-launch/_server';`,
|
|
175
199
|
];
|
|
176
200
|
for (let index = 0; index < groups.length; index += 1) {
|
|
177
201
|
server.push(payloadImport(registry, groups[index].declaration.file, `group${index}`));
|
|
178
202
|
}
|
|
179
|
-
server.push(`export const registry = { ${groups.map((group, index) => `${JSON.stringify(group.namespace)}: group${index}`).join(", ")} };`, `export const appBinding = { id: ${JSON.stringify(appId)}, context };`, `export const createContext = (request: Request) => createRequestScope(appBinding, request);`, `export const handleRequest = (request: Request) => handleRpc(registry, appBinding, request);`, `export const provideServer = () => provideLaunchServer(registry, appBinding);`, "");
|
|
203
|
+
server.push(`export const registry = { ${groups.map((group, index) => `${JSON.stringify(group.namespace)}: group${index}`).join(", ")} };`, `export const appBinding = { id: ${JSON.stringify(appId)}, context };`, `export const createContext = (request: Request) => createRequestScope(appBinding, request);`, `export const handleRequest = (request: Request, options: HandleOptions) => handleRpc(registry, appBinding, request, options);`, `export const provideServer = () => provideLaunchServer(registry, appBinding);`, "");
|
|
180
204
|
add(desired, registry, server.join("\n"));
|
|
181
205
|
const byOwner = new Map(groups.map((group) => [group.owner, group]));
|
|
182
206
|
for (const owner of sources.declarations) {
|
|
@@ -198,7 +222,11 @@ function emitLaunch(sources, desired, context, groups, appId) {
|
|
|
198
222
|
`import { injectClient } from '@loozo/angular-launch/_generated';`,
|
|
199
223
|
`import type { Client } from '@loozo/angular-launch';`,
|
|
200
224
|
];
|
|
225
|
+
if (tanstackQuery) {
|
|
226
|
+
lines.push(`import { createQueries } from '@loozo/angular-launch/_tanstack-query';`, `import type { RpcQueries } from '@loozo/angular-launch/tanstack-query';`);
|
|
227
|
+
}
|
|
201
228
|
const metadata = Object.create(null);
|
|
229
|
+
const queriesMetadata = Object.create(null);
|
|
202
230
|
for (let index = 0; index < available.length; index += 1) {
|
|
203
231
|
const group = available[index];
|
|
204
232
|
lines.push(payloadImport(file, group.declaration.file, `group${index}`, true));
|
|
@@ -210,8 +238,16 @@ function emitLaunch(sources, desired, context, groups, appId) {
|
|
|
210
238
|
errors,
|
|
211
239
|
})),
|
|
212
240
|
};
|
|
241
|
+
queriesMetadata[group.namespace] = Object.create(null);
|
|
242
|
+
for (const { name, kind, input } of group.methods) {
|
|
243
|
+
queriesMetadata[group.namespace][name] = { kind, input };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
lines.push(`export type Rpc = { ${available.map((group, index) => `readonly ${JSON.stringify(group.namespace)}: Client<typeof group${index}>`).join("; ")} };`, `export function injectRpc(): Rpc { return injectClient(${JSON.stringify(metadata)} as const) as Rpc; }`);
|
|
247
|
+
if (tanstackQuery) {
|
|
248
|
+
lines.push(`export type Queries = { ${available.map((group, index) => `readonly ${JSON.stringify(group.namespace)}: RpcQueries<typeof group${index}>`).join("; ")} };`, `export function injectQueries(): Queries { return createQueries(injectRpc(), ${JSON.stringify(queriesMetadata)} as const) as Queries; }`);
|
|
213
249
|
}
|
|
214
|
-
lines.push(
|
|
250
|
+
lines.push("");
|
|
215
251
|
add(desired, file, lines.join("\n"));
|
|
216
252
|
}
|
|
217
253
|
return payloads;
|
|
@@ -255,7 +291,7 @@ async function validateBindings(sources, validation, context, groups, compiler)
|
|
|
255
291
|
baseUrl: undefined,
|
|
256
292
|
skipLibCheck: false,
|
|
257
293
|
};
|
|
258
|
-
const anchor = await (compiler?.launchAnchor ?? new AnchorState()).anchor(entryFile, ["defineContext", "defineRpc"
|
|
294
|
+
const anchor = await (compiler?.launchAnchor ?? new AnchorState()).anchor(entryFile, ["defineContext", "defineRpc"], canonicalOptions);
|
|
259
295
|
const actualEntry = program.getSourceFile(entryFile);
|
|
260
296
|
const actualModule = checker.getSymbolAtLocation(actualEntry);
|
|
261
297
|
const expectedCalls = new Map();
|
|
@@ -265,9 +301,6 @@ async function validateBindings(sources, validation, context, groups, compiler)
|
|
|
265
301
|
expectedCalls.set(key(context.call), "defineContext");
|
|
266
302
|
for (const group of groups) {
|
|
267
303
|
expectedCalls.set(key(group.declaration.call), "defineRpc");
|
|
268
|
-
for (const method of group.methods) {
|
|
269
|
-
expectedCalls.set(key(method.call), method.kind);
|
|
270
|
-
}
|
|
271
304
|
}
|
|
272
305
|
const promises = [];
|
|
273
306
|
for (const source of program.getSourceFiles()) {
|
|
@@ -279,7 +312,7 @@ async function validateBindings(sources, validation, context, groups, compiler)
|
|
|
279
312
|
const expected = expectedCalls.get(key(node));
|
|
280
313
|
let spelling;
|
|
281
314
|
const invoked = unalias(checker, checker.getSymbolAtLocation(node.expression));
|
|
282
|
-
for (const name of ["defineContext", "defineRpc"
|
|
315
|
+
for (const name of ["defineContext", "defineRpc"]) {
|
|
283
316
|
const exported = unalias(checker, checker.getExportsOfModule(actualModule).find((symbol) => symbol.name === name));
|
|
284
317
|
if (invoked && invoked === exported) {
|
|
285
318
|
spelling = name;
|
|
@@ -290,7 +323,7 @@ async function validateBindings(sources, validation, context, groups, compiler)
|
|
|
290
323
|
}
|
|
291
324
|
if (expected || spelling) {
|
|
292
325
|
if (!expected || spelling !== expected) {
|
|
293
|
-
fail(node, "
|
|
326
|
+
fail(node, "defineContext and defineRpc calls must be default declarations");
|
|
294
327
|
}
|
|
295
328
|
const imported = namedImport(source, node.expression, expected);
|
|
296
329
|
promises.push((async () => {
|
|
@@ -327,7 +360,7 @@ async function validateBindings(sources, validation, context, groups, compiler)
|
|
|
327
360
|
const source = program.getSourceFile(group.declaration.file);
|
|
328
361
|
const assignment = source.statements.find(ts.isExportAssignment);
|
|
329
362
|
const call = assignment.expression;
|
|
330
|
-
for (const expression of
|
|
363
|
+
for (const expression of builderCallback(call.arguments[1]).procedures.values()) {
|
|
331
364
|
const procedure = expression;
|
|
332
365
|
const fields = properties(procedure.arguments[0], "Procedure options");
|
|
333
366
|
const input = fields.get("input");
|
|
@@ -422,7 +455,7 @@ function checkGeneratedDomain(sources, validation, generated) {
|
|
|
422
455
|
}));
|
|
423
456
|
}
|
|
424
457
|
}
|
|
425
|
-
async function runGeneration(workspace, options, stopped, compiler) {
|
|
458
|
+
async function runGeneration(workspace, options, stopped, compiler, discovered = () => undefined) {
|
|
426
459
|
// The built package root (dist/ in the workspace, the tarball root when installed).
|
|
427
460
|
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
428
461
|
const manifest = JSON.parse(await readFile(resolve(root, "package.json"), "utf8"));
|
|
@@ -465,6 +498,7 @@ async function runGeneration(workspace, options, stopped, compiler) {
|
|
|
465
498
|
throw new Error("Launch generation requires effective strict TypeScript checking: noCheck must be false");
|
|
466
499
|
}
|
|
467
500
|
const { context, groups } = await groupsOf(sources);
|
|
501
|
+
discovered(context.file);
|
|
468
502
|
const appManifest = JSON.parse(await readFile(resolve(application, "package.json"), "utf8"));
|
|
469
503
|
if (typeof appManifest.name !== "string" || appManifest.name.length === 0) {
|
|
470
504
|
throw new Error("Launch application package.json requires a name for generated app identity");
|
|
@@ -479,7 +513,7 @@ async function runGeneration(workspace, options, stopped, compiler) {
|
|
|
479
513
|
.update("\0")
|
|
480
514
|
.update(context.call.getSourceFile().text)
|
|
481
515
|
.digest("hex");
|
|
482
|
-
const payloads = emitLaunch(sources, desired, context, groups, appId);
|
|
516
|
+
const payloads = emitLaunch(sources, desired, context, groups, appId, options.tanstackQuery === true);
|
|
483
517
|
await auditPath(sources.output);
|
|
484
518
|
const outputInventory = await walk(sources.output);
|
|
485
519
|
const globals = [
|
|
@@ -570,9 +604,9 @@ export function generate(workspace, options, stopped = () => false) {
|
|
|
570
604
|
* passed per call instead.
|
|
571
605
|
* @returns The session. Dispose it when done.
|
|
572
606
|
*/
|
|
573
|
-
export function createGenerationSession(workspace, { tsconfig, scanDirectories, outDirectory }) {
|
|
607
|
+
export function createGenerationSession(workspace, { tsconfig, scanDirectories, outDirectory, tanstackQuery }) {
|
|
574
608
|
const application = resolve(workspace);
|
|
575
|
-
const fixed = { tsconfig, scanDirectories: [...scanDirectories], outDirectory };
|
|
609
|
+
const fixed = { tsconfig, scanDirectories: [...scanDirectories], outDirectory, tanstackQuery };
|
|
576
610
|
const compiler = {
|
|
577
611
|
discovery: new CompilerState(),
|
|
578
612
|
overlay: new CompilerState(),
|
|
@@ -586,7 +620,7 @@ export function createGenerationSession(workspace, { tsconfig, scanDirectories,
|
|
|
586
620
|
slot.clear();
|
|
587
621
|
}
|
|
588
622
|
}
|
|
589
|
-
|
|
623
|
+
const session = {
|
|
590
624
|
async generate({ check = false } = {}, stopped = () => false) {
|
|
591
625
|
if (closed) {
|
|
592
626
|
throw new Error("Generation session is disposed");
|
|
@@ -607,7 +641,9 @@ export function createGenerationSession(workspace, { tsconfig, scanDirectories,
|
|
|
607
641
|
}
|
|
608
642
|
return false;
|
|
609
643
|
}
|
|
610
|
-
const work = runGeneration(application, { ...fixed, check }, isStopped, compiler)
|
|
644
|
+
const work = runGeneration(application, { ...fixed, check }, isStopped, compiler, (file) => {
|
|
645
|
+
contextFiles.set(session, file);
|
|
646
|
+
});
|
|
611
647
|
active = work;
|
|
612
648
|
try {
|
|
613
649
|
await work;
|
|
@@ -629,4 +665,5 @@ export function createGenerationSession(workspace, { tsconfig, scanDirectories,
|
|
|
629
665
|
clear();
|
|
630
666
|
},
|
|
631
667
|
};
|
|
668
|
+
return session;
|
|
632
669
|
}
|
package/index.d.ts
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One problem an input schema found, as sent to the client in `INVALID_INPUT` data.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Only the schema issue's message and path are sent, never vendor details, input
|
|
6
|
+
* values or stacks, so write schema messages for users.
|
|
7
|
+
*/
|
|
8
|
+
export interface InputIssue {
|
|
9
|
+
/**
|
|
10
|
+
* Where the problem is, as property names and array indexes from the procedure's
|
|
11
|
+
* input. Empty for the input as a whole, or when the schema's path can't be
|
|
12
|
+
* represented in JSON, such as a symbol key.
|
|
13
|
+
*/
|
|
14
|
+
readonly path: readonly (string | number)[];
|
|
15
|
+
/** The schema's description of the problem. */
|
|
16
|
+
readonly message: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The data of an `INVALID_INPUT` error.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* A request that isn't a valid RPC envelope, such as a body that isn't JSON, has no
|
|
23
|
+
* issues.
|
|
24
|
+
*/
|
|
25
|
+
export interface InvalidInputData {
|
|
26
|
+
/** The problems the input schema found, in the schema's order. */
|
|
27
|
+
readonly issues: readonly InputIssue[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts Standard Schema issues to the issues sent to the client.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Internal; not exported from a public entry point. A path segment may be a property
|
|
34
|
+
* key or a `{ key }` object. An issue with a segment that isn't a string or a finite
|
|
35
|
+
* number gets the root path `[]`; it isn't stringified.
|
|
36
|
+
*
|
|
37
|
+
* @param issues - The issues a schema returned.
|
|
38
|
+
* @returns Each issue's message and normalized path, in the same order.
|
|
39
|
+
*/
|
|
40
|
+
export declare function inputIssues(issues: readonly {
|
|
41
|
+
readonly message: string;
|
|
42
|
+
readonly path?: readonly (PropertyKey | {
|
|
43
|
+
readonly key: PropertyKey;
|
|
44
|
+
})[] | undefined;
|
|
45
|
+
}[]): InputIssue[];
|
|
46
|
+
/**
|
|
47
|
+
* Checks whether a strict JSON value is exactly {@link InvalidInputData}.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* Internal; not exported from a public entry point. Used by the client to recognize
|
|
51
|
+
* `INVALID_INPUT` responses. Extra properties make the value unrecognized.
|
|
52
|
+
*
|
|
53
|
+
* @param value - Received error data, already checked to be strict JSON.
|
|
54
|
+
* @returns `true` when `value` is `{ issues }` with only `{ path, message }` issues.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isInvalidInputData(value: unknown): value is InvalidInputData;
|
package/input-issues.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function segment(value) {
|
|
2
|
+
if (typeof value === "string") {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Converts Standard Schema issues to the issues sent to the client.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Internal; not exported from a public entry point. A path segment may be a property
|
|
15
|
+
* key or a `{ key }` object. An issue with a segment that isn't a string or a finite
|
|
16
|
+
* number gets the root path `[]`; it isn't stringified.
|
|
17
|
+
*
|
|
18
|
+
* @param issues - The issues a schema returned.
|
|
19
|
+
* @returns Each issue's message and normalized path, in the same order.
|
|
20
|
+
*/
|
|
21
|
+
export function inputIssues(issues) {
|
|
22
|
+
const result = [];
|
|
23
|
+
for (const issue of issues) {
|
|
24
|
+
let path = [];
|
|
25
|
+
for (const raw of issue.path ?? []) {
|
|
26
|
+
let normalized;
|
|
27
|
+
if (typeof raw === "object" && raw !== null) {
|
|
28
|
+
normalized = segment(raw.key);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
normalized = segment(raw);
|
|
32
|
+
}
|
|
33
|
+
if (normalized === undefined) {
|
|
34
|
+
path = [];
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
path.push(normalized);
|
|
38
|
+
}
|
|
39
|
+
result.push({ path, message: issue.message });
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether a strict JSON value is exactly {@link InvalidInputData}.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Internal; not exported from a public entry point. Used by the client to recognize
|
|
48
|
+
* `INVALID_INPUT` responses. Extra properties make the value unrecognized.
|
|
49
|
+
*
|
|
50
|
+
* @param value - Received error data, already checked to be strict JSON.
|
|
51
|
+
* @returns `true` when `value` is `{ issues }` with only `{ path, message }` issues.
|
|
52
|
+
*/
|
|
53
|
+
export function isInvalidInputData(value) {
|
|
54
|
+
if (typeof value !== "object" ||
|
|
55
|
+
value === null ||
|
|
56
|
+
!("issues" in value) ||
|
|
57
|
+
Object.keys(value).length !== 1 ||
|
|
58
|
+
!Array.isArray(value.issues)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
for (const issue of value.issues) {
|
|
62
|
+
if (typeof issue !== "object" ||
|
|
63
|
+
issue === null ||
|
|
64
|
+
!("path" in issue) ||
|
|
65
|
+
!("message" in issue) ||
|
|
66
|
+
Object.keys(issue).length !== 2 ||
|
|
67
|
+
typeof issue.message !== "string" ||
|
|
68
|
+
!Array.isArray(issue.path)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
for (const part of issue.path) {
|
|
72
|
+
if (typeof part !== "string" && typeof part !== "number") {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loozo/angular-launch",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Typed queries, mutations and declared errors on Angular's native router, HTTP and SSR pipeline.",
|
|
5
5
|
"bugs": "https://github.com/theo-matzavinos/loozo/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,6 +32,14 @@
|
|
|
32
32
|
"types": "./generation/index.d.ts",
|
|
33
33
|
"node": "./generation/index.js"
|
|
34
34
|
},
|
|
35
|
+
"./tanstack-query": {
|
|
36
|
+
"types": "./tanstack-query/index.d.ts",
|
|
37
|
+
"default": "./tanstack-query/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./_tanstack-query": {
|
|
40
|
+
"types": "./tanstack-query/generated.d.ts",
|
|
41
|
+
"default": "./tanstack-query/generated.js"
|
|
42
|
+
},
|
|
35
43
|
"./package.json": "./package.json"
|
|
36
44
|
},
|
|
37
45
|
"publishConfig": {
|
|
@@ -39,12 +47,22 @@
|
|
|
39
47
|
"registry": "https://registry.npmjs.org/"
|
|
40
48
|
},
|
|
41
49
|
"dependencies": {
|
|
50
|
+
"@angular-devkit/architect": "0.2202.2",
|
|
51
|
+
"chokidar": "5.0.0",
|
|
42
52
|
"typescript": "6.0.3"
|
|
43
53
|
},
|
|
44
54
|
"peerDependencies": {
|
|
55
|
+
"@angular/build": "~22.2.0",
|
|
45
56
|
"@angular/common": "^22.0.0",
|
|
46
57
|
"@angular/core": "^22.0.0",
|
|
47
|
-
"@loozo/angular-router": "0.0.
|
|
58
|
+
"@loozo/angular-router": "0.0.6",
|
|
59
|
+
"@tanstack/angular-query": "^5.0.0-rc.5",
|
|
48
60
|
"rxjs": "^7.8.2"
|
|
49
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"@tanstack/angular-query": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"builders": "./builders.json"
|
|
50
68
|
}
|