@takeshape/schema 11.132.2 → 11.133.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.
@@ -1,8 +1,18 @@
1
+ import type { Entitlements } from '@takeshape/util';
1
2
  import type { FormMap, ShapeJSON, ShapeMap } from './project-schema/index.ts';
2
3
  import type { Content } from './types/index.ts';
4
+ export type SchemaDefaultsOptions = {
5
+ entitlements: Pick<Entitlements, 'staticSites'>;
6
+ };
3
7
  export declare function isAsset(content: Content): boolean;
4
8
  export declare function getAssetS3Path(content: Content): string | undefined;
5
9
  export declare function setAssetS3Path(content: Content, path: string): void;
6
10
  export declare const jsonShape: ShapeJSON;
7
- export declare const builtInShapes: ShapeMap;
8
- export declare const builtInForms: FormMap;
11
+ export declare function getBuiltInShapes(options: SchemaDefaultsOptions): ShapeMap;
12
+ export declare function getBuiltInForms(options: SchemaDefaultsOptions): FormMap;
13
+ export declare const allBuiltInShapes: {
14
+ [x: string]: ShapeJSON;
15
+ };
16
+ export declare const allBuiltInForms: {
17
+ [x: string]: import("./project-schema/latest.ts").FormsConfig;
18
+ };
@@ -29,7 +29,7 @@ export const jsonShape = {
29
29
  title: JSON_SHAPE_NAME,
30
30
  schema: {}
31
31
  };
