@takeshape/schema 12.2.2 → 12.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schema-util.d.ts +2 -2
- package/dist/schema-util.js +16 -4
- package/package.json +6 -6
package/dist/schema-util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Maybe } from '@takeshape/util';
|
|
2
2
|
import { type SchemaDefaultsOptions } from './builtin-schema.ts';
|
|
3
|
-
import type { ProjectSchemaJSON, PropertySchema, QueryJSON, ServiceConfig, ShapeJSON, ShapeMap, ShapeSchema } from './project-schema/index.ts';
|
|
3
|
+
import type { FieldMapping, ProjectSchemaJSON, PropertySchema, QueryJSON, ServiceConfig, ShapeJSON, ShapeMap, ShapeSchema } from './project-schema/index.ts';
|
|
4
4
|
import { type RefItem, type RefItemWithPath, type ServicesContext, type ServicesShapesContext } from './refs.ts';
|
|
5
5
|
import { type LatestProjectSchemaWithServices, type LayerSchema, type SchemaPath, type SchemaPropertyName, type SchemaPropertyNode, type SchemaWithArgs, type ServiceMap } from './types/index.ts';
|
|
6
6
|
export declare function isBuiltinShape(ref: string): boolean;
|
|
@@ -99,7 +99,7 @@ export declare function shapeToJsonSchema(projectSchema: ProjectSchemaJSON, shap
|
|
|
99
99
|
'@l10n'?: boolean;
|
|
100
100
|
'@key'?: string;
|
|
101
101
|
'@workflow'?: string;
|
|
102
|
-
'@mapping'?:
|
|
102
|
+
'@mapping'?: FieldMapping;
|
|
103
103
|
'@tag'?: string;
|
|
104
104
|
'@tags'?: string[];
|
|
105
105
|
'@deprecationReason'?: string;
|
package/dist/schema-util.js
CHANGED
|
@@ -10,7 +10,7 @@ import { AGENTS_SCHEMA_PATH, getAgentMap } from './agents.js';
|
|
|
10
10
|
import { workflowsEnabled } from "./api-version.js";
|
|
11
11
|
import { allBuiltInShapes, getBuiltInForms, getBuiltInShapes } from "./builtin-schema.js";
|
|
12
12
|
import { SERVICE_OBJECT_PATTERN_NAME } from "./constants.js";
|
|
13
|
-
import { createTemplateShapeName, dereferenceObjectSchema, dereferenceSchema, getRef, getRefOrItemsRef, getRefShapeName, isValidRefItem, parseRef, parseReturnShape, refItemToNamespacedShapeName, refItemToShape, refItemToShapeSchema, refToRefItem, returnShapeToSchema, serializePropertyRef } from "./refs.js";
|
|
13
|
+
import { createTemplateShapeName, dereferenceObjectSchema, dereferenceSchema, getRef, getRefOrItemsRef, getRefShapeName, isValidRefItem, parseName, 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";
|
|
15
15
|
import { isUnionSchema } from "./unions.js";
|
|
16
16
|
import { getArgs } from "./util/has-arg.js";
|
|
@@ -233,15 +233,25 @@ export function getIdField(obj) {
|
|
|
233
233
|
/**
|
|
234
234
|
* Get properties necessary for cached / remote data to work with the TSSearchable interface.
|
|
235
235
|
*/
|
|
236
|
-
function getCachedBuiltInProperties(shape, properties) {
|
|
236
|
+
function getCachedBuiltInProperties(projectSchema, shape, properties) {
|
|
237
237
|
const idField = getIdField(shape.cache);
|
|
238
|
+
const idFieldSchema = properties[idField];
|
|
239
|
+
let idMapping;
|
|
240
|
+
// Determine _id mapping: prefer existing mapping on idField, fallback to constructing from shape name
|
|
241
|
+
if (idFieldSchema) {
|
|
242
|
+
idMapping = idFieldSchema['@mapping'];
|
|
243
|
+
if (!idMapping) {
|
|
244
|
+
const { layerId, name } = parseName(projectSchema, shape.name);
|
|
245
|
+
idMapping = `${layerId}:${name}.${idField}`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
238
248
|
// TODO Implement `searchSummary` and `_shapeId` here, and remove `getRemoteShapeTSSearchableFields`
|
|
239
249
|
return {
|
|
240
250
|
_id: {
|
|
241
251
|
title: 'Id',
|
|
242
252
|
type: 'string',
|
|
243
253
|
...properties._id,
|
|
244
|
-
...(
|
|
254
|
+
...(idMapping ? { '@mapping': idMapping } : {})
|
|
245
255
|
}
|
|
246
256
|
};
|
|
247
257
|
}
|
|
@@ -363,7 +373,9 @@ export function applyBuiltinPropertiesToShape(projectSchema, shape) {
|
|
|
363
373
|
const { properties } = shapeObjectSchema;
|
|
364
374
|
const commonProperties = getCommonBuiltInProperties(shape);
|
|
365
375
|
const modelProperties = profile === BuiltInPropertiesProfile.Model ? getModelBuiltInProperties(projectSchema, shape) : undefined;
|
|
366
|
-
const cachedProperties = profile === BuiltInPropertiesProfile.Cached
|
|
376
|
+
const cachedProperties = profile === BuiltInPropertiesProfile.Cached
|
|
377
|
+
? getCachedBuiltInProperties(projectSchema, shape, properties)
|
|
378
|
+
: undefined;
|
|
367
379
|
return {
|
|
368
380
|
...shape,
|
|
369
381
|
schema: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"p-reduce": "3.0.0",
|
|
58
58
|
"semver": "7.7.2",
|
|
59
59
|
"tiny-invariant": "1.3.3",
|
|
60
|
-
"@takeshape/
|
|
61
|
-
"@takeshape/
|
|
62
|
-
"@takeshape/
|
|
60
|
+
"@takeshape/json-schema": "12.3.0",
|
|
61
|
+
"@takeshape/util": "12.3.0",
|
|
62
|
+
"@takeshape/errors": "12.3.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@takeshape/json-schema-to-typescript": "11.0.0",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"glob": "11.0.1",
|
|
77
77
|
"json-schema-to-ts": "3.1.1",
|
|
78
78
|
"shortid": "2.2.16",
|
|
79
|
-
"@takeshape/
|
|
80
|
-
"@takeshape/
|
|
79
|
+
"@takeshape/infra": "12.3.0",
|
|
80
|
+
"@takeshape/logger": "12.3.0"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=24"
|