@takeshape/schema 11.122.2 → 11.123.2
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/util/find-shape-at-path.d.ts +2 -2
- package/dist/util/get-return-shape.d.ts +1 -1
- package/dist/util/has-arg.d.ts +2 -1
- package/dist/util/query-field-path.d.ts +9 -0
- package/dist/util/query-field-path.js +23 -0
- package/dist/validate/validate.d.ts +3 -1
- package/dist/validate/validate.js +13 -7
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ export * from './util/is-asset-property.ts';
|
|
|
52
52
|
export * from './util/mcp.ts';
|
|
53
53
|
export * from './util/merge.ts';
|
|
54
54
|
export * from './util/patch-schema.ts';
|
|
55
|
+
export * from './util/query-field-path.ts';
|
|
55
56
|
export * from './util/shapes.ts';
|
|
56
57
|
export * from './validate/errors.ts';
|
|
57
58
|
export * from './validate/validate.ts';
|
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ export * from "./util/is-asset-property.js";
|
|
|
49
49
|
export * from "./util/mcp.js";
|
|
50
50
|
export * from "./util/merge.js";
|
|
51
51
|
export * from "./util/patch-schema.js";
|
|
52
|
+
export * from "./util/query-field-path.js";
|
|
52
53
|
export * from "./util/shapes.js";
|
|
53
54
|
export * from "./validate/errors.js";
|
|
54
55
|
export * from "./validate/validate.js";
|
|
@@ -8,7 +8,7 @@ import type { ProjectSchemaJSON, PropertySchema, ShapeJSON } from '../project-sc
|
|
|
8
8
|
* @example
|
|
9
9
|
* findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds {'@ref': Shopify_Product}
|
|
10
10
|
*/
|
|
11
|
-
export declare function findSchemaAtPath(projectSchema: ProjectSchemaJSON, schema: PropertySchema, queryPath: string[]): PropertySchema | undefined;
|
|
11
|
+
export declare function findSchemaAtPath(projectSchema: Pick<ProjectSchemaJSON, 'services' | 'shapes'>, schema: PropertySchema, queryPath: string[]): PropertySchema | undefined;
|
|
12
12
|
/**
|
|
13
13
|
*
|
|
14
14
|
* @param projectSchema
|
|
@@ -18,4 +18,4 @@ export declare function findSchemaAtPath(projectSchema: ProjectSchemaJSON, schem
|
|
|
18
18
|
* @example
|
|
19
19
|
* findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds Shopify_Product
|
|
20
20
|
*/
|
|
21
|
-
export declare function findShapeAtPath(projectSchema: ProjectSchemaJSON, propSchema: PropertySchema, queryPath: string[]): ShapeJSON | undefined;
|
|
21
|
+
export declare function findShapeAtPath(projectSchema: Pick<ProjectSchemaJSON, 'services' | 'shapes'>, propSchema: PropertySchema, queryPath: string[]): ShapeJSON | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ProjectSchemaJSON, PropertySchema, QueryJSON, ShapeJSON } from '../project-schema/index.ts';
|
|
2
2
|
import { type ServicesShapesContext } from '../refs.ts';
|
|
3
3
|
export declare function getReturnShapeRef(context: ServicesShapesContext, propOrQuery: PropertySchema | QueryJSON): import("@takeshape/util").Maybe<import("../refs.ts").RefItem>;
|
|
4
|
-
export declare function getReturnShape(projectSchema: ProjectSchemaJSON, propOrQuery: PropertySchema | QueryJSON): ShapeJSON | undefined;
|
|
4
|
+
export declare function getReturnShape(projectSchema: Pick<ProjectSchemaJSON, 'services' | 'shapes'>, propOrQuery: PropertySchema | QueryJSON): ShapeJSON | undefined;
|
package/dist/util/has-arg.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Args, ObjectSchema, ProjectSchemaJSON } from '../project-schema/index.ts';
|
|
2
|
+
import { type ServicesShapesContext } from '../refs.ts';
|
|
2
3
|
import { type SchemaWithArgs } from '../types/index.ts';
|
|
3
4
|
export declare function getArgs(prop: SchemaWithArgs): Args | undefined;
|
|
4
|
-
export declare function getArgsSchema(projectSchema:
|
|
5
|
+
export declare function getArgsSchema(projectSchema: ServicesShapesContext, args: Args): ObjectSchema | undefined;
|
|
5
6
|
export declare function hasArg(projectSchema: ProjectSchemaJSON, prop: SchemaWithArgs, argPath: string | string[]): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProjectSchemaJSON } from '../project-schema/index.ts';
|
|
2
|
+
export declare function getQueryFieldPath(operation: 'query' | 'mutation', fieldName: string): ['queries' | 'mutations', ...string[]];
|
|
3
|
+
/**
|
|
4
|
+
* Get a query or property schema
|
|
5
|
+
* @param schema
|
|
6
|
+
* @param queryFieldPath
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function findSchemaAtQueryFieldPath(schema: Pick<ProjectSchemaJSON, 'queries' | 'mutations' | 'services' | 'shapes'>, queryFieldPath: ReturnType<typeof getQueryFieldPath>): import("../project-schema/latest.ts").PropertySchema | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { findSchemaAtPath } from "./find-shape-at-path.js";
|
|
2
|
+
import { getReturnShape } from "./get-return-shape.js";
|
|
3
|
+
function parseFieldName(fieldName) {
|
|
4
|
+
return fieldName.split('.');
|
|
5
|
+
}
|
|
6
|
+
export function getQueryFieldPath(operation, fieldName) {
|
|
7
|
+
return [operation === 'query' ? 'queries' : 'mutations', ...parseFieldName(fieldName)];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get a query or property schema
|
|
11
|
+
* @param schema
|
|
12
|
+
* @param queryFieldPath
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export function findSchemaAtQueryFieldPath(schema, queryFieldPath) {
|
|
16
|
+
const [operationName, queryName, ...fieldPath] = queryFieldPath;
|
|
17
|
+
const queryOrMutation = schema[operationName]?.[queryName];
|
|
18
|
+
if (!queryOrMutation) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const shape = getReturnShape(schema, queryOrMutation);
|
|
22
|
+
return shape ? findSchemaAtPath(schema, shape.schema, fieldPath) : undefined;
|
|
23
|
+
}
|
|
@@ -37,7 +37,9 @@ export type ValidateContext = {
|
|
|
37
37
|
generatedApi?: Pick<ProjectSchemaJSON, 'queries' | 'mutations'>;
|
|
38
38
|
structureOnly?: boolean;
|
|
39
39
|
} & EntitlementsOptions & ValidateSyntaxOptions;
|
|
40
|
-
export type ValidateReferencesContext = SetRequired<ValidateContext, 'resolveLayer'
|
|
40
|
+
export type ValidateReferencesContext = SetRequired<ValidateContext, 'resolveLayer'> & {
|
|
41
|
+
projectSchema: ProjectSchemaJSON;
|
|
42
|
+
};
|
|
41
43
|
export declare function validateSchemaSyntax(obj: unknown, options?: ValidateSyntaxOptions): SchemaValidationResult;
|
|
42
44
|
/**
|
|
43
45
|
* Validates a schema using a matching validation based on the `schemaVersion` property.
|
|
@@ -31,6 +31,7 @@ import { legacyProjectSchemaImportOptionalProps, projectSchemaImportOptionalProp
|
|
|
31
31
|
import { isAIResolver, isBasicResolver, isComposeResolver, isExtendsSchema, isObjectSchema } from "../types/utils.js";
|
|
32
32
|
import { isUnionSchema } from "../unions.js";
|
|
33
33
|
import { getMcpToolMap, TOOL_SCHEMA_PATH } from '../util/mcp.js';
|
|
34
|
+
import { findSchemaAtQueryFieldPath, getQueryFieldPath } from "../util/query-field-path.js";
|
|
34
35
|
import { getShape } from "../util/shapes.js";
|
|
35
36
|
import { CURRENT_SCHEMA_VERSION, LEGACY_API_VERSION, LEGACY_SCHEMA_VERSION } from "../versions.js";
|
|
36
37
|
import { defaultWorkflow } from "../workflows.js";
|
|
@@ -331,17 +332,18 @@ async function validateResolverReferences(context, basePath, baseResolver) {
|
|
|
331
332
|
await pMap(enumerateBasicResolvers(baseResolver, basePath), async ([resolver, path]) => {
|
|
332
333
|
if (resolver.name === 'graphql:query' || resolver.name === 'graphql:mutation') {
|
|
333
334
|
const { service, fieldName } = resolver;
|
|
334
|
-
const
|
|
335
|
+
const operationProp = resolver.name === 'graphql:query' ? 'query' : 'mutation';
|
|
336
|
+
const { projectSchema: { services } } = context;
|
|
335
337
|
const layerState = await context.resolveLayer(service);
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
+
const { schema: layerSchema, status: layerStatus } = layerState;
|
|
339
|
+
const valid = layerStatus === 'ok'
|
|
340
|
+
? Boolean(findSchemaAtQueryFieldPath({ ...layerSchema, services }, getQueryFieldPath(operationProp, fieldName)))
|
|
338
341
|
: allowDisconnected(context, layerState.status);
|
|
339
342
|
if (!valid) {
|
|
340
|
-
const operation = resolver.name === 'graphql:query' ? 'query' : 'mutation';
|
|
341
343
|
errors.push({
|
|
342
344
|
type: 'notFound',
|
|
343
345
|
path: path.concat('fieldName'),
|
|
344
|
-
message: `Missing ${
|
|
346
|
+
message: `Missing ${operationProp} "${resolver.fieldName}" in service layer "${service}"`
|
|
345
347
|
});
|
|
346
348
|
}
|
|
347
349
|
}
|
|
@@ -956,10 +958,14 @@ export async function validateSchema(context, obj) {
|
|
|
956
958
|
return invalidVersionResult;
|
|
957
959
|
}
|
|
958
960
|
const syntaxValidation = validateSyntax(contextWithDefaults, schema);
|
|
959
|
-
|
|
961
|
+
const validateReferencesContext = {
|
|
962
|
+
...contextWithDefaults,
|
|
963
|
+
projectSchema: schema
|
|
964
|
+
};
|
|
965
|
+
if (!syntaxValidation.valid || !isValidateReferencesContext(validateReferencesContext)) {
|
|
960
966
|
return syntaxValidation;
|
|
961
967
|
}
|
|
962
|
-
return validateReferences(
|
|
968
|
+
return validateReferences(validateReferencesContext, schema);
|
|
963
969
|
}
|
|
964
970
|
export function ensureValidLatestSchemaSyntax(obj) {
|
|
965
971
|
const { valid, schema, errors } = validateSchemaSyntax(obj);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.123.2",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"p-reduce": "2.1.0",
|
|
57
57
|
"semver": "7.7.2",
|
|
58
58
|
"tiny-invariant": "1.3.3",
|
|
59
|
-
"@takeshape/errors": "11.
|
|
60
|
-
"@takeshape/
|
|
61
|
-
"@takeshape/
|
|
59
|
+
"@takeshape/errors": "11.123.2",
|
|
60
|
+
"@takeshape/json-schema": "11.123.2",
|
|
61
|
+
"@takeshape/util": "11.123.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@takeshape/json-schema-to-typescript": "11.0.0",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"glob": "7.2.3",
|
|
76
76
|
"json-schema-to-ts": "3.1.1",
|
|
77
77
|
"shortid": "2.2.16",
|
|
78
|
-
"@takeshape/infra": "11.
|
|
79
|
-
"@takeshape/logger": "11.
|
|
78
|
+
"@takeshape/infra": "11.123.2",
|
|
79
|
+
"@takeshape/logger": "11.123.2"
|
|
80
80
|
},
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=22"
|