32
- export const builtInShapes = {
32
+ const builtInShapes = {
33
33
  [JSON_SHAPE_NAME]: jsonShape,
34
34
  TSRelationship: {
35
35
  id: 'TSRelationship',
@@ -169,6 +169,93 @@ export const builtInShapes = {
169
169
  title: 'Asset Image Meta',
170
170
  schema: assetImageMeta.schema
171
171
  },
172
+ TSReference: {
173
+ id: 'TSReference',
174
+ name: 'TSReference',
175
+ title: 'TakeShape Reference',
176
+ schema: {
177
+ type: 'object',
178
+ properties: {
179
+ _tid: {
180
+ type: 'string'
181
+ },
182
+ data: {
183
+ '@ref': 'TSSearchable',
184
+ '@resolver': {
185
+ name: 'takeshape:get',
186
+ service: 'takeshape',
187
+ args: {
188
+ ops: [{ path: 'tid', mapping: '$source._tid' }]
189
+ }
190
+ }
191
+ }
192
+ },
193
+ required: ['_tid']
194
+ }
195
+ },
196
+ TSEmbeddingSearchArgs: {
197
+ id: 'TSEmbeddingSearchArgs',
198
+ name: 'TSEmbeddingSearchArgs',
199
+ title: 'Embedding Search Args',
200
+ schema: embeddingSearchArgs.schema
201
+ },
202
+ [agentRunMode.shapeName]: {
203
+ title: 'Agent Run Mode',
204
+ id: agentRunMode.shapeName,
205
+ name: agentRunMode.shapeName,
206
+ schema: agentRunMode.schema
207
+ },
208
+ [agentGenerateArgs.shapeName]: {
209
+ title: 'Generate Args',
210
+ id: agentGenerateArgs.shapeName,
211
+ name: agentGenerateArgs.shapeName,
212
+ schema: agentGenerateArgs.schema
213
+ },
214
+ [agentChatArgs.shapeName]: {
215
+ title: 'Chat Args',
216
+ id: agentChatArgs.shapeName,
217
+ name: agentChatArgs.shapeName,
218
+ schema: agentChatArgs.schema
219
+ },
220
+ // Preserved for backward compatibility
221
+ [agentChatResponse.shapeName]: {
222
+ title: 'Chat Agent Response',
223
+ id: agentChatResponse.shapeName,
224
+ name: agentChatResponse.shapeName,
225
+ schema: agentChatResponse.schema
226
+ },
227
+ [agentChatPayload.shapeName]: {
228
+ title: 'Chat Agent Payload',
229
+ id: agentChatPayload.shapeName,
230
+ name: agentChatPayload.shapeName,
231
+ schema: agentChatPayload.schema
232
+ },
233
+ [inspectAgentResponse.shapeName]: {
234
+ title: 'Inspect Agent Response',
235
+ id: inspectAgentResponse.shapeName,
236
+ name: inspectAgentResponse.shapeName,
237
+ schema: inspectAgentResponse.schema
238
+ },
239
+ [createAgentSessionResponse.shapeName]: {
240
+ title: 'Create Agent Session Response',
241
+ id: createAgentSessionResponse.shapeName,
242
+ name: createAgentSessionResponse.shapeName,
243
+ schema: createAgentSessionResponse.schema
244
+ },
245
+ [abortAgentMessageResponse.shapeName]: {
246
+ title: 'Abort Agent Message Response',
247
+ id: abortAgentMessageResponse.shapeName,
248
+ name: abortAgentMessageResponse.shapeName,
249
+ schema: abortAgentMessageResponse.schema
250
+ },
251
+ [sendAgentFeedbackArgs.shapeName]: {
252
+ title: 'Send Agent Feedback Args',
253
+ id: sendAgentFeedbackArgs.shapeName,
254
+ name: sendAgentFeedbackArgs.shapeName,
255
+ schema: sendAgentFeedbackArgs.schema
256
+ }
257
+ };
258
+ const staticSiteShapes = {
172
259
  TSStaticSite: {
173
260
  id: 'SITE',
174
261
  name: 'TSStaticSite',
@@ -318,94 +405,9 @@ export const builtInShapes = {
318
405
  }
319
406
  }
320
407
  }
321
- },
322
- TSReference: {
323
- id: 'TSReference',
324
- name: 'TSReference',
325
- title: 'TakeShape Reference',
326
- schema: {
327
- type: 'object',
328
- properties: {
329
- _tid: {
330
- type: 'string'
331
- },
332
- data: {
333
- '@ref': 'TSSearchable',
334
- '@resolver': {
335
- name: 'takeshape:get',
336
- service: 'takeshape',
337
- args: {
338
- ops: [{ path: 'tid', mapping: '$source._tid' }]
339
- }
340
- }
341
- }
342
- },
343
- required: ['_tid']
344
- }
345
- },
346
- TSEmbeddingSearchArgs: {
347
- id: 'TSEmbeddingSearchArgs',
348
- name: 'TSEmbeddingSearchArgs',
349
- title: 'Embedding Search Args',
350
- schema: embeddingSearchArgs.schema
351
- },
352
- [agentRunMode.shapeName]: {
353
- title: 'Agent Run Mode',
354
- id: agentRunMode.shapeName,
355
- name: agentRunMode.shapeName,
356
- schema: agentRunMode.schema
357
- },
358
- [agentGenerateArgs.shapeName]: {
359
- title: 'Generate Args',
360
- id: agentGenerateArgs.shapeName,
361
- name: agentGenerateArgs.shapeName,
362
- schema: agentGenerateArgs.schema
363
- },
364
- [agentChatArgs.shapeName]: {
365
- title: 'Chat Args',
366
- id: agentChatArgs.shapeName,
367
- name: agentChatArgs.shapeName,
368
- schema: agentChatArgs.schema
369
- },
370
- // Preserved for backward compatibility
371
- [agentChatResponse.shapeName]: {
372
- title: 'Chat Agent Response',
373
- id: agentChatResponse.shapeName,
374
- name: agentChatResponse.shapeName,
375
- schema: agentChatResponse.schema
376
- },
377
- [agentChatPayload.shapeName]: {
378
- title: 'Chat Agent Payload',
379
- id: agentChatPayload.shapeName,
380
- name: agentChatPayload.shapeName,
381
- schema: agentChatPayload.schema
382
- },
383
- [inspectAgentResponse.shapeName]: {
384
- title: 'Inspect Agent Response',
385
- id: inspectAgentResponse.shapeName,
386
- name: inspectAgentResponse.shapeName,
387
- schema: inspectAgentResponse.schema
388
- },
389
- [createAgentSessionResponse.shapeName]: {
390
- title: 'Create Agent Session Response',
391
- id: createAgentSessionResponse.shapeName,
392
- name: createAgentSessionResponse.shapeName,
393
- schema: createAgentSessionResponse.schema
394
- },
395
- [abortAgentMessageResponse.shapeName]: {
396
- title: 'Abort Agent Message Response',
397
- id: abortAgentMessageResponse.shapeName,
398
- name: abortAgentMessageResponse.shapeName,
399
- schema: abortAgentMessageResponse.schema
400
- },
401
- [sendAgentFeedbackArgs.shapeName]: {
402
- title: 'Send Agent Feedback Args',
403
- id: sendAgentFeedbackArgs.shapeName,
404
- name: sendAgentFeedbackArgs.shapeName,
405
- schema: sendAgentFeedbackArgs.schema
406
408
  }
407
409
  };
408
- export const builtInForms = {
410
+ const builtInForms = {
409
411
  Asset: {
410
412
  default: {
411
413
  order: ['title', 'description', 'caption', 'credit', 'filename', 'path', 'mimeType', 'sourceUrl', 'uploadStatus'],
@@ -439,7 +441,9 @@ export const builtInForms = {
439
441
  }
440
442
  }
441
443
  }
442
- },
444
+ }
445
+ };
446
+ const staticSiteForms = {
443
447
  TSStaticSite: {
444
448
  default: {
445
449
  order: ['title', 'provider', 'destination', 'idKey', 'secretKey', 'environmentVariables'],
@@ -619,3 +623,11 @@ export const builtInForms = {
619
623
  }
620
624
  }
621
625
  };
626
+ export function getBuiltInShapes(options) {
627
+ return options?.entitlements.staticSites ? { ...builtInShapes, ...staticSiteShapes } : builtInShapes;
628
+ }
629
+ export function getBuiltInForms(options) {
630
+ return options.entitlements.staticSites ? { ...builtInForms, ...staticSiteForms } : builtInForms;
631
+ }
632
+ export const allBuiltInShapes = { ...builtInShapes, ...staticSiteShapes };
633
+ export const allBuiltInForms = { ...builtInForms, ...staticSiteForms };
package/dist/mocks.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { SchemaDefaultsOptions } from './builtin-schema.js';
1
2
  import type { ProjectSchemaJSON, ServiceConfig, ServiceConfigJSON, ShapeJSON } from './project-schema/index.ts';
2
3
  import type { CachedShape, ServiceKey } from './types/types.ts';
3
4
  /**
@@ -7,7 +8,7 @@ export declare function createMockSchema(projectId: string, schema?: Partial<Pro
7
8
  /**
8
9
  * Capturing a common pattern used in tests. Creates an empty schema, with defaults.
9
10
  */
10
- export declare function createMockSchemaWithDefaults(projectId: string, schema?: Partial<ProjectSchemaJSON>): ProjectSchemaJSON;
11
+ export declare function createMockSchemaWithDefaults(projectId: string, schema?: Partial<ProjectSchemaJSON>, options?: SchemaDefaultsOptions): ProjectSchemaJSON;
11
12
  export declare function createMockServiceConfig(serviceKey: ServiceKey, serviceConfig?: Partial<ServiceConfig>): ServiceConfig;
12
13
  export declare function createMockStoredServiceConfig(serviceKey: ServiceKey, serviceConfig?: Partial<ServiceConfigJSON>): ServiceConfigJSON;
13
14
  export declare function addMockIndexingConfig(shape: ShapeJSON): CachedShape;
package/dist/mocks.js CHANGED
@@ -13,12 +13,12 @@ export function createMockSchema(projectId, schema = {}) {
13
13
  /**
14
14
  * Capturing a common pattern used in tests. Creates an empty schema, with defaults.
15
15
  */
16
- export function createMockSchemaWithDefaults(projectId, schema = {}) {
16
+ export function createMockSchemaWithDefaults(projectId, schema = {}, options) {
17
17
  return applyDefaultsToSchema({
18
18
  ...emptySchema(projectId),
19
19
  ...schema,
20
20
  projectId
21
- });
21
+ }, options);
22
22
  }
23
23
  export function createMockServiceConfig(serviceKey, serviceConfig) {
24
24
  return {
@@ -5,8 +5,7 @@ export class RuntimeSchema extends ProjectSchemaImpl {
5
5
  super(runtimeSchema, layers);
6
6
  }
7
7
  static buildSchema(userSchema, layers) {
8
- // biome-ignore lint/suspicious/noConsole: ignore
9
- const runtimeSchema = buildRuntimeSchema(userSchema, layers, console.log);
8
+ const runtimeSchema = buildRuntimeSchema(userSchema, layers);
10
9
  return new RuntimeSchema(runtimeSchema, layers);
11
10
  }
12
11
  static safeBuildSchema(userSchema, layers) {
@@ -2,7 +2,7 @@ import { isDefined } from '@takeshape/util';
2
2
  import camelCase from 'lodash/camelCase.js';
3
3
  import find from 'lodash/find.js';
4
4
  import uniq from 'lodash/uniq.js';
5
- import { builtInShapes } from "./builtin-schema.js";
5
+ import { allBuiltInShapes } from "./builtin-schema.js";
6
6
  import { followRef, getRefShapeName, getShapeByRef, shapeToRefString } from "./refs.js";
7
7
  import { isModelShape, isObjectSchema, isPropertySchemaWithRelationship } from "./types/index.js";
8
8
  import { isUnionSchema } from "./unions.js";
@@ -26,7 +26,7 @@ export function getRelationshipSchema(projectSchema, relationship) {
26
26
  if ('shapeIds' in relationship) {
27
27
  shapeRefs = relationship.shapeIds
28
28
  .map((shapeId) => {
29
- const shape = getShapeById(projectSchema, shapeId) ?? find(builtInShapes, (shape) => shape.id === shapeId);
29
+ const shape = getShapeById(projectSchema, shapeId) ?? find(allBuiltInShapes, (shape) => shape.id === shapeId);
30
30
  return (shape && {
31
31
  '@ref': shapeToRefString(projectSchema, shape)
32
32
  });
@@ -1,5 +1,6 @@
1
+ import type { SchemaDefaultsOptions } from './builtin-schema.js';
1
2
  import type { ProjectSchemaJSON } from './project-schema/index.ts';
2
3
  import { type ServiceLayers } from './types/index.ts';
3
4
  export declare function applyLegacyCompatibilityTweaks(projectSchema: ProjectSchemaJSON): ProjectSchemaJSON;
4
- export declare const applyDefaultsAndFlatten: (projectSchema: ProjectSchemaJSON) => ProjectSchemaJSON;
5
- export declare function buildRuntimeSchema(projectSchema: ProjectSchemaJSON, serviceLayers: ServiceLayers, log: (messsage: string, error: Error) => void): ProjectSchemaJSON;
5
+ export declare function applyDefaultsAndFlatten(projectSchema: ProjectSchemaJSON, options?: SchemaDefaultsOptions): ProjectSchemaJSON;
6
+ export declare function buildRuntimeSchema(projectSchema: ProjectSchemaJSON, serviceLayers: ServiceLayers, options?: SchemaDefaultsOptions): ProjectSchemaJSON;
@@ -1,6 +1,5 @@
1
1
  import { SchemaBuildError } from '@takeshape/errors';
2
2
  import { deepClone } from '@takeshape/util';
3
- import compose from 'lodash/fp/compose.js';
4
3
  import isError from 'lodash/isError.js';
5
4
  import set from 'lodash/set.js';
6
5
  import { addAiQueries } from "./agents.js";
@@ -64,18 +63,23 @@ export function applyLegacyCompatibilityTweaks(projectSchema) {
64
63
  addRelatedFields(newSchema, findExistingRelationships(projectSchema, projectSchema.shapes));
65
64
  return newSchema;
66
65
  }
67
- export const applyDefaultsAndFlatten = compose(flattenTemplates, applyLegacyCompatibilityTweaks, applyDefaultsToSchema, addAiQueries);
68
- export function buildRuntimeSchema(projectSchema, serviceLayers, log) {
66
+ export function applyDefaultsAndFlatten(projectSchema, options) {
67
+ let newSchema = projectSchema;
68
+ newSchema = addAiQueries(newSchema);
69
+ newSchema = applyDefaultsToSchema(newSchema, options);
70
+ newSchema = applyLegacyCompatibilityTweaks(newSchema);
71
+ newSchema = flattenTemplates(newSchema);
72
+ return newSchema;
73
+ }
74
+ export function buildRuntimeSchema(projectSchema, serviceLayers, options) {
69
75
  try {
70
76
  const projectSchemaWithDependencies = resolveSchemaShapeDependencies(projectSchema, serviceLayers);
71
- return applyDefaultsAndFlatten(projectSchemaWithDependencies);
77
+ return applyDefaultsAndFlatten(projectSchemaWithDependencies, options);
72
78
  }
73
79
  catch (err) {
74
- const error = new SchemaBuildError('An error occurred while building the schema', {
80
+ throw new SchemaBuildError('An error occurred while building the schema', {
75
81
  cause: isError(err) ? err : undefined,
76
82
  schema: projectSchema
77
83
  });
78
- log('build runtime error', error);
79
- throw error;
80
84
  }
81
85
  }
@@ -1,4 +1,5 @@
1
1
  import { type Maybe } from '@takeshape/util';
2
+ import { type SchemaDefaultsOptions } from './builtin-schema.ts';
2
3
  import type { ProjectSchemaJSON, PropertySchema, QueryJSON, ServiceConfig, ShapeJSON, ShapeMap, ShapeSchema } from './project-schema/index.ts';
3
4
  import { type RefItem, type RefItemWithPath, type ServicesContext, type ServicesShapesContext } from './refs.ts';
4
5
  import { type LatestProjectSchemaWithServices, type LayerSchema, type SchemaPath, type SchemaPropertyName, type SchemaPropertyNode, type SchemaWithArgs, type ServiceMap } from './types/index.ts';
@@ -39,8 +40,8 @@ export declare function applyBuiltinPropertiesToShape(projectSchema: ProjectSche
39
40
  * Get all built-in shapes that are depended on by the given project schema.
40
41
  * Required built-in shapes are always included.
41
42
  */
42
- export declare function getBuiltinsUsed(projectSchema: ProjectSchemaJSON): ShapeMap;
43
- export declare function applyDefaultsToSchema<T extends ProjectSchemaJSON>(projectSchema: T): T;
43
+ export declare function getBuiltinsUsed(builtInShapes: ShapeMap, projectSchema: ProjectSchemaJSON): ShapeMap;
44
+ export declare function applyDefaultsToSchema<T extends ProjectSchemaJSON>(projectSchema: T, options?: SchemaDefaultsOptions): T;
44
45
  export declare function getArgsReference(projectSchema: ServicesContext, argsSchema: SchemaWithArgs): Maybe<RefItem>;
45
46
  export declare function getArgsReferenceWithPath(context: ServicesContext, argsSchema: SchemaWithArgs, schemaPath?: SchemaPath): Maybe<RefItemWithPath>;
46
47
  export declare function getArgsShapeSchema(context: ServicesShapesContext, argsSchema: SchemaWithArgs): Maybe<ShapeSchema>;
@@ -1,4 +1,4 @@
1
- import { deepClone, ensureArray, pascalCase, visit } from '@takeshape/util';
1
+ import { DEFAULT_ENTITLEMENTS, deepClone, ensureArray, pascalCase, visit } from '@takeshape/util';
2
2
  import curry from 'lodash/fp/curry.js';
3
3
  import orderBy from 'lodash/fp/orderBy.js';
4
4
  import isArray from 'lodash/isArray.js';
@@ -8,7 +8,7 @@ import mapValues from 'lodash/mapValues.js';
8
8
  import uniq from 'lodash/uniq.js';
9
9
  import { AGENTS_SCHEMA_PATH, getAgentMap } from './agents.js';
10
10
  import { workflowsEnabled } from "./api-version.js";
11
- import { builtInForms, builtInShapes } from "./builtin-schema.js";
11
+ import { allBuiltInShapes, getBuiltInForms, getBuiltInShapes } from "./builtin-schema.js";
12
12
  import { SERVICE_OBJECT_PATTERN_NAME } from "./constants.js";
13
13
  import { createTemplateShapeName, dereferenceObjectSchema, dereferenceSchema, getRef, getRefOrItemsRef, getRefShapeName, isValidRefItem, parseRef, parseReturnShape, refItemToNamespacedShapeName, refItemToShape, refItemToShapeSchema, refToRefItem, returnShapeToSchema, serializePropertyRef } from "./refs.js";
14
14
  import { getArgsType, isAllOfSchema, isArraySchema, isCachedShape, isExtendsSchema, isGraphqlResolver, isModelShape, isObjectSchema, isOneOfSchema, isReferenceableShape, isRefSchema } from "./types/index.js";
@@ -19,9 +19,9 @@ import { CURRENT_API_VERSION, CURRENT_SCHEMA_VERSION } from "./versions.js";
19
19
  import { defaultWorkflow, getStatusField } from "./workflows.js";
20
20
  export function isBuiltinShape(ref) {
21
21
  const parsed = parseRef({}, ref);
22
- return Boolean(parsed.layerId === 'local' && builtInShapes[parsed.shapeName]);
22
+ return Boolean(parsed.layerId === 'local' && allBuiltInShapes[parsed.shapeName]);
23
23
  }
24
- const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(builtInShapes));
24
+ const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(allBuiltInShapes));
25
25
  export function isBuiltinQuery(name) {
26
26
  return builtInQueriesAndMutations.queries[name] !== undefined;
27
27
  }
@@ -383,7 +383,7 @@ const requiredBuiltinShapes = ['Asset', 'TSRelationship', 'TSStaticSite', 'TSUse
383
383
  * Get all built-in shapes that are depended on by the given project schema.
384
384
  * Required built-in shapes are always included.
385
385
  */
386
- export function getBuiltinsUsed(projectSchema) {
386
+ export function getBuiltinsUsed(builtInShapes, projectSchema) {
387
387
  const builtinsUsed = {};
388
388
  const shapeNames = uniq(requiredBuiltinShapes.concat(getAllRefs(projectSchema, (refItem) => refItem.layerId === 'local' && isBuiltinShape(refItem.shapeName)).map((ref) => refItemToNamespacedShapeName(projectSchema, ref))));
389
389
  const schemaWithAllBuiltins = {
@@ -391,15 +391,24 @@ export function getBuiltinsUsed(projectSchema) {
391
391
  shapes: builtInShapes
392
392
  };
393
393
  for (const builtinShapeName of shapeNames) {
394
- builtinsUsed[builtinShapeName] = builtInShapes[builtinShapeName];
395
- for (const depShapeName of getShapeDependencies(schemaWithAllBuiltins, builtInShapes[builtinShapeName])) {
396
- builtinsUsed[depShapeName] = builtInShapes[depShapeName];
394
+ if (builtInShapes[builtinShapeName]) {
395
+ builtinsUsed[builtinShapeName] = builtInShapes[builtinShapeName];
396
+ for (const depShapeName of getShapeDependencies(schemaWithAllBuiltins, builtInShapes[builtinShapeName])) {
397
+ builtinsUsed[depShapeName] = builtInShapes[depShapeName];
398
+ }
397
399
  }
398
400
  }
399
401
  return builtinsUsed;
400
402
  }
401
- export function applyDefaultsToSchema(projectSchema) {
402
- const builtinsUsed = getBuiltinsUsed(projectSchema);
403
+ export function applyDefaultsToSchema(projectSchema, options) {
404
+ const optionsWithDefaults = {
405
+ entitlements: DEFAULT_ENTITLEMENTS,
406
+ ...options
407
+ };
408
+ const builtInShapes = getBuiltInShapes(optionsWithDefaults);
409
+ const builtinsUsed = getBuiltinsUsed(builtInShapes, projectSchema);
410
+ const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(builtInShapes));
411
+ const builtInForms = getBuiltInForms(optionsWithDefaults);
403
412
  return {
404
413
  ...projectSchema,
405
414
  workflows: {
@@ -2,9 +2,8 @@ import { type SchemaValidationErrorItem } from '@takeshape/errors';
2
2
  import { type Entitlements } from '@takeshape/util';
3
3
  import type { SetRequired } from 'type-fest';
4
4
  import type { RoleImport, RoleInput } from '../auth-schemas.ts';
5
- import type { AnyProjectSchemaJSON, ProjectSchemaJSON } from '../project-schema/index.ts';
5
+ import type { AnyProjectSchemaJSON, ProjectSchemaJSON, ShapeMap } from '../project-schema/index.ts';
6
6
  import type { LayerState, ProjectSchemaImport } from '../types/types.ts';
7
- export declare const builtInShapeNames: Set<string>;
8
7
  export type SchemaValidationResult = {
9
8
  valid: true;
10
9
  schema: AnyProjectSchemaJSON;
@@ -33,8 +32,11 @@ export type EntitlementsOptions = {
33
32
  entitlements: Entitlements;
34
33
  };
35
34
  export type ValidateContext = {
35
+ builtInShapes: ShapeMap;
36
+ builtInShapeNames: Set<string>;
37
+ } & ValidateOptions;
38
+ export type ValidateOptions = {
36
39
  allowDisconnectedLayers?: boolean;
37
- generatedApi?: Pick<ProjectSchemaJSON, 'queries' | 'mutations'>;
38
40
  structureOnly?: boolean;
39
41
  } & EntitlementsOptions & ValidateSyntaxOptions;
40
42
  export type ValidateReferencesContext = SetRequired<ValidateContext, 'resolveLayer'> & {
@@ -44,7 +46,7 @@ export declare function validateSchemaSyntax(obj: unknown, options?: ValidateSyn
44
46
  /**
45
47
  * Validates a schema using a matching validation based on the `schemaVersion` property.
46
48
  */
47
- export declare function validateSchema(context: ValidateContext, obj: unknown): Promise<SchemaValidationResult>;
49
+ export declare function validateSchema(options: ValidateOptions, obj: unknown): Promise<SchemaValidationResult>;
48
50
  export declare function ensureValidLatestSchemaSyntax(obj: unknown): ProjectSchemaJSON;
49
51
  /**
50
52
  * Validates and returns a `RoleInput`, which is a subset of the `Role`
@@ -1,6 +1,6 @@
1
1
  import { SchemaValidationError } from '@takeshape/errors';
2
2
  import { createAjv } from '@takeshape/json-schema';
3
- import { DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL, ensureArray, isIntegerLike, isRecord, value } from '@takeshape/util';
3
+ import { DEFAULT_ENTITLEMENTS, DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL, ensureArray, isIntegerLike, isRecord, value } from '@takeshape/util';
4
4
  import { JSONPath } from 'jsonpath-plus';
5
5
  import flatten from 'lodash/flatten.js';
6
6
  import get from 'lodash/get.js';
@@ -17,7 +17,7 @@ import gte from 'semver/functions/gte.js';
17
17
  import lt from 'semver/functions/lt.js';
18
18
  import neq from 'semver/functions/neq.js';
19
19
  import { GUARDS_SCHEMA_PATH, getGuards, isGuardEnabled } from "../agents.js";
20
- import { builtInShapes } from "../builtin-schema.js";
20
+ import { getBuiltInShapes } from "../builtin-schema.js";
21
21
  import { isEnumLikeSchema } from "../enum.js";
22
22
  import { isLatestProjectSchemaJSON } from "../project-schema/index.js";
23
23
  import { createGetNamespace, getRefShapeName, getToolRef, isValidServiceId, parsePropertyRef, parseRef, propertyRefItemToPath, propertyRefItemToResolverPath, refItemToNamespacedShapeName, refItemToShape, serializeRef } from "../refs.js";
@@ -38,7 +38,6 @@ import { defaultWorkflow } from "../workflows.js";
38
38
  import { validateAgents, validateAIToolConfig } from "./ai.js";
39
39
  import { formatError } from "./errors.js";
40
40
  import { pushErrors } from './util.js';
41
- export const builtInShapeNames = new Set([...Object.keys(builtInShapes), ...scalars, 'object']);
42
41
  function findDuplicates(items) {
43
42
  const seen = {};
44
43
  for (const item of items) {
@@ -153,13 +152,13 @@ function enumerateBasicResolvers(resolver, path) {
153
152
  visit(resolver, path);
154
153
  return results;
155
154
  }
156
- function validateResolver(projectSchema, basePath, baseResolver) {
155
+ function validateResolver(context, projectSchema, basePath, baseResolver) {
157
156
  const errors = [];
158
157
  const isValidShapeName = (shapeName) => {
159
158
  if (!shapeName) {
160
159
  return false;
161
160
  }
162
- const shape = getShape(projectSchema, shapeName) ?? getShape({ shapes: builtInShapes }, shapeName);
161
+ const shape = getShape(projectSchema, shapeName) ?? getShape({ shapes: context.builtInShapes }, shapeName);
163
162
  if (shape?.model) {
164
163
  return true;
165
164
  }
@@ -293,16 +292,16 @@ function validateResolver(projectSchema, basePath, baseResolver) {
293
292
  }
294
293
  return errors;
295
294
  }
296
- function validateLocalQueryConfig(projectSchema, query, operation, name) {
295
+ function validateLocalQueryConfig(context, projectSchema, query, operation, name) {
297
296
  const location = operation === 'query' ? 'queries' : 'mutations';
298
- return validateResolver(projectSchema, [location, name, 'resolver'], query.resolver);
297
+ return validateResolver(context, projectSchema, [location, name, 'resolver'], query.resolver);
299
298
  }
300
299
  const operationProps = [['query', 'queries'], ['mutation', 'mutations']];
301
- function validateLocalQueryConfigs(projectSchema) {
300
+ function validateLocalQueryConfigs(context, projectSchema) {
302
301
  const errors = [];
303
302
  for (const [operation, prop] of operationProps) {
304
303
  for (const name of Object.keys(projectSchema[prop])) {
305
- errors.push(...validateLocalQueryConfig(projectSchema, projectSchema[prop][name], operation, name));
304
+ errors.push(...validateLocalQueryConfig(context, projectSchema, projectSchema[prop][name], operation, name));
306
305
  }
307
306
  }
308
307
  return errors;
@@ -427,8 +426,8 @@ function validateLocalShapeJoinRef(projectSchema, item) {
427
426
  }
428
427
  return [];
429
428
  }
430
- function validateLocalShapeJoins(projectSchema) {
431
- return listShapeJoins(projectSchema).flatMap((item) => validateLocalShapeJoinRef(projectSchema, item).concat(validateResolver(projectSchema, item.path.concat('resolver'), item.join.resolver)));
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)));
432
431
  }
433
432
  async function validateShapeJoinRef(context, projectSchema, item) {
434
433
  const refItem = parseRef(projectSchema, item.ref);
@@ -549,9 +548,9 @@ function isAllOfPath(path) {
549
548
  function isLocalRef(refItem) {
550
549
  return refItem.layerId === 'local';
551
550
  }
552
- function validateLocalRefs(projectSchema) {
551
+ function validateLocalRefs(context, projectSchema) {
553
552
  const errors = [];
554
- const shapeNames = new Set([...builtInShapeNames, ...Object.keys(projectSchema.shapes)]);
553
+ const shapeNames = new Set([...context.builtInShapeNames, ...Object.keys(projectSchema.shapes)]);
555
554
  const refs = getAllRefs(projectSchema).filter(isLocalRef);
556
555
  for (const item of refs) {
557
556
  if (item.template && !isValidTemplate(item.template)) {
@@ -596,7 +595,7 @@ function validateLocalRefs(projectSchema) {
596
595
  function isValidRef(context, projectSchema, layer, item) {
597
596
  const { layerId } = item;
598
597
  const shapeName = refItemToNamespacedShapeName(projectSchema, item);
599
- const localShapeExists = Boolean(projectSchema.shapes[shapeName]) || builtInShapeNames.has(shapeName);
598
+ const localShapeExists = Boolean(projectSchema.shapes[shapeName]) || context.builtInShapeNames.has(shapeName);
600
599
  return (isValidServiceId(projectSchema, layerId) &&
601
600
  (layerId === 'local' ? localShapeExists : localShapeExists || isValidShapeReference(context, layer, shapeName)));
602
601
  }
@@ -647,13 +646,13 @@ function visitShapePropertiesJson(projectSchema, callback) {
647
646
  callback(property, propertyPath.slice(3, -2).split(`']['`));
648
647
  }, undefined);
649
648
  }
650
- function validateDirectives(projectSchema) {
649
+ function validateDirectives(context, projectSchema) {
651
650
  const errors = [];
652
651
  visitShapePropertiesJson(projectSchema, (property, propertyPath) => {
653
652
  const resolver = property['@resolver'];
654
653
  if (resolver) {
655
654
  const propPath = propertyPath.concat('@resolver');
656
- const resolverErrors = validateResolver(projectSchema, propPath, resolver);
655
+ const resolverErrors = validateResolver(context, projectSchema, propPath, resolver);
657
656
  if (resolverErrors) {
658
657
  errors.push(...resolverErrors);
659
658
  }
@@ -882,10 +881,10 @@ function validateSyntax(context, schema) {
882
881
  .concat(checkShapeNames(schema.shapes))
883
882
  .concat(checkShapeIds(schema.shapes))
884
883
  .concat(validateWorkflows(schema))
885
- .concat(validateLocalQueryConfigs(schema))
886
- .concat(validateLocalRefs(schema))
887
- .concat(validateLocalShapeJoins(schema))
888
- .concat(validateDirectives(schema))
884
+ .concat(validateLocalQueryConfigs(context, schema))
885
+ .concat(validateLocalRefs(context, schema))
886
+ .concat(validateLocalShapeJoins(context, schema))
887
+ .concat(validateDirectives(context, schema))
889
888
  .concat(validateLocales(schema))
890
889
  .concat(checkWorkflowStepNames(schema.workflows))
891
890
  .concat(checkWorkflowStepKeys(schema.workflows))
@@ -937,19 +936,23 @@ export function validateSchemaSyntax(obj, options = {}) {
937
936
  /**
938
937
  * Validates a schema using a matching validation based on the `schemaVersion` property.
939
938
  */
940
- export async function validateSchema(context, obj) {
939
+ export async function validateSchema(options, obj) {
941
940
  if (isUndefined(obj)) {
942
941
  return schemaUndefinedResult;
943
942
  }
944
- const contextWithDefaults = {
943
+ const builtInShapes = getBuiltInShapes({ entitlements: options.entitlements ?? DEFAULT_ENTITLEMENTS });
944
+ const builtInShapeNames = new Set([...Object.keys(builtInShapes), ...scalars, 'object']);
945
+ const context = {
945
946
  allowDisconnectedLayers: true,
946
- ...context
947
+ builtInShapes,
948
+ builtInShapeNames,
949
+ ...options
947
950
  };
948
951
  const schemaVersion = normalizeSchemaVersion(obj);
949
952
  if (!schemaVersion) {
950
953
  return invalidVersionResult;
951
954
  }
952
- const structuralValidation = validateStructure(schemaVersion, contextWithDefaults, obj);
955
+ const structuralValidation = validateStructure(schemaVersion, context, obj);
953
956
  if (!structuralValidation.valid || context.structureOnly) {
954
957
  return structuralValidation;
955
958
  }
@@ -957,9 +960,9 @@ export async function validateSchema(context, obj) {
957
960
  if (!isLatestProjectSchemaJSON(schema)) {
958
961
  return invalidVersionResult;
959
962
  }
960
- const syntaxValidation = validateSyntax(contextWithDefaults, schema);
963
+ const syntaxValidation = validateSyntax(context, schema);
961
964
  const validateReferencesContext = {
962
- ...contextWithDefaults,
965
+ ...context,
963
966
  projectSchema: schema
964
967
  };
965
968
  if (!syntaxValidation.valid || !isValidateReferencesContext(validateReferencesContext)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/schema",
3
- "version": "11.132.2",
3
+ "version": "11.133.1",
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.132.2",
60
- "@takeshape/json-schema": "11.132.2",
61
- "@takeshape/util": "11.132.2"
59
+ "@takeshape/errors": "11.133.1",
60
+ "@takeshape/util": "11.133.1",
61
+ "@takeshape/json-schema": "11.133.1"
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.132.2",
79
- "@takeshape/logger": "11.132.2"
78
+ "@takeshape/infra": "11.133.1",
79
+ "@takeshape/logger": "11.133.1"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22"