@shopify/hydrogen-codegen 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/cjs/defaults.cjs +19 -8
- package/dist/cjs/defaults.cjs.map +1 -1
- package/dist/cjs/index.cjs +7 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/preset.cjs +20 -107
- package/dist/cjs/preset.cjs.map +1 -1
- package/dist/cjs/schema.cjs +11 -9
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/esm/defaults.js +19 -8
- package/dist/esm/defaults.js.map +1 -1
- package/dist/esm/index.d.ts +330 -84
- package/dist/esm/index.js +2 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/preset.js +20 -85
- package/dist/esm/preset.js.map +1 -1
- package/dist/esm/schema.js +12 -9
- package/dist/esm/schema.js.map +1 -1
- package/package.json +4 -15
- package/dist/cjs/client.cjs +0 -4
- package/dist/cjs/client.cjs.map +0 -1
- package/dist/cjs/patch.cjs +0 -4
- package/dist/cjs/patch.cjs.map +0 -1
- package/dist/cjs/pluck.cjs +0 -39
- package/dist/cjs/pluck.cjs.map +0 -1
- package/dist/cjs/plugin.cjs +0 -81
- package/dist/cjs/plugin.cjs.map +0 -1
- package/dist/cjs/sources.cjs +0 -43
- package/dist/cjs/sources.cjs.map +0 -1
- package/dist/esm/client.js +0 -3
- package/dist/esm/client.js.map +0 -1
- package/dist/esm/patch.d.ts +0 -2
- package/dist/esm/patch.js +0 -3
- package/dist/esm/patch.js.map +0 -1
- package/dist/esm/pluck.js +0 -37
- package/dist/esm/pluck.js.map +0 -1
- package/dist/esm/plugin.js +0 -77
- package/dist/esm/plugin.js.map +0 -1
- package/dist/esm/sources.js +0 -41
- package/dist/esm/sources.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Hydrogen Codegen
|
|
2
2
|
|
|
3
|
-
A codegen plugin and preset for generating TypeScript types from GraphQL queries in a `d.ts` file. It does not require any function wrapper and adds no runtime overhead (0 bytes to the bundle).
|
|
3
|
+
A codegen plugin and preset for generating TypeScript types from GraphQL queries in a `d.ts` file. It wraps the [`@shopify/graphql-codegen` package](https://github.com/Shopify/graphql-codegen) and adds utilities for Hydrogen. It does not require any function wrapper and adds no runtime overhead (0 bytes to the bundle).
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
const {shop} = await client.query(`#graphql
|
|
@@ -16,7 +16,7 @@ The GraphQL client must use TypeScript interfaces that are extended in the gener
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
When using Hydrogen CLI, this package is already
|
|
19
|
+
When using Hydrogen CLI, this package is already configured for you to generate types for the Shopify Storefront API. However, if you want to use it standalone with the GraphQL CLI or just want to add other APIs to Hydrogen, you can use the following example configuration:
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
22
|
// <root>/codegen.ts
|
|
@@ -51,3 +51,5 @@ export default {
|
|
|
51
51
|
},
|
|
52
52
|
} as CodegenConfig;
|
|
53
53
|
```
|
|
54
|
+
|
|
55
|
+
For more examples and information, refer to [@shopify/graphql-codegen](https://github.com/Shopify/graphql-codegen).
|
package/dist/cjs/defaults.cjs
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const QUERIES_PLACEHOLDER = "%queries%";
|
|
4
|
+
const MUTATIONS_PLACEHOLDER = "%mutations%";
|
|
5
5
|
const sfapiDefaultInterfaceExtensionCode = `
|
|
6
6
|
declare module '@shopify/hydrogen' {
|
|
7
|
-
interface StorefrontQueries extends ${
|
|
8
|
-
interface StorefrontMutations extends ${
|
|
7
|
+
interface StorefrontQueries extends ${QUERIES_PLACEHOLDER} {}
|
|
8
|
+
interface StorefrontMutations extends ${MUTATIONS_PLACEHOLDER} {}
|
|
9
9
|
}`;
|
|
10
10
|
const caapiDefaultInterfaceExtensionCode = `
|
|
11
11
|
declare module '@shopify/hydrogen' {
|
|
12
|
-
interface CustomerAccountQueries extends ${
|
|
13
|
-
interface CustomerAccountMutations extends ${
|
|
12
|
+
interface CustomerAccountQueries extends ${QUERIES_PLACEHOLDER} {}
|
|
13
|
+
interface CustomerAccountMutations extends ${MUTATIONS_PLACEHOLDER} {}
|
|
14
14
|
}`;
|
|
15
|
+
function replacePlaceholders(code, queryType, mutationType) {
|
|
16
|
+
return code.replace(QUERIES_PLACEHOLDER, queryType).replace(MUTATIONS_PLACEHOLDER, mutationType);
|
|
17
|
+
}
|
|
15
18
|
const sfapiDefaultValues = {
|
|
16
19
|
importTypesFrom: "@shopify/hydrogen/storefront-api-types",
|
|
17
20
|
namespacedImportName: "StorefrontAPI",
|
|
18
|
-
interfaceExtensionCode:
|
|
21
|
+
interfaceExtensionCode: ({ queryType, mutationType }) => replacePlaceholders(
|
|
22
|
+
sfapiDefaultInterfaceExtensionCode,
|
|
23
|
+
queryType,
|
|
24
|
+
mutationType
|
|
25
|
+
)
|
|
19
26
|
};
|
|
20
27
|
const caapiDefaultValues = {
|
|
21
28
|
importTypesFrom: "@shopify/hydrogen/customer-account-api-types",
|
|
22
29
|
namespacedImportName: "CustomerAccountAPI",
|
|
23
|
-
interfaceExtensionCode:
|
|
30
|
+
interfaceExtensionCode: ({ queryType, mutationType }) => replacePlaceholders(
|
|
31
|
+
caapiDefaultInterfaceExtensionCode,
|
|
32
|
+
queryType,
|
|
33
|
+
mutationType
|
|
34
|
+
)
|
|
24
35
|
};
|
|
25
36
|
function getDefaultOptions(outputFile = "") {
|
|
26
37
|
return /^(customer|caapi\.)/i.test(outputFile) ? caapiDefaultValues : sfapiDefaultValues;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/defaults.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/defaults.ts"],"names":[],"mappings":"AAEA,MAAM,sBAAsB;AAC5B,MAAM,wBAAwB;AAE9B,MAAM,qCAAqC;AAAA;AAAA,wCAEH,mBAAmB;AAAA,0CACjB,qBAAqB;AAAA;AAG/D,MAAM,qCAAqC;AAAA;AAAA,6CAEE,mBAAmB;AAAA,+CACjB,qBAAqB;AAAA;AAGpE,SAAS,oBACP,MACA,WACA,cACA;AACA,SAAO,KACJ,QAAQ,qBAAqB,SAAS,EACtC,QAAQ,uBAAuB,YAAY;AAChD;AAQA,MAAM,qBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,wBAAwB,CAAC,EAAC,WAAW,aAAY,MAC/C;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACJ;AAEA,MAAM,qBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,wBAAwB,CAAC,EAAC,WAAW,aAAY,MAC/C;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACJ;AAEO,SAAS,kBAAkB,aAAa,IAAI;AACjD,SAAO,uBAAuB,KAAK,UAAU,IACzC,qBACA;AACN","sourcesContent":["import type {PresetConfig} from './preset';\n\nconst QUERIES_PLACEHOLDER = '%queries%';\nconst MUTATIONS_PLACEHOLDER = '%mutations%';\n\nconst sfapiDefaultInterfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface StorefrontQueries extends ${QUERIES_PLACEHOLDER} {}\n interface StorefrontMutations extends ${MUTATIONS_PLACEHOLDER} {}\n}`;\n\nconst caapiDefaultInterfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface CustomerAccountQueries extends ${QUERIES_PLACEHOLDER} {}\n interface CustomerAccountMutations extends ${MUTATIONS_PLACEHOLDER} {}\n}`;\n\nfunction replacePlaceholders(\n code: string,\n queryType: string,\n mutationType: string,\n) {\n return code\n .replace(QUERIES_PLACEHOLDER, queryType)\n .replace(MUTATIONS_PLACEHOLDER, mutationType);\n}\n\ntype DefaultValues = {\n importTypesFrom: string;\n namespacedImportName: string;\n interfaceExtensionCode: NonNullable<PresetConfig['interfaceExtension']>;\n};\n\nconst sfapiDefaultValues: DefaultValues = {\n importTypesFrom: '@shopify/hydrogen/storefront-api-types',\n namespacedImportName: 'StorefrontAPI',\n interfaceExtensionCode: ({queryType, mutationType}) =>\n replacePlaceholders(\n sfapiDefaultInterfaceExtensionCode,\n queryType,\n mutationType,\n ),\n};\n\nconst caapiDefaultValues: DefaultValues = {\n importTypesFrom: '@shopify/hydrogen/customer-account-api-types',\n namespacedImportName: 'CustomerAccountAPI',\n interfaceExtensionCode: ({queryType, mutationType}) =>\n replacePlaceholders(\n caapiDefaultInterfaceExtensionCode,\n queryType,\n mutationType,\n ),\n};\n\nexport function getDefaultOptions(outputFile = '') {\n return /^(customer|caapi\\.)/i.test(outputFile)\n ? caapiDefaultValues\n : sfapiDefaultValues;\n}\n"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var preset_js = require('./preset.cjs');
|
|
4
|
-
var plugin_js = require('./plugin.cjs');
|
|
5
4
|
var schema_js = require('./schema.cjs');
|
|
6
|
-
var
|
|
7
|
-
var pluck_js = require('./pluck.cjs');
|
|
5
|
+
var graphqlCodegen = require('@shopify/graphql-codegen');
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
|
|
@@ -12,25 +10,21 @@ Object.defineProperty(exports, 'preset', {
|
|
|
12
10
|
enumerable: true,
|
|
13
11
|
get: function () { return preset_js.preset; }
|
|
14
12
|
});
|
|
15
|
-
Object.defineProperty(exports, 'plugin', {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return plugin_js.plugin; }
|
|
18
|
-
});
|
|
19
13
|
Object.defineProperty(exports, 'getSchema', {
|
|
20
14
|
enumerable: true,
|
|
21
15
|
get: function () { return schema_js.getSchema; }
|
|
22
16
|
});
|
|
23
|
-
Object.defineProperty(exports, '
|
|
17
|
+
Object.defineProperty(exports, 'pluckConfig', {
|
|
24
18
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
19
|
+
get: function () { return graphqlCodegen.pluckConfig; }
|
|
26
20
|
});
|
|
27
|
-
Object.defineProperty(exports, '
|
|
21
|
+
Object.defineProperty(exports, 'plugin', {
|
|
28
22
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
23
|
+
get: function () { return graphqlCodegen.plugin; }
|
|
30
24
|
});
|
|
31
|
-
Object.defineProperty(exports, '
|
|
25
|
+
Object.defineProperty(exports, 'processSources', {
|
|
32
26
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
27
|
+
get: function () { return graphqlCodegen.processSources; }
|
|
34
28
|
});
|
|
35
29
|
//# sourceMappingURL=out.js.map
|
|
36
30
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,SAAQ,cAAgC;AACxC,SAAQ,iBAAgB;AACxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAOK","sourcesContent":["export {preset, type PresetConfig} from './preset.js';\nexport {getSchema} from './schema.js';\nexport {\n plugin,\n pluckConfig,\n processSources,\n type GenericVariables,\n type EmptyVariables,\n type ClientReturn,\n type IsOptionalVariables,\n type ClientVariables,\n type ClientVariablesInRestParams,\n} from '@shopify/graphql-codegen';\n"]}
|
package/dist/cjs/preset.cjs
CHANGED
|
@@ -1,119 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var typescriptPlugin = require('@graphql-codegen/typescript');
|
|
5
|
-
var typescriptOperationPlugin = require('@graphql-codegen/typescript-operations');
|
|
6
|
-
var sources_js = require('./sources.cjs');
|
|
3
|
+
var graphqlCodegen = require('@shopify/graphql-codegen');
|
|
7
4
|
var defaults_js = require('./defaults.cjs');
|
|
8
|
-
var plugin_js = require('./plugin.cjs');
|
|
9
|
-
|
|
10
|
-
function _interopNamespace(e) {
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
12
|
-
var n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
Object.keys(e).forEach(function (k) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var addPlugin__namespace = /*#__PURE__*/_interopNamespace(addPlugin);
|
|
29
|
-
var typescriptPlugin__namespace = /*#__PURE__*/_interopNamespace(typescriptPlugin);
|
|
30
|
-
var typescriptOperationPlugin__namespace = /*#__PURE__*/_interopNamespace(typescriptOperationPlugin);
|
|
31
5
|
|
|
32
6
|
const preset = {
|
|
33
7
|
[Symbol.for("name")]: "hydrogen",
|
|
34
8
|
buildGeneratesSection: (options) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
9
|
+
try {
|
|
10
|
+
const defaultOptions = defaults_js.getDefaultOptions(options.baseOutputDir);
|
|
11
|
+
return graphqlCodegen.preset.buildGeneratesSection({
|
|
12
|
+
...options,
|
|
13
|
+
presetConfig: {
|
|
14
|
+
importTypes: {
|
|
15
|
+
namespace: defaultOptions.namespacedImportName,
|
|
16
|
+
from: defaultOptions.importTypesFrom
|
|
17
|
+
},
|
|
18
|
+
interfaceExtension: defaultOptions.interfaceExtensionCode,
|
|
19
|
+
...options.presetConfig
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
} catch (err) {
|
|
23
|
+
const error = err;
|
|
24
|
+
error.message = error.message.replace(
|
|
25
|
+
"[@shopify/graphql-codegen]",
|
|
26
|
+
"[hydrogen-preset]"
|
|
41
27
|
);
|
|
28
|
+
throw error;
|
|
42
29
|
}
|
|
43
|
-
const sourcesWithOperations = sources_js.processSources(options.documents);
|
|
44
|
-
const sources = sourcesWithOperations.map(({ source }) => source);
|
|
45
|
-
const defaultOptions = defaults_js.getDefaultOptions(options.baseOutputDir);
|
|
46
|
-
const importTypes = options.presetConfig.importTypes ?? true;
|
|
47
|
-
const namespacedImportName = options.presetConfig.namespacedImportName ?? defaultOptions.namespacedImportName;
|
|
48
|
-
const importTypesFrom = options.presetConfig.importTypesFrom ?? defaultOptions.importTypesFrom;
|
|
49
|
-
const interfaceExtensionCode = options.presetConfig.interfaceExtension?.({
|
|
50
|
-
queryType: plugin_js.GENERATED_QUERY_INTERFACE_NAME,
|
|
51
|
-
mutationType: plugin_js.GENERATED_MUTATION_INTERFACE_NAME
|
|
52
|
-
}) ?? defaultOptions.interfaceExtensionCode;
|
|
53
|
-
const pluginMap = {
|
|
54
|
-
...options.pluginMap,
|
|
55
|
-
[`add`]: addPlugin__namespace,
|
|
56
|
-
[`typescript`]: typescriptPlugin__namespace,
|
|
57
|
-
[`typescript-operations`]: typescriptOperationPlugin__namespace,
|
|
58
|
-
[`gen-dts`]: { plugin: plugin_js.plugin }
|
|
59
|
-
};
|
|
60
|
-
const plugins = [
|
|
61
|
-
// 1. Disable eslint for the generated file
|
|
62
|
-
{
|
|
63
|
-
[`add`]: {
|
|
64
|
-
content: `/* eslint-disable eslint-comments/disable-enable-pair */
|
|
65
|
-
/* eslint-disable eslint-comments/no-unlimited-disable */
|
|
66
|
-
/* eslint-disable */`
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
// 2. Import all the generated API types from Hydrogen or generate all the types from the schema.
|
|
70
|
-
importTypes ? {
|
|
71
|
-
[`add`]: {
|
|
72
|
-
content: `import * as ${namespacedImportName} from '${importTypesFrom}';
|
|
73
|
-
`
|
|
74
|
-
}
|
|
75
|
-
} : {
|
|
76
|
-
[`typescript`]: {
|
|
77
|
-
useTypeImports: true,
|
|
78
|
-
useImplementingTypes: true,
|
|
79
|
-
enumsAsTypes: true
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
// 3. Generate the operations (i.e. queries, mutations, and fragments types)
|
|
83
|
-
{
|
|
84
|
-
[`typescript-operations`]: {
|
|
85
|
-
useTypeImports: true,
|
|
86
|
-
// Use `import type` instead of `import`
|
|
87
|
-
preResolveTypes: false,
|
|
88
|
-
// Use Pick<...> instead of primitives
|
|
89
|
-
mergeFragmentTypes: true,
|
|
90
|
-
// Merge equal fragment interfaces. Avoids adding `| {}` to Metaobject
|
|
91
|
-
skipTypename: options.presetConfig.skipTypenameInOperations ?? true,
|
|
92
|
-
// Skip __typename fields
|
|
93
|
-
namespacedImportName: importTypes ? namespacedImportName : void 0
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
// 4. Augment Hydrogen query/mutation interfaces with the generated operations
|
|
97
|
-
{ [`gen-dts`]: { sourcesWithOperations, interfaceExtensionCode } },
|
|
98
|
-
// 5. Custom plugins from the user
|
|
99
|
-
...options.plugins
|
|
100
|
-
];
|
|
101
|
-
return [
|
|
102
|
-
{
|
|
103
|
-
filename: options.baseOutputDir,
|
|
104
|
-
plugins,
|
|
105
|
-
pluginMap,
|
|
106
|
-
schema: options.schema,
|
|
107
|
-
config: {
|
|
108
|
-
// For the TS plugin:
|
|
109
|
-
defaultScalarType: "unknown",
|
|
110
|
-
// Allow overwriting defaults:
|
|
111
|
-
...options.config
|
|
112
|
-
},
|
|
113
|
-
documents: sources,
|
|
114
|
-
documentTransforms: options.documentTransforms
|
|
115
|
-
}
|
|
116
|
-
];
|
|
117
30
|
}
|
|
118
31
|
};
|
|
119
32
|
|
package/dist/cjs/preset.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"sources":["../../src/preset.ts"],"names":[],"mappings":"AACA;AAAA,EACE,UAAU;AAAA,OAEL;AACP,SAAQ,yBAAwB;AAIzB,MAAM,SAA2C;AAAA,EACtD,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG;AAAA,EACtB,uBAAuB,CAAC,YAAY;AAClC,QAAI;AACF,YAAM,iBAAiB,kBAAkB,QAAQ,aAAa;AAE9D,aAAO,eAAe,sBAAsB;AAAA,QAC1C,GAAG;AAAA,QACH,cAAc;AAAA,UACZ,aAAa;AAAA,YACX,WAAW,eAAe;AAAA,YAC1B,MAAM,eAAe;AAAA,UACvB;AAAA,UACA,oBAAoB,eAAe;AAAA,UACnC,GAAG,QAAQ;AAAA,QACb;AAAA,MACF,CAAC;AAAA,IACH,SAAS,KAAK;AACZ,YAAM,QAAQ;AAEd,YAAM,UAAU,MAAM,QAAQ;AAAA,QAC5B;AAAA,QACA;AAAA,MACF;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AACF","sourcesContent":["import type {Types} from '@graphql-codegen/plugin-helpers';\nimport {\n preset as internalPreset,\n type PresetConfig as InternalPresetConfig,\n} from '@shopify/graphql-codegen';\nimport {getDefaultOptions} from './defaults.js';\n\nexport type PresetConfig = Partial<InternalPresetConfig>;\n\nexport const preset: Types.OutputPreset<PresetConfig> = {\n [Symbol.for('name')]: 'hydrogen',\n buildGeneratesSection: (options) => {\n try {\n const defaultOptions = getDefaultOptions(options.baseOutputDir);\n\n return internalPreset.buildGeneratesSection({\n ...options,\n presetConfig: {\n importTypes: {\n namespace: defaultOptions.namespacedImportName,\n from: defaultOptions.importTypesFrom,\n },\n interfaceExtension: defaultOptions.interfaceExtensionCode,\n ...options.presetConfig,\n } satisfies PresetConfig,\n });\n } catch (err) {\n const error = err as Error;\n\n error.message = error.message.replace(\n '[@shopify/graphql-codegen]',\n '[hydrogen-preset]',\n );\n\n throw error;\n }\n },\n};\n"]}
|
package/dist/cjs/schema.cjs
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);
|
|
4
|
-
|
|
4
|
+
function getSchema(api, options) {
|
|
5
5
|
if (api !== "storefront" && api !== "customer-account") {
|
|
6
6
|
throw new Error(
|
|
7
7
|
`The provided API type "${api}" is unknown. Please use "storefront" or "customer-account".`
|
|
8
8
|
);
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
try {
|
|
11
|
+
return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`);
|
|
12
|
+
} catch {
|
|
13
|
+
if (options?.throwIfMissing !== false) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`Could not find a schema for "${api}".
|
|
16
|
+
Please make sure a recent version of \`@shopify/hydrogen\` is installed.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
|
-
const schema = staticSFAPISchema;
|
|
18
21
|
|
|
19
22
|
exports.getSchema = getSchema;
|
|
20
|
-
exports.schema = schema;
|
|
21
23
|
//# sourceMappingURL=out.js.map
|
|
22
24
|
//# sourceMappingURL=schema.cjs.map
|
package/dist/cjs/schema.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;
|
|
1
|
+
{"version":3,"sources":["../../src/schema.ts"],"names":[],"mappings":"AACA;AAgBO,SAAS,UAAU,KAAU,SAA4B;AAC9D,MAAI,QAAQ,gBAAgB,QAAQ,oBAAoB;AACtD,UAAM,IAAI;AAAA,MACR,0BAA0B,GAAG;AAAA,IAC/B;AAAA,EACF;AAEA,MAAI;AACF,WAAO,QAAQ,QAAQ,2BAA2B,GAAG,cAAc;AAAA,EACrE,QAAQ;AACN,QAAI,SAAS,mBAAmB,OAAO;AACrC,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG;AAAA;AAAA,MACrC;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["// This comment is used during ESM build:\n//! import {createRequire} from 'module'; const require = createRequire(import.meta.url);\n\ntype Api = 'storefront' | 'customer-account';\ntype Options<T extends boolean> = {throwIfMissing?: T};\n\n/**\n * Resolves a schema path for the provided API type. Only the API types currently\n * bundled in Hydrogen are allowed: \"storefront\" and \"customer\".\n * @param api\n * @returns\n */\nexport function getSchema(api: Api, options?: Options<true>): string;\nexport function getSchema(\n api: Api,\n options: Options<false>,\n): string | undefined;\nexport function getSchema(api: Api, options?: Options<boolean>) {\n if (api !== 'storefront' && api !== 'customer-account') {\n throw new Error(\n `The provided API type \"${api}\" is unknown. Please use \"storefront\" or \"customer-account\".`,\n );\n }\n\n try {\n return require.resolve(`@shopify/hydrogen-react/${api}.schema.json`);\n } catch {\n if (options?.throwIfMissing !== false) {\n throw new Error(\n `Could not find a schema for \"${api}\".\\nPlease make sure a recent version of \\`@shopify/hydrogen\\` is installed.`,\n );\n }\n }\n}\n"]}
|
package/dist/esm/defaults.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const QUERIES_PLACEHOLDER = "%queries%";
|
|
2
|
+
const MUTATIONS_PLACEHOLDER = "%mutations%";
|
|
3
3
|
const sfapiDefaultInterfaceExtensionCode = `
|
|
4
4
|
declare module '@shopify/hydrogen' {
|
|
5
|
-
interface StorefrontQueries extends ${
|
|
6
|
-
interface StorefrontMutations extends ${
|
|
5
|
+
interface StorefrontQueries extends ${QUERIES_PLACEHOLDER} {}
|
|
6
|
+
interface StorefrontMutations extends ${MUTATIONS_PLACEHOLDER} {}
|
|
7
7
|
}`;
|
|
8
8
|
const caapiDefaultInterfaceExtensionCode = `
|
|
9
9
|
declare module '@shopify/hydrogen' {
|
|
10
|
-
interface CustomerAccountQueries extends ${
|
|
11
|
-
interface CustomerAccountMutations extends ${
|
|
10
|
+
interface CustomerAccountQueries extends ${QUERIES_PLACEHOLDER} {}
|
|
11
|
+
interface CustomerAccountMutations extends ${MUTATIONS_PLACEHOLDER} {}
|
|
12
12
|
}`;
|
|
13
|
+
function replacePlaceholders(code, queryType, mutationType) {
|
|
14
|
+
return code.replace(QUERIES_PLACEHOLDER, queryType).replace(MUTATIONS_PLACEHOLDER, mutationType);
|
|
15
|
+
}
|
|
13
16
|
const sfapiDefaultValues = {
|
|
14
17
|
importTypesFrom: "@shopify/hydrogen/storefront-api-types",
|
|
15
18
|
namespacedImportName: "StorefrontAPI",
|
|
16
|
-
interfaceExtensionCode:
|
|
19
|
+
interfaceExtensionCode: ({ queryType, mutationType }) => replacePlaceholders(
|
|
20
|
+
sfapiDefaultInterfaceExtensionCode,
|
|
21
|
+
queryType,
|
|
22
|
+
mutationType
|
|
23
|
+
)
|
|
17
24
|
};
|
|
18
25
|
const caapiDefaultValues = {
|
|
19
26
|
importTypesFrom: "@shopify/hydrogen/customer-account-api-types",
|
|
20
27
|
namespacedImportName: "CustomerAccountAPI",
|
|
21
|
-
interfaceExtensionCode:
|
|
28
|
+
interfaceExtensionCode: ({ queryType, mutationType }) => replacePlaceholders(
|
|
29
|
+
caapiDefaultInterfaceExtensionCode,
|
|
30
|
+
queryType,
|
|
31
|
+
mutationType
|
|
32
|
+
)
|
|
22
33
|
};
|
|
23
34
|
function getDefaultOptions(outputFile = "") {
|
|
24
35
|
return /^(customer|caapi\.)/i.test(outputFile) ? caapiDefaultValues : sfapiDefaultValues;
|
package/dist/esm/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/defaults.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/defaults.ts"],"names":[],"mappings":"AAEA,MAAM,sBAAsB;AAC5B,MAAM,wBAAwB;AAE9B,MAAM,qCAAqC;AAAA;AAAA,wCAEH,mBAAmB;AAAA,0CACjB,qBAAqB;AAAA;AAG/D,MAAM,qCAAqC;AAAA;AAAA,6CAEE,mBAAmB;AAAA,+CACjB,qBAAqB;AAAA;AAGpE,SAAS,oBACP,MACA,WACA,cACA;AACA,SAAO,KACJ,QAAQ,qBAAqB,SAAS,EACtC,QAAQ,uBAAuB,YAAY;AAChD;AAQA,MAAM,qBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,wBAAwB,CAAC,EAAC,WAAW,aAAY,MAC/C;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACJ;AAEA,MAAM,qBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,wBAAwB,CAAC,EAAC,WAAW,aAAY,MAC/C;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACJ;AAEO,SAAS,kBAAkB,aAAa,IAAI;AACjD,SAAO,uBAAuB,KAAK,UAAU,IACzC,qBACA;AACN","sourcesContent":["import type {PresetConfig} from './preset';\n\nconst QUERIES_PLACEHOLDER = '%queries%';\nconst MUTATIONS_PLACEHOLDER = '%mutations%';\n\nconst sfapiDefaultInterfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface StorefrontQueries extends ${QUERIES_PLACEHOLDER} {}\n interface StorefrontMutations extends ${MUTATIONS_PLACEHOLDER} {}\n}`;\n\nconst caapiDefaultInterfaceExtensionCode = `\ndeclare module '@shopify/hydrogen' {\n interface CustomerAccountQueries extends ${QUERIES_PLACEHOLDER} {}\n interface CustomerAccountMutations extends ${MUTATIONS_PLACEHOLDER} {}\n}`;\n\nfunction replacePlaceholders(\n code: string,\n queryType: string,\n mutationType: string,\n) {\n return code\n .replace(QUERIES_PLACEHOLDER, queryType)\n .replace(MUTATIONS_PLACEHOLDER, mutationType);\n}\n\ntype DefaultValues = {\n importTypesFrom: string;\n namespacedImportName: string;\n interfaceExtensionCode: NonNullable<PresetConfig['interfaceExtension']>;\n};\n\nconst sfapiDefaultValues: DefaultValues = {\n importTypesFrom: '@shopify/hydrogen/storefront-api-types',\n namespacedImportName: 'StorefrontAPI',\n interfaceExtensionCode: ({queryType, mutationType}) =>\n replacePlaceholders(\n sfapiDefaultInterfaceExtensionCode,\n queryType,\n mutationType,\n ),\n};\n\nconst caapiDefaultValues: DefaultValues = {\n importTypesFrom: '@shopify/hydrogen/customer-account-api-types',\n namespacedImportName: 'CustomerAccountAPI',\n interfaceExtensionCode: ({queryType, mutationType}) =>\n replacePlaceholders(\n caapiDefaultInterfaceExtensionCode,\n queryType,\n mutationType,\n ),\n};\n\nexport function getDefaultOptions(outputFile = '') {\n return /^(customer|caapi\\.)/i.test(outputFile)\n ? caapiDefaultValues\n : sfapiDefaultValues;\n}\n"]}
|