@takeshape/schema 11.144.1 → 11.154.1
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/examples/latest/all-fields-shapes-inline.json +1 -1
- package/examples/latest/all-fields-shapes.json +1 -1
- package/examples/latest/betzino.json +1 -1
- package/examples/latest/blog-schema.json +1 -1
- package/examples/latest/brewery-schema.json +1 -1
- package/examples/latest/chat-agent-schema.json +1 -1
- package/examples/latest/clear-cache-schema.json +1 -1
- package/examples/latest/complex-project-schema.json +1 -1
- package/examples/latest/complex-schema.json +1 -1
- package/examples/latest/edit-schema.json +1 -1
- package/examples/latest/frank-and-fred-schema.json +1 -1
- package/examples/latest/generate-agent-schema.json +1 -1
- package/examples/latest/klirr-schema.json +1 -1
- package/examples/latest/layers/rick-and-morty-layer.json +1 -1
- package/examples/latest/layers/shopify-layer-2023-01.json +1 -1
- package/examples/latest/layers/shopify-storefront-2023-04.json +1 -1
- package/examples/latest/layers/wordpress-2024-01.json +1 -1
- package/examples/latest/massive-schema.json +1 -1
- package/examples/latest/mill-components-schema.json +1 -1
- package/examples/latest/nested-shape-arrays.json +1 -1
- package/examples/latest/one-earth.json +1 -1
- package/examples/latest/pet-oneof-array.json +1 -1
- package/examples/latest/post-schema.json +1 -1
- package/examples/latest/pruned-shopify-product-schema.json +1 -1
- package/examples/latest/rag-example.json +1 -1
- package/examples/latest/real-world-schema.json +1 -1
- package/examples/latest/recursive-repeater-schema.json +1 -1
- package/examples/latest/recursive-schema.json +1 -1
- package/examples/latest/rick-and-morty-ast.json +1 -1
- package/examples/latest/rick-and-morty-graphql.json +1 -1
- package/examples/latest/rick-and-morty-rest.json +1 -1
- package/examples/latest/rick-and-morty-user-schema.json +1 -1
- package/examples/latest/rick-and-morty-with-indexing.json +1 -1
- package/examples/latest/schema-where-filter.json +1 -1
- package/examples/latest/schema-with-repeater-draftjs.json +1 -1
- package/examples/latest/schema-with-rick-and-morty.json +1 -1
- package/examples/latest/shape-books-v3_2_0.json +1 -1
- package/examples/latest/shape-books.json +1 -1
- package/examples/latest/shape-editor-schema-edited.json +1 -1
- package/examples/latest/shape-editor-schema-initial.json +1 -1
- package/examples/latest/shapedb-crud-every-prop-type.json +1 -1
- package/examples/latest/shopify-lookbook.json +1 -1
- package/examples/latest/shopify-product-2022-07.json +1 -1
- package/examples/latest/shopify-product-2023-04.json +1 -1
- package/examples/latest/shopify-store-with-widget.json +1 -1
- package/examples/latest/stripe-product-runtime-schema.json +1 -1
- package/examples/latest/stripe-starter-resolved.json +1 -1
- package/examples/latest/user-schema-no-required.json +1 -1
- package/examples/latest/user-schema-with-defaults.json +1 -1
- package/examples/latest/valvoline-ai-demo.json +1461 -1421
- package/examples/latest/vector-search-schema.json +1 -1
- package/package.json +10 -9
- package/dist/agents.d.ts +0 -62
- package/dist/agents.js +0 -338
- package/dist/api-version.d.ts +0 -5
- package/dist/api-version.js +0 -17
- package/dist/auth-schemas.d.ts +0 -128
- package/dist/auth-schemas.js +0 -7
- package/dist/auth-utils.d.ts +0 -5
- package/dist/auth-utils.js +0 -6
- package/dist/builtin-schema.d.ts +0 -18
- package/dist/builtin-schema.js +0 -683
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -1
- package/dist/content-schema-transform.d.ts +0 -35
- package/dist/content-schema-transform.js +0 -162
- package/dist/create-input-schema.d.ts +0 -9
- package/dist/create-input-schema.js +0 -68
- package/dist/enum.d.ts +0 -2
- package/dist/enum.js +0 -9
- package/dist/flatten-templates.d.ts +0 -2
- package/dist/flatten-templates.js +0 -20
- package/dist/get-is-leaf.d.ts +0 -3
- package/dist/get-is-leaf.js +0 -56
- package/dist/index.d.ts +0 -62
- package/dist/index.js +0 -59
- package/dist/interfaces.d.ts +0 -14
- package/dist/interfaces.js +0 -86
- package/dist/layers/layers.d.ts +0 -26
- package/dist/layers/layers.js +0 -301
- package/dist/layers/refs.d.ts +0 -102
- package/dist/layers/refs.js +0 -220
- package/dist/layers/type-utils.d.ts +0 -59
- package/dist/layers/type-utils.js +0 -118
- package/dist/layers/visitor.d.ts +0 -5
- package/dist/layers/visitor.js +0 -38
- package/dist/migration/index.d.ts +0 -73
- package/dist/migration/index.js +0 -103
- package/dist/migration/to/v3.0.0.d.ts +0 -4
- package/dist/migration/to/v3.0.0.js +0 -212
- package/dist/migration/to/v3.1.0.d.ts +0 -4
- package/dist/migration/to/v3.1.0.js +0 -194
- package/dist/migration/to/v3.10.0.d.ts +0 -4
- package/dist/migration/to/v3.10.0.js +0 -67
- package/dist/migration/to/v3.11.0.d.ts +0 -4
- package/dist/migration/to/v3.11.0.js +0 -85
- package/dist/migration/to/v3.12.3.d.ts +0 -4
- package/dist/migration/to/v3.12.3.js +0 -87
- package/dist/migration/to/v3.13.0.d.ts +0 -4
- package/dist/migration/to/v3.13.0.js +0 -17
- package/dist/migration/to/v3.17.0.d.ts +0 -4
- package/dist/migration/to/v3.17.0.js +0 -22
- package/dist/migration/to/v3.18.0.d.ts +0 -4
- package/dist/migration/to/v3.18.0.js +0 -64
- package/dist/migration/to/v3.18.1.d.ts +0 -4
- package/dist/migration/to/v3.18.1.js +0 -12
- package/dist/migration/to/v3.18.2.d.ts +0 -4
- package/dist/migration/to/v3.18.2.js +0 -19
- package/dist/migration/to/v3.20.0.d.ts +0 -4
- package/dist/migration/to/v3.20.0.js +0 -24
- package/dist/migration/to/v3.22.0.d.ts +0 -4
- package/dist/migration/to/v3.22.0.js +0 -25
- package/dist/migration/to/v3.24.0.d.ts +0 -4
- package/dist/migration/to/v3.24.0.js +0 -11
- package/dist/migration/to/v3.25.0.d.ts +0 -4
- package/dist/migration/to/v3.25.0.js +0 -11
- package/dist/migration/to/v3.3.0.d.ts +0 -4
- package/dist/migration/to/v3.3.0.js +0 -13
- package/dist/migration/to/v3.31.0.d.ts +0 -4
- package/dist/migration/to/v3.31.0.js +0 -38
- package/dist/migration/to/v3.32.0.d.ts +0 -4
- package/dist/migration/to/v3.32.0.js +0 -59
- package/dist/migration/to/v3.34.0.d.ts +0 -6
- package/dist/migration/to/v3.34.0.js +0 -111
- package/dist/migration/to/v3.36.0.d.ts +0 -4
- package/dist/migration/to/v3.36.0.js +0 -22
- package/dist/migration/to/v3.39.0.d.ts +0 -4
- package/dist/migration/to/v3.39.0.js +0 -45
- package/dist/migration/to/v3.40.0.d.ts +0 -4
- package/dist/migration/to/v3.40.0.js +0 -26
- package/dist/migration/to/v3.46.0.d.ts +0 -4
- package/dist/migration/to/v3.46.0.js +0 -35
- package/dist/migration/to/v3.57.0.d.ts +0 -4
- package/dist/migration/to/v3.57.0.js +0 -18
- package/dist/migration/to/v3.9.0.d.ts +0 -4
- package/dist/migration/to/v3.9.0.js +0 -79
- package/dist/migration/types.d.ts +0 -26
- package/dist/migration/types.js +0 -3
- package/dist/migration/utils.d.ts +0 -2
- package/dist/migration/utils.js +0 -6
- package/dist/mocks.d.ts +0 -14
- package/dist/mocks.js +0 -58
- package/dist/models/agent.d.ts +0 -3
- package/dist/models/agent.js +0 -29
- package/dist/models/project-schema.d.ts +0 -18
- package/dist/models/project-schema.js +0 -119
- package/dist/models/query.d.ts +0 -3
- package/dist/models/query.js +0 -38
- package/dist/models/runtime-schema.d.ts +0 -9
- package/dist/models/runtime-schema.js +0 -20
- package/dist/models/shape.d.ts +0 -4
- package/dist/models/shape.js +0 -36
- package/dist/models/types.d.ts +0 -36
- package/dist/models/types.js +0 -1
- package/dist/models/user-schema.d.ts +0 -7
- package/dist/models/user-schema.js +0 -9
- package/dist/patterns.d.ts +0 -12
- package/dist/patterns.js +0 -1
- package/dist/project-schema/index.d.ts +0 -211
- package/dist/project-schema/index.js +0 -83
- package/dist/project-schema/latest.d.ts +0 -2619
- package/dist/project-schema/latest.js +0 -7
- package/dist/project-schema/migrate.d.ts +0 -4
- package/dist/project-schema/migrate.js +0 -218
- package/dist/project-schema/v1.0.0.d.ts +0 -299
- package/dist/project-schema/v1.0.0.js +0 -7
- package/dist/project-schema/v3.0.0.d.ts +0 -478
- package/dist/project-schema/v3.0.0.js +0 -7
- package/dist/project-schema/v3.1.0.d.ts +0 -621
- package/dist/project-schema/v3.1.0.js +0 -7
- package/dist/project-schema/v3.10.0.d.ts +0 -1201
- package/dist/project-schema/v3.10.0.js +0 -7
- package/dist/project-schema/v3.11.0.d.ts +0 -1210
- package/dist/project-schema/v3.11.0.js +0 -7
- package/dist/project-schema/v3.12.0.d.ts +0 -1214
- package/dist/project-schema/v3.12.0.js +0 -7
- package/dist/project-schema/v3.12.1.d.ts +0 -1273
- package/dist/project-schema/v3.12.1.js +0 -7
- package/dist/project-schema/v3.12.2.d.ts +0 -1283
- package/dist/project-schema/v3.12.2.js +0 -7
- package/dist/project-schema/v3.12.3.d.ts +0 -1306
- package/dist/project-schema/v3.12.3.js +0 -7
- package/dist/project-schema/v3.13.0.d.ts +0 -1317
- package/dist/project-schema/v3.13.0.js +0 -7
- package/dist/project-schema/v3.13.1.d.ts +0 -1412
- package/dist/project-schema/v3.13.1.js +0 -7
- package/dist/project-schema/v3.14.0.d.ts +0 -1436
- package/dist/project-schema/v3.14.0.js +0 -7
- package/dist/project-schema/v3.15.0.d.ts +0 -1458
- package/dist/project-schema/v3.15.0.js +0 -7
- package/dist/project-schema/v3.16.0.d.ts +0 -1470
- package/dist/project-schema/v3.16.0.js +0 -7
- package/dist/project-schema/v3.17.0.d.ts +0 -1467
- package/dist/project-schema/v3.17.0.js +0 -7
- package/dist/project-schema/v3.17.1.d.ts +0 -1468
- package/dist/project-schema/v3.17.1.js +0 -7
- package/dist/project-schema/v3.18.0.d.ts +0 -1333
- package/dist/project-schema/v3.18.0.js +0 -7
- package/dist/project-schema/v3.18.1.d.ts +0 -1332
- package/dist/project-schema/v3.18.1.js +0 -7
- package/dist/project-schema/v3.18.2.d.ts +0 -1332
- package/dist/project-schema/v3.18.2.js +0 -7
- package/dist/project-schema/v3.19.0.d.ts +0 -1336
- package/dist/project-schema/v3.19.0.js +0 -7
- package/dist/project-schema/v3.2.0.d.ts +0 -632
- package/dist/project-schema/v3.2.0.js +0 -7
- package/dist/project-schema/v3.20.0.d.ts +0 -1336
- package/dist/project-schema/v3.20.0.js +0 -7
- package/dist/project-schema/v3.21.0.d.ts +0 -1338
- package/dist/project-schema/v3.21.0.js +0 -7
- package/dist/project-schema/v3.22.0.d.ts +0 -1344
- package/dist/project-schema/v3.22.0.js +0 -7
- package/dist/project-schema/v3.23.0.d.ts +0 -1376
- package/dist/project-schema/v3.23.0.js +0 -7
- package/dist/project-schema/v3.24.0.d.ts +0 -1364
- package/dist/project-schema/v3.24.0.js +0 -7
- package/dist/project-schema/v3.25.0.d.ts +0 -1363
- package/dist/project-schema/v3.25.0.js +0 -7
- package/dist/project-schema/v3.26.0.d.ts +0 -1388
- package/dist/project-schema/v3.26.0.js +0 -7
- package/dist/project-schema/v3.27.0.d.ts +0 -1397
- package/dist/project-schema/v3.27.0.js +0 -7
- package/dist/project-schema/v3.28.0.d.ts +0 -1416
- package/dist/project-schema/v3.28.0.js +0 -7
- package/dist/project-schema/v3.29.0.d.ts +0 -1423
- package/dist/project-schema/v3.29.0.js +0 -7
- package/dist/project-schema/v3.3.0.d.ts +0 -632
- package/dist/project-schema/v3.3.0.js +0 -7
- package/dist/project-schema/v3.30.0.d.ts +0 -1416
- package/dist/project-schema/v3.30.0.js +0 -7
- package/dist/project-schema/v3.31.0.d.ts +0 -1448
- package/dist/project-schema/v3.31.0.js +0 -7
- package/dist/project-schema/v3.32.0.d.ts +0 -1439
- package/dist/project-schema/v3.32.0.js +0 -7
- package/dist/project-schema/v3.33.0.d.ts +0 -1445
- package/dist/project-schema/v3.33.0.js +0 -7
- package/dist/project-schema/v3.34.0.d.ts +0 -1445
- package/dist/project-schema/v3.34.0.js +0 -7
- package/dist/project-schema/v3.35.0.d.ts +0 -1464
- package/dist/project-schema/v3.35.0.js +0 -7
- package/dist/project-schema/v3.36.0.d.ts +0 -1470
- package/dist/project-schema/v3.36.0.js +0 -7
- package/dist/project-schema/v3.37.0.d.ts +0 -1522
- package/dist/project-schema/v3.37.0.js +0 -7
- package/dist/project-schema/v3.38.0.d.ts +0 -1522
- package/dist/project-schema/v3.38.0.js +0 -7
- package/dist/project-schema/v3.39.0.d.ts +0 -1529
- package/dist/project-schema/v3.39.0.js +0 -7
- package/dist/project-schema/v3.4.0.d.ts +0 -624
- package/dist/project-schema/v3.4.0.js +0 -7
- package/dist/project-schema/v3.40.0.d.ts +0 -1530
- package/dist/project-schema/v3.40.0.js +0 -7
- package/dist/project-schema/v3.41.0.d.ts +0 -1530
- package/dist/project-schema/v3.41.0.js +0 -7
- package/dist/project-schema/v3.42.0.d.ts +0 -1534
- package/dist/project-schema/v3.42.0.js +0 -7
- package/dist/project-schema/v3.43.0.d.ts +0 -1536
- package/dist/project-schema/v3.43.0.js +0 -7
- package/dist/project-schema/v3.44.0.d.ts +0 -1621
- package/dist/project-schema/v3.44.0.js +0 -7
- package/dist/project-schema/v3.45.0.d.ts +0 -1650
- package/dist/project-schema/v3.45.0.js +0 -7
- package/dist/project-schema/v3.46.0.d.ts +0 -1703
- package/dist/project-schema/v3.46.0.js +0 -7
- package/dist/project-schema/v3.47.0.d.ts +0 -1736
- package/dist/project-schema/v3.47.0.js +0 -7
- package/dist/project-schema/v3.48.0.d.ts +0 -2208
- package/dist/project-schema/v3.48.0.js +0 -7
- package/dist/project-schema/v3.49.0.d.ts +0 -2217
- package/dist/project-schema/v3.49.0.js +0 -7
- package/dist/project-schema/v3.5.0.d.ts +0 -649
- package/dist/project-schema/v3.5.0.js +0 -7
- package/dist/project-schema/v3.5.1.d.ts +0 -649
- package/dist/project-schema/v3.5.1.js +0 -7
- package/dist/project-schema/v3.50.0.d.ts +0 -2269
- package/dist/project-schema/v3.50.0.js +0 -7
- package/dist/project-schema/v3.51.0.d.ts +0 -2269
- package/dist/project-schema/v3.51.0.js +0 -7
- package/dist/project-schema/v3.52.0.d.ts +0 -2269
- package/dist/project-schema/v3.52.0.js +0 -7
- package/dist/project-schema/v3.53.0.d.ts +0 -2350
- package/dist/project-schema/v3.53.0.js +0 -7
- package/dist/project-schema/v3.54.0.d.ts +0 -2369
- package/dist/project-schema/v3.54.0.js +0 -7
- package/dist/project-schema/v3.55.0.d.ts +0 -2369
- package/dist/project-schema/v3.55.0.js +0 -7
- package/dist/project-schema/v3.56.0.d.ts +0 -2405
- package/dist/project-schema/v3.56.0.js +0 -7
- package/dist/project-schema/v3.57.0.d.ts +0 -2601
- package/dist/project-schema/v3.57.0.js +0 -7
- package/dist/project-schema/v3.58.0.d.ts +0 -2601
- package/dist/project-schema/v3.58.0.js +0 -7
- package/dist/project-schema/v3.59.0.d.ts +0 -2619
- package/dist/project-schema/v3.59.0.js +0 -7
- package/dist/project-schema/v3.6.0.d.ts +0 -658
- package/dist/project-schema/v3.6.0.js +0 -7
- package/dist/project-schema/v3.7.0.d.ts +0 -961
- package/dist/project-schema/v3.7.0.js +0 -7
- package/dist/project-schema/v3.8.0.d.ts +0 -979
- package/dist/project-schema/v3.8.0.js +0 -7
- package/dist/project-schema/v3.9.0.d.ts +0 -1178
- package/dist/project-schema/v3.9.0.js +0 -7
- package/dist/project-schema/v4.0.0.d.ts +0 -1328
- package/dist/project-schema/v4.0.0.js +0 -7
- package/dist/refs.d.ts +0 -218
- package/dist/refs.js +0 -616
- package/dist/relationships.d.ts +0 -40
- package/dist/relationships.js +0 -302
- package/dist/resolvers/ai/abort-agent-message-args.d.ts +0 -16
- package/dist/resolvers/ai/abort-agent-message-args.js +0 -13
- package/dist/resolvers/ai/abort-agent-message-response.d.ts +0 -39
- package/dist/resolvers/ai/abort-agent-message-response.js +0 -19
- package/dist/resolvers/ai/agent-chat-args.d.ts +0 -17
- package/dist/resolvers/ai/agent-chat-args.js +0 -14
- package/dist/resolvers/ai/agent-chat-payload.d.ts +0 -35
- package/dist/resolvers/ai/agent-chat-payload.js +0 -26
- package/dist/resolvers/ai/agent-chat-response.d.ts +0 -289
- package/dist/resolvers/ai/agent-chat-response.js +0 -21
- package/dist/resolvers/ai/agent-generate-args.d.ts +0 -17
- package/dist/resolvers/ai/agent-generate-args.js +0 -14
- package/dist/resolvers/ai/agent-message-input.d.ts +0 -73
- package/dist/resolvers/ai/agent-message-input.js +0 -39
- package/dist/resolvers/ai/agent-message-output.d.ts +0 -169
- package/dist/resolvers/ai/agent-message-output.js +0 -77
- package/dist/resolvers/ai/agent-message-payload.d.ts +0 -507
- package/dist/resolvers/ai/agent-message-payload.js +0 -156
- package/dist/resolvers/ai/agent-run-mode.d.ts +0 -7
- package/dist/resolvers/ai/agent-run-mode.js +0 -9
- package/dist/resolvers/ai/agent-session-payload.d.ts +0 -515
- package/dist/resolvers/ai/agent-session-payload.js +0 -175
- package/dist/resolvers/ai/create-agent-session-response.d.ts +0 -199
- package/dist/resolvers/ai/create-agent-session-response.js +0 -9
- package/dist/resolvers/ai/embedding-search.d.ts +0 -54
- package/dist/resolvers/ai/embedding-search.js +0 -46
- package/dist/resolvers/ai/get-agent-message-args.d.ts +0 -16
- package/dist/resolvers/ai/get-agent-message-args.js +0 -13
- package/dist/resolvers/ai/get-agent-message-response.d.ts +0 -805
- package/dist/resolvers/ai/get-agent-message-response.js +0 -63
- package/dist/resolvers/ai/inspect-agent-args.d.ts +0 -16
- package/dist/resolvers/ai/inspect-agent-args.js +0 -13
- package/dist/resolvers/ai/inspect-agent-response.d.ts +0 -504
- package/dist/resolvers/ai/inspect-agent-response.js +0 -48
- package/dist/resolvers/ai/send-agent-feedback-args.d.ts +0 -52
- package/dist/resolvers/ai/send-agent-feedback-args.js +0 -16
- package/dist/resolvers/ai/send-agent-message-args.d.ts +0 -48
- package/dist/resolvers/ai/send-agent-message-args.js +0 -36
- package/dist/resolvers/ai/send-agent-message-response.d.ts +0 -353
- package/dist/resolvers/ai/send-agent-message-response.js +0 -51
- package/dist/resolvers/ai/types.d.ts +0 -6
- package/dist/resolvers/ai/types.js +0 -1
- package/dist/resolvers/takeshape/assets/asset-image-meta.d.ts +0 -79
- package/dist/resolvers/takeshape/assets/asset-image-meta.js +0 -98
- package/dist/resolvers/takeshape/assets/asset-image-params.d.ts +0 -901
- package/dist/resolvers/takeshape/assets/asset-image-params.js +0 -726
- package/dist/resolvers/takeshape/assets/asset-image.d.ts +0 -17
- package/dist/resolvers/takeshape/assets/asset-image.js +0 -15
- package/dist/resolvers/takeshape/assets/asset.d.ts +0 -125
- package/dist/resolvers/takeshape/assets/asset.js +0 -107
- package/dist/resolvers/takeshape/assets/constants.d.ts +0 -11
- package/dist/resolvers/takeshape/assets/constants.js +0 -11
- package/dist/resolvers/takeshape/builtins/constants.d.ts +0 -1
- package/dist/resolvers/takeshape/builtins/constants.js +0 -1
- package/dist/runtime-schema.d.ts +0 -6
- package/dist/runtime-schema.js +0 -85
- package/dist/scalars.d.ts +0 -2
- package/dist/scalars.js +0 -4
- package/dist/schema-transform.d.ts +0 -19
- package/dist/schema-transform.js +0 -74
- package/dist/schema-util.d.ts +0 -266
- package/dist/schema-util.js +0 -1127
- package/dist/schemas/auth-schemas.json +0 -374
- package/dist/schemas/index.d.ts +0 -4
- package/dist/schemas/index.js +0 -170
- package/dist/schemas/project-schema/experimental-2025-07.json +0 -1297
- package/dist/schemas/project-schema/latest.d.ts +0 -180
- package/dist/schemas/project-schema/latest.js +0 -11
- package/dist/schemas/project-schema/latest.json +0 -4846
- package/dist/schemas/project-schema/meta-schema-v1.0.0.json +0 -193
- package/dist/schemas/project-schema/meta-schema-v3.0.0.json +0 -608
- package/dist/schemas/project-schema/meta-schema-v3.1.0.json +0 -608
- package/dist/schemas/project-schema/meta-schema-v3.2.0.json +0 -612
- package/dist/schemas/project-schema/meta-schema-v3.3.0.json +0 -612
- package/dist/schemas/project-schema/meta-schema-v3.4.0.json +0 -637
- package/dist/schemas/project-schema/meta-schema-v3.5.0.json +0 -626
- package/dist/schemas/project-schema/meta-schema-v3.5.1.json +0 -626
- package/dist/schemas/project-schema/meta-schema-v3.6.0.json +0 -629
- package/dist/schemas/project-schema/meta-schema-v3.7.0.json +0 -1137
- package/dist/schemas/project-schema/meta-schema-v3.8.0.json +0 -1137
- package/dist/schemas/project-schema/meta-schema-v3.9.0.json +0 -1477
- package/dist/schemas/project-schema/v1.0.0.json +0 -321
- package/dist/schemas/project-schema/v3.0.0.json +0 -414
- package/dist/schemas/project-schema/v3.1.0.json +0 -572
- package/dist/schemas/project-schema/v3.10.0.json +0 -2097
- package/dist/schemas/project-schema/v3.11.0.json +0 -2141
- package/dist/schemas/project-schema/v3.12.0.json +0 -2144
- package/dist/schemas/project-schema/v3.12.1.json +0 -2282
- package/dist/schemas/project-schema/v3.12.2.json +0 -2304
- package/dist/schemas/project-schema/v3.12.3.json +0 -2357
- package/dist/schemas/project-schema/v3.13.0.json +0 -2377
- package/dist/schemas/project-schema/v3.14.0.json +0 -2385
- package/dist/schemas/project-schema/v3.15.0.json +0 -2365
- package/dist/schemas/project-schema/v3.16.0.json +0 -2373
- package/dist/schemas/project-schema/v3.17.0.json +0 -2378
- package/dist/schemas/project-schema/v3.17.1.json +0 -2380
- package/dist/schemas/project-schema/v3.18.0.json +0 -2356
- package/dist/schemas/project-schema/v3.18.1.json +0 -2357
- package/dist/schemas/project-schema/v3.18.2.json +0 -2357
- package/dist/schemas/project-schema/v3.19.0.json +0 -2369
- package/dist/schemas/project-schema/v3.2.0.json +0 -580
- package/dist/schemas/project-schema/v3.20.0.json +0 -2369
- package/dist/schemas/project-schema/v3.21.0.json +0 -2376
- package/dist/schemas/project-schema/v3.22.0.json +0 -2381
- package/dist/schemas/project-schema/v3.23.0.json +0 -2456
- package/dist/schemas/project-schema/v3.24.0.json +0 -2556
- package/dist/schemas/project-schema/v3.25.0.json +0 -2552
- package/dist/schemas/project-schema/v3.26.0.json +0 -2599
- package/dist/schemas/project-schema/v3.27.0.json +0 -2611
- package/dist/schemas/project-schema/v3.28.0.json +0 -2656
- package/dist/schemas/project-schema/v3.29.0.json +0 -2670
- package/dist/schemas/project-schema/v3.3.0.json +0 -581
- package/dist/schemas/project-schema/v3.30.0.json +0 -2656
- package/dist/schemas/project-schema/v3.31.0.json +0 -2714
- package/dist/schemas/project-schema/v3.32.0.json +0 -2708
- package/dist/schemas/project-schema/v3.33.0.json +0 -2715
- package/dist/schemas/project-schema/v3.34.0.json +0 -2715
- package/dist/schemas/project-schema/v3.35.0.json +0 -2748
- package/dist/schemas/project-schema/v3.36.0.json +0 -2756
- package/dist/schemas/project-schema/v3.37.0.json +0 -2821
- package/dist/schemas/project-schema/v3.38.0.json +0 -2819
- package/dist/schemas/project-schema/v3.39.0.json +0 -2827
- package/dist/schemas/project-schema/v3.4.0.json +0 -571
- package/dist/schemas/project-schema/v3.40.0.json +0 -2830
- package/dist/schemas/project-schema/v3.41.0.json +0 -2830
- package/dist/schemas/project-schema/v3.42.0.json +0 -2835
- package/dist/schemas/project-schema/v3.43.0.json +0 -2841
- package/dist/schemas/project-schema/v3.44.0.json +0 -3013
- package/dist/schemas/project-schema/v3.45.0.json +0 -3064
- package/dist/schemas/project-schema/v3.46.0.json +0 -3136
- package/dist/schemas/project-schema/v3.47.0.json +0 -3189
- package/dist/schemas/project-schema/v3.48.0.json +0 -3196
- package/dist/schemas/project-schema/v3.49.0.json +0 -3239
- package/dist/schemas/project-schema/v3.5.0.json +0 -571
- package/dist/schemas/project-schema/v3.5.1.json +0 -571
- package/dist/schemas/project-schema/v3.50.0.json +0 -3320
- package/dist/schemas/project-schema/v3.51.0.json +0 -3326
- package/dist/schemas/project-schema/v3.52.0.json +0 -3326
- package/dist/schemas/project-schema/v3.53.0.json +0 -3476
- package/dist/schemas/project-schema/v3.54.0.json +0 -3512
- package/dist/schemas/project-schema/v3.55.0.json +0 -3515
- package/dist/schemas/project-schema/v3.56.0.json +0 -3530
- package/dist/schemas/project-schema/v3.57.0.json +0 -4815
- package/dist/schemas/project-schema/v3.58.0.json +0 -4815
- package/dist/schemas/project-schema/v3.59.0.json +0 -4846
- package/dist/schemas/project-schema/v3.6.0.json +0 -587
- package/dist/schemas/project-schema/v3.7.0.json +0 -587
- package/dist/schemas/project-schema/v3.8.0.json +0 -604
- package/dist/schemas/project-schema/v3.9.0.json +0 -604
- package/dist/schemas/project-schema/v4.0.0.json +0 -2316
- package/dist/schemas/project-schema.json +0 -214
- package/dist/service-dependencies.d.ts +0 -13
- package/dist/service-dependencies.js +0 -165
- package/dist/services/services.d.ts +0 -31
- package/dist/services/services.js +0 -145
- package/dist/services/types.d.ts +0 -11
- package/dist/services/types.js +0 -1
- package/dist/services/util.d.ts +0 -16
- package/dist/services/util.js +0 -36
- package/dist/shape-paths.d.ts +0 -7
- package/dist/shape-paths.js +0 -28
- package/dist/taxonomies.d.ts +0 -15
- package/dist/taxonomies.js +0 -24
- package/dist/template-shapes/index.d.ts +0 -7
- package/dist/template-shapes/index.js +0 -33
- package/dist/template-shapes/names.d.ts +0 -10
- package/dist/template-shapes/names.js +0 -21
- package/dist/template-shapes/templates.d.ts +0 -32
- package/dist/template-shapes/templates.js +0 -316
- package/dist/template-shapes/types.d.ts +0 -15
- package/dist/template-shapes/types.js +0 -7
- package/dist/template-shapes/where.d.ts +0 -37
- package/dist/template-shapes/where.js +0 -400
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -2
- package/dist/types/transforms.d.ts +0 -15
- package/dist/types/transforms.js +0 -1
- package/dist/types/types.d.ts +0 -200
- package/dist/types/types.js +0 -10
- package/dist/types/utils.d.ts +0 -112
- package/dist/types/utils.js +0 -269
- package/dist/unions.d.ts +0 -14
- package/dist/unions.js +0 -77
- package/dist/util/ai-tools.d.ts +0 -2
- package/dist/util/ai-tools.js +0 -14
- package/dist/util/api-indexing.d.ts +0 -9
- package/dist/util/api-indexing.js +0 -57
- package/dist/util/coerce-value.d.ts +0 -9
- package/dist/util/coerce-value.js +0 -32
- package/dist/util/detect-cycles.d.ts +0 -7
- package/dist/util/detect-cycles.js +0 -45
- package/dist/util/expressions.d.ts +0 -34
- package/dist/util/expressions.js +0 -350
- package/dist/util/find-shape-at-path.d.ts +0 -21
- package/dist/util/find-shape-at-path.js +0 -53
- package/dist/util/form-config.d.ts +0 -11
- package/dist/util/form-config.js +0 -62
- package/dist/util/get-conflicting-properties.d.ts +0 -6
- package/dist/util/get-conflicting-properties.js +0 -55
- package/dist/util/get-return-shape.d.ts +0 -4
- package/dist/util/get-return-shape.js +0 -30
- package/dist/util/has-arg.d.ts +0 -6
- package/dist/util/has-arg.js +0 -25
- package/dist/util/is-asset-property.d.ts +0 -3
- package/dist/util/is-asset-property.js +0 -11
- package/dist/util/mcp.d.ts +0 -8
- package/dist/util/mcp.js +0 -21
- package/dist/util/merge.d.ts +0 -15
- package/dist/util/merge.js +0 -254
- package/dist/util/patch-schema.d.ts +0 -8
- package/dist/util/patch-schema.js +0 -51
- package/dist/util/query-field-path.d.ts +0 -9
- package/dist/util/query-field-path.js +0 -23
- package/dist/util/shapes.d.ts +0 -5
- package/dist/util/shapes.js +0 -22
- package/dist/validate/ai.d.ts +0 -6
- package/dist/validate/ai.js +0 -183
- package/dist/validate/errors.d.ts +0 -3
- package/dist/validate/errors.js +0 -20
- package/dist/validate/types.d.ts +0 -1
- package/dist/validate/types.js +0 -1
- package/dist/validate/util.d.ts +0 -3
- package/dist/validate/util.js +0 -28
- package/dist/validate/validate.d.ts +0 -80
- package/dist/validate/validate.js +0 -1058
- package/dist/versions.d.ts +0 -4
- package/dist/versions.js +0 -4
- package/dist/workflows.d.ts +0 -14
- package/dist/workflows.js +0 -66
|
@@ -1,1058 +0,0 @@
|
|
|
1
|
-
import { SchemaValidationError } from '@takeshape/errors';
|
|
2
|
-
import { createAjv } from '@takeshape/json-schema';
|
|
3
|
-
import { DEFAULT_ENTITLEMENTS, DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL, ensureArray, isIntegerLike, isRecord, value } from '@takeshape/util';
|
|
4
|
-
import { JSONPath } from 'jsonpath-plus';
|
|
5
|
-
import flatten from 'lodash/flatten.js';
|
|
6
|
-
import get from 'lodash/get.js';
|
|
7
|
-
import initial from 'lodash/initial.js';
|
|
8
|
-
import isEqual from 'lodash/isEqual.js';
|
|
9
|
-
import isUndefined from 'lodash/isUndefined.js';
|
|
10
|
-
import last from 'lodash/last.js';
|
|
11
|
-
import pick from 'lodash/pick.js';
|
|
12
|
-
import size from 'lodash/size.js';
|
|
13
|
-
import uniqBy from 'lodash/uniqBy.js';
|
|
14
|
-
import pMap from 'p-map';
|
|
15
|
-
import coerce from 'semver/functions/coerce.js';
|
|
16
|
-
import gte from 'semver/functions/gte.js';
|
|
17
|
-
import lt from 'semver/functions/lt.js';
|
|
18
|
-
import neq from 'semver/functions/neq.js';
|
|
19
|
-
import { GUARDS_SCHEMA_PATH, getGuards, isGuardEnabled } from "../agents.js";
|
|
20
|
-
import { getBuiltInShapes } from "../builtin-schema.js";
|
|
21
|
-
import { isEnumLikeSchema } from "../enum.js";
|
|
22
|
-
import { isLatestProjectSchemaJSON } from "../project-schema/index.js";
|
|
23
|
-
import { createGetNamespace, getRefShapeName, getToolRef, isValidServiceId, parsePropertyRef, parseRef, propertyRefItemToPath, propertyRefItemToResolverPath, refItemToNamespacedShapeName, refItemToShape, serializeRef } from "../refs.js";
|
|
24
|
-
import { getRelationship } from "../relationships.js";
|
|
25
|
-
import { scalars } from "../scalars.js";
|
|
26
|
-
import { getAllRefs } from "../schema-util.js";
|
|
27
|
-
import authSchemas from '../schemas/auth-schemas.json' with { type: 'json' };
|
|
28
|
-
import { allProjectSchemas } from "../schemas/index.js";
|
|
29
|
-
import { isValidTemplate } from "../template-shapes/index.js";
|
|
30
|
-
import { legacyProjectSchemaImportOptionalProps, projectSchemaImportOptionalProps } from "../types/types.js";
|
|
31
|
-
import { isAIResolver, isBasicResolver, isComposeResolver, isExtendsSchema, isObjectSchema } from "../types/utils.js";
|
|
32
|
-
import { isUnionSchema } from "../unions.js";
|
|
33
|
-
import { getMcpToolMap, TOOL_SCHEMA_PATH } from '../util/mcp.js';
|
|
34
|
-
import { findSchemaAtQueryFieldPath, getQueryFieldPath } from "../util/query-field-path.js";
|
|
35
|
-
import { getShape } from "../util/shapes.js";
|
|
36
|
-
import { CURRENT_SCHEMA_VERSION, LEGACY_API_VERSION, LEGACY_SCHEMA_VERSION } from "../versions.js";
|
|
37
|
-
import { defaultWorkflow } from "../workflows.js";
|
|
38
|
-
import { validateAgents, validateAIToolConfig } from "./ai.js";
|
|
39
|
-
import { formatError } from "./errors.js";
|
|
40
|
-
import { pushErrors } from './util.js';
|
|
41
|
-
function findDuplicates(items) {
|
|
42
|
-
const seen = {};
|
|
43
|
-
for (const item of items) {
|
|
44
|
-
if (seen[item.value]) {
|
|
45
|
-
seen[item.value].push(item.path);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
seen[item.value] = [item.path];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return Object.entries(seen)
|
|
52
|
-
.filter((entry) => entry[1].length > 1)
|
|
53
|
-
.flatMap((entry) => ({ value: entry[0], paths: entry[1] }));
|
|
54
|
-
}
|
|
55
|
-
function checkShapeIds(shapes) {
|
|
56
|
-
const items = Object.entries(shapes).map((entry) => ({
|
|
57
|
-
path: ['shapes', entry[0], 'id'],
|
|
58
|
-
value: entry[1].id
|
|
59
|
-
}));
|
|
60
|
-
return findDuplicates(items).flatMap((dupe) => dupe.paths.map((path) => ({
|
|
61
|
-
path,
|
|
62
|
-
type: 'conflict',
|
|
63
|
-
message: `Shapes must have unique ids. "${dupe.value}" is not unique.`
|
|
64
|
-
})));
|
|
65
|
-
}
|
|
66
|
-
function checkShapeNames(shapes) {
|
|
67
|
-
Object.entries(shapes).map((entry) => ({
|
|
68
|
-
path: ['shapes', entry[0], 'id'],
|
|
69
|
-
value: entry[1].id
|
|
70
|
-
}));
|
|
71
|
-
return Object.entries(shapes)
|
|
72
|
-
.filter(([name, shape]) => name !== shape.name)
|
|
73
|
-
.map(([name, shape]) => ({
|
|
74
|
-
path: ['shapes', name, 'name'],
|
|
75
|
-
type: 'conflict',
|
|
76
|
-
message: `Shape.name "${shape.name}" must match key "${name}".`
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
function checkToolNames(tools) {
|
|
80
|
-
return Object.entries(tools)
|
|
81
|
-
.filter(([name, tool]) => name !== tool.name)
|
|
82
|
-
.map(([name, tool]) => ({
|
|
83
|
-
path: [...TOOL_SCHEMA_PATH, name, 'name'],
|
|
84
|
-
type: 'conflict',
|
|
85
|
-
message: `Tool.name "${tool.name}" must match key "${name}".`
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
function checkWorkflowStepNames(workflows) {
|
|
89
|
-
return Object.entries(workflows).flatMap(([name, workflow]) => {
|
|
90
|
-
const items = workflow.steps.map((step, i) => ({
|
|
91
|
-
path: ['workflows', name, 'steps', i, 'name'],
|
|
92
|
-
value: step.name.toLowerCase()
|
|
93
|
-
}));
|
|
94
|
-
return findDuplicates(items).flatMap((dupe) => dupe.paths.map((path) => ({
|
|
95
|
-
path,
|
|
96
|
-
type: 'conflict',
|
|
97
|
-
message: `Workflow steps must have unique names. "${dupe.value}" is not unique in workflow "${workflow.name}."`
|
|
98
|
-
})));
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function checkWorkflowStepKeys(workflows) {
|
|
102
|
-
const items = Object.entries(workflows).flatMap(([name, workflow]) => workflow.steps.map((step, i) => ({
|
|
103
|
-
path: ['workflows', name, 'steps', i, 'key'],
|
|
104
|
-
value: step.key
|
|
105
|
-
})));
|
|
106
|
-
return findDuplicates(items).flatMap((dupe) => dupe.paths.map((path) => ({
|
|
107
|
-
path,
|
|
108
|
-
type: 'conflict',
|
|
109
|
-
message: `Workflow keys must be unique at the schema level. Key "${dupe.value}" is not unique.`
|
|
110
|
-
})));
|
|
111
|
-
}
|
|
112
|
-
function validateWorkflowVersion(projectSchema) {
|
|
113
|
-
const errors = [];
|
|
114
|
-
if (projectSchema.apiVersion === LEGACY_API_VERSION && Object.keys(projectSchema.workflows).length) {
|
|
115
|
-
errors.push({
|
|
116
|
-
path: ['workflows'],
|
|
117
|
-
type: 'invalidVersion',
|
|
118
|
-
message: `apiVersion ${projectSchema.apiVersion} does not support workflows`
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return errors;
|
|
122
|
-
}
|
|
123
|
-
function validateWorkflows(projectSchema) {
|
|
124
|
-
const errors = validateWorkflowVersion(projectSchema);
|
|
125
|
-
for (const name of Object.keys(projectSchema.shapes)) {
|
|
126
|
-
const shape = projectSchema.shapes[name];
|
|
127
|
-
if (shape.workflow && shape.workflow !== defaultWorkflow.name && !projectSchema.workflows[shape.workflow]) {
|
|
128
|
-
errors.push({
|
|
129
|
-
type: 'notFound',
|
|
130
|
-
path: ['shapes', name, 'workflow'],
|
|
131
|
-
message: `Invalid Workflow "${shape.workflow}" for shape "${shape.name}"`
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return errors;
|
|
136
|
-
}
|
|
137
|
-
function getSemver(schemaVersion) {
|
|
138
|
-
return coerce(schemaVersion) ?? LEGACY_SCHEMA_VERSION;
|
|
139
|
-
}
|
|
140
|
-
function enumerateBasicResolvers(resolver, path) {
|
|
141
|
-
const results = [];
|
|
142
|
-
const visit = (resolver, path) => {
|
|
143
|
-
if (isComposeResolver(resolver)) {
|
|
144
|
-
resolver.compose.forEach((resolver, i) => {
|
|
145
|
-
visit(resolver, [...path, 'compose', i]);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
results.push([resolver, path]);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
visit(resolver, path);
|
|
153
|
-
return results;
|
|
154
|
-
}
|
|
155
|
-
function validateResolver(context, projectSchema, basePath, baseResolver) {
|
|
156
|
-
const errors = [];
|
|
157
|
-
const isValidShapeName = (shapeName) => {
|
|
158
|
-
if (!shapeName) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
const shape = getShape(projectSchema, shapeName) ?? getShape({ shapes: context.builtInShapes }, shapeName);
|
|
162
|
-
if (shape?.model) {
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
return Boolean(shape?.cache?.enabled && shape.loaders);
|
|
166
|
-
};
|
|
167
|
-
const validateDeletgateResolver = (resolver, path) => {
|
|
168
|
-
const parsed = parsePropertyRef(resolver.to);
|
|
169
|
-
if (!parsed) {
|
|
170
|
-
return {
|
|
171
|
-
type: 'conflict',
|
|
172
|
-
path: path.concat('to'),
|
|
173
|
-
message: `Unable to parse property ref "${resolver.to}"`
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
if (parsed.layerId !== 'local') {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const targetResolver = get(projectSchema, propertyRefItemToResolverPath(getNamespace, parsed));
|
|
180
|
-
if (!isBasicResolver(targetResolver) && !isComposeResolver(targetResolver)) {
|
|
181
|
-
return {
|
|
182
|
-
type: 'notFound',
|
|
183
|
-
path: basePath.concat('to'),
|
|
184
|
-
message: `Missing resolver config at property ref "${resolver.to}"`
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const validateAITGuardrail = (guardrail, basePath) => {
|
|
189
|
-
if (guardrail.name === 'similarity') {
|
|
190
|
-
if (!isValidShapeName(guardrail.shape)) {
|
|
191
|
-
return {
|
|
192
|
-
type: 'notFound',
|
|
193
|
-
path: basePath.concat('shape'),
|
|
194
|
-
message: `Invalid shape "${guardrail.shape}" for ${guardrail.shape}, must use an indexed shape`
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
const validateAIGenerateTextResolver = (resolver, path) => {
|
|
200
|
-
if (resolver.tools) {
|
|
201
|
-
for (let i = 0, n = resolver.tools.length; i < n; i++) {
|
|
202
|
-
pushErrors(errors, validateAIToolConfig(projectSchema, getNamespace, resolver.tools[i], path.concat(['tools', i])));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (resolver.guardrails) {
|
|
206
|
-
for (let i = 0, n = resolver.guardrails.length; i < n; i++) {
|
|
207
|
-
pushErrors(errors, validateAITGuardrail(resolver.guardrails[i], path.concat(['guardrails', i])));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const { toolChoice } = resolver.options ?? {};
|
|
211
|
-
if (toolChoice === 'required') {
|
|
212
|
-
if (!resolver.tools?.length) {
|
|
213
|
-
errors.push({
|
|
214
|
-
type: 'notFound',
|
|
215
|
-
path: path.concat(['options', 'toolChoice']),
|
|
216
|
-
message: `Must have at least one tool configured to specify "required"`
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else if (toolChoice && toolChoice !== 'auto' && toolChoice !== 'none') {
|
|
221
|
-
const parsed = parsePropertyRef(toolChoice);
|
|
222
|
-
if (parsed) {
|
|
223
|
-
const matchingTool = resolver.tools?.find((tool) => isEqual(parsed, parsePropertyRef(getToolRef(tool))));
|
|
224
|
-
if (!matchingTool) {
|
|
225
|
-
errors.push({
|
|
226
|
-
type: 'notFound',
|
|
227
|
-
path: path.concat(['options', 'toolChoice']),
|
|
228
|
-
message: `Missing tool "${toolChoice}" must be specified in "tools" array`
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
errors.push({
|
|
234
|
-
type: 'conflict',
|
|
235
|
-
path: path.concat(['options', 'toolChoice']),
|
|
236
|
-
message: `Unable to parse property ref "${toolChoice}"`
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const validateChunkResolver = (resolver, path) => {
|
|
242
|
-
if (resolver.options.type === 'semantic') {
|
|
243
|
-
if (!projectSchema.services?.[resolver.options.serviceId]) {
|
|
244
|
-
errors.push({
|
|
245
|
-
type: 'notFound',
|
|
246
|
-
path: path.concat(['options', 'serviceId']),
|
|
247
|
-
message: `Invalid service "${resolver.options.serviceId}"`
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
const getNamespace = createGetNamespace(projectSchema);
|
|
253
|
-
for (const [resolver, path] of enumerateBasicResolvers(baseResolver, basePath)) {
|
|
254
|
-
if (isBasicResolver(resolver)) {
|
|
255
|
-
if ('service' in resolver &&
|
|
256
|
-
resolver.service !== 'shapedb' &&
|
|
257
|
-
resolver.service !== 'takeshape' &&
|
|
258
|
-
!projectSchema.services?.[resolver.service]) {
|
|
259
|
-
errors.push({
|
|
260
|
-
type: 'notFound',
|
|
261
|
-
path: path.concat(['service']),
|
|
262
|
-
message: `Invalid service "${resolver.service}"`
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
if (resolver.shapeName) {
|
|
266
|
-
const { shapeName } = resolver;
|
|
267
|
-
if (!isValidShapeName(shapeName)) {
|
|
268
|
-
errors.push({
|
|
269
|
-
type: 'notFound',
|
|
270
|
-
path: path.concat(['shapeName']),
|
|
271
|
-
message: `Invalid Model Shape "${shapeName ?? ''}"`
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (resolver.name === 'delegate') {
|
|
276
|
-
pushErrors(errors, validateDeletgateResolver(resolver, path));
|
|
277
|
-
}
|
|
278
|
-
else if (isAIResolver(resolver)) {
|
|
279
|
-
validateAIGenerateTextResolver(resolver, path);
|
|
280
|
-
}
|
|
281
|
-
else if (resolver.name === 'util:chunk') {
|
|
282
|
-
validateChunkResolver(resolver, path);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
errors.push({
|
|
287
|
-
type: 'notFound',
|
|
288
|
-
path,
|
|
289
|
-
message: 'Invalid resolver'
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return errors;
|
|
294
|
-
}
|
|
295
|
-
function validateLocalQueryConfig(context, projectSchema, query, operation, name) {
|
|
296
|
-
const location = operation === 'query' ? 'queries' : 'mutations';
|
|
297
|
-
return validateResolver(context, projectSchema, [location, name, 'resolver'], query.resolver);
|
|
298
|
-
}
|
|
299
|
-
const operationProps = [['query', 'queries'], ['mutation', 'mutations']];
|
|
300
|
-
function validateLocalQueryConfigs(context, projectSchema) {
|
|
301
|
-
const errors = [];
|
|
302
|
-
for (const [operation, prop] of operationProps) {
|
|
303
|
-
for (const name of Object.keys(projectSchema[prop])) {
|
|
304
|
-
errors.push(...validateLocalQueryConfig(context, projectSchema, projectSchema[prop][name], operation, name));
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return errors;
|
|
308
|
-
}
|
|
309
|
-
function allowDisconnected(context, status) {
|
|
310
|
-
return Boolean(context.allowDisconnectedLayers) && status !== 'notAvailable';
|
|
311
|
-
}
|
|
312
|
-
function isValidShapeReference(context, layerState, shapeName) {
|
|
313
|
-
if (layerState.status !== 'ok') {
|
|
314
|
-
return allowDisconnected(context, layerState.status);
|
|
315
|
-
}
|
|
316
|
-
return Boolean(layerState.schema.shapes[shapeName]);
|
|
317
|
-
}
|
|
318
|
-
async function validateResolverReferences(context, basePath, baseResolver) {
|
|
319
|
-
const errors = [];
|
|
320
|
-
const isInvalidPropertyRef = async (refStr) => {
|
|
321
|
-
const ref = parsePropertyRef(refStr);
|
|
322
|
-
// ref string format and local refs are validated in validateResolver()
|
|
323
|
-
if (!ref || ref.layerId === 'local') {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
const layerState = await context.resolveLayer(ref.layerId);
|
|
327
|
-
return layerState.status === 'ok'
|
|
328
|
-
? !get(layerState.schema, propertyRefItemToPath(value(''), ref))
|
|
329
|
-
: !allowDisconnected(context, layerState.status);
|
|
330
|
-
};
|
|
331
|
-
await pMap(enumerateBasicResolvers(baseResolver, basePath), async ([resolver, path]) => {
|
|
332
|
-
if (resolver.name === 'graphql:query' || resolver.name === 'graphql:mutation') {
|
|
333
|
-
const { service, fieldName } = resolver;
|
|
334
|
-
const operationProp = resolver.name === 'graphql:query' ? 'query' : 'mutation';
|
|
335
|
-
const { projectSchema: { services } } = context;
|
|
336
|
-
const layerState = await context.resolveLayer(service);
|
|
337
|
-
const { schema: layerSchema, status: layerStatus } = layerState;
|
|
338
|
-
const valid = layerStatus === 'ok'
|
|
339
|
-
? Boolean(findSchemaAtQueryFieldPath({ ...layerSchema, services }, getQueryFieldPath(operationProp, fieldName)))
|
|
340
|
-
: allowDisconnected(context, layerState.status);
|
|
341
|
-
if (!valid) {
|
|
342
|
-
errors.push({
|
|
343
|
-
type: 'notFound',
|
|
344
|
-
path: path.concat('fieldName'),
|
|
345
|
-
message: `Missing ${operationProp} "${resolver.fieldName}" in service layer "${service}"`
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
else if (resolver.name === 'delegate') {
|
|
350
|
-
if (await isInvalidPropertyRef(resolver.to)) {
|
|
351
|
-
errors.push({
|
|
352
|
-
type: 'notFound',
|
|
353
|
-
path: path.concat('to'),
|
|
354
|
-
message: `Missing resolver config at property ref "${resolver.to}"`
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
else if (isAIResolver(resolver)) {
|
|
359
|
-
if (resolver.tools) {
|
|
360
|
-
await pMap(resolver.tools, async (tool, i) => {
|
|
361
|
-
const toolRef = getToolRef(tool);
|
|
362
|
-
if (await isInvalidPropertyRef(toolRef)) {
|
|
363
|
-
errors.push({
|
|
364
|
-
type: 'notFound',
|
|
365
|
-
path: path.concat(typeof tool === 'string' ? ['tools', i] : ['tools', i, 'ref']),
|
|
366
|
-
message: `Invalid ref "${toolRef}"`
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
return errors;
|
|
374
|
-
}
|
|
375
|
-
async function validateQueryConfig(context, { query, name, operation }) {
|
|
376
|
-
const location = operation === 'query' ? 'queries' : 'mutations';
|
|
377
|
-
return validateResolverReferences(context, [location, name, 'resolver'], query.resolver);
|
|
378
|
-
}
|
|
379
|
-
async function validateQueryConfigs(context, projectSchema) {
|
|
380
|
-
const isLessThanV3_9_0 = lt(getSemver(projectSchema.schemaVersion), '3.9.0');
|
|
381
|
-
if (isLessThanV3_9_0) {
|
|
382
|
-
return [];
|
|
383
|
-
}
|
|
384
|
-
const promises = [];
|
|
385
|
-
for (const [operation, prop] of operationProps) {
|
|
386
|
-
for (const name of Object.keys(projectSchema[prop])) {
|
|
387
|
-
promises.push(validateQueryConfig(context, {
|
|
388
|
-
query: projectSchema[prop][name],
|
|
389
|
-
operation,
|
|
390
|
-
name
|
|
391
|
-
}));
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return flatten(await Promise.all(promises));
|
|
395
|
-
}
|
|
396
|
-
function listShapeJoins(projectSchema) {
|
|
397
|
-
const joins = [];
|
|
398
|
-
for (const shapeKey of Object.keys(projectSchema.shapes)) {
|
|
399
|
-
const shape = projectSchema.shapes[shapeKey];
|
|
400
|
-
if (shape.joins) {
|
|
401
|
-
for (const joinRef of Object.keys(shape.joins)) {
|
|
402
|
-
const join = shape.joins[joinRef];
|
|
403
|
-
joins.push({
|
|
404
|
-
ref: joinRef,
|
|
405
|
-
path: ['shapes', shapeKey, 'joins', joinRef],
|
|
406
|
-
join
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
return joins;
|
|
412
|
-
}
|
|
413
|
-
function validateLocalShapeJoinRef(projectSchema, item) {
|
|
414
|
-
const refItem = parseRef(projectSchema, item.ref);
|
|
415
|
-
if (refItem.layerId === 'local') {
|
|
416
|
-
const shape = refItemToShape(projectSchema, refItem);
|
|
417
|
-
if (!shape) {
|
|
418
|
-
return [
|
|
419
|
-
{
|
|
420
|
-
type: 'notFound',
|
|
421
|
-
path: item.path,
|
|
422
|
-
message: `Invalid join "${item.ref}" not found`
|
|
423
|
-
}
|
|
424
|
-
];
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return [];
|
|
428
|
-
}
|
|
429
|
-
function validateLocalShapeJoins(context, projectSchema) {
|
|
430
|
-
return listShapeJoins(projectSchema).flatMap((item) => validateLocalShapeJoinRef(projectSchema, item).concat(validateResolver(context, projectSchema, item.path.concat('resolver'), item.join.resolver)));
|
|
431
|
-
}
|
|
432
|
-
async function validateShapeJoinRef(context, projectSchema, item) {
|
|
433
|
-
const refItem = parseRef(projectSchema, item.ref);
|
|
434
|
-
if (refItem) {
|
|
435
|
-
const layer = await context.resolveLayer(refItem.layerId);
|
|
436
|
-
const valid = isValidRef(context, projectSchema, layer, refItem);
|
|
437
|
-
if (!valid) {
|
|
438
|
-
return [
|
|
439
|
-
{
|
|
440
|
-
type: 'notFound',
|
|
441
|
-
path: item.path,
|
|
442
|
-
message: `Invalid join "${item.ref}" not found`
|
|
443
|
-
}
|
|
444
|
-
];
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return [];
|
|
448
|
-
}
|
|
449
|
-
async function validateShapeJoins(context, projectSchema) {
|
|
450
|
-
const promises = [];
|
|
451
|
-
for (const item of listShapeJoins(projectSchema)) {
|
|
452
|
-
promises.push(validateShapeJoinRef(context, projectSchema, item), validateResolverReferences(context, item.path, item.join.resolver));
|
|
453
|
-
}
|
|
454
|
-
return flatten(await Promise.all(promises));
|
|
455
|
-
}
|
|
456
|
-
function validateShapeLoaders(context, projectSchema, shape) {
|
|
457
|
-
const errors = [];
|
|
458
|
-
if (shape.loaders) {
|
|
459
|
-
const getNamespace = createGetNamespace(projectSchema);
|
|
460
|
-
const listLoader = shape.loaders.list;
|
|
461
|
-
if (listLoader) {
|
|
462
|
-
ensureArray(listLoader).forEach((config, i) => {
|
|
463
|
-
const ref = parsePropertyRef(config.query);
|
|
464
|
-
const query = ref && get(projectSchema, propertyRefItemToPath(getNamespace, ref));
|
|
465
|
-
if (!query) {
|
|
466
|
-
errors.push({
|
|
467
|
-
path: Array.isArray(listLoader)
|
|
468
|
-
? ['shapes', shape.name, 'loaders', 'list', i, 'query']
|
|
469
|
-
: ['shapes', shape.name, 'loaders', 'list', 'query'],
|
|
470
|
-
type: 'notFound',
|
|
471
|
-
message: `Invalid query "${config.query}"`
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
const getLoader = shape.loaders.get;
|
|
477
|
-
if (getLoader) {
|
|
478
|
-
const ref = parsePropertyRef(getLoader.query);
|
|
479
|
-
const query = ref && get(projectSchema, propertyRefItemToPath(getNamespace, ref));
|
|
480
|
-
if (!query) {
|
|
481
|
-
errors.push({
|
|
482
|
-
path: ['shapes', shape.name, 'loaders', 'get', 'query'],
|
|
483
|
-
type: 'notFound',
|
|
484
|
-
message: `Invalid query "${getLoader.query}"`
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (shape.cache?.triggers && !context.ignoreEntitlements) {
|
|
490
|
-
const min = context.entitlements.minScheduleTriggerInterval ?? DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL;
|
|
491
|
-
for (let i = 0; i < shape.cache.triggers.length; i++) {
|
|
492
|
-
const trigger = shape.cache.triggers[i];
|
|
493
|
-
if (trigger.type === 'schedule' && trigger.interval < min) {
|
|
494
|
-
errors.push({
|
|
495
|
-
path: ['shapes', shape.name, 'cache', 'triggers', i, 'interval'],
|
|
496
|
-
type: 'entitlement',
|
|
497
|
-
message: `Trigger interval ${trigger.interval} is below minimum ${min}`
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return errors;
|
|
503
|
-
}
|
|
504
|
-
function visitProperties(projectSchema, callback) {
|
|
505
|
-
JSONPath('$..properties.*', projectSchema, (property, _type, { path: propertyPath }) => {
|
|
506
|
-
callback(property, propertyPath.slice(3, -2).split(`']['`));
|
|
507
|
-
}, undefined);
|
|
508
|
-
}
|
|
509
|
-
function validateIndexedShapes(context, projectSchema) {
|
|
510
|
-
const errors = [];
|
|
511
|
-
const { shapes } = projectSchema;
|
|
512
|
-
for (const shape of Object.values(shapes)) {
|
|
513
|
-
const newErrors = validateShapeLoaders(context, projectSchema, shape);
|
|
514
|
-
if (newErrors.length) {
|
|
515
|
-
errors.push(...newErrors);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
let nestedCount = 0;
|
|
519
|
-
visitProperties(projectSchema, (property, propertyPath) => {
|
|
520
|
-
const indexed = property['@indexed'];
|
|
521
|
-
if (isRecord(indexed) && indexed.nested) {
|
|
522
|
-
nestedCount += 1;
|
|
523
|
-
if (property.type !== 'array') {
|
|
524
|
-
errors.push({
|
|
525
|
-
path: propertyPath,
|
|
526
|
-
type: 'location',
|
|
527
|
-
message: 'Nested indexes may only appear next to fields of type: "array"'
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
if (nestedCount > 50) {
|
|
533
|
-
errors.push({
|
|
534
|
-
path: ['shapes'],
|
|
535
|
-
type: 'tooMany',
|
|
536
|
-
message: `${nestedCount} nested indexes found`
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
return errors;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Verify the path has an allOf schema and not just prop named "allOf"
|
|
543
|
-
*/
|
|
544
|
-
function isAllOfPath(path) {
|
|
545
|
-
const index = path.indexOf('allOf');
|
|
546
|
-
return index !== -1 && isIntegerLike(path[index + 1]);
|
|
547
|
-
}
|
|
548
|
-
function isLocalRef(refItem) {
|
|
549
|
-
return refItem.layerId === 'local';
|
|
550
|
-
}
|
|
551
|
-
function validateLocalRefs(context, projectSchema) {
|
|
552
|
-
const errors = [];
|
|
553
|
-
const shapeNames = new Set([...context.builtInShapeNames, ...Object.keys(projectSchema.shapes)]);
|
|
554
|
-
const refs = getAllRefs(projectSchema).filter(isLocalRef);
|
|
555
|
-
for (const item of refs) {
|
|
556
|
-
if (item.template && !isValidTemplate(item.template)) {
|
|
557
|
-
errors.push({
|
|
558
|
-
type: 'notFound',
|
|
559
|
-
path: item.path,
|
|
560
|
-
message: `Invalid template "${item.template}"`
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
const shapeName = refItemToNamespacedShapeName(projectSchema, item);
|
|
564
|
-
if (!shapeNames.has(shapeName)) {
|
|
565
|
-
const invalidRef = get(projectSchema, item.path);
|
|
566
|
-
const path = invalidRef.items ? [...item.path, 'items', '@ref'] : item.path;
|
|
567
|
-
const ref = get(projectSchema, path);
|
|
568
|
-
errors.push({
|
|
569
|
-
type: 'notFound',
|
|
570
|
-
path,
|
|
571
|
-
message: `Invalid ref "${ref}"`
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
// Make sure refs inside allOf don't refer to their own Shape
|
|
575
|
-
if (item.path[1] === shapeName && isAllOfPath(item.path)) {
|
|
576
|
-
errors.push({
|
|
577
|
-
type: 'conflict',
|
|
578
|
-
path: item.path,
|
|
579
|
-
message: 'allOf cannot be self-referential'
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
const parentPath = initial(item.path);
|
|
583
|
-
const parentSchema = get(projectSchema, parentPath);
|
|
584
|
-
const propName = last(item.path);
|
|
585
|
-
if (propName === '@ref' && parentSchema.$ref) {
|
|
586
|
-
errors.push({
|
|
587
|
-
type: 'conflict',
|
|
588
|
-
path: parentPath,
|
|
589
|
-
message: 'Ref cannot have both @ref and $ref'
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
return errors;
|
|
594
|
-
}
|
|
595
|
-
function isValidRef(context, projectSchema, layer, item) {
|
|
596
|
-
const { layerId } = item;
|
|
597
|
-
const shapeName = refItemToNamespacedShapeName(projectSchema, item);
|
|
598
|
-
const localShapeExists = Boolean(projectSchema.shapes[shapeName]) || context.builtInShapeNames.has(shapeName);
|
|
599
|
-
return (isValidServiceId(projectSchema, layerId) &&
|
|
600
|
-
(layerId === 'local' ? localShapeExists : localShapeExists || isValidShapeReference(context, layer, shapeName)));
|
|
601
|
-
}
|
|
602
|
-
function mustBeInterface({ path }) {
|
|
603
|
-
return path[0] === 'shapes' && path[2] === 'interfaces';
|
|
604
|
-
}
|
|
605
|
-
async function validateRefs(context, projectSchema) {
|
|
606
|
-
const { resolveLayer } = context;
|
|
607
|
-
const errors = [];
|
|
608
|
-
const refs = getAllRefs(projectSchema);
|
|
609
|
-
const layerIds = new Set();
|
|
610
|
-
for (const item of refs) {
|
|
611
|
-
if (item.layerId !== 'local') {
|
|
612
|
-
layerIds.add(item.layerId);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
const layersById = Object.fromEntries(await pMap(layerIds, async (layerId) => [layerId, await resolveLayer(layerId)]));
|
|
616
|
-
for (const item of refs) {
|
|
617
|
-
if (item.template && !isValidTemplate(item.template)) {
|
|
618
|
-
errors.push({
|
|
619
|
-
type: 'notFound',
|
|
620
|
-
path: item.path,
|
|
621
|
-
message: `Invalid template "${item.path}"`
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
const { layerId } = item;
|
|
625
|
-
const layer = layersById[layerId];
|
|
626
|
-
const valid = isValidRef(context, projectSchema, layer, item);
|
|
627
|
-
if (!valid) {
|
|
628
|
-
errors.push({
|
|
629
|
-
type: 'notFound',
|
|
630
|
-
path: item.path,
|
|
631
|
-
message: `Invalid ref "${get(projectSchema, item.path)}"`
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
else if (mustBeInterface(item) && (layerId === 'local' || layer?.status === 'ok')) {
|
|
635
|
-
// only validate interfaces with connected layers isValidRef above handles when allowDisconnectedLayers false
|
|
636
|
-
const context = layer?.schema ?? projectSchema;
|
|
637
|
-
const shape = get(context, item.path.slice(0, 2));
|
|
638
|
-
const layerWithServices = { ...context, services: projectSchema.services };
|
|
639
|
-
errors.push(...validateShapeImplementsInterface(layerWithServices, shape, item, item.path));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return errors;
|
|
643
|
-
}
|
|
644
|
-
function visitShapePropertiesJson(projectSchema, callback) {
|
|
645
|
-
JSONPath('shapes.*.schema.properties.*', projectSchema, (property, _type, { path: propertyPath }) => {
|
|
646
|
-
callback(property, propertyPath.slice(3, -2).split(`']['`));
|
|
647
|
-
}, undefined);
|
|
648
|
-
}
|
|
649
|
-
function validateDirectives(context, projectSchema) {
|
|
650
|
-
const errors = [];
|
|
651
|
-
visitShapePropertiesJson(projectSchema, (property, propertyPath) => {
|
|
652
|
-
const resolver = property['@resolver'];
|
|
653
|
-
if (resolver) {
|
|
654
|
-
const propPath = propertyPath.concat('@resolver');
|
|
655
|
-
const resolverErrors = validateResolver(context, projectSchema, propPath, resolver);
|
|
656
|
-
if (resolverErrors) {
|
|
657
|
-
errors.push(...resolverErrors);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
return errors;
|
|
662
|
-
}
|
|
663
|
-
function validateOneOfs(projectSchema) {
|
|
664
|
-
const errors = [];
|
|
665
|
-
visitShapePropertiesJson(projectSchema, (property, propertyPath) => {
|
|
666
|
-
const oneOfPath = property.items ? ['items', 'oneOf'] : ['oneOf'];
|
|
667
|
-
const relationship = getRelationship(property);
|
|
668
|
-
const schema = (property.items ? property.items : property);
|
|
669
|
-
const isUnion = isUnionSchema(schema);
|
|
670
|
-
if (schema.oneOf && !relationship && !isUnion && !isEnumLikeSchema(schema)) {
|
|
671
|
-
errors.push({
|
|
672
|
-
type: 'conflict',
|
|
673
|
-
path: propertyPath.concat(oneOfPath),
|
|
674
|
-
message: 'Invalid oneOf must contain only @ref or title + enum/const schemas'
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
if (isUnion &&
|
|
678
|
-
schema.oneOf.length !== uniqBy(schema.oneOf, (refSchema) => getRefShapeName(projectSchema, refSchema)).length) {
|
|
679
|
-
errors.push({
|
|
680
|
-
type: 'conflict',
|
|
681
|
-
path: propertyPath.concat(oneOfPath),
|
|
682
|
-
message: 'Invalid oneOf must not contain duplicate references'
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
return errors;
|
|
687
|
-
}
|
|
688
|
-
function validateLocales(projectSchema) {
|
|
689
|
-
const { locales, defaultLocale } = projectSchema;
|
|
690
|
-
const errors = [];
|
|
691
|
-
if (locales && !locales.includes(defaultLocale)) {
|
|
692
|
-
errors.push({
|
|
693
|
-
type: 'notFound',
|
|
694
|
-
path: ['locales'],
|
|
695
|
-
message: `Default locale "${defaultLocale}" missing from locales`
|
|
696
|
-
});
|
|
697
|
-
}
|
|
698
|
-
return errors;
|
|
699
|
-
}
|
|
700
|
-
const importantFields = ['type', '@ref', 'allOf', 'oneOf', 'anyOf', 'extends', 'items', '@tag'];
|
|
701
|
-
function isSchemaEqual(a, b) {
|
|
702
|
-
return isEqual(pick(a, importantFields), pick(b, importantFields));
|
|
703
|
-
}
|
|
704
|
-
function matchesInterface(shape, interfaceShape, path) {
|
|
705
|
-
const errors = [];
|
|
706
|
-
const { schema } = shape;
|
|
707
|
-
const interfaceSchema = interfaceShape.schema;
|
|
708
|
-
for (const name of Object.keys(interfaceSchema.properties)) {
|
|
709
|
-
const propSchema = schema.properties[name];
|
|
710
|
-
const interfacePropSchema = interfaceSchema.properties[name];
|
|
711
|
-
if (!propSchema) {
|
|
712
|
-
errors.push({
|
|
713
|
-
type: 'notFound',
|
|
714
|
-
path,
|
|
715
|
-
message: `"${shape.name}" is missing property "${name}" required by interface "${interfaceShape.name}"`
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
else if (!isSchemaEqual(propSchema, interfacePropSchema)) {
|
|
719
|
-
errors.push({
|
|
720
|
-
type: 'conflict',
|
|
721
|
-
path: [...path, name],
|
|
722
|
-
message: `"${shape.name}.${name}" must match "${interfaceShape.name}.${name}"`
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
const propRequired = Boolean(schema.required?.includes(name));
|
|
727
|
-
const interfacePropRequired = Boolean(interfaceSchema.required?.includes(name));
|
|
728
|
-
if (interfacePropRequired !== propRequired) {
|
|
729
|
-
errors.push({
|
|
730
|
-
type: 'conflict',
|
|
731
|
-
path: [...path, name],
|
|
732
|
-
message: `"${shape.name}.${name}" must ${interfacePropRequired ? '' : 'not '}be required to match "${interfaceShape.name}.${name}"`
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
return errors;
|
|
738
|
-
}
|
|
739
|
-
function validateShapeImplementsInterface(projectSchema, shape, interfaceRefItem, path) {
|
|
740
|
-
const errors = [];
|
|
741
|
-
const interfaceShape = refItemToShape(projectSchema, interfaceRefItem);
|
|
742
|
-
if (!interfaceShape) {
|
|
743
|
-
errors.push({
|
|
744
|
-
type: 'notFound',
|
|
745
|
-
path,
|
|
746
|
-
message: `Invalid interface "${serializeRef(interfaceRefItem)}" not found`
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
else if (interfaceShape.type !== 'interface') {
|
|
750
|
-
errors.push({
|
|
751
|
-
type: 'conflict',
|
|
752
|
-
path,
|
|
753
|
-
message: `"${shape.name}" cannot implement non-interface "${interfaceShape.name}"`
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
else if (isExtendsSchema(shape.schema)) {
|
|
757
|
-
// TODO stricter extends validation needs https://app.shortcut.com/takeshape/story/9783/use-service-schemas-during-schema-validation
|
|
758
|
-
}
|
|
759
|
-
else if (isObjectSchema(shape.schema) && isObjectSchema(interfaceShape.schema)) {
|
|
760
|
-
const matchErrors = matchesInterface(shape, interfaceShape, [
|
|
761
|
-
'shapes',
|
|
762
|
-
shape.name,
|
|
763
|
-
'schema',
|
|
764
|
-
'properties'
|
|
765
|
-
]);
|
|
766
|
-
if (matchErrors.length) {
|
|
767
|
-
errors.push(...matchErrors);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
return errors;
|
|
771
|
-
}
|
|
772
|
-
function validateInterfaceImplementations(projectSchema) {
|
|
773
|
-
const errors = [];
|
|
774
|
-
for (const shape of Object.values(projectSchema.shapes)) {
|
|
775
|
-
if (shape.interfaces?.length) {
|
|
776
|
-
if (!isObjectSchema(shape.schema) && !isExtendsSchema(shape.schema)) {
|
|
777
|
-
return [
|
|
778
|
-
{
|
|
779
|
-
path: ['shapes', shape.name, 'schema'],
|
|
780
|
-
type: 'conflict',
|
|
781
|
-
message: `"${shape.name}" must have an object or extends schema to implement interfaces`
|
|
782
|
-
}
|
|
783
|
-
];
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
return errors;
|
|
788
|
-
}
|
|
789
|
-
function validateInterfaces(projectSchema) {
|
|
790
|
-
const errors = [];
|
|
791
|
-
// Validate interface shapes must be an object schema with at least one property
|
|
792
|
-
for (const shape of Object.values(projectSchema.shapes)) {
|
|
793
|
-
if (shape.type === 'interface') {
|
|
794
|
-
if (shape.model) {
|
|
795
|
-
errors.push({
|
|
796
|
-
path: ['shapes', shape.name, 'model'],
|
|
797
|
-
type: 'conflict',
|
|
798
|
-
message: `"${shape.name}" may not be both an interface and model. Create a separate model shape which implements this interface.`
|
|
799
|
-
});
|
|
800
|
-
}
|
|
801
|
-
else if (isObjectSchema(shape.schema)) {
|
|
802
|
-
if (size(shape.schema.properties) === 0) {
|
|
803
|
-
errors.push({
|
|
804
|
-
path: ['shapes', shape.name, 'schema', 'properties'],
|
|
805
|
-
type: 'conflict',
|
|
806
|
-
message: `Interface "${shape.name}" must define at least one property`
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
errors.push({
|
|
812
|
-
path: ['shapes', shape.name, 'schema'],
|
|
813
|
-
type: 'conflict',
|
|
814
|
-
message: `Interface "${shape.name}" must define an object schema`
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return errors;
|
|
820
|
-
}
|
|
821
|
-
function isValidateReferencesContext(context) {
|
|
822
|
-
return Boolean(context.resolveLayer);
|
|
823
|
-
}
|
|
824
|
-
const ajv = createAjv();
|
|
825
|
-
function validateStructure(schemaVersion, context, schema, ref) {
|
|
826
|
-
const coerced = coerce(schemaVersion);
|
|
827
|
-
const versionStr = coerced?.format();
|
|
828
|
-
const hasExperimental = Boolean(coerced && gte(coerced, '3.48.0') && lt(coerced, '3.57.0'));
|
|
829
|
-
const relevantSchemas = allProjectSchemas.filter((metaSchema) => (hasExperimental && metaSchema.$id.endsWith('experimental-2025-07#')) ||
|
|
830
|
-
metaSchema.$id.endsWith(`v${versionStr}#`));
|
|
831
|
-
for (const relevantSchema of relevantSchemas) {
|
|
832
|
-
if (!ajv.getSchema(relevantSchema.$id)) {
|
|
833
|
-
ajv.addSchema(relevantSchema);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
ajv.validate(`https://schema.takeshape.io/project-schema/v${versionStr}#${ref ?? ''}`, schema);
|
|
837
|
-
let errors = ajv.errors?.map(formatError) ?? [];
|
|
838
|
-
const { suppressErrors } = context;
|
|
839
|
-
if (errors.length && suppressErrors) {
|
|
840
|
-
errors = errors.filter((error) => !suppressErrors(error));
|
|
841
|
-
}
|
|
842
|
-
if (errors.length) {
|
|
843
|
-
return {
|
|
844
|
-
valid: false,
|
|
845
|
-
schema: undefined,
|
|
846
|
-
errors
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
return {
|
|
850
|
-
valid: true,
|
|
851
|
-
schema: schema,
|
|
852
|
-
errors: undefined
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
function validateGuards(context, schema) {
|
|
856
|
-
const errors = [];
|
|
857
|
-
if (context.ignoreEntitlements) {
|
|
858
|
-
return errors;
|
|
859
|
-
}
|
|
860
|
-
const numGuards = getGuards(schema).filter(isGuardEnabled).length;
|
|
861
|
-
const entitledGuards = context.entitlements.guards ?? 0;
|
|
862
|
-
if (numGuards > entitledGuards) {
|
|
863
|
-
errors.push({
|
|
864
|
-
type: 'entitlement',
|
|
865
|
-
message: `Number of enabled guards exceeds your entitled limit of ${entitledGuards}`,
|
|
866
|
-
path: [...GUARDS_SCHEMA_PATH]
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
return errors;
|
|
870
|
-
}
|
|
871
|
-
function formatValidationResult(context, errors, schema) {
|
|
872
|
-
const { suppressErrors } = context;
|
|
873
|
-
if (suppressErrors) {
|
|
874
|
-
errors = errors.filter((error) => !suppressErrors(error));
|
|
875
|
-
}
|
|
876
|
-
return errors.length ? { valid: false, schema: undefined, errors } : { valid: true, schema, errors: undefined };
|
|
877
|
-
}
|
|
878
|
-
function validateSyntax(context, schema) {
|
|
879
|
-
let errors = [];
|
|
880
|
-
errors = errors
|
|
881
|
-
.concat(checkShapeNames(schema.shapes))
|
|
882
|
-
.concat(checkShapeIds(schema.shapes))
|
|
883
|
-
.concat(validateWorkflows(schema))
|
|
884
|
-
.concat(validateLocalQueryConfigs(context, schema))
|
|
885
|
-
.concat(validateLocalRefs(context, schema))
|
|
886
|
-
.concat(validateLocalShapeJoins(context, schema))
|
|
887
|
-
.concat(validateDirectives(context, schema))
|
|
888
|
-
.concat(validateLocales(schema))
|
|
889
|
-
.concat(checkWorkflowStepNames(schema.workflows))
|
|
890
|
-
.concat(checkWorkflowStepKeys(schema.workflows))
|
|
891
|
-
.concat(validateOneOfs(schema))
|
|
892
|
-
.concat(validateIndexedShapes(context, schema))
|
|
893
|
-
.concat(validateInterfaces(schema))
|
|
894
|
-
.concat(validateInterfaceImplementations(schema))
|
|
895
|
-
.concat(validateAgents(schema))
|
|
896
|
-
.concat(validateGuards(context, schema));
|
|
897
|
-
const mcpTools = getMcpToolMap(schema);
|
|
898
|
-
if (mcpTools) {
|
|
899
|
-
errors = errors.concat(checkToolNames(mcpTools ?? {}));
|
|
900
|
-
}
|
|
901
|
-
return formatValidationResult(context, errors, schema);
|
|
902
|
-
}
|
|
903
|
-
async function validateReferences(context, schema) {
|
|
904
|
-
const errors = flatten(await Promise.all([
|
|
905
|
-
validateRefs(context, schema),
|
|
906
|
-
validateQueryConfigs(context, schema),
|
|
907
|
-
validateShapeJoins(context, schema)
|
|
908
|
-
]));
|
|
909
|
-
return formatValidationResult(context, errors, schema);
|
|
910
|
-
}
|
|
911
|
-
const schemaUndefinedResult = {
|
|
912
|
-
valid: false,
|
|
913
|
-
schema: undefined,
|
|
914
|
-
errors: [{ path: [], type: 'undefined', message: 'Schema is undefined' }]
|
|
915
|
-
};
|
|
916
|
-
const invalidVersionResult = {
|
|
917
|
-
valid: false,
|
|
918
|
-
schema: undefined,
|
|
919
|
-
errors: [{ path: [], type: 'invalidVersion', message: 'Unknown schema version' }]
|
|
920
|
-
};
|
|
921
|
-
function normalizeSchemaVersion(obj) {
|
|
922
|
-
if (isRecord(obj)) {
|
|
923
|
-
return typeof obj.schemaVersion === 'string' ? obj.schemaVersion : '1';
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
export function validateSchemaSyntax(obj, options = {}) {
|
|
927
|
-
if (isUndefined(obj)) {
|
|
928
|
-
return schemaUndefinedResult;
|
|
929
|
-
}
|
|
930
|
-
const schemaVersion = normalizeSchemaVersion(obj);
|
|
931
|
-
if (!schemaVersion) {
|
|
932
|
-
return invalidVersionResult;
|
|
933
|
-
}
|
|
934
|
-
return validateStructure(schemaVersion, options, obj);
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* Validates a schema using a matching validation based on the `schemaVersion` property.
|
|
938
|
-
*/
|
|
939
|
-
export async function validateSchema(options, obj) {
|
|
940
|
-
if (isUndefined(obj)) {
|
|
941
|
-
return schemaUndefinedResult;
|
|
942
|
-
}
|
|
943
|
-
const builtInShapes = getBuiltInShapes({ entitlements: options.entitlements ?? DEFAULT_ENTITLEMENTS });
|
|
944
|
-
const builtInShapeNames = new Set([...Object.keys(builtInShapes), ...scalars, 'object']);
|
|
945
|
-
const context = {
|
|
946
|
-
allowDisconnectedLayers: true,
|
|
947
|
-
builtInShapes,
|
|
948
|
-
builtInShapeNames,
|
|
949
|
-
...options
|
|
950
|
-
};
|
|
951
|
-
const schemaVersion = normalizeSchemaVersion(obj);
|
|
952
|
-
if (!schemaVersion) {
|
|
953
|
-
return invalidVersionResult;
|
|
954
|
-
}
|
|
955
|
-
const structuralValidation = validateStructure(schemaVersion, context, obj);
|
|
956
|
-
if (!structuralValidation.valid || context.structureOnly) {
|
|
957
|
-
return structuralValidation;
|
|
958
|
-
}
|
|
959
|
-
const { schema } = structuralValidation;
|
|
960
|
-
if (!isLatestProjectSchemaJSON(schema)) {
|
|
961
|
-
return invalidVersionResult;
|
|
962
|
-
}
|
|
963
|
-
const syntaxValidation = validateSyntax(context, schema);
|
|
964
|
-
const validateReferencesContext = {
|
|
965
|
-
...context,
|
|
966
|
-
projectSchema: schema
|
|
967
|
-
};
|
|
968
|
-
if (!syntaxValidation.valid || !isValidateReferencesContext(validateReferencesContext)) {
|
|
969
|
-
return syntaxValidation;
|
|
970
|
-
}
|
|
971
|
-
return validateReferences(validateReferencesContext, schema);
|
|
972
|
-
}
|
|
973
|
-
export function ensureValidLatestSchemaSyntax(obj) {
|
|
974
|
-
const { valid, schema, errors } = validateSchemaSyntax(obj);
|
|
975
|
-
if (!valid && errors) {
|
|
976
|
-
throw new Error(`Invalid Schema "${errors[0].path.join(',')}": "${errors[0].message}"`);
|
|
977
|
-
}
|
|
978
|
-
if (isUndefined(schema)) {
|
|
979
|
-
throw new Error('Invalid schema: schema is undefined');
|
|
980
|
-
}
|
|
981
|
-
if (neq(CURRENT_SCHEMA_VERSION, coerce(schema.schemaVersion) ?? LEGACY_SCHEMA_VERSION)) {
|
|
982
|
-
throw new Error(`Expected schemaVersion: "${CURRENT_SCHEMA_VERSION}", got "${schema.schemaVersion}"`);
|
|
983
|
-
}
|
|
984
|
-
return schema;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* The roles import validator ensures required properties, and strips several
|
|
988
|
-
* which might exist in an export but wouldn't apply to an import operation.
|
|
989
|
-
*/
|
|
990
|
-
function createRoleInputValidator() {
|
|
991
|
-
const validator = createAjv({ useDefaults: true, removeAdditional: true });
|
|
992
|
-
const { RoleInput, ...definitions } = authSchemas.definitions;
|
|
993
|
-
return validator.compile({
|
|
994
|
-
$id: 'RoleInput',
|
|
995
|
-
definitions,
|
|
996
|
-
...RoleInput
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
* Validates and returns a `RoleInput`, which is a subset of the `Role`
|
|
1001
|
-
* type's properties suitable for importing.
|
|
1002
|
-
*/
|
|
1003
|
-
export function validateRoleInput(maybeRoleInput) {
|
|
1004
|
-
const validate = createRoleInputValidator();
|
|
1005
|
-
if (validate(maybeRoleInput)) {
|
|
1006
|
-
return maybeRoleInput;
|
|
1007
|
-
}
|
|
1008
|
-
throw new SchemaValidationError('RoleInput was invalid', validate.errors?.map(formatError));
|
|
1009
|
-
}
|
|
1010
|
-
/**
|
|
1011
|
-
* The roles import validator ensures required properties, and strips several
|
|
1012
|
-
* which might exist in an export but wouldn't apply to an import operation.
|
|
1013
|
-
*/
|
|
1014
|
-
function createRoleImportValidator() {
|
|
1015
|
-
const validator = createAjv({ useDefaults: true, removeAdditional: true });
|
|
1016
|
-
const { RoleImport, ...definitions } = authSchemas.definitions;
|
|
1017
|
-
return validator.compile({
|
|
1018
|
-
$id: 'RoleImport',
|
|
1019
|
-
definitions,
|
|
1020
|
-
...RoleImport
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Validates and returns a `RoleImport` array, which is a collection of `RoleInput`s.
|
|
1025
|
-
*/
|
|
1026
|
-
export function ensureValidRoleImport(maybeRoles) {
|
|
1027
|
-
const validate = createRoleImportValidator();
|
|
1028
|
-
if (validate(maybeRoles)) {
|
|
1029
|
-
return maybeRoles;
|
|
1030
|
-
}
|
|
1031
|
-
throw new SchemaValidationError('Roles were invalid', validate.errors?.map(formatError));
|
|
1032
|
-
}
|
|
1033
|
-
export function suppressPaths(paths) {
|
|
1034
|
-
return (error) => {
|
|
1035
|
-
return paths.includes(error.path.join('.'));
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
/**
|
|
1039
|
-
* Only use when validating an imported schema! ignore fields optional when importing
|
|
1040
|
-
*/
|
|
1041
|
-
export function validateProjectSchemaImport(maybeSchema) {
|
|
1042
|
-
return validateSchemaSyntax(maybeSchema, {
|
|
1043
|
-
suppressErrors: suppressPaths([...projectSchemaImportOptionalProps, ...legacyProjectSchemaImportOptionalProps])
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* Only use when validating an imported schema!
|
|
1048
|
-
*
|
|
1049
|
-
* New style validation for parity with the `validateRoleImport` fn. Returns
|
|
1050
|
-
* a valid, clean `ImportProjectSchema` or throws a `SchemaValidationError`.
|
|
1051
|
-
*/
|
|
1052
|
-
export function ensureValidProjectSchemaImport(maybeSchema) {
|
|
1053
|
-
const validateResult = validateProjectSchemaImport(maybeSchema);
|
|
1054
|
-
if (validateResult.valid) {
|
|
1055
|
-
return validateResult.schema;
|
|
1056
|
-
}
|
|
1057
|
-
throw new SchemaValidationError('ProjectSchema could not be validated', validateResult.errors);
|
|
1058
|
-
}
|