@ptdgrp/typedgql 1.0.0-beta.13 → 1.0.0-beta.14
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/dist/node.cjs +1 -1
- package/dist/node.d.cts +5 -1
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.mts +5 -1
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +1 -1
- package/dist/{options-CaWo97vV.d.cts → options-BWcHrC-1.d.mts} +14 -8
- package/dist/options-BWcHrC-1.d.mts.map +1 -0
- package/dist/{options-D2L-tv7C.d.mts → options-CgrZ2der.d.cts} +14 -8
- package/dist/options-CgrZ2der.d.cts.map +1 -0
- package/dist/{schema-loader-DxKAN2ER.cjs → schema-loader-DO6j6Gbm.cjs} +247 -135
- package/dist/{schema-loader-CB4j3yYF.mjs → schema-loader-dqwha5aR.mjs} +214 -136
- package/dist/schema-loader-dqwha5aR.mjs.map +1 -0
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +1 -1
- package/package.json +1 -1
- package/dist/options-CaWo97vV.d.cts.map +0 -1
- package/dist/options-D2L-tv7C.d.mts.map +0 -1
- package/dist/schema-loader-CB4j3yYF.mjs.map +0 -1
package/dist/node.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_schema_loader = require('./schema-loader-
|
|
2
|
+
const require_schema_loader = require('./schema-loader-DO6j6Gbm.cjs');
|
|
3
3
|
|
|
4
4
|
exports.Generator = require_schema_loader.Generator;
|
|
5
5
|
exports.loadLocalSchema = require_schema_loader.loadLocalSchema;
|
package/dist/node.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as CodegenOptions } from "./options-
|
|
1
|
+
import { t as CodegenOptions } from "./options-CgrZ2der.cjs";
|
|
2
2
|
import { GraphQLSchema } from "graphql";
|
|
3
3
|
|
|
4
4
|
//#region src/codegen/generator.d.ts
|
|
@@ -17,6 +17,8 @@ declare class Generator {
|
|
|
17
17
|
private generateEnumInputMetadata;
|
|
18
18
|
private writeSimpleIndex;
|
|
19
19
|
private generateAsyncRuntime;
|
|
20
|
+
private generateScalarTypes;
|
|
21
|
+
private writeScalarMapAliases;
|
|
20
22
|
private writeIndex;
|
|
21
23
|
/**
|
|
22
24
|
* Creates node_modules/@ptdgrp/typedgql/index.ts
|
|
@@ -29,6 +31,8 @@ declare class Generator {
|
|
|
29
31
|
private hasGeneratedEnums;
|
|
30
32
|
private hasGeneratedInputs;
|
|
31
33
|
private validateSchema;
|
|
34
|
+
private validateScalarTypeDeclarations;
|
|
35
|
+
private hasScalarTypes;
|
|
32
36
|
}
|
|
33
37
|
//#endregion
|
|
34
38
|
//#region src/codegen/schema-loader.d.ts
|
package/dist/node.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.cts","names":[],"sources":["../src/codegen/generator.ts","../src/codegen/schema-loader.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"node.d.cts","names":[],"sources":["../src/codegen/generator.ts","../src/codegen/schema-loader.ts"],"mappings":";;;;cAwDa,SAAA;EAAA,UACW,OAAA,EAAS,cAAA;cAAT,OAAA,EAAS,cAAA;EADX;EAAA,YAIR,SAAA,CAAA;EAIN,QAAA,CAAA,GAAQ,OAAA;EAAA,QAkJN,qBAAA;EAAA,QASA,uCAAA;EAAA,QAOM,sBAAA;EAAA,QAmEA,kBAAA;EAAA,QAUA,iBAAA;EAAA,QAaA,qBAAA;EAAA,QAcA,yBAAA;EAAA,QAMA,gBAAA;EAAA,QAeA,oBAAA;EAAA,QAMA,mBAAA;EAAA,QA4BN,qBAAA;EAAA,QAeM,UAAA;EA9LN;;;;;EAAA,QAqRM,sBAAA;EAAA,QAaA,sCAAA;EAAA,QAuCN,qBAAA;EAAA,QAgFA,iBAAA;EAAA,QAeA,kBAAA;EAAA,QAiBA,cAAA;EAAA,QAqFA,8BAAA;EAAA,QAWA,cAAA;AAAA;;;iBCvuBY,gBAAA,CACpB,QAAA,UACA,OAAA;EAAA,CAAa,GAAA;AAAA,IACZ,OAAA,CAAQ,aAAA;AAAA,iBAuBW,eAAA,CACpB,QAAA,WACC,OAAA,CAAQ,aAAA"}
|
package/dist/node.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as CodegenOptions } from "./options-
|
|
1
|
+
import { t as CodegenOptions } from "./options-BWcHrC-1.mjs";
|
|
2
2
|
import { GraphQLSchema } from "graphql";
|
|
3
3
|
|
|
4
4
|
//#region src/codegen/generator.d.ts
|
|
@@ -17,6 +17,8 @@ declare class Generator {
|
|
|
17
17
|
private generateEnumInputMetadata;
|
|
18
18
|
private writeSimpleIndex;
|
|
19
19
|
private generateAsyncRuntime;
|
|
20
|
+
private generateScalarTypes;
|
|
21
|
+
private writeScalarMapAliases;
|
|
20
22
|
private writeIndex;
|
|
21
23
|
/**
|
|
22
24
|
* Creates node_modules/@ptdgrp/typedgql/index.ts
|
|
@@ -29,6 +31,8 @@ declare class Generator {
|
|
|
29
31
|
private hasGeneratedEnums;
|
|
30
32
|
private hasGeneratedInputs;
|
|
31
33
|
private validateSchema;
|
|
34
|
+
private validateScalarTypeDeclarations;
|
|
35
|
+
private hasScalarTypes;
|
|
32
36
|
}
|
|
33
37
|
//#endregion
|
|
34
38
|
//#region src/codegen/schema-loader.d.ts
|
package/dist/node.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/codegen/generator.ts","../src/codegen/schema-loader.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"node.d.mts","names":[],"sources":["../src/codegen/generator.ts","../src/codegen/schema-loader.ts"],"mappings":";;;;cAwDa,SAAA;EAAA,UACW,OAAA,EAAS,cAAA;cAAT,OAAA,EAAS,cAAA;EADX;EAAA,YAIR,SAAA,CAAA;EAIN,QAAA,CAAA,GAAQ,OAAA;EAAA,QAkJN,qBAAA;EAAA,QASA,uCAAA;EAAA,QAOM,sBAAA;EAAA,QAmEA,kBAAA;EAAA,QAUA,iBAAA;EAAA,QAaA,qBAAA;EAAA,QAcA,yBAAA;EAAA,QAMA,gBAAA;EAAA,QAeA,oBAAA;EAAA,QAMA,mBAAA;EAAA,QA4BN,qBAAA;EAAA,QAeM,UAAA;EA9LN;;;;;EAAA,QAqRM,sBAAA;EAAA,QAaA,sCAAA;EAAA,QAuCN,qBAAA;EAAA,QAgFA,iBAAA;EAAA,QAeA,kBAAA;EAAA,QAiBA,cAAA;EAAA,QAqFA,8BAAA;EAAA,QAWA,cAAA;AAAA;;;iBCvuBY,gBAAA,CACpB,QAAA,UACA,OAAA;EAAA,CAAa,GAAA;AAAA,IACZ,OAAA,CAAQ,aAAA;AAAA,iBAuBW,eAAA,CACpB,QAAA,WACC,OAAA,CAAQ,aAAA"}
|
package/dist/node.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as loadRemoteSchema, r as Generator, t as loadLocalSchema } from "./schema-loader-
|
|
1
|
+
import { n as loadRemoteSchema, r as Generator, t as loadLocalSchema } from "./schema-loader-dqwha5aR.mjs";
|
|
2
2
|
|
|
3
3
|
export { Generator, loadLocalSchema, loadRemoteSchema };
|
|
@@ -56,18 +56,24 @@ interface CodegenOptions {
|
|
|
56
56
|
/**
|
|
57
57
|
* Scalar type mapping for generated TypeScript types.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* Each mapped scalar is exposed as `UserScalarTypes.<ScalarName>` in generated
|
|
60
|
+
* files, and codegen emits `export type <ScalarName> = <mappedType>` inside
|
|
61
|
+
* generated `scalar-types.ts`.
|
|
61
62
|
*
|
|
62
63
|
* Example:
|
|
63
|
-
* `
|
|
64
|
+
* `{ JSON: "JsonObject", DateTime: "string" }`
|
|
64
65
|
*/
|
|
65
66
|
readonly scalarTypeMap?: {
|
|
66
|
-
readonly [key: string]: string
|
|
67
|
-
readonly typeName: string;
|
|
68
|
-
readonly importSource: string;
|
|
69
|
-
};
|
|
67
|
+
readonly [key: string]: string;
|
|
70
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* TypeScript declaration source emitted into generated `scalar-types.ts` namespace.
|
|
71
|
+
*
|
|
72
|
+
* Only `type/interface` declarations are allowed.
|
|
73
|
+
* Exported declarations are visible for consumers, and non-exported ones can
|
|
74
|
+
* be used as private helper types inside the namespace.
|
|
75
|
+
*/
|
|
76
|
+
readonly scalarTypeDeclarations?: string;
|
|
71
77
|
/**
|
|
72
78
|
* Override ID field name per GraphQL object/interface type.
|
|
73
79
|
*
|
|
@@ -96,4 +102,4 @@ interface CodegenOptions {
|
|
|
96
102
|
}
|
|
97
103
|
//#endregion
|
|
98
104
|
export { CodegenOptions as t };
|
|
99
|
-
//# sourceMappingURL=options-
|
|
105
|
+
//# sourceMappingURL=options-BWcHrC-1.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-BWcHrC-1.d.mts","names":[],"sources":["../src/codegen/options.ts"],"mappings":";;;;;AAQA;;;;UAAiB,cAAA;EA6CU;;;;;;EAAA,SAtChB,YAAA,QAAoB,OAAA,CAAQ,aAAA;EAY5B;;;;;EAAA,SANA,SAAA;EA2CA;;;;;EAAA,SArCA,MAAA;EA2DyC;;;;;;EAAA,SApDzC,cAAA;;;;;;;WAOA,aAAA;;;;;;;;WAQA,eAAA;;;;WAIA,aAAA,GAAgB,aAAA;;;;;;;;;;;WAWhB,aAAA;IAAA,UACG,GAAA;EAAA;;;;;;;;WASH,sBAAA;;;;;;WAMA,UAAA;IAAA,UAAyB,GAAA;EAAA;;;;;;WAMzB,0BAAA;IAAA,UAAyC,GAAA;EAAA;;;;;;;;;WASzC,MAAA;AAAA"}
|
|
@@ -56,18 +56,24 @@ interface CodegenOptions {
|
|
|
56
56
|
/**
|
|
57
57
|
* Scalar type mapping for generated TypeScript types.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
59
|
+
* Each mapped scalar is exposed as `UserScalarTypes.<ScalarName>` in generated
|
|
60
|
+
* files, and codegen emits `export type <ScalarName> = <mappedType>` inside
|
|
61
|
+
* generated `scalar-types.ts`.
|
|
61
62
|
*
|
|
62
63
|
* Example:
|
|
63
|
-
* `
|
|
64
|
+
* `{ JSON: "JsonObject", DateTime: "string" }`
|
|
64
65
|
*/
|
|
65
66
|
readonly scalarTypeMap?: {
|
|
66
|
-
readonly [key: string]: string
|
|
67
|
-
readonly typeName: string;
|
|
68
|
-
readonly importSource: string;
|
|
69
|
-
};
|
|
67
|
+
readonly [key: string]: string;
|
|
70
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* TypeScript declaration source emitted into generated `scalar-types.ts` namespace.
|
|
71
|
+
*
|
|
72
|
+
* Only `type/interface` declarations are allowed.
|
|
73
|
+
* Exported declarations are visible for consumers, and non-exported ones can
|
|
74
|
+
* be used as private helper types inside the namespace.
|
|
75
|
+
*/
|
|
76
|
+
readonly scalarTypeDeclarations?: string;
|
|
71
77
|
/**
|
|
72
78
|
* Override ID field name per GraphQL object/interface type.
|
|
73
79
|
*
|
|
@@ -96,4 +102,4 @@ interface CodegenOptions {
|
|
|
96
102
|
}
|
|
97
103
|
//#endregion
|
|
98
104
|
export { CodegenOptions as t };
|
|
99
|
-
//# sourceMappingURL=options-
|
|
105
|
+
//# sourceMappingURL=options-CgrZ2der.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-CgrZ2der.d.cts","names":[],"sources":["../src/codegen/options.ts"],"mappings":";;;;;AAQA;;;;UAAiB,cAAA;EA6CU;;;;;;EAAA,SAtChB,YAAA,QAAoB,OAAA,CAAQ,aAAA;EAY5B;;;;;EAAA,SANA,SAAA;EA2CA;;;;;EAAA,SArCA,MAAA;EA2DyC;;;;;;EAAA,SApDzC,cAAA;;;;;;;WAOA,aAAA;;;;;;;;WAQA,eAAA;;;;WAIA,aAAA,GAAgB,aAAA;;;;;;;;;;;WAWhB,aAAA;IAAA,UACG,GAAA;EAAA;;;;;;;;WASH,sBAAA;;;;;;WAMA,UAAA;IAAA,UAAyB,GAAA;EAAA;;;;;;WAMzB,0BAAA;IAAA,UAAyC,GAAA;EAAA;;;;;;;;;WASzC,MAAA;AAAA"}
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
1
28
|
let graphql = require("graphql");
|
|
2
29
|
let fs_promises = require("fs/promises");
|
|
3
30
|
let fs = require("fs");
|
|
4
31
|
let path = require("path");
|
|
32
|
+
let typescript = require("typescript");
|
|
33
|
+
typescript = __toESM(typescript);
|
|
5
34
|
|
|
6
35
|
//#region src/codegen/utils.ts
|
|
7
36
|
/**
|
|
@@ -36,6 +65,132 @@ function toKebabCase(name) {
|
|
|
36
65
|
return name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z\d])([A-Z])/g, "$1-$2").toLowerCase();
|
|
37
66
|
}
|
|
38
67
|
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/codegen/imports.ts
|
|
70
|
+
/**
|
|
71
|
+
* Shared import collector for codegen writers.
|
|
72
|
+
*
|
|
73
|
+
* Responsibilities:
|
|
74
|
+
* - normalize imports by source
|
|
75
|
+
* - deduplicate symbols
|
|
76
|
+
* - keep emitted import statements stable (sorted)
|
|
77
|
+
*/
|
|
78
|
+
var JSImportCollector = class {
|
|
79
|
+
typeBySource = /* @__PURE__ */ new Map();
|
|
80
|
+
valueBySource = /* @__PURE__ */ new Map();
|
|
81
|
+
sideEffects = /* @__PURE__ */ new Set();
|
|
82
|
+
constructor(sink, sourceMap) {
|
|
83
|
+
this.sink = sink;
|
|
84
|
+
this.sourceMap = sourceMap;
|
|
85
|
+
}
|
|
86
|
+
useMapped(symbol) {
|
|
87
|
+
const spec = this.sourceMap[symbol];
|
|
88
|
+
if (spec.kind === "type") this.useType(spec.source, symbol);
|
|
89
|
+
else this.useValue(spec.source, symbol);
|
|
90
|
+
}
|
|
91
|
+
useType(source, symbol) {
|
|
92
|
+
this.collect(this.typeBySource, source, symbol);
|
|
93
|
+
}
|
|
94
|
+
useValue(source, symbol) {
|
|
95
|
+
this.collect(this.valueBySource, source, symbol);
|
|
96
|
+
}
|
|
97
|
+
useSideEffect(source) {
|
|
98
|
+
this.sideEffects.add(source);
|
|
99
|
+
}
|
|
100
|
+
emit() {
|
|
101
|
+
for (const [source, symbols] of this.sorted(this.typeBySource)) this.sink(`import type { ${Array.from(symbols).sort().join(", ")} } from '${source}';`);
|
|
102
|
+
for (const [source, symbols] of this.sorted(this.valueBySource)) this.sink(`import { ${Array.from(symbols).sort().join(", ")} } from '${source}';`);
|
|
103
|
+
for (const source of Array.from(this.sideEffects).sort()) this.sink(`import '${source}';`);
|
|
104
|
+
}
|
|
105
|
+
collect(map, source, symbol) {
|
|
106
|
+
const set = map.get(source) ?? /* @__PURE__ */ new Set();
|
|
107
|
+
set.add(symbol);
|
|
108
|
+
map.set(source, set);
|
|
109
|
+
}
|
|
110
|
+
sorted(map) {
|
|
111
|
+
return Array.from(map.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const RUNTIME_ENTRY_SOURCE = "../../dist/index.mjs";
|
|
115
|
+
const TYPE_HIERARCHY_SOURCE = "../type-hierarchy";
|
|
116
|
+
const ENUM_INPUT_METADATA_SOURCE = "../enum-input-metadata";
|
|
117
|
+
const SCALAR_TYPES_SOURCE = "../scalar-types";
|
|
118
|
+
const SCALAR_TYPES_NAMESPACE = "UserScalarTypes";
|
|
119
|
+
const CODEGEN_IMPORT_SOURCE_MAP = {
|
|
120
|
+
AcceptableVariables: {
|
|
121
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
122
|
+
kind: "type"
|
|
123
|
+
},
|
|
124
|
+
UnresolvedVariables: {
|
|
125
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
126
|
+
kind: "type"
|
|
127
|
+
},
|
|
128
|
+
DirectiveArgs: {
|
|
129
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
130
|
+
kind: "type"
|
|
131
|
+
},
|
|
132
|
+
Selection: {
|
|
133
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
134
|
+
kind: "type"
|
|
135
|
+
},
|
|
136
|
+
ShapeOf: {
|
|
137
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
138
|
+
kind: "type"
|
|
139
|
+
},
|
|
140
|
+
VariablesOf: {
|
|
141
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
142
|
+
kind: "type"
|
|
143
|
+
},
|
|
144
|
+
ValueOrThunk: {
|
|
145
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
146
|
+
kind: "type"
|
|
147
|
+
},
|
|
148
|
+
FragmentSpread: {
|
|
149
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
150
|
+
kind: "type"
|
|
151
|
+
},
|
|
152
|
+
createSelection: {
|
|
153
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
154
|
+
kind: "value"
|
|
155
|
+
},
|
|
156
|
+
withOperationName: {
|
|
157
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
158
|
+
kind: "value"
|
|
159
|
+
},
|
|
160
|
+
createSchemaType: {
|
|
161
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
162
|
+
kind: "value"
|
|
163
|
+
},
|
|
164
|
+
registerSchemaTypeFactory: {
|
|
165
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
166
|
+
kind: "value"
|
|
167
|
+
},
|
|
168
|
+
resolveRegisteredSchemaType: {
|
|
169
|
+
source: RUNTIME_ENTRY_SOURCE,
|
|
170
|
+
kind: "value"
|
|
171
|
+
},
|
|
172
|
+
ENUM_INPUT_METADATA: {
|
|
173
|
+
source: ENUM_INPUT_METADATA_SOURCE,
|
|
174
|
+
kind: "value"
|
|
175
|
+
},
|
|
176
|
+
SCALAR_TYPE_NAMESPACE: {
|
|
177
|
+
source: SCALAR_TYPES_SOURCE,
|
|
178
|
+
kind: "type"
|
|
179
|
+
},
|
|
180
|
+
WithTypeName: {
|
|
181
|
+
source: TYPE_HIERARCHY_SOURCE,
|
|
182
|
+
kind: "type"
|
|
183
|
+
},
|
|
184
|
+
ImplementationType: {
|
|
185
|
+
source: TYPE_HIERARCHY_SOURCE,
|
|
186
|
+
kind: "type"
|
|
187
|
+
},
|
|
188
|
+
EnumInputMetadataBuilder: {
|
|
189
|
+
source: "../dist/index.mjs",
|
|
190
|
+
kind: "value"
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
39
194
|
//#endregion
|
|
40
195
|
//#region src/codegen/writer.ts
|
|
41
196
|
const SCOPE_BRACKETS = {
|
|
@@ -74,7 +229,7 @@ var Writer = class {
|
|
|
74
229
|
needIndent = false;
|
|
75
230
|
importStatements = /* @__PURE__ */ new Set();
|
|
76
231
|
importedTypes = /* @__PURE__ */ new Set();
|
|
77
|
-
|
|
232
|
+
usesScalarTypeNamespaceImport = false;
|
|
78
233
|
importFinalized = false;
|
|
79
234
|
constructor(stream, options) {
|
|
80
235
|
this.stream = stream;
|
|
@@ -117,11 +272,7 @@ var Writer = class {
|
|
|
117
272
|
return;
|
|
118
273
|
}
|
|
119
274
|
if (namedType instanceof graphql.GraphQLScalarType && this.options.scalarTypeMap) {
|
|
120
|
-
|
|
121
|
-
if (typeof mapped !== "object") return;
|
|
122
|
-
const set = this.importedScalarTypes.get(mapped.importSource) ?? /* @__PURE__ */ new Set();
|
|
123
|
-
set.add(mapped.typeName);
|
|
124
|
-
this.importedScalarTypes.set(mapped.importSource, set);
|
|
275
|
+
if (this.options.scalarTypeMap[namedType.name]) this.usesScalarTypeNamespaceImport = true;
|
|
125
276
|
}
|
|
126
277
|
}
|
|
127
278
|
importStatement(statement) {
|
|
@@ -209,9 +360,13 @@ var Writer = class {
|
|
|
209
360
|
return;
|
|
210
361
|
}
|
|
211
362
|
if (type instanceof graphql.GraphQLScalarType) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
363
|
+
if (this.options.scalarTypeMap?.[type.name]) {
|
|
364
|
+
this.text(`${SCALAR_TYPES_NAMESPACE}.${type.name}`);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const fallback = SCALAR_MAP[type.name];
|
|
368
|
+
if (!fallback) throw new Error(`Unknown scalar type ${type.name}`);
|
|
369
|
+
this.text(fallback);
|
|
215
370
|
return;
|
|
216
371
|
}
|
|
217
372
|
if (type instanceof graphql.GraphQLEnumType || type instanceof graphql.GraphQLInputObjectType) {
|
|
@@ -259,10 +414,10 @@ var Writer = class {
|
|
|
259
414
|
}
|
|
260
415
|
}
|
|
261
416
|
writeMappedScalarImports() {
|
|
262
|
-
if (this.
|
|
263
|
-
const
|
|
264
|
-
const
|
|
265
|
-
|
|
417
|
+
if (!this.usesScalarTypeNamespaceImport) return;
|
|
418
|
+
const source = CODEGEN_IMPORT_SOURCE_MAP.SCALAR_TYPE_NAMESPACE.source;
|
|
419
|
+
const importSource = this.isUnderGlobalDir() ? source.replace(/^\.\.\//, "./") : source;
|
|
420
|
+
this.stream.write(`import type { ${SCALAR_TYPES_NAMESPACE} } from '${importSource}';\n`);
|
|
266
421
|
}
|
|
267
422
|
typeApplication(typeName, renderTypeArg) {
|
|
268
423
|
this.text(`${typeName}<`);
|
|
@@ -307,7 +462,7 @@ var Writer = class {
|
|
|
307
462
|
});
|
|
308
463
|
}
|
|
309
464
|
get hasAnyImports() {
|
|
310
|
-
return this.importStatements.size !== 0 || this.importedTypes.size !== 0 || this.
|
|
465
|
+
return this.importStatements.size !== 0 || this.importedTypes.size !== 0 || this.usesScalarTypeNamespaceImport;
|
|
311
466
|
}
|
|
312
467
|
writeUnion(members) {
|
|
313
468
|
this.enter("blank");
|
|
@@ -329,126 +484,6 @@ function unwrapType(type) {
|
|
|
329
484
|
return type;
|
|
330
485
|
}
|
|
331
486
|
|
|
332
|
-
//#endregion
|
|
333
|
-
//#region src/codegen/imports.ts
|
|
334
|
-
/**
|
|
335
|
-
* Shared import collector for codegen writers.
|
|
336
|
-
*
|
|
337
|
-
* Responsibilities:
|
|
338
|
-
* - normalize imports by source
|
|
339
|
-
* - deduplicate symbols
|
|
340
|
-
* - keep emitted import statements stable (sorted)
|
|
341
|
-
*/
|
|
342
|
-
var JSImportCollector = class {
|
|
343
|
-
typeBySource = /* @__PURE__ */ new Map();
|
|
344
|
-
valueBySource = /* @__PURE__ */ new Map();
|
|
345
|
-
sideEffects = /* @__PURE__ */ new Set();
|
|
346
|
-
constructor(sink, sourceMap) {
|
|
347
|
-
this.sink = sink;
|
|
348
|
-
this.sourceMap = sourceMap;
|
|
349
|
-
}
|
|
350
|
-
useMapped(symbol) {
|
|
351
|
-
const spec = this.sourceMap[symbol];
|
|
352
|
-
if (spec.kind === "type") this.useType(spec.source, symbol);
|
|
353
|
-
else this.useValue(spec.source, symbol);
|
|
354
|
-
}
|
|
355
|
-
useType(source, symbol) {
|
|
356
|
-
this.collect(this.typeBySource, source, symbol);
|
|
357
|
-
}
|
|
358
|
-
useValue(source, symbol) {
|
|
359
|
-
this.collect(this.valueBySource, source, symbol);
|
|
360
|
-
}
|
|
361
|
-
useSideEffect(source) {
|
|
362
|
-
this.sideEffects.add(source);
|
|
363
|
-
}
|
|
364
|
-
emit() {
|
|
365
|
-
for (const [source, symbols] of this.sorted(this.typeBySource)) this.sink(`import type { ${Array.from(symbols).sort().join(", ")} } from '${source}';`);
|
|
366
|
-
for (const [source, symbols] of this.sorted(this.valueBySource)) this.sink(`import { ${Array.from(symbols).sort().join(", ")} } from '${source}';`);
|
|
367
|
-
for (const source of Array.from(this.sideEffects).sort()) this.sink(`import '${source}';`);
|
|
368
|
-
}
|
|
369
|
-
collect(map, source, symbol) {
|
|
370
|
-
const set = map.get(source) ?? /* @__PURE__ */ new Set();
|
|
371
|
-
set.add(symbol);
|
|
372
|
-
map.set(source, set);
|
|
373
|
-
}
|
|
374
|
-
sorted(map) {
|
|
375
|
-
return Array.from(map.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const RUNTIME_ENTRY_SOURCE = "../../dist/index.mjs";
|
|
379
|
-
const TYPE_HIERARCHY_SOURCE = "../type-hierarchy";
|
|
380
|
-
const ENUM_INPUT_METADATA_SOURCE = "../enum-input-metadata";
|
|
381
|
-
const CODEGEN_IMPORT_SOURCE_MAP = {
|
|
382
|
-
AcceptableVariables: {
|
|
383
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
384
|
-
kind: "type"
|
|
385
|
-
},
|
|
386
|
-
UnresolvedVariables: {
|
|
387
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
388
|
-
kind: "type"
|
|
389
|
-
},
|
|
390
|
-
DirectiveArgs: {
|
|
391
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
392
|
-
kind: "type"
|
|
393
|
-
},
|
|
394
|
-
Selection: {
|
|
395
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
396
|
-
kind: "type"
|
|
397
|
-
},
|
|
398
|
-
ShapeOf: {
|
|
399
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
400
|
-
kind: "type"
|
|
401
|
-
},
|
|
402
|
-
VariablesOf: {
|
|
403
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
404
|
-
kind: "type"
|
|
405
|
-
},
|
|
406
|
-
ValueOrThunk: {
|
|
407
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
408
|
-
kind: "type"
|
|
409
|
-
},
|
|
410
|
-
FragmentSpread: {
|
|
411
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
412
|
-
kind: "type"
|
|
413
|
-
},
|
|
414
|
-
createSelection: {
|
|
415
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
416
|
-
kind: "value"
|
|
417
|
-
},
|
|
418
|
-
withOperationName: {
|
|
419
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
420
|
-
kind: "value"
|
|
421
|
-
},
|
|
422
|
-
createSchemaType: {
|
|
423
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
424
|
-
kind: "value"
|
|
425
|
-
},
|
|
426
|
-
registerSchemaTypeFactory: {
|
|
427
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
428
|
-
kind: "value"
|
|
429
|
-
},
|
|
430
|
-
resolveRegisteredSchemaType: {
|
|
431
|
-
source: RUNTIME_ENTRY_SOURCE,
|
|
432
|
-
kind: "value"
|
|
433
|
-
},
|
|
434
|
-
ENUM_INPUT_METADATA: {
|
|
435
|
-
source: ENUM_INPUT_METADATA_SOURCE,
|
|
436
|
-
kind: "value"
|
|
437
|
-
},
|
|
438
|
-
WithTypeName: {
|
|
439
|
-
source: TYPE_HIERARCHY_SOURCE,
|
|
440
|
-
kind: "type"
|
|
441
|
-
},
|
|
442
|
-
ImplementationType: {
|
|
443
|
-
source: TYPE_HIERARCHY_SOURCE,
|
|
444
|
-
kind: "type"
|
|
445
|
-
},
|
|
446
|
-
EnumInputMetadataBuilder: {
|
|
447
|
-
source: "../dist/index.mjs",
|
|
448
|
-
kind: "value"
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
|
|
452
487
|
//#endregion
|
|
453
488
|
//#region src/codegen/writers/selection.ts
|
|
454
489
|
var SelectionWriter = class extends Writer {
|
|
@@ -1571,9 +1606,38 @@ var EnumInputMetadataWriter = class EnumInputMetadataWriter extends Writer {
|
|
|
1571
1606
|
};
|
|
1572
1607
|
|
|
1573
1608
|
//#endregion
|
|
1574
|
-
//#region \0raw:/
|
|
1609
|
+
//#region \0raw:/Users/ashen/Projects/typedgql/src/codegen/templates/async-runtime.template
|
|
1575
1610
|
var async_runtime_default = "import type { Selection } from \"../dist/index.mjs\";\nimport { TextBuilder, runtimeOf } from \"../dist/index.mjs\";\n\nexport type GraphQLExecutor = (\n request: string,\n variables: Record<string, unknown>,\n) => Promise<unknown>;\n\nexport type GraphQLSubscriber = (\n request: string,\n variables: Record<string, unknown>,\n) => AsyncIterable<unknown> | Promise<AsyncIterable<unknown>>;\n\n// Set global fallback executor used by `execute(...)`.\nexport function setGraphQLExecutor(executor: GraphQLExecutor) {\n graphQLExecutor = executor;\n}\n\n// Set global fallback subscriber used by `subscribe(...)`.\nexport function setGraphQLSubscriber(subscriber: GraphQLSubscriber) {\n graphQLSubscriber = subscriber;\n}\nexport type Simplify<T> = SimplifyDepth<T>;\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype Dec = [0,0,1,2,3,4,5,6,7,8,9];\ntype GraphQLRawResponse = {\n readonly data?: unknown;\n readonly errors?: unknown;\n};\nexport type SimplifyDepth<T, D extends number = 5> =\n D extends 0 ? T :\n T extends Primitive | Function ? T :\n T extends readonly (infer U)[] ? readonly SimplifyDepth<U, Dec[D]>[] :\n T extends object ? { [K in keyof T]: SimplifyDepth<T[K], Dec[D]> } & {} :\n T;\n\nexport async function execute<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Query\" | \"Mutation\", TData, TVariables>,\n options?: {\n readonly operationName?: string;\n readonly variables?: TVariables;\n readonly executor?: GraphQLExecutor;\n },\n): Promise<Simplify<TData>> {\n // Per-call override has priority over the globally registered executor.\n const executor = options?.executor ?? graphQLExecutor;\n if (executor === undefined) {\n throw new Error(\n \"Executor not set. Call 'setGraphQLExecutor' first or pass executor in options.\",\n );\n }\n\n const request = buildRequest(selection, options?.operationName);\n const rawResponse = exceptNullValues(\n await executor(request, options?.variables ?? {}),\n ) as GraphQLRawResponse;\n // GraphQL transport errors are surfaced as exceptions.\n if (rawResponse.errors) {\n throw new GraphQLError(rawResponse.errors);\n }\n return rawResponse.data as unknown as Simplify<TData>;\n}\n\nexport async function* subscribe<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Subscription\", TData, TVariables>,\n options?: {\n readonly operationName?: string;\n readonly variables?: TVariables;\n readonly subscriber?: GraphQLSubscriber;\n },\n): AsyncIterable<Simplify<TData>> {\n // Per-call override has priority over the globally registered subscriber.\n const subscriber = options?.subscriber ?? graphQLSubscriber;\n if (subscriber === undefined) {\n throw new Error(\n \"Subscriber not set. Call 'setGraphQLSubscriber' first or pass subscriber in options.\",\n );\n }\n\n const request = buildRequest(selection, options?.operationName);\n const stream = await subscriber(request, options?.variables ?? {});\n // Stream payloads follow standard GraphQL response shape.\n for await (const payload of stream) {\n const rawResponse = exceptNullValues(payload) as GraphQLRawResponse;\n if (rawResponse.errors) {\n throw new GraphQLError(rawResponse.errors);\n }\n yield rawResponse.data as unknown as Simplify<TData>;\n }\n}\n\nexport interface Response<TData> {\n readonly data?: TData;\n readonly error?: Error;\n}\n\nexport class GraphQLError extends Error {\n readonly errors: readonly GraphQLSubError[];\n\n constructor(errors: unknown) {\n super();\n this.errors = normalizeGraphQLErrors(errors);\n }\n}\n\nexport interface GraphQLSubError {\n readonly message: string;\n readonly path: string[];\n}\n\nlet graphQLExecutor: GraphQLExecutor | undefined = undefined;\nlet graphQLSubscriber: GraphQLSubscriber | undefined = undefined;\n\nfunction normalizeGraphQLErrors(errors: unknown): readonly GraphQLSubError[] {\n if (!Array.isArray(errors)) {\n return [{ message: \"Unknown GraphQL error\", path: [] }];\n }\n return errors.map((item) => {\n if (!item || typeof item !== \"object\") {\n return { message: String(item), path: [] };\n }\n const rec = item as Record<string, unknown>;\n return {\n message: typeof rec.message === \"string\" ? rec.message : \"Unknown GraphQL error\",\n path: Array.isArray(rec.path)\n ? rec.path.filter((p): p is string => typeof p === \"string\")\n : [],\n };\n });\n}\n\n// Build GraphQL document from selection tree and inferred variable declarations.\nfunction buildRequest<\n TData extends object,\n TVariables extends Record<string, unknown>,\n>(\n selection: Selection<\"Query\" | \"Mutation\" | \"Subscription\", TData, TVariables>,\n operationName?: string,\n): string {\n const runtime = runtimeOf(selection);\n const writer = new TextBuilder();\n writer.text(`${runtime.schemaType.name.toLowerCase()} ${operationName ?? runtime.operationName ?? \"\"}`);\n if (runtime.variableTypeMap.size !== 0) {\n writer.scope(\n {\n type: \"arguments\",\n multiLines: runtime.variableTypeMap.size > 2,\n suffix: \" \",\n },\n () => {\n for (const [name, type] of runtime.variableTypeMap) {\n writer.separator();\n writer.text(`$${name}: ${type}`);\n }\n },\n );\n }\n writer.text(selection.toString());\n writer.text(selection.toFragmentString());\n return writer.toString();\n}\n\n// Convert all nullable fields to `undefined` for easier TS optional-field ergonomics.\nfunction exceptNullValues<T>(value: T): T {\n if (value == null) return undefined as any;\n if (typeof value !== \"object\") return value;\n if (Array.isArray(value)) {\n return value.map((el) => el == null ? undefined : exceptNullValues(el)) as any;\n }\n const out: any = {};\n for (const k in value) {\n const v = value[k];\n out[k] = v != null ? exceptNullValues(v) : undefined;\n }\n return out;\n}\n";
|
|
1576
1611
|
|
|
1612
|
+
//#endregion
|
|
1613
|
+
//#region src/codegen/scalar-type-declarations.ts
|
|
1614
|
+
function analyzeScalarTypeDeclarations(source) {
|
|
1615
|
+
if (!source || source.trim().length === 0) return { exportedNames: /* @__PURE__ */ new Set() };
|
|
1616
|
+
if ((typescript.default.transpileModule(source, {
|
|
1617
|
+
reportDiagnostics: true,
|
|
1618
|
+
compilerOptions: {
|
|
1619
|
+
target: typescript.default.ScriptTarget.ESNext,
|
|
1620
|
+
module: typescript.default.ModuleKind.ESNext
|
|
1621
|
+
},
|
|
1622
|
+
fileName: "scalar-types.ts"
|
|
1623
|
+
}).diagnostics ?? []).some((d) => d.category === typescript.default.DiagnosticCategory.Error)) throw new Error("scalarTypeDeclarations has TypeScript syntax errors");
|
|
1624
|
+
const sf = typescript.default.createSourceFile("scalar-types.ts", source, typescript.default.ScriptTarget.Latest, true, typescript.default.ScriptKind.TS);
|
|
1625
|
+
const exportedNames = /* @__PURE__ */ new Set();
|
|
1626
|
+
for (let i = 0; i < sf.statements.length; i++) {
|
|
1627
|
+
const stmt = sf.statements[i];
|
|
1628
|
+
if (typescript.default.isTypeAliasDeclaration(stmt) || typescript.default.isInterfaceDeclaration(stmt)) {
|
|
1629
|
+
if (stmt.modifiers?.some((m) => m.kind === typescript.default.SyntaxKind.ExportKeyword)) {
|
|
1630
|
+
const name = stmt.name.text;
|
|
1631
|
+
if (exportedNames.has(name)) throw new Error(`scalarTypeDeclarations has duplicate export '${name}'`);
|
|
1632
|
+
exportedNames.add(name);
|
|
1633
|
+
}
|
|
1634
|
+
continue;
|
|
1635
|
+
}
|
|
1636
|
+
throw new Error(`scalarTypeDeclarations statement[${i}] must be type/interface declaration`);
|
|
1637
|
+
}
|
|
1638
|
+
return { exportedNames };
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1577
1641
|
//#endregion
|
|
1578
1642
|
//#region src/codegen/generator.ts
|
|
1579
1643
|
/** Default output directory: node_modules/@ptdgrp/typedgql/__generated */
|
|
@@ -1609,6 +1673,7 @@ var Generator = class {
|
|
|
1609
1673
|
async generate() {
|
|
1610
1674
|
const schema = await this.options.schemaLoader();
|
|
1611
1675
|
this.validateSchema(schema);
|
|
1676
|
+
this.validateScalarTypeDeclarations();
|
|
1612
1677
|
await (0, fs_promises.rm)(this.targetDir, {
|
|
1613
1678
|
recursive: true,
|
|
1614
1679
|
force: true
|
|
@@ -1688,6 +1753,7 @@ var Generator = class {
|
|
|
1688
1753
|
promises.push(this.generateTypeHierarchy(schema, typeHierarchy));
|
|
1689
1754
|
promises.push(this.generateEnumInputMetadata(schema));
|
|
1690
1755
|
promises.push(this.generateAsyncRuntime());
|
|
1756
|
+
if (this.hasScalarTypes()) promises.push(this.generateScalarTypes());
|
|
1691
1757
|
promises.push(this.writeIndex(schema, ctx));
|
|
1692
1758
|
await Promise.all(promises);
|
|
1693
1759
|
if (this.options.targetDir === void 0) await this.writePackageEntrypoint(schema, ctx);
|
|
@@ -1768,6 +1834,35 @@ var Generator = class {
|
|
|
1768
1834
|
stream.write(async_runtime_default);
|
|
1769
1835
|
await endStream(stream);
|
|
1770
1836
|
}
|
|
1837
|
+
async generateScalarTypes() {
|
|
1838
|
+
const stream = createStream((0, path.join)(this.targetDir, "scalar-types.ts"));
|
|
1839
|
+
const analysis = analyzeScalarTypeDeclarations(this.options.scalarTypeDeclarations);
|
|
1840
|
+
const code = this.options.scalarTypeDeclarations?.trim();
|
|
1841
|
+
if (code && code.length !== 0) {
|
|
1842
|
+
const indented = code.split("\n").map((line) => line.length === 0 ? line : ` ${line}`).join("\n");
|
|
1843
|
+
stream.write(`export declare namespace ${SCALAR_TYPES_NAMESPACE} {\n`);
|
|
1844
|
+
stream.write(`${indented}\n`);
|
|
1845
|
+
this.writeScalarMapAliases(stream, analysis.exportedNames);
|
|
1846
|
+
stream.write("}\n");
|
|
1847
|
+
} else {
|
|
1848
|
+
const scalarMap = this.options.scalarTypeMap;
|
|
1849
|
+
if (scalarMap && Object.keys(scalarMap).length !== 0) {
|
|
1850
|
+
stream.write(`export declare namespace ${SCALAR_TYPES_NAMESPACE} {\n`);
|
|
1851
|
+
this.writeScalarMapAliases(stream, analysis.exportedNames);
|
|
1852
|
+
stream.write("}\n");
|
|
1853
|
+
} else stream.write("export {};\n");
|
|
1854
|
+
}
|
|
1855
|
+
await endStream(stream);
|
|
1856
|
+
}
|
|
1857
|
+
writeScalarMapAliases(stream, exportedNames) {
|
|
1858
|
+
const scalarMap = this.options.scalarTypeMap;
|
|
1859
|
+
if (!scalarMap) return;
|
|
1860
|
+
const entries = Object.entries(scalarMap).sort((a, b) => a[0].localeCompare(b[0]));
|
|
1861
|
+
for (const [scalarName, mappedType] of entries) {
|
|
1862
|
+
if (exportedNames.has(scalarName)) continue;
|
|
1863
|
+
stream.write(` export type ${scalarName} = ${mappedType};\n`);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1771
1866
|
async writeIndex(schema, ctx) {
|
|
1772
1867
|
const stream = createStream((0, path.join)(this.targetDir, "index.ts"));
|
|
1773
1868
|
const selectionSuffix = this.options.selectionSuffix ?? "Selection";
|
|
@@ -1778,6 +1873,7 @@ var Generator = class {
|
|
|
1778
1873
|
stream.write(`import type { ${selectionTypeName} } from "./selections/${toKebabCase(selectionTypeName)}";\n`);
|
|
1779
1874
|
}
|
|
1780
1875
|
stream.write(`import { ENUM_INPUT_METADATA } from "./enum-input-metadata";\n\n`);
|
|
1876
|
+
if (this.hasScalarTypes()) stream.write(`export type { ${SCALAR_TYPES_NAMESPACE} } from "./scalar-types";\n`);
|
|
1781
1877
|
stream.write(`export type { GraphQLExecutor, GraphQLSubscriber, Simplify } from "./client-runtime";\n`);
|
|
1782
1878
|
stream.write(`export { setGraphQLExecutor, setGraphQLSubscriber, execute, subscribe } from "./client-runtime";\n`);
|
|
1783
1879
|
stream.write("export type { ImplementationType } from './type-hierarchy';\n");
|
|
@@ -1847,6 +1943,7 @@ var Generator = class {
|
|
|
1847
1943
|
const mutationType = typeMap["Mutation"];
|
|
1848
1944
|
const subscriptionType = typeMap["Subscription"];
|
|
1849
1945
|
stream.write(`export * from './__generated/index';\n`);
|
|
1946
|
+
if (this.hasScalarTypes()) stream.write(`export type { ${SCALAR_TYPES_NAMESPACE} } from './__generated/scalar-types';\n`);
|
|
1850
1947
|
stream.write(`export type { Selection, ExecutableSelection, ShapeOf, VariablesOf, Expand, FieldSelection, DirectiveArgs, EnumInputMetadata, EnumInputMetaType, AcceptableVariables, UnresolvedVariables, ValueOrThunk, SchemaType, SchemaField, SchemaTypeCategory, SchemaFieldCategory, FieldOptions } from './dist/index.mjs';\n`);
|
|
1851
1948
|
stream.write(`export { FragmentSpread, FragmentRef, StringValue, runtimeOf, createSchemaType, resolveRegisteredSchemaType, registerSchemaTypeFactory, SelectionNode, createSelection, ParameterRef, EnumInputMetadataBuilder, TextBuilder, cyrb53 } from './dist/index.mjs';\n`);
|
|
1852
1949
|
stream.write(`import { fragment$ } from './__generated/index';\n`);
|
|
@@ -1916,6 +2013,15 @@ var Generator = class {
|
|
|
1916
2013
|
}
|
|
1917
2014
|
}
|
|
1918
2015
|
}
|
|
2016
|
+
validateScalarTypeDeclarations() {
|
|
2017
|
+
analyzeScalarTypeDeclarations(this.options.scalarTypeDeclarations);
|
|
2018
|
+
const scalarMap = this.options.scalarTypeMap;
|
|
2019
|
+
if (!scalarMap) return;
|
|
2020
|
+
for (const scalarName of Object.keys(scalarMap)) if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(scalarName)) throw new Error(`scalarTypeMap key '${scalarName}' is not identifier`);
|
|
2021
|
+
}
|
|
2022
|
+
hasScalarTypes() {
|
|
2023
|
+
return (this.options.scalarTypeDeclarations?.trim().length ?? 0) !== 0 || Object.keys(this.options.scalarTypeMap ?? {}).length !== 0;
|
|
2024
|
+
}
|
|
1919
2025
|
};
|
|
1920
2026
|
function createStream(path$1) {
|
|
1921
2027
|
return (0, fs.createWriteStream)(path$1);
|
|
@@ -1954,6 +2060,12 @@ Object.defineProperty(exports, 'Generator', {
|
|
|
1954
2060
|
return Generator;
|
|
1955
2061
|
}
|
|
1956
2062
|
});
|
|
2063
|
+
Object.defineProperty(exports, '__toESM', {
|
|
2064
|
+
enumerable: true,
|
|
2065
|
+
get: function () {
|
|
2066
|
+
return __toESM;
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
1957
2069
|
Object.defineProperty(exports, 'loadLocalSchema', {
|
|
1958
2070
|
enumerable: true,
|
|
1959
2071
|
get: function () {
|