@aventara/client 0.1.0-pilot.1 → 0.1.0-pilot.3
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 +44 -9
- package/dist/avclient.bin.js +0 -10
- package/dist/cli/command.parser.d.ts +15 -10
- package/dist/cli/command.parser.js +13 -19
- package/dist/cli/generate.command.js +0 -6
- package/dist/cli/generation-failure.renderer.js +0 -14
- package/dist/cli/generation-success.renderer.d.ts +4 -1
- package/dist/cli/generation-success.renderer.js +0 -13
- package/dist/cli/terminal.prompter.d.ts +1 -2
- package/dist/cli/warning.renderer.d.ts +2 -2
- package/dist/cli/warning.renderer.js +0 -8
- package/dist/cli.d.ts +8 -16
- package/dist/cli.js +5 -25
- package/dist/config/client-config.interface.d.ts +18 -16
- package/dist/config/client-config.interface.js +0 -13
- package/dist/config/config.loader.d.ts +34 -22
- package/dist/config/config.loader.js +49 -52
- package/dist/config/config.resolver.d.ts +13 -19
- package/dist/config/config.resolver.js +9 -48
- package/dist/config/env.cascade.d.ts +12 -14
- package/dist/config/env.cascade.js +0 -19
- package/dist/config/module-style.resolver.d.ts +52 -0
- package/dist/config/module-style.resolver.js +75 -0
- package/dist/config/tsconfig.locator.d.ts +45 -0
- package/dist/config/tsconfig.locator.js +52 -0
- package/dist/contract/contract.acceptance.d.ts +12 -26
- package/dist/contract/contract.acceptance.js +0 -54
- package/dist/contract/contract.fetcher.d.ts +12 -17
- package/dist/contract/contract.fetcher.js +0 -24
- package/dist/contract/contract.loader.d.ts +4 -5
- package/dist/contract/contract.loader.js +0 -10
- package/dist/emit/banner.emitter.d.ts +11 -12
- package/dist/emit/banner.emitter.js +0 -26
- package/dist/emit/client-surface.emitter.d.ts +17 -21
- package/dist/emit/client-surface.emitter.js +29 -55
- package/dist/emit/client-tree.emitter.d.ts +11 -20
- package/dist/emit/client-tree.emitter.js +12 -54
- package/dist/emit/contract-carrier.emitter.d.ts +5 -6
- package/dist/emit/contract-carrier.emitter.js +0 -28
- package/dist/emit/derivation.emitter.d.ts +7 -7
- package/dist/emit/derivation.emitter.js +2 -161
- package/dist/emit/descriptor.emitter.js +2 -28
- package/dist/emit/emitted-tree.interface.d.ts +40 -17
- package/dist/emit/emitted-tree.interface.js +6 -16
- package/dist/emit/enum.emitter.d.ts +4 -4
- package/dist/emit/enum.emitter.js +0 -24
- package/dist/emit/module-specifier.scanner.d.ts +25 -0
- package/dist/emit/module-specifier.scanner.js +160 -0
- package/dist/emit/module-style.interface.d.ts +58 -0
- package/dist/emit/module-style.interface.js +8 -0
- package/dist/emit/name.deriver.d.ts +33 -61
- package/dist/emit/name.deriver.js +0 -134
- package/dist/emit/named-type.emitter.d.ts +14 -21
- package/dist/emit/named-type.emitter.js +3 -30
- package/dist/emit/runtime.emitter.d.ts +23 -50
- package/dist/emit/runtime.emitter.js +68 -159
- package/dist/emit/scalar.codec.d.ts +20 -33
- package/dist/emit/scalar.codec.js +13 -69
- package/dist/emit/transaction.emitter.d.ts +6 -14
- package/dist/emit/transaction.emitter.js +24 -33
- package/dist/generate.d.ts +20 -34
- package/dist/generate.js +14 -22
- package/dist/index.js +0 -5
- package/dist/init/client-config.template.d.ts +6 -4
- package/dist/init/client-config.template.js +10 -13
- package/dist/init/client-init.errors.js +0 -3
- package/dist/init/client-init.orchestrator.js +8 -9
- package/dist/init/client-init.planner.d.ts +1 -9
- package/dist/init/client-init.planner.js +16 -24
- package/dist/init/client-init.questions.d.ts +8 -12
- package/dist/init/client-init.questions.js +0 -11
- package/dist/init/client-project.inspector.d.ts +6 -0
- package/dist/init/client-project.inspector.js +2 -2
- package/dist/node-version.guard.js +0 -12
- package/dist/output/output.validator.d.ts +49 -27
- package/dist/output/output.validator.js +113 -74
- package/dist/output/output.writer.d.ts +59 -52
- package/dist/output/output.writer.js +72 -134
- package/package.json +6 -4
|
@@ -1,80 +1,5 @@
|
|
|
1
1
|
import { isOperationVariantAvailable, } from "@aventara/core";
|
|
2
2
|
import { FRAMEWORK_ERROR_CLASS_NAMES } from "./runtime.emitter.js";
|
|
3
|
-
/**
|
|
4
|
-
* Name derivation and the rename ladder for the emitted tree.
|
|
5
|
-
*
|
|
6
|
-
* # Renamed, not refused (architect decision, 2026-10-04)
|
|
7
|
-
*
|
|
8
|
-
* S4 shipped "verbatim, or refused — never renamed". The architect overturned it:
|
|
9
|
-
* a Contract name the emitted TypeScript cannot declare as-is is RENAMED, and the
|
|
10
|
-
* rename is the TypeScript identifier's alone. The name the server uses — the
|
|
11
|
-
* wire name a Resource is addressed by — is kept beside it unchanged
|
|
12
|
-
* (`EmittedName.contractName`), so a later emitter that sends a request reads that,
|
|
13
|
-
* never the identifier. Every rename is one warning line on the result; generation
|
|
14
|
-
* does not print.
|
|
15
|
-
*
|
|
16
|
-
* A name is unusable as-is when it is not an identifier, is a reserved word, is a
|
|
17
|
-
* predefined type's name, is a name the generated runtime owns, or — an enum only
|
|
18
|
-
* — is also a Resource's name. Its ladder is tried in order and the first rung
|
|
19
|
-
* that is usable AND free of every other emitted name (verbatim or renamed) wins:
|
|
20
|
-
*
|
|
21
|
-
* - Resource `X`: `XModel` → `ResourceX` → `X_` → `_X` → `_X_` → refused;
|
|
22
|
-
* - enum `X`: `XEnum` → `EnumX` → `X_` → refused.
|
|
23
|
-
*
|
|
24
|
-
* Only a name whose whole ladder is unusable or taken is refused, in one sentence —
|
|
25
|
-
* and a name no rename can repair, which is refused without trying a rung: the
|
|
26
|
-
* empty name. Every rung of its ladder is a bare affix (`Model`, `Enum`, `_`) that
|
|
27
|
-
* names nothing on the server, so "renaming" it would invent an identifier rather
|
|
28
|
-
* than repair one (architect's rule, 2026-10-04: refuse when unrepairable).
|
|
29
|
-
*
|
|
30
|
-
* # Determinism
|
|
31
|
-
*
|
|
32
|
-
* The same Contract always yields the same names, whatever order its keys arrive
|
|
33
|
-
* in: every name usable as-is is claimed first (so a usable name is never displaced
|
|
34
|
-
* by another's rename), then Resources are renamed, then enums, each registry in
|
|
35
|
-
* UTF-16 code-unit order of its contract names. An enum sharing a Resource's name
|
|
36
|
-
* walks its ladder and the Resource keeps the name.
|
|
37
|
-
*
|
|
38
|
-
* # One namespace
|
|
39
|
-
*
|
|
40
|
-
* Enum and Resource identifiers share the generated client's root namespace with
|
|
41
|
-
* each other and with the runtime's own exports. §15.6 names a Resource's type by
|
|
42
|
-
* the Resource's name (`Spell`), so that namespace is claimed now, before the
|
|
43
|
-
* Resource types are emitted. Names are case-sensitive.
|
|
44
|
-
*
|
|
45
|
-
* # Derived names (Phase 12-rest Q10; the ladder rule, a plan ruling)
|
|
46
|
-
*
|
|
47
|
-
* §15.6 derives named types from a Resource (`SpellWhere`, `SpellOrderBy`, …;
|
|
48
|
-
* {@link RESOURCE_NAMED_TYPES}), each only when the operation it reads is
|
|
49
|
-
* advertised. A Resource's base name is taken at the first rung — its own name
|
|
50
|
-
* first, when usable — where the base AND every name derived from it are free of
|
|
51
|
-
* every other emitted name: `User` beside a Resource `UserWhere` walks to
|
|
52
|
-
* `UserModel`, one warning. Derived names a Resource claims are claimed for good,
|
|
53
|
-
* so a later Resource or enum never takes one. The generated modules that declare
|
|
54
|
-
* these names use no global type a Resource could shadow (`types.d.ts` imports two
|
|
55
|
-
* helpers, which are reserved).
|
|
56
|
-
*
|
|
57
|
-
* # Properties (Phase 12-rest Q12)
|
|
58
|
-
*
|
|
59
|
-
* A Resource is reached as a property of the client, named by its contract name.
|
|
60
|
-
* A contract name equal to one of the client's own members
|
|
61
|
-
* ({@link CLIENT_MEMBER_NAMES}) walks the Resource ladder for its PROPERTY only,
|
|
62
|
-
* one warning; the wire name, and the TypeScript type names, are unaffected.
|
|
63
|
-
*
|
|
64
|
-
* Reads registry KEYS and which operations are advertised. No capability member.
|
|
65
|
-
*/
|
|
66
|
-
/**
|
|
67
|
-
* The names the generated client declares in the root namespace: those §15.4
|
|
68
|
-
* and §13.4 give it, under the architect's names (Phase 12-rest Q7–Q9) — the
|
|
69
|
-
* `avClient` singleton, `AvClient`, `AvClientOptions`, `CallOptions`, `Fetch`,
|
|
70
|
-
* `Decimal`, `FrameworkError`, `NotFoundError`, `TransportError`,
|
|
71
|
-
* `OperationCode`/`ValidationCode` and `Operation<T>`, plus `Cause` and
|
|
72
|
-
* `ValidationIssue` (public by the architect's decision of 2026-10-04) — every
|
|
73
|
-
* `FrameworkError` subclass Q2 adds, read from the runtime emitter that declares
|
|
74
|
-
* them, and the two helpers `types.d.ts` imports to declare the named types
|
|
75
|
-
* (`ResourceArgument`, `ResourceRecord`). A Contract name equal to one of them
|
|
76
|
-
* walks its rename ladder. In UTF-16 code-unit order.
|
|
77
|
-
*/
|
|
78
3
|
export const RESERVED_EMITTED_NAMES = [
|
|
79
4
|
...new Set([
|
|
80
5
|
"AvClient",
|
|
@@ -96,7 +21,6 @@ export const RESERVED_EMITTED_NAMES = [
|
|
|
96
21
|
...FRAMEWORK_ERROR_CLASS_NAMES,
|
|
97
22
|
]),
|
|
98
23
|
].sort();
|
|
99
|
-
/** §15.6's set exactly (Q10 = a), in §15.6's order. */
|
|
100
24
|
export const RESOURCE_NAMED_TYPES = [
|
|
101
25
|
{ suffix: "", family: "find", variant: "unique" },
|
|
102
26
|
{ suffix: "Where", family: "find", variant: "many", argument: "where" },
|
|
@@ -117,20 +41,10 @@ export const RESOURCE_NAMED_TYPES = [
|
|
|
117
41
|
{ suffix: "Select", family: "find", variant: "many", argument: "select" },
|
|
118
42
|
{ suffix: "Include", family: "find", variant: "many", argument: "include" },
|
|
119
43
|
];
|
|
120
|
-
/** The named types a Resource with `operations` gets: those whose operation it advertises. */
|
|
121
44
|
export function namedTypesOf(operations) {
|
|
122
45
|
const families = (operations ?? {});
|
|
123
46
|
return RESOURCE_NAMED_TYPES.filter((named) => isOperationVariantAvailable(families[named.family]?.[named.variant]));
|
|
124
47
|
}
|
|
125
|
-
/**
|
|
126
|
-
* The client's own members, which a Resource property must not shadow (Q12):
|
|
127
|
-
* `tx` and `transaction` (reserved whether or not the contract advertises
|
|
128
|
-
* transactions, so a property never moves with `transactions`), `then` — a client
|
|
129
|
-
* with a `then` is a thenable, and `await` would call it — and every name
|
|
130
|
-
* `Object.prototype` carries in ES2022, `constructor` among them. Fixed here, not
|
|
131
|
-
* read from the running Node, so the output never moves with the generator's
|
|
132
|
-
* runtime. In UTF-16 code-unit order.
|
|
133
|
-
*/
|
|
134
48
|
export const CLIENT_MEMBER_NAMES = [
|
|
135
49
|
"__defineGetter__",
|
|
136
50
|
"__defineSetter__",
|
|
@@ -148,25 +62,10 @@ export const CLIENT_MEMBER_NAMES = [
|
|
|
148
62
|
"tx",
|
|
149
63
|
"valueOf",
|
|
150
64
|
];
|
|
151
|
-
/**
|
|
152
|
-
* A TypeScript identifier: ID_Start, `$` or `_`, then ID_Continue, `$`, ZWNJ, ZWJ —
|
|
153
|
-
* ECMAScript's IdentifierName. ZWNJ and ZWJ are ID_Continue since Unicode 15.1, so
|
|
154
|
-
* on this repository's Node (Unicode 17.0, measured) their explicit escapes are
|
|
155
|
-
* redundant; they stay so the rule does not depend on the runtime's tables.
|
|
156
|
-
*/
|
|
157
65
|
const IDENTIFIER = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u;
|
|
158
|
-
/** Whether `text` is an IdentifierName — the rule above, for every emitter. */
|
|
159
66
|
export function isIdentifierName(text) {
|
|
160
67
|
return IDENTIFIER.test(text);
|
|
161
68
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Words `export type <name> = …` or `export const <name> = …` does not accept in a
|
|
164
|
-
* module, measured against this repository's `tsc` (2026-10-04, NodeNext strict):
|
|
165
|
-
* ECMAScript's reserved words, the strict-mode reserved words (a module is
|
|
166
|
-
* strict), `await` (a module may await at top level), `as`, which is not reserved
|
|
167
|
-
* but does not parse after `type`, and `arguments`/`eval`, which strict code
|
|
168
|
-
* cannot bind (TS1215) — measured again when enums gained their const.
|
|
169
|
-
*/
|
|
170
69
|
const RESERVED_WORDS = new Set([
|
|
171
70
|
"arguments",
|
|
172
71
|
"as",
|
|
@@ -218,7 +117,6 @@ const RESERVED_WORDS = new Set([
|
|
|
218
117
|
"with",
|
|
219
118
|
"yield",
|
|
220
119
|
]);
|
|
221
|
-
/** TS2457: a type alias cannot take a predefined type's name. */
|
|
222
120
|
const PREDEFINED_TYPES = new Set([
|
|
223
121
|
"any",
|
|
224
122
|
"bigint",
|
|
@@ -232,7 +130,6 @@ const PREDEFINED_TYPES = new Set([
|
|
|
232
130
|
"unknown",
|
|
233
131
|
]);
|
|
234
132
|
const RESERVED_EMITTED = new Set(RESERVED_EMITTED_NAMES);
|
|
235
|
-
/** The rungs a name of `kind` tries, in order (architect decision, 2026-10-04). */
|
|
236
133
|
const LADDERS = {
|
|
237
134
|
Resource: (name) => [
|
|
238
135
|
`${name}Model`,
|
|
@@ -243,12 +140,6 @@ const LADDERS = {
|
|
|
243
140
|
],
|
|
244
141
|
enum: (name) => [`${name}Enum`, `Enum${name}`, `${name}_`],
|
|
245
142
|
};
|
|
246
|
-
/**
|
|
247
|
-
* The emitted names of a Contract's enums and Resources, renamed where a name
|
|
248
|
-
* cannot be declared as-is.
|
|
249
|
-
*
|
|
250
|
-
* @throws GeneratedNameError naming every name no rung of its ladder can repair.
|
|
251
|
-
*/
|
|
252
143
|
export function deriveEmittedNames(contract) {
|
|
253
144
|
const resourceNames = Object.keys(contract.resources).sort();
|
|
254
145
|
const enumNames = Object.keys(contract.enums).sort();
|
|
@@ -257,15 +148,11 @@ export function deriveEmittedNames(contract) {
|
|
|
257
148
|
(kind === "enum" && resourceSet.has(name)
|
|
258
149
|
? "shares its name with a Resource"
|
|
259
150
|
: undefined);
|
|
260
|
-
// Every name usable as-is is claimed before any rename picks a rung, so a
|
|
261
|
-
// usable name is never displaced by another's rename.
|
|
262
151
|
const taken = new Set([
|
|
263
152
|
...resourceNames.filter((name) => reasonOf("Resource", name) === undefined),
|
|
264
153
|
...enumNames.filter((name) => reasonOf("enum", name) === undefined),
|
|
265
154
|
]);
|
|
266
|
-
// The names Resources derive (Q10), claimed as each Resource settles.
|
|
267
155
|
const derivedTaken = new Set();
|
|
268
|
-
/** `base`'s derived names for Resource `name`, or the first that is not free. */
|
|
269
156
|
const derivedNames = (name, base) => namedTypesOf(contract.resources[name]?.operations)
|
|
270
157
|
.filter((named) => named.suffix !== "")
|
|
271
158
|
.map((named) => `${base}${named.suffix}`);
|
|
@@ -323,8 +210,6 @@ export function deriveEmittedNames(contract) {
|
|
|
323
210
|
});
|
|
324
211
|
return settle(identifier);
|
|
325
212
|
};
|
|
326
|
-
// Resources first: in a clash the Resource keeps the name, and a Resource's
|
|
327
|
-
// rename is settled before any enum's.
|
|
328
213
|
const resources = resourceNames.map((name) => resolve("Resource", name));
|
|
329
214
|
const enums = enumNames.map((name) => resolve("enum", name));
|
|
330
215
|
const properties = resourceProperties(resourceNames, warnings, refusals);
|
|
@@ -334,12 +219,6 @@ export function deriveEmittedNames(contract) {
|
|
|
334
219
|
return { enums, resources, properties, warnings: byName(warnings) };
|
|
335
220
|
}
|
|
336
221
|
const CLIENT_MEMBERS = new Set(CLIENT_MEMBER_NAMES);
|
|
337
|
-
/**
|
|
338
|
-
* Each Resource's property on the client (Q12): its contract name, unless that is
|
|
339
|
-
* one of the client's members — then the first rung of the Resource ladder that is
|
|
340
|
-
* neither a member nor another Resource's property. A property need not be an
|
|
341
|
-
* identifier (it is a key, quoted where needed), so only those two tests apply.
|
|
342
|
-
*/
|
|
343
222
|
function resourceProperties(resourceNames, warnings, refusals) {
|
|
344
223
|
const claimed = new Set(resourceNames.filter((name) => !CLIENT_MEMBERS.has(name)));
|
|
345
224
|
return resourceNames.map((name) => {
|
|
@@ -364,7 +243,6 @@ function resourceProperties(resourceNames, warnings, refusals) {
|
|
|
364
243
|
return { contractName: name, property };
|
|
365
244
|
});
|
|
366
245
|
}
|
|
367
|
-
/** Why `name` cannot be declared as-is in any position, or `undefined`. */
|
|
368
246
|
function unusableBecause(name) {
|
|
369
247
|
return !isIdentifierName(name)
|
|
370
248
|
? "is not a TypeScript identifier"
|
|
@@ -376,20 +254,14 @@ function unusableBecause(name) {
|
|
|
376
254
|
? "is the generated client's own name for its runtime"
|
|
377
255
|
: undefined;
|
|
378
256
|
}
|
|
379
|
-
/**
|
|
380
|
-
* The lines' texts by name in UTF-16 code units. The sort is stable and lines are
|
|
381
|
-
* collected Resources first, so a Resource precedes an enum of the same name.
|
|
382
|
-
*/
|
|
383
257
|
function byName(lines) {
|
|
384
258
|
return [...lines]
|
|
385
259
|
.sort((left, right) => compareCodeUnits(left.name, right.name))
|
|
386
260
|
.map((line) => line.text);
|
|
387
261
|
}
|
|
388
|
-
/** `Array.prototype.sort`'s default order, stated: UTF-16 code units. */
|
|
389
262
|
function compareCodeUnits(left, right) {
|
|
390
263
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
391
264
|
}
|
|
392
|
-
/** The refusal that stops generation over names no rename can repair. */
|
|
393
265
|
export class GeneratedNameError extends Error {
|
|
394
266
|
name = "GeneratedNameError";
|
|
395
267
|
constructor(problems) {
|
|
@@ -397,12 +269,6 @@ export class GeneratedNameError extends Error {
|
|
|
397
269
|
`Rename ${problems.length === 1 ? "it" : "them"} on the server, then generate again.`);
|
|
398
270
|
}
|
|
399
271
|
}
|
|
400
|
-
/**
|
|
401
|
-
* `value` as an object-literal key that makes it an OWN property: bare when it is
|
|
402
|
-
* an IdentifierName (reserved words included — a property name may be one), a
|
|
403
|
-
* string literal otherwise — except `__proto__`, which bare or quoted sets the
|
|
404
|
-
* prototype instead (measured on Node 24), so it is computed.
|
|
405
|
-
*/
|
|
406
272
|
export function ownPropertyKey(value) {
|
|
407
273
|
if (value === "__proto__") {
|
|
408
274
|
return '["__proto__"]';
|
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
import type { ClientContract } from "@aventara/core";
|
|
2
2
|
import type { EmittedModule } from "./emitted-tree.interface.js";
|
|
3
|
+
import { type ClientModuleStyle } from "./module-style.interface.js";
|
|
3
4
|
import { type EmittedNames } from "./name.deriver.js";
|
|
4
5
|
/**
|
|
5
|
-
* `generated/types.d.ts` — §15.6's named Resource types (Q10 = a): `X`, `XWhere`,
|
|
6
|
-
* `XUniqueWhere`, `XOrderBy`, `XCreateData`, `XUpdateData`, `XSelect`,
|
|
7
|
-
* `XInclude`, each only when the operation it reads is advertised, `X` being the
|
|
8
|
-
* Resource's emitted name (`name.deriver.ts`'s ladder, which keeps every derived
|
|
9
|
-
* name free).
|
|
10
|
-
*
|
|
11
6
|
* Each is an ALIAS over the copied derivation — `ResourceRecord` /
|
|
12
7
|
* `ResourceArgument`, declared in `client.ts` — never a walked-out literal type:
|
|
13
|
-
* the derivation stays one. A Resource is addressed by its contract name, a
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* The module declares no name but these, and uses no global type a Resource
|
|
17
|
-
* named like one could shadow.
|
|
8
|
+
* the derivation stays one. A Resource is addressed by its contract name, a string
|
|
9
|
+
* literal type, so nothing here depends on how it was renamed.
|
|
18
10
|
*
|
|
19
|
-
*
|
|
11
|
+
* The module declares no name but these, and uses no global type a Resource named
|
|
12
|
+
* like one could shadow.
|
|
20
13
|
*
|
|
21
14
|
* TypeScript resolves a type alias where it is DECLARED, so a consumer pays for
|
|
22
15
|
* every Resource's named types whether it uses them or not — measured ≈2,800
|
|
23
|
-
* instantiations per Resource
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
16
|
+
* instantiations per Resource. Emitted as `types.d.ts`, they cost nothing under
|
|
17
|
+
* `skipLibCheck: true` (the common default) until used, and the same as a `.ts`
|
|
18
|
+
* under `skipLibCheck: false`. It is live, not a dead declaration: nothing else
|
|
19
|
+
* declares these names, and no `types.ts` sits beside it to shadow it
|
|
20
|
+
* (`client-tree.emitter.spec.ts`). Only types are declared here, so nothing a
|
|
21
|
+
* bundler needs lives in it; `AvClient.ts` re-exports it by `export type *`
|
|
22
|
+
* (TypeScript 5.0, inside the 5.5 peer floor) — an `export *` would survive to the
|
|
23
|
+
* JavaScript and import a `types.js` that does not exist.
|
|
31
24
|
*/
|
|
32
|
-
export declare function emitNamedTypesModule(contract: ClientContract, names: EmittedNames): EmittedModule;
|
|
25
|
+
export declare function emitNamedTypesModule(contract: ClientContract, names: EmittedNames, style: ClientModuleStyle): EmittedModule;
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
+
import { importSpecifier, } from "./module-style.interface.js";
|
|
1
2
|
import { namedTypesOf } from "./name.deriver.js";
|
|
2
|
-
|
|
3
|
-
* `generated/types.d.ts` — §15.6's named Resource types (Q10 = a): `X`, `XWhere`,
|
|
4
|
-
* `XUniqueWhere`, `XOrderBy`, `XCreateData`, `XUpdateData`, `XSelect`,
|
|
5
|
-
* `XInclude`, each only when the operation it reads is advertised, `X` being the
|
|
6
|
-
* Resource's emitted name (`name.deriver.ts`'s ladder, which keeps every derived
|
|
7
|
-
* name free).
|
|
8
|
-
*
|
|
9
|
-
* Each is an ALIAS over the copied derivation — `ResourceRecord` /
|
|
10
|
-
* `ResourceArgument`, declared in `client.ts` — never a walked-out literal type:
|
|
11
|
-
* the derivation stays one. A Resource is addressed by its contract name, a
|
|
12
|
-
* string literal type, so nothing here depends on how it was renamed.
|
|
13
|
-
*
|
|
14
|
-
* The module declares no name but these, and uses no global type a Resource
|
|
15
|
-
* named like one could shadow.
|
|
16
|
-
*
|
|
17
|
-
* # A declaration file (architect, 2026-10-05)
|
|
18
|
-
*
|
|
19
|
-
* TypeScript resolves a type alias where it is DECLARED, so a consumer pays for
|
|
20
|
-
* every Resource's named types whether it uses them or not — measured ≈2,800
|
|
21
|
-
* instantiations per Resource (plan §21). Emitted as `types.d.ts`, they cost
|
|
22
|
-
* nothing under `skipLibCheck: true` (the common default) until used, and the
|
|
23
|
-
* same as a `.ts` under `skipLibCheck: false`. It is live, not a dead
|
|
24
|
-
* declaration: nothing else declares these names, and no `types.ts` sits beside
|
|
25
|
-
* it to shadow it (`client-tree.emitter.spec.ts`). Only types are declared here,
|
|
26
|
-
* so nothing a bundler needs lives in it; `AvClient.ts` re-exports it by
|
|
27
|
-
* `export type *` (TypeScript 5.0, inside the 5.5 peer floor) — an `export *`
|
|
28
|
-
* would survive to the JavaScript and import a `types.js` that does not exist.
|
|
29
|
-
*/
|
|
30
|
-
export function emitNamedTypesModule(contract, names) {
|
|
3
|
+
export function emitNamedTypesModule(contract, names, style) {
|
|
31
4
|
const declarations = names.resources.flatMap(({ contractName, identifier }) => {
|
|
32
5
|
const resource = JSON.stringify(contractName);
|
|
33
6
|
return namedTypesOf(contract.resources[contractName]?.operations).map((named) => {
|
|
@@ -45,6 +18,6 @@ export function emitNamedTypesModule(contract, names) {
|
|
|
45
18
|
path: "types.d.ts",
|
|
46
19
|
source: declarations.length === 0
|
|
47
20
|
? "export {};\n"
|
|
48
|
-
: `import type { ${imported.join(", ")} } from "./client
|
|
21
|
+
: `import type { ${imported.join(", ")} } from ${JSON.stringify(importSpecifier("./client", style))};\n\n${declarations.join("")}`,
|
|
49
22
|
};
|
|
50
23
|
}
|
|
@@ -1,45 +1,41 @@
|
|
|
1
1
|
import { type ClientContract } from "@aventara/core";
|
|
2
2
|
import type { ClientEntrypoint } from "../config/client-config.interface.js";
|
|
3
3
|
import type { EmittedModule } from "./emitted-tree.interface.js";
|
|
4
|
+
import { type ClientModuleStyle } from "./module-style.interface.js";
|
|
4
5
|
/**
|
|
5
6
|
* The runtime modules the generated client carries: `metadata.ts`, the
|
|
6
7
|
* framework `Decimal`, the outcome codes and error classes, and the transport
|
|
7
8
|
* here; the scalar codec in `scalar.codec.ts`.
|
|
8
9
|
*/
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* from nothing: its public type is its own, never an ORM's (§6.2, C-801).
|
|
11
|
+
* Bundled with the client and imported from nothing: its public type is its own,
|
|
12
|
+
* never an ORM's.
|
|
13
13
|
*
|
|
14
14
|
* It holds the decimal string it was made from, digit for digit, and does no
|
|
15
15
|
* arithmetic — the surface is core's `Decimal` (a string constructor and
|
|
16
16
|
* `toString`) plus `toJSON`, so a value means the same on both sides of the wire.
|
|
17
|
-
* A proven decimal library may later sit behind it
|
|
18
|
-
*
|
|
17
|
+
* A proven decimal library may later sit behind it; none is needed to carry
|
|
18
|
+
* digits.
|
|
19
19
|
*
|
|
20
|
-
* `
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* relies on it: `serializeWireBody` refuses an unencoded Decimal regardless, so a
|
|
24
|
-
* value the codec did not encode cannot slip onto the wire through `toJSON`.
|
|
20
|
+
* No `equals`, no arithmetic. The request body never relies on it:
|
|
21
|
+
* `serializeWireBody` refuses an unencoded Decimal regardless, so a value the
|
|
22
|
+
* codec did not encode cannot slip onto the wire through `toJSON`.
|
|
25
23
|
*
|
|
26
24
|
* The grammar is core's `Decimal` grammar, read from `AvProtocol.scalarFormats`
|
|
27
|
-
* and emitted by value
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* and emitted by value. Unlike core's, the constructor refuses a non-string
|
|
26
|
+
* outright: a pattern test coerces its argument, so `5` would otherwise pass as
|
|
27
|
+
* `"5"` and be kept as a number.
|
|
30
28
|
*/
|
|
31
29
|
export declare function emitDecimalModule(): EmittedModule;
|
|
32
30
|
/**
|
|
33
|
-
* `metadata.ts` — what this client was generated against: the ClientContract
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* over the same inputs could change breaks byte-equality (§19.3's spirit). The
|
|
31
|
+
* `metadata.ts` — what this client was generated against: the ClientContract hash
|
|
32
|
+
* and the protocol version, and the resolved entrypoint as the client's default.
|
|
33
|
+
* Nothing else: no driver, no timestamp, no generator version, no host path —
|
|
34
|
+
* anything a re-run over the same inputs could change breaks byte-equality. The
|
|
38
35
|
* entrypoint is an input like the contract: changing it regenerates different
|
|
39
|
-
* bytes and leaves the hash alone
|
|
40
|
-
* (refused at resolution, Q5).
|
|
36
|
+
* bytes and leaves the hash alone, and it never carries credentials.
|
|
41
37
|
*
|
|
42
|
-
* The hash and the version are what every operation request sends
|
|
38
|
+
* The hash and the version are what every operation request sends, from
|
|
43
39
|
* `runtime/transport.ts`; all three are internal — `AvClient.ts` exports none.
|
|
44
40
|
*/
|
|
45
41
|
export declare function emitMetadataModule(protocol: ClientContract["protocol"], entrypoint: ClientEntrypoint): EmittedModule;
|
|
@@ -48,40 +44,17 @@ export declare function emitMetadataModule(protocol: ClientContract["protocol"],
|
|
|
48
44
|
* code-unit order — names the root namespace reserves (`name.deriver.ts`).
|
|
49
45
|
*/
|
|
50
46
|
export declare const FRAMEWORK_ERROR_CLASS_NAMES: readonly string[];
|
|
51
|
-
/**
|
|
52
|
-
* The names `AvClient.ts` re-exports from `generated/runtime/errors.ts`: the classes and the
|
|
53
|
-
* two code unions §15.4 requires, and `Cause` and `ValidationIssue` — the types a
|
|
54
|
-
* thrown FrameworkError carries, public by the architect's decision of
|
|
55
|
-
* 2026-10-04 — in UTF-16 code-unit order.
|
|
56
|
-
*/
|
|
57
47
|
export declare function errorsModuleExports(): readonly string[];
|
|
58
48
|
/**
|
|
59
|
-
* `
|
|
60
|
-
*
|
|
61
|
-
* Both code unions are emitted from core's exported arrays (Q3), so the emitted
|
|
62
|
-
* tree states each code exactly once and core stays their one source; the
|
|
63
|
-
* subclass set and the code each one throws are Q2's (above), accepted as-is by
|
|
64
|
-
* the architect on 2026-10-04. Exported beyond what `AvClient.ts` re-exports: the
|
|
65
|
-
* two arrays, `OperationErrorCode` and `frameworkErrorOf`, which
|
|
66
|
-
* `runtime/transport.ts` reads.
|
|
49
|
+
* Exported beyond what `AvClient.ts` re-exports: the two arrays,
|
|
50
|
+
* `OperationErrorCode` and `frameworkErrorOf`, which `runtime/transport.ts` reads.
|
|
67
51
|
*/
|
|
68
52
|
export declare function emitErrorsModule(): EmittedModule;
|
|
69
53
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* `<entrypoint>/_resources/<resource>/<family>/<variant>` (§12.1–§12.3), the
|
|
73
|
-
* identity headers on every request (§12.4), per-request options that are never
|
|
74
|
-
* serialized (§15.7), and the envelope read back by §13.5's rule.
|
|
75
|
-
*
|
|
76
|
-
* `execute` is Q1 = B's primitive: exported from this module for the
|
|
77
|
-
* per-variant methods to wrap, and re-exported from nowhere — it is not public
|
|
78
|
-
* surface. It reads no capability and no operation descriptor; the caller names
|
|
79
|
-
* the operation.
|
|
54
|
+
* It reads no capability and no operation descriptor; the caller names the
|
|
55
|
+
* operation.
|
|
80
56
|
*
|
|
81
57
|
* Fetch and AbortSignal are the platform's, reached through the structural types
|
|
82
|
-
* below so the module compiles with neither DOM nor Node types
|
|
83
|
-
*
|
|
84
|
-
* Stale-route recovery is not here: it is F-716, Phase 10's, and the emitted
|
|
85
|
-
* module documents it as a hole in its own doc comment (S9).
|
|
58
|
+
* below so the module compiles with neither DOM nor Node types.
|
|
86
59
|
*/
|
|
87
|
-
export declare function emitTransportModule(): EmittedModule;
|
|
60
|
+
export declare function emitTransportModule(style: ClientModuleStyle): EmittedModule;
|