@takeshape/schema 11.69.0 → 11.70.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/content-schema-transform.js +7 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/__tests__/fixtures.d.ts +15 -0
- package/dist/models/__tests__/fixtures.js +56 -0
- package/dist/models/__tests__/query.test.js +14 -22
- package/dist/models/__tests__/runtime-schema.test.js +43 -0
- package/dist/models/__tests__/shape.test.js +18 -55
- package/dist/models/query.d.ts +8 -16
- package/dist/models/query.js +22 -27
- package/dist/models/runtime-schema.d.ts +13 -0
- package/dist/models/runtime-schema.js +78 -0
- package/dist/models/shape.d.ts +7 -37
- package/dist/models/shape.js +22 -77
- package/dist/models/types.d.ts +7 -5
- package/dist/refs.d.ts +1 -1
- package/dist/types/transforms.d.ts +3 -1
- package/examples/latest/rick-and-morty-user-schema.json +104 -0
- package/examples/source/rick-and-morty-user-schema.json +104 -0
- package/package.json +5 -5
- package/dist/models/__tests__/project-schema.test.js +0 -67
- package/dist/models/__tests__/service.test.d.ts +0 -1
- package/dist/models/__tests__/service.test.js +0 -17
- package/dist/models/project-schema.d.ts +0 -36
- package/dist/models/project-schema.js +0 -92
- package/dist/models/service.d.ts +0 -12
- package/dist/models/service.js +0 -20
- /package/dist/models/__tests__/{project-schema.test.d.ts → runtime-schema.test.d.ts} +0 -0
|
@@ -57,7 +57,7 @@ export function findTransforms(pluginMap, schema, name, shape) {
|
|
|
57
57
|
}
|
|
58
58
|
export function getContentTransform({ transforms, accumulators, keyTransform = preferKey, sourceKeyTransform = preferSourceKey, passThrough = true, allowNullObjects = false, projectSchema }) {
|
|
59
59
|
const nonDefaultLocales = getNonDefaultLocales(projectSchema);
|
|
60
|
-
const prepare = (schema, obj, name = '') => {
|
|
60
|
+
const prepare = (schema, obj, name = '', parent) => {
|
|
61
61
|
const shapeName = getRefShapeName(projectSchema, schema);
|
|
62
62
|
schema = dereferenceSchema(projectSchema, schema);
|
|
63
63
|
if (accumulators) {
|
|
@@ -68,13 +68,13 @@ export function getContentTransform({ transforms, accumulators, keyTransform = p
|
|
|
68
68
|
const shape = shapeName ? projectSchema.shapes[shapeName] : undefined;
|
|
69
69
|
const transform = findTransforms(transforms, schema, name, shape);
|
|
70
70
|
if (transform) {
|
|
71
|
-
const next = (value, schema, name) => prepare(schema, value, name);
|
|
72
|
-
return transform.process(obj, schema, name, shape, next);
|
|
71
|
+
const next = (value, schema, name, parent) => prepare(schema, value, name, parent);
|
|
72
|
+
return transform.process(obj, { ...schema, $parent: parent }, name, shape, next);
|
|
73
73
|
}
|
|
74
74
|
if (obj && isUnionSchema(schema)) {
|
|
75
75
|
for (const { shapeId, propSchema } of enumerateOneOfKeys(projectSchema, schema.oneOf)) {
|
|
76
76
|
if (obj._shapeId === shapeId) {
|
|
77
|
-
return prepare(propSchema, obj, name);
|
|
77
|
+
return prepare(propSchema, obj, name, schema);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -85,7 +85,7 @@ export function getContentTransform({ transforms, accumulators, keyTransform = p
|
|
|
85
85
|
const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema, obj));
|
|
86
86
|
const localizedSourceKeys = getLocalizedSourceKeys(sourceKeys, nonDefaultLocales);
|
|
87
87
|
for (const { key: sourceKey, locale } of localizedSourceKeys) {
|
|
88
|
-
const value = prepare(fieldSchema, get(obj, sourceKey), name);
|
|
88
|
+
const value = prepare(fieldSchema, get(obj, sourceKey), name, schema);
|
|
89
89
|
if (value !== undefined) {
|
|
90
90
|
assigned.add(sourceKey);
|
|
91
91
|
const transform = findTransforms(transforms, dereferenceSchema(projectSchema, fieldSchema), name);
|
|
@@ -106,10 +106,10 @@ export function getContentTransform({ transforms, accumulators, keyTransform = p
|
|
|
106
106
|
if (isArraySchema(schema)) {
|
|
107
107
|
const itemSchema = schema.items;
|
|
108
108
|
if (Array.isArray(obj)) {
|
|
109
|
-
return obj.map((item) => prepare(itemSchema, item, name));
|
|
109
|
+
return obj.map((item) => prepare(itemSchema, item, name, schema));
|
|
110
110
|
}
|
|
111
111
|
if (obj === undefined) {
|
|
112
|
-
prepare(itemSchema, obj, name);
|
|
112
|
+
prepare(itemSchema, obj, name, parent);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
if (allowNullObjects && isObjectSchema(schema) && obj === null) {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './interfaces.ts';
|
|
|
12
12
|
export * from './migration/index.ts';
|
|
13
13
|
export type { ProjectSchemaUpdate } from './migration/types.ts';
|
|
14
14
|
export * from './mocks.ts';
|
|
15
|
+
export * from './models/runtime-schema.ts';
|
|
15
16
|
export * from './patterns.ts';
|
|
16
17
|
export * from './project-schema/index.ts';
|
|
17
18
|
export * from './project-schema/migrate.ts';
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./get-is-leaf.js";
|
|
|
10
10
|
export * from "./interfaces.js";
|
|
11
11
|
export * from "./migration/index.js";
|
|
12
12
|
export * from "./mocks.js";
|
|
13
|
+
export * from "./models/runtime-schema.js";
|
|
13
14
|
export * from "./patterns.js";
|
|
14
15
|
export * from "./project-schema/index.js";
|
|
15
16
|
export * from "./project-schema/migrate.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProjectSchemaJSON } from '../../project-schema/index.ts';
|
|
2
|
+
import type { ServiceLayers } from '../../types/index.ts';
|
|
3
|
+
export declare const rickLayers: ServiceLayers;
|
|
4
|
+
export declare const rickSchema: ProjectSchemaJSON;
|
|
5
|
+
export declare const expectedSupaArgsSchema: {
|
|
6
|
+
properties: {
|
|
7
|
+
a: {
|
|
8
|
+
type: string;
|
|
9
|
+
};
|
|
10
|
+
b: {
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import rickLayerJson from '@/examples/latest/layers/rick-and-morty-layer.json';
|
|
2
|
+
import rickSchemaJson from '@/examples/latest/rick-and-morty-user-schema.json';
|
|
3
|
+
import { createShape } from "../../schema-util.js";
|
|
4
|
+
export const rickLayers = {
|
|
5
|
+
rick: {
|
|
6
|
+
id: 'rick',
|
|
7
|
+
schema: rickLayerJson,
|
|
8
|
+
status: 'ok'
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const rickSchema = {
|
|
12
|
+
...rickSchemaJson,
|
|
13
|
+
queries: {
|
|
14
|
+
...rickSchemaJson.queries,
|
|
15
|
+
shapeArgs: {
|
|
16
|
+
shape: 'JSON',
|
|
17
|
+
resolver: {
|
|
18
|
+
name: 'util:noop'
|
|
19
|
+
},
|
|
20
|
+
args: 'SupaArgs'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
shapes: {
|
|
24
|
+
...rickSchemaJson.shapes,
|
|
25
|
+
ArgsA: createShape('ArgsA', {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
a: {
|
|
29
|
+
type: 'boolean'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
ArgsB: createShape('ArgsB', {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
b: {
|
|
37
|
+
type: 'boolean'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
SupaArgs: createShape('SupaArgs', {
|
|
42
|
+
extends: [{ '@ref': 'local:ArgsA' }, { '@ref': 'local:ArgsB' }]
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export const expectedSupaArgsSchema = {
|
|
47
|
+
properties: {
|
|
48
|
+
a: {
|
|
49
|
+
type: 'boolean'
|
|
50
|
+
},
|
|
51
|
+
b: {
|
|
52
|
+
type: 'boolean'
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
type: 'object'
|
|
56
|
+
};
|
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const rawQuery = projectSchema.queries[queryName];
|
|
11
|
-
const queryModel = new QueryModel(projectSchemaModel, queryType, queryName);
|
|
12
|
-
test('can create from query', () => {
|
|
13
|
-
expect(queryModel instanceof QueryModel).toEqual(true);
|
|
2
|
+
import { RuntimeSchema } from "../runtime-schema.js";
|
|
3
|
+
import { expectedSupaArgsSchema, rickLayers, rickSchema } from './fixtures.js';
|
|
4
|
+
const runtimeSchema = new RuntimeSchema(rickSchema, rickLayers);
|
|
5
|
+
describe('Query', () => {
|
|
6
|
+
test('ref', () => {
|
|
7
|
+
const ref = 'rick:Query.episodes';
|
|
8
|
+
const query = runtimeSchema.getQuery(ref);
|
|
9
|
+
expect(query?.ref).toBe(ref);
|
|
14
10
|
});
|
|
15
|
-
test('
|
|
16
|
-
const
|
|
17
|
-
expect(
|
|
11
|
+
test('argsSchema - inline args', () => {
|
|
12
|
+
const argsSchema = runtimeSchema.getQuery('rick:Query.episodes')?.argsSchema;
|
|
13
|
+
expect(argsSchema?.type).toBe('object');
|
|
18
14
|
});
|
|
19
|
-
test('
|
|
20
|
-
|
|
21
|
-
expect(
|
|
22
|
-
expect(queryModel.json).toEqual(rawQuery);
|
|
23
|
-
expect(queryModel.description).toEqual(rawQuery.description);
|
|
24
|
-
expect(queryModel.resolver).toEqual(rawQuery.resolver);
|
|
25
|
-
expect(queryModel.returnShape).toEqual(rawQuery.shape);
|
|
15
|
+
test('argsSchema - shape args', () => {
|
|
16
|
+
const argsSchema = runtimeSchema.getQuery('shapeArgs')?.argsSchema;
|
|
17
|
+
expect(argsSchema).toEqual(expectedSupaArgsSchema);
|
|
26
18
|
});
|
|
27
19
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { RuntimeSchema } from "../runtime-schema.js";
|
|
3
|
+
import { rickLayers, rickSchema } from './fixtures.js';
|
|
4
|
+
describe('RuntimeSchema', () => {
|
|
5
|
+
const runtimeSchema = new RuntimeSchema(rickSchema, rickLayers);
|
|
6
|
+
test('getShape - local', () => {
|
|
7
|
+
const ref = 'local:Asset';
|
|
8
|
+
const assetFromRef = runtimeSchema.getShape(ref);
|
|
9
|
+
const assetFromName = runtimeSchema.getShape('Asset');
|
|
10
|
+
expect(assetFromName?.ref).toBe(ref);
|
|
11
|
+
expect(assetFromName).toBe(assetFromRef);
|
|
12
|
+
});
|
|
13
|
+
test('getShape - overridden', () => {
|
|
14
|
+
const ref = 'rick:Character';
|
|
15
|
+
const shapeFromRef = runtimeSchema.getShape(ref);
|
|
16
|
+
const shapeFromName = runtimeSchema.getShape('Rick_Character');
|
|
17
|
+
expect(shapeFromRef?.ref).toBe(ref);
|
|
18
|
+
expect(shapeFromRef).toBe(shapeFromName);
|
|
19
|
+
});
|
|
20
|
+
test('getShape - remote', () => {
|
|
21
|
+
const ref = 'rick:FilterEpisode';
|
|
22
|
+
const shape = runtimeSchema.getShape(ref);
|
|
23
|
+
expect(shape?.ref).toBe(ref);
|
|
24
|
+
});
|
|
25
|
+
test('getQuery - local', () => {
|
|
26
|
+
const queryFromName = runtimeSchema.getQuery('getAssetList');
|
|
27
|
+
const queryFromRef = runtimeSchema.getQuery('Query.getAssetList');
|
|
28
|
+
expect(queryFromName).toBeTruthy();
|
|
29
|
+
expect(queryFromName).toEqual(queryFromRef);
|
|
30
|
+
});
|
|
31
|
+
test('getQuery - overridden', () => {
|
|
32
|
+
const ref = 'rick:Query.characters';
|
|
33
|
+
const queryFromName = runtimeSchema.getQuery(ref);
|
|
34
|
+
const queryFromRef = runtimeSchema.getQuery('Query.Rick_characters');
|
|
35
|
+
expect(queryFromName?.ref).toBe(ref);
|
|
36
|
+
expect(queryFromName).toEqual(queryFromRef);
|
|
37
|
+
});
|
|
38
|
+
test('getQuery - remote', () => {
|
|
39
|
+
const ref = 'rick:Query.episodes';
|
|
40
|
+
const query = runtimeSchema.getQuery(ref);
|
|
41
|
+
expect(query?.ref).toEqual(ref);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -1,61 +1,24 @@
|
|
|
1
1
|
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const shapeRef = 'local:Asset';
|
|
9
|
-
const shapeRefItem = {
|
|
10
|
-
isForeign: false,
|
|
2
|
+
import { expectedSupaArgsSchema, rickLayers, rickSchema } from '@/src/models/__tests__/fixtures.js';
|
|
3
|
+
import { RuntimeSchema } from "../runtime-schema.js";
|
|
4
|
+
import { Shape } from "../shape.js";
|
|
5
|
+
const runtimeSchema = new RuntimeSchema(rickSchema, rickLayers);
|
|
6
|
+
describe('Shape', () => {
|
|
7
|
+
const refItem = {
|
|
11
8
|
serviceKey: 'local',
|
|
12
|
-
typeName: '
|
|
13
|
-
|
|
9
|
+
typeName: 'SupaArgs',
|
|
10
|
+
isForeign: false,
|
|
11
|
+
isValidService: true,
|
|
12
|
+
isLocal: true
|
|
14
13
|
};
|
|
15
|
-
const rawShape =
|
|
16
|
-
const
|
|
17
|
-
test('
|
|
18
|
-
expect(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expect(() => new ShapeModel(projectSchemaModel, 'local:Bogus')).toThrowError('Error creating shape model: local:Bogus is not in project schema');
|
|
22
|
-
});
|
|
23
|
-
test('created using ref item', () => {
|
|
24
|
-
const shapeModelCreatedUsingRefItem = new ShapeModel(projectSchemaModel, {
|
|
25
|
-
isForeign: false,
|
|
26
|
-
serviceKey: 'local',
|
|
27
|
-
typeName: 'Asset',
|
|
28
|
-
isValidService: true
|
|
29
|
-
});
|
|
30
|
-
expect(shapeModelCreatedUsingRefItem instanceof ShapeModel).toEqual(true);
|
|
31
|
-
});
|
|
32
|
-
test('invalid ref item', () => {
|
|
33
|
-
expect(() => new ShapeModel(projectSchemaModel, {
|
|
34
|
-
isForeign: false,
|
|
35
|
-
serviceKey: 'local',
|
|
36
|
-
typeName: 'Bogus',
|
|
37
|
-
isValidService: true
|
|
38
|
-
})).toThrowError('Error creating shape model: ref item argument could not be resolved to a shape');
|
|
39
|
-
});
|
|
40
|
-
test('basic accessors', () => {
|
|
41
|
-
expect(shapeModel.json).toEqual(rawShape);
|
|
42
|
-
expect(shapeModel.id).toEqual(rawShape.id);
|
|
43
|
-
expect(shapeModel.name).toEqual(rawShape.name);
|
|
44
|
-
expect(shapeModel.title).toEqual(rawShape.title);
|
|
45
|
-
expect(shapeModel.description).toEqual(rawShape.description);
|
|
46
|
-
expect(shapeModel.schema).toEqual(rawShape.schema);
|
|
47
|
-
expect(shapeModel.schemaPropertyList.getValues().length).toEqual(21);
|
|
48
|
-
expect(shapeModel.schemaPropertyAccessor.getValue('uploadStatus').title).toEqual('Upload status');
|
|
49
|
-
expect(shapeModel.refString).toEqual(shapeRef);
|
|
50
|
-
expect(shapeModel.refItem).toEqual(shapeRefItem);
|
|
51
|
-
expect(shapeModel.serviceId).toEqual('local');
|
|
52
|
-
expect(shapeModel.modelType).toEqual('multiple');
|
|
53
|
-
expect(shapeModel.interfaces).toEqual(undefined);
|
|
14
|
+
const rawShape = rickSchema.shapes.SupaArgs;
|
|
15
|
+
const shape = new Shape(runtimeSchema, refItem, rawShape);
|
|
16
|
+
test('getters', () => {
|
|
17
|
+
expect(shape.name).toBe(rawShape.name);
|
|
18
|
+
expect(shape.ref).toBe('local:SupaArgs');
|
|
19
|
+
expect(shape.refItem).toBe(refItem);
|
|
54
20
|
});
|
|
55
|
-
test('
|
|
56
|
-
expect(
|
|
57
|
-
expect(shapeModel.isCached).toEqual(false);
|
|
58
|
-
expect(shapeModel.isAsset).toEqual(true);
|
|
59
|
-
expect(shapeModel.isInterfaceShape).toEqual(false);
|
|
21
|
+
test('getObjectSchema', () => {
|
|
22
|
+
expect(shape.getObjectSchema()).toEqual(expectedSupaArgsSchema);
|
|
60
23
|
});
|
|
61
24
|
});
|
package/dist/models/query.d.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
private readonly _rawQuery;
|
|
10
|
-
constructor(projectSchemaModel: IProjectSchema, _queryType: 'query' | 'mutation', _queryName: string);
|
|
11
|
-
get queryType(): "query" | "mutation";
|
|
12
|
-
get name(): string;
|
|
13
|
-
get json(): QueryJSON;
|
|
14
|
-
get description(): string | undefined;
|
|
15
|
-
get resolver(): import("../project-schema/latest.ts").Resolver;
|
|
16
|
-
get returnShape(): import("../project-schema/latest.ts").ReturnShape;
|
|
1
|
+
import type { ObjectSchema } from '../project-schema/latest.ts';
|
|
2
|
+
import { type QueryEntry } from '../refs.ts';
|
|
3
|
+
import type { IRuntimeSchema } from './types.ts';
|
|
4
|
+
export declare class Query {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(parent: IRuntimeSchema, entry: QueryEntry);
|
|
7
|
+
get ref(): string;
|
|
8
|
+
get argsSchema(): ObjectSchema | undefined;
|
|
17
9
|
}
|
package/dist/models/query.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this
|
|
10
|
-
this
|
|
11
|
-
this
|
|
1
|
+
import { serializePropertyRef } from "../refs.js";
|
|
2
|
+
export class Query {
|
|
3
|
+
#parent;
|
|
4
|
+
#name;
|
|
5
|
+
#query;
|
|
6
|
+
#ref;
|
|
7
|
+
constructor(parent, entry) {
|
|
8
|
+
this.#parent = parent;
|
|
9
|
+
this.#name = entry.name;
|
|
10
|
+
this.#query = entry.query;
|
|
11
|
+
this.#ref = entry.ref;
|
|
12
12
|
}
|
|
13
|
-
get
|
|
14
|
-
return this
|
|
13
|
+
get ref() {
|
|
14
|
+
return serializePropertyRef(this.#ref);
|
|
15
15
|
}
|
|
16
|
-
get
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
get resolver() {
|
|
26
|
-
return this.json.resolver;
|
|
27
|
-
}
|
|
28
|
-
get returnShape() {
|
|
29
|
-
return this.json.shape;
|
|
16
|
+
get argsSchema() {
|
|
17
|
+
const args = this.#query.args;
|
|
18
|
+
if (args) {
|
|
19
|
+
if (typeof args === 'object') {
|
|
20
|
+
return args;
|
|
21
|
+
}
|
|
22
|
+
return this.#parent.getShape(args)?.getObjectSchema();
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
30
25
|
}
|
|
31
26
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProjectSchemaJSON, PropertySchema } from '../project-schema/index.ts';
|
|
2
|
+
import type { ServiceLayers } from '../types/types.ts';
|
|
3
|
+
import { Query } from './query.js';
|
|
4
|
+
import { Shape } from './shape.js';
|
|
5
|
+
import type { IRuntimeSchema } from './types.ts';
|
|
6
|
+
export declare class RuntimeSchema implements IRuntimeSchema {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(userSchema: ProjectSchemaJSON, layers: ServiceLayers);
|
|
9
|
+
get runtimeSchemaJson(): ProjectSchemaJSON;
|
|
10
|
+
getShape(rawShapeRef: string): Shape | undefined;
|
|
11
|
+
getQuery(rawQueryRef: string): Query | undefined;
|
|
12
|
+
dereferenceSchema(propertySchema: PropertySchema): PropertySchema;
|
|
13
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { dereferenceSchema, getQuery, normalizePropertyRef, normalizeRefExpression, parsePropertyRef, refExpressionToRefItem, refItemToNamespacedShapeName } from "../refs.js";
|
|
2
|
+
import { buildRuntimeSchema } from "../runtime-schema.js";
|
|
3
|
+
import { getShape } from "../util/shapes.js";
|
|
4
|
+
import { Query } from './query.js';
|
|
5
|
+
import { Shape } from './shape.js';
|
|
6
|
+
export class RuntimeSchema {
|
|
7
|
+
#userSchema;
|
|
8
|
+
#runtimeSchema;
|
|
9
|
+
#layers;
|
|
10
|
+
#shapeCache;
|
|
11
|
+
#queryCache;
|
|
12
|
+
constructor(userSchema, layers) {
|
|
13
|
+
this.#userSchema = userSchema;
|
|
14
|
+
this.#layers = layers;
|
|
15
|
+
this.#shapeCache = new Map();
|
|
16
|
+
this.#queryCache = new Map();
|
|
17
|
+
}
|
|
18
|
+
get runtimeSchemaJson() {
|
|
19
|
+
if (!this.#runtimeSchema) {
|
|
20
|
+
this.#runtimeSchema = buildRuntimeSchema(this.#userSchema, this.#layers, console.log);
|
|
21
|
+
}
|
|
22
|
+
return this.#runtimeSchema;
|
|
23
|
+
}
|
|
24
|
+
getShape(rawShapeRef) {
|
|
25
|
+
const shapeRef = normalizeRefExpression(this.#userSchema, rawShapeRef);
|
|
26
|
+
let shape = this.#shapeCache.get(shapeRef);
|
|
27
|
+
if (!shape) {
|
|
28
|
+
const refItem = refExpressionToRefItem(this.runtimeSchemaJson, rawShapeRef);
|
|
29
|
+
if (refItem) {
|
|
30
|
+
const namespacedName = refItemToNamespacedShapeName(refItem);
|
|
31
|
+
const shapeJson = getShape(this.runtimeSchemaJson, namespacedName);
|
|
32
|
+
if (shapeJson) {
|
|
33
|
+
shape = new Shape(this, refItem, shapeJson);
|
|
34
|
+
this.#shapeCache.set(shapeRef, shape);
|
|
35
|
+
}
|
|
36
|
+
else if (refItem.serviceKey !== 'local') {
|
|
37
|
+
const layerSchema = this.#layers[refItem.serviceKey]?.schema;
|
|
38
|
+
if (layerSchema) {
|
|
39
|
+
const shapeJson = getShape(layerSchema, namespacedName);
|
|
40
|
+
if (shapeJson) {
|
|
41
|
+
shape = new Shape(this, refItem, shapeJson);
|
|
42
|
+
this.#shapeCache.set(shapeRef, shape);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return shape;
|
|
49
|
+
}
|
|
50
|
+
getQuery(rawQueryRef) {
|
|
51
|
+
const queryRef = normalizePropertyRef(rawQueryRef);
|
|
52
|
+
let query = this.#queryCache.get(queryRef);
|
|
53
|
+
if (!query) {
|
|
54
|
+
const queryEntry = getQuery(this.runtimeSchemaJson, queryRef);
|
|
55
|
+
if (queryEntry) {
|
|
56
|
+
query = new Query(this, queryEntry);
|
|
57
|
+
this.#queryCache.set(queryRef, query);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const parsedRef = parsePropertyRef(queryRef);
|
|
61
|
+
if (parsedRef && parsedRef.serviceId !== 'local') {
|
|
62
|
+
const layerSchema = this.#layers[parsedRef.serviceId]?.schema;
|
|
63
|
+
if (layerSchema) {
|
|
64
|
+
const queryEntry = getQuery(layerSchema, parsedRef.propertyName);
|
|
65
|
+
if (queryEntry) {
|
|
66
|
+
query = new Query(this, { ...queryEntry, ref: parsedRef });
|
|
67
|
+
this.#queryCache.set(queryRef, query);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return query;
|
|
74
|
+
}
|
|
75
|
+
dereferenceSchema(propertySchema) {
|
|
76
|
+
return dereferenceSchema(this.runtimeSchemaJson, propertySchema);
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/models/shape.d.ts
CHANGED
|
@@ -1,41 +1,11 @@
|
|
|
1
|
-
import type { ShapeJSON } from '../project-schema/
|
|
1
|
+
import type { ShapeJSON } from '../project-schema/latest.ts';
|
|
2
2
|
import { type RefItem } from '../refs.ts';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare class ShapeModel {
|
|
8
|
-
private readonly _projectSchemaModel;
|
|
9
|
-
private readonly _rawShape;
|
|
10
|
-
private readonly _shapeRefItem;
|
|
11
|
-
private readonly _shapeAtRef;
|
|
12
|
-
constructor(_projectSchemaModel: IProjectSchema, refArg: RefItem | string);
|
|
13
|
-
get json(): ShapeJSON;
|
|
14
|
-
get id(): string;
|
|
3
|
+
import type { IRuntimeSchema } from './types.ts';
|
|
4
|
+
export declare class Shape {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(parent: IRuntimeSchema, ref: RefItem, shape: ShapeJSON);
|
|
15
7
|
get name(): string;
|
|
16
|
-
get
|
|
17
|
-
get description(): string | undefined;
|
|
18
|
-
get schema(): import("../project-schema/latest.ts").ShapeSchema;
|
|
19
|
-
get schemaPropertyList(): {
|
|
20
|
-
_propertyIterator: Map<string, import("../project-schema/latest.ts").PropertySchema>;
|
|
21
|
-
orderBy: (iteratees?: ((n: import("../types/types.ts").SchemaPropertyNode) => string)[], orders?: ("asc" | "desc")[]) => /*elided*/ any;
|
|
22
|
-
sortWith: (comparator?: (a: import("../types/types.ts").SchemaPropertyNode, b: import("../types/types.ts").SchemaPropertyNode) => number) => /*elided*/ any;
|
|
23
|
-
sortByNamesWithList: (comparatorArray?: string[]) => /*elided*/ any;
|
|
24
|
-
filterBy: (predicate: (n: import("../types/types.ts").SchemaPropertyNode) => boolean) => /*elided*/ any;
|
|
25
|
-
forEach: (iteratee: (n: import("../types/types.ts").SchemaPropertyNode) => void) => /*elided*/ any;
|
|
26
|
-
getNodes: () => import("../types/types.ts").SchemaPropertyNode[];
|
|
27
|
-
getObject: () => Record<string, import("../project-schema/latest.ts").PropertySchema>;
|
|
28
|
-
getNames: () => import("../types/types.ts").SchemaPropertyName[];
|
|
29
|
-
getValues: () => import("../project-schema/latest.ts").PropertySchema[];
|
|
30
|
-
};
|
|
31
|
-
get schemaPropertyAccessor(): import("../schema-util.ts").SchemaPropertyAccessor;
|
|
32
|
-
get refString(): string;
|
|
8
|
+
get ref(): string;
|
|
33
9
|
get refItem(): RefItem;
|
|
34
|
-
|
|
35
|
-
get modelType(): import("../project-schema/latest.ts").ModelType | undefined;
|
|
36
|
-
get interfaces(): string[] | undefined;
|
|
37
|
-
get isModel(): boolean;
|
|
38
|
-
get isCached(): boolean;
|
|
39
|
-
get isAsset(): boolean;
|
|
40
|
-
get isInterfaceShape(): boolean;
|
|
10
|
+
getObjectSchema(): import("../project-schema/latest.ts").ObjectSchema | undefined;
|
|
41
11
|
}
|
package/dist/models/shape.js
CHANGED
|
@@ -1,85 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_shapeAtRef;
|
|
13
|
-
constructor(_projectSchemaModel, refArg) {
|
|
14
|
-
this._projectSchemaModel = _projectSchemaModel;
|
|
15
|
-
if (typeof refArg === 'string') {
|
|
16
|
-
const rawShape = getShapeByRef(_projectSchemaModel.json, refArg);
|
|
17
|
-
if (!rawShape) {
|
|
18
|
-
throw new Error(`Error creating shape model: ${refArg} is not in project schema`);
|
|
19
|
-
}
|
|
20
|
-
this._rawShape = rawShape;
|
|
21
|
-
this._shapeRefItem = _projectSchemaModel.atRefToRefItem(refArg);
|
|
22
|
-
this._shapeAtRef = refArg;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const rawShape = refItemToShape(_projectSchemaModel.json, refArg);
|
|
26
|
-
if (!rawShape) {
|
|
27
|
-
throw new Error('Error creating shape model: ref item argument could not be resolved to a shape');
|
|
28
|
-
}
|
|
29
|
-
this._rawShape = rawShape;
|
|
30
|
-
this._shapeRefItem = refArg;
|
|
31
|
-
this._shapeAtRef = `${refArg.serviceKey}:${refArg.typeName}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
get json() {
|
|
35
|
-
return this._rawShape;
|
|
36
|
-
}
|
|
37
|
-
get id() {
|
|
38
|
-
return this._rawShape.id;
|
|
1
|
+
import { refItemToAtRef } from "../refs.js";
|
|
2
|
+
import { isObjectSchema } from "../types/utils.js";
|
|
3
|
+
export class Shape {
|
|
4
|
+
#parent;
|
|
5
|
+
#ref;
|
|
6
|
+
#shape;
|
|
7
|
+
#dereferencedSchema;
|
|
8
|
+
constructor(parent, ref, shape) {
|
|
9
|
+
this.#parent = parent;
|
|
10
|
+
this.#ref = ref;
|
|
11
|
+
this.#shape = shape;
|
|
39
12
|
}
|
|
40
13
|
get name() {
|
|
41
|
-
return this.
|
|
42
|
-
}
|
|
43
|
-
get title() {
|
|
44
|
-
return this._rawShape.title;
|
|
45
|
-
}
|
|
46
|
-
get description() {
|
|
47
|
-
return this._rawShape.description;
|
|
48
|
-
}
|
|
49
|
-
get schema() {
|
|
50
|
-
return this._rawShape.schema;
|
|
51
|
-
}
|
|
52
|
-
get schemaPropertyList() {
|
|
53
|
-
return createSchemaPropertyList(this._projectSchemaModel.json, this._rawShape);
|
|
54
|
-
}
|
|
55
|
-
get schemaPropertyAccessor() {
|
|
56
|
-
return createSchemaPropertyAccessor(this._projectSchemaModel.json, this._rawShape);
|
|
14
|
+
return this.#shape.name;
|
|
57
15
|
}
|
|
58
|
-
get
|
|
59
|
-
return this
|
|
16
|
+
get ref() {
|
|
17
|
+
return refItemToAtRef(this.#ref);
|
|
60
18
|
}
|
|
61
19
|
get refItem() {
|
|
62
|
-
return this
|
|
20
|
+
return this.#ref;
|
|
63
21
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return this._rawShape.interfaces;
|
|
72
|
-
}
|
|
73
|
-
get isModel() {
|
|
74
|
-
return isModelShape(this._rawShape);
|
|
75
|
-
}
|
|
76
|
-
get isCached() {
|
|
77
|
-
return isCachedShape(this._rawShape);
|
|
78
|
-
}
|
|
79
|
-
get isAsset() {
|
|
80
|
-
return this._rawShape.id === 'ASSET';
|
|
81
|
-
}
|
|
82
|
-
get isInterfaceShape() {
|
|
83
|
-
return isInterfaceShape(this._rawShape);
|
|
22
|
+
getObjectSchema() {
|
|
23
|
+
if (!this.#dereferencedSchema) {
|
|
24
|
+
this.#dereferencedSchema = this.#parent.dereferenceSchema(this.#shape.schema);
|
|
25
|
+
}
|
|
26
|
+
if (isObjectSchema(this.#dereferencedSchema)) {
|
|
27
|
+
return this.#dereferencedSchema;
|
|
28
|
+
}
|
|
84
29
|
}
|
|
85
30
|
}
|
package/dist/models/types.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { Query } from '@/src/models/query.js';
|
|
2
|
+
import type { Shape } from '@/src/models/shape.js';
|
|
3
|
+
import type { PropertySchema } from '../project-schema/index.ts';
|
|
4
|
+
export interface IRuntimeSchema {
|
|
5
|
+
getShape(shapeRef: string): Shape | undefined;
|
|
6
|
+
getQuery(queryRef: string): Query | undefined;
|
|
7
|
+
dereferenceSchema(propertySchema: PropertySchema): PropertySchema;
|
|
6
8
|
}
|
package/dist/refs.d.ts
CHANGED
|
@@ -221,6 +221,6 @@ export type QueryEntry = {
|
|
|
221
221
|
query: QueryJSON;
|
|
222
222
|
ref: PropertyRefItem;
|
|
223
223
|
};
|
|
224
|
-
export declare function getQuery(projectSchema: ProjectSchemaJSON, queryRef: string): Maybe<QueryEntry>;
|
|
224
|
+
export declare function getQuery(projectSchema: Pick<ProjectSchemaJSON, 'services' | 'shapes' | 'queries' | 'mutations'>, queryRef: string): Maybe<QueryEntry>;
|
|
225
225
|
export declare function ensureQuery(projectSchema: ProjectSchemaJSON, queryRef: string): QueryEntry;
|
|
226
226
|
export declare function normalizeRefs(projectSchema: ProjectSchemaJSON, property: PropertySchema): PropertySchema;
|
|
@@ -5,7 +5,9 @@ export type KeyTransform = (name: string, schema: PropertySchema, sourceKey?: st
|
|
|
5
5
|
export type PropertyTransform = {
|
|
6
6
|
keyTransform?: KeyTransform;
|
|
7
7
|
filter(schema: PropertySchema, name: string, shape?: ShapeJSON): boolean;
|
|
8
|
-
process(value: unknown, schema: PropertySchema
|
|
8
|
+
process(value: unknown, schema: PropertySchema & {
|
|
9
|
+
$parent?: PropertySchema;
|
|
10
|
+
}, name: string, shape: ShapeJSON | undefined, next: (value: unknown, schema: PropertySchema, name: string) => unknown): unknown;
|
|
9
11
|
};
|
|
10
12
|
export type SchemaType = '*' | 'object' | 'array' | 'string' | 'number' | 'integer' | 'boolean';
|
|
11
13
|
export type PropertyTransformMap = {
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projectId": "a8b9ea5b-2522-442d-9b68-be0bef4a1a74",
|
|
3
|
+
"defaultLocale": "en-us",
|
|
4
|
+
"locales": ["en-us"],
|
|
5
|
+
"queries": {
|
|
6
|
+
"Rick_characters": {
|
|
7
|
+
"resolver": {
|
|
8
|
+
"name": "graphql:query",
|
|
9
|
+
"service": "rick",
|
|
10
|
+
"fieldName": "characters"
|
|
11
|
+
},
|
|
12
|
+
"args": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"properties": {
|
|
15
|
+
"page": { "type": "integer" },
|
|
16
|
+
"filter": { "@ref": "rick:FilterCharacter" }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"shape": "Rick_Characters"
|
|
20
|
+
},
|
|
21
|
+
"getIndexedRickCharacterList": {
|
|
22
|
+
"shape": "PaginatedList<Rick_Character>",
|
|
23
|
+
"resolver": {
|
|
24
|
+
"shapeName": "Rick_Character",
|
|
25
|
+
"name": "takeshape:queryApiIndex",
|
|
26
|
+
"service": "takeshape",
|
|
27
|
+
"options": { "indexedShape": "Rick_Character" }
|
|
28
|
+
},
|
|
29
|
+
"description": "Fetch Rick_Character data from the API Index.",
|
|
30
|
+
"args": "TSListArgs<Rick_Character>"
|
|
31
|
+
},
|
|
32
|
+
"Rick_character": {
|
|
33
|
+
"resolver": {
|
|
34
|
+
"name": "graphql:query",
|
|
35
|
+
"service": "rick",
|
|
36
|
+
"fieldName": "character"
|
|
37
|
+
},
|
|
38
|
+
"args": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"properties": { "id": { "type": "string", "@tag": "id" } },
|
|
41
|
+
"required": ["id"]
|
|
42
|
+
},
|
|
43
|
+
"shape": "Rick_Character"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"mutations": {},
|
|
47
|
+
"shapes": {
|
|
48
|
+
"Rick_Character": {
|
|
49
|
+
"id": "Rick_Character",
|
|
50
|
+
"name": "Rick_Character",
|
|
51
|
+
"title": "Rick Character",
|
|
52
|
+
"cache": {
|
|
53
|
+
"enabled": true,
|
|
54
|
+
"triggers": [{ "type": "schedule", "loader": "list", "interval": 1440 }],
|
|
55
|
+
"fragment": { "maxDepth": 2 }
|
|
56
|
+
},
|
|
57
|
+
"loaders": {
|
|
58
|
+
"list": { "query": "rick:Query.characters" },
|
|
59
|
+
"get": { "query": "rick:Query.character" }
|
|
60
|
+
},
|
|
61
|
+
"schema": {
|
|
62
|
+
"extends": [
|
|
63
|
+
{ "@ref": "rick:Character" },
|
|
64
|
+
{
|
|
65
|
+
"type": "object",
|
|
66
|
+
"properties": {
|
|
67
|
+
"custom": {
|
|
68
|
+
"@mapping": "shapedb:Rick_Character.qg6KuTt2V",
|
|
69
|
+
"type": "string",
|
|
70
|
+
"title": "Custom"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"workflows": {},
|
|
79
|
+
"forms": {
|
|
80
|
+
"Rick_Character": {
|
|
81
|
+
"default": {
|
|
82
|
+
"properties": { "custom": { "widget": "singleLineText" } },
|
|
83
|
+
"order": ["custom"]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"schemaVersion": "3.53.0",
|
|
88
|
+
"apiVersion": "2",
|
|
89
|
+
"services": {
|
|
90
|
+
"rick": {
|
|
91
|
+
"id": "rick",
|
|
92
|
+
"title": "Rick",
|
|
93
|
+
"namespace": "Rick",
|
|
94
|
+
"provider": "graphql",
|
|
95
|
+
"serviceType": "graphql",
|
|
96
|
+
"authenticationType": "none",
|
|
97
|
+
"options": {
|
|
98
|
+
"endpoint": "https://rickandmortyapi.com/graphql",
|
|
99
|
+
"introspectedAt": "2025-04-23T18:13:21.722Z"
|
|
100
|
+
},
|
|
101
|
+
"healthCheck": { "checkName": "graphqlIntrospection" }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projectId": "a8b9ea5b-2522-442d-9b68-be0bef4a1a74",
|
|
3
|
+
"defaultLocale": "en-us",
|
|
4
|
+
"locales": ["en-us"],
|
|
5
|
+
"queries": {
|
|
6
|
+
"Rick_characters": {
|
|
7
|
+
"resolver": {
|
|
8
|
+
"name": "graphql:query",
|
|
9
|
+
"service": "rick",
|
|
10
|
+
"fieldName": "characters"
|
|
11
|
+
},
|
|
12
|
+
"args": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"properties": {
|
|
15
|
+
"page": { "type": "integer" },
|
|
16
|
+
"filter": { "@ref": "rick:FilterCharacter" }
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"shape": "Rick_Characters"
|
|
20
|
+
},
|
|
21
|
+
"getIndexedRickCharacterList": {
|
|
22
|
+
"shape": "PaginatedList<Rick_Character>",
|
|
23
|
+
"resolver": {
|
|
24
|
+
"shapeName": "Rick_Character",
|
|
25
|
+
"name": "takeshape:queryApiIndex",
|
|
26
|
+
"service": "takeshape",
|
|
27
|
+
"options": { "indexedShape": "Rick_Character" }
|
|
28
|
+
},
|
|
29
|
+
"description": "Fetch Rick_Character data from the API Index.",
|
|
30
|
+
"args": "TSListArgs<Rick_Character>"
|
|
31
|
+
},
|
|
32
|
+
"Rick_character": {
|
|
33
|
+
"resolver": {
|
|
34
|
+
"name": "graphql:query",
|
|
35
|
+
"service": "rick",
|
|
36
|
+
"fieldName": "character"
|
|
37
|
+
},
|
|
38
|
+
"args": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"properties": { "id": { "type": "string", "@tag": "id" } },
|
|
41
|
+
"required": ["id"]
|
|
42
|
+
},
|
|
43
|
+
"shape": "Rick_Character"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"mutations": {},
|
|
47
|
+
"shapes": {
|
|
48
|
+
"Rick_Character": {
|
|
49
|
+
"id": "Rick_Character",
|
|
50
|
+
"name": "Rick_Character",
|
|
51
|
+
"title": "Rick Character",
|
|
52
|
+
"cache": {
|
|
53
|
+
"enabled": true,
|
|
54
|
+
"triggers": [{ "type": "schedule", "loader": "list", "interval": 1440 }],
|
|
55
|
+
"fragment": { "maxDepth": 2 }
|
|
56
|
+
},
|
|
57
|
+
"loaders": {
|
|
58
|
+
"list": { "query": "rick:Query.characters" },
|
|
59
|
+
"get": { "query": "rick:Query.character" }
|
|
60
|
+
},
|
|
61
|
+
"schema": {
|
|
62
|
+
"extends": [
|
|
63
|
+
{ "@ref": "rick:Character" },
|
|
64
|
+
{
|
|
65
|
+
"type": "object",
|
|
66
|
+
"properties": {
|
|
67
|
+
"custom": {
|
|
68
|
+
"@mapping": "shapedb:Rick_Character.qg6KuTt2V",
|
|
69
|
+
"type": "string",
|
|
70
|
+
"title": "Custom"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"workflows": {},
|
|
79
|
+
"forms": {
|
|
80
|
+
"Rick_Character": {
|
|
81
|
+
"default": {
|
|
82
|
+
"properties": { "custom": { "widget": "singleLineText" } },
|
|
83
|
+
"order": ["custom"]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"schemaVersion": "3.53.0",
|
|
88
|
+
"apiVersion": "2",
|
|
89
|
+
"services": {
|
|
90
|
+
"rick": {
|
|
91
|
+
"id": "rick",
|
|
92
|
+
"title": "Rick",
|
|
93
|
+
"namespace": "Rick",
|
|
94
|
+
"provider": "graphql",
|
|
95
|
+
"serviceType": "graphql",
|
|
96
|
+
"authenticationType": "none",
|
|
97
|
+
"options": {
|
|
98
|
+
"endpoint": "https://rickandmortyapi.com/graphql",
|
|
99
|
+
"introspectedAt": "2025-04-23T18:13:21.722Z"
|
|
100
|
+
},
|
|
101
|
+
"healthCheck": { "checkName": "graphqlIntrospection" }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.70.2",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"p-reduce": "^2.1.0",
|
|
57
57
|
"semver": "^7.3.2",
|
|
58
58
|
"tiny-invariant": "^1.2.0",
|
|
59
|
-
"@takeshape/errors": "11.
|
|
60
|
-
"@takeshape/json-schema": "11.
|
|
61
|
-
"@takeshape/util": "11.
|
|
59
|
+
"@takeshape/errors": "11.70.2",
|
|
60
|
+
"@takeshape/json-schema": "11.70.2",
|
|
61
|
+
"@takeshape/util": "11.70.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@takeshape/json-schema-to-typescript": "^11.0.0",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"glob": "^7.1.6",
|
|
74
74
|
"meow": "^9.0.0",
|
|
75
75
|
"shortid": "^2.2.15",
|
|
76
|
-
"@takeshape/infra": "11.
|
|
76
|
+
"@takeshape/infra": "11.70.2"
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|
|
79
79
|
"node": ">=20"
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import shopifySchemaJson from '@/examples/latest/shopify-store-with-widget.json';
|
|
3
|
-
import { ProjectSchema } from "../project-schema.js";
|
|
4
|
-
import { QueryModel } from "../query.js";
|
|
5
|
-
import { ServiceConfig } from "../service.js";
|
|
6
|
-
import { ShapeModel } from "../shape.js";
|
|
7
|
-
const projectSchema = shopifySchemaJson;
|
|
8
|
-
describe('ProjectSchemaModel', () => {
|
|
9
|
-
const projectSchemaModel = new ProjectSchema(projectSchema);
|
|
10
|
-
test('basic accessors', () => {
|
|
11
|
-
expect(projectSchemaModel.json).toEqual(projectSchema);
|
|
12
|
-
expect(projectSchemaModel.projectId).toEqual(projectSchema.projectId);
|
|
13
|
-
expect(projectSchemaModel.$schema).toEqual(projectSchema.$schema);
|
|
14
|
-
expect(projectSchemaModel.author).toEqual(projectSchema.author);
|
|
15
|
-
expect(projectSchemaModel.getShapeByName('Asset') instanceof ShapeModel).toEqual(true);
|
|
16
|
-
expect(projectSchemaModel.getShapeByName('Bogus')).toBeUndefined();
|
|
17
|
-
expect(projectSchemaModel.getShapeById('ASSET') instanceof ShapeModel).toEqual(true);
|
|
18
|
-
expect(projectSchemaModel.getShapeById('Bogus')).toBeUndefined();
|
|
19
|
-
expect(projectSchemaModel.getShapeByRef('local:Asset') instanceof ShapeModel).toEqual(true);
|
|
20
|
-
expect(projectSchemaModel.refs.length).toEqual(429);
|
|
21
|
-
expect(projectSchemaModel.getQueryByName('getAssetList') instanceof QueryModel).toEqual(true);
|
|
22
|
-
expect(projectSchemaModel.getMutationByName('updateAsset') instanceof QueryModel).toEqual(true);
|
|
23
|
-
expect(projectSchemaModel.getServiceById('gregs-takeshape-store') instanceof ServiceConfig).toEqual(true);
|
|
24
|
-
});
|
|
25
|
-
test('getShapeByName', () => {
|
|
26
|
-
expect(projectSchemaModel.getShapeByRef('local:Asset') instanceof ShapeModel).toEqual(true);
|
|
27
|
-
});
|
|
28
|
-
test('allShapes', () => {
|
|
29
|
-
const allShapes = projectSchemaModel.shapes;
|
|
30
|
-
expect(allShapes.length).toEqual(213);
|
|
31
|
-
for (const shapeModel of allShapes) {
|
|
32
|
-
expect(shapeModel instanceof ShapeModel).toEqual(true);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
test('queries', () => {
|
|
36
|
-
const queries = projectSchemaModel.queries;
|
|
37
|
-
expect(queries.length).toEqual(8);
|
|
38
|
-
for (const queryModel of queries) {
|
|
39
|
-
expect(queryModel instanceof QueryModel).toEqual(true);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
test('mutations', () => {
|
|
43
|
-
const mutations = projectSchemaModel.mutations;
|
|
44
|
-
expect(mutations.length).toEqual(18);
|
|
45
|
-
for (const mutationModel of mutations) {
|
|
46
|
-
expect(mutationModel instanceof QueryModel).toEqual(true);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
test('basic utils', () => {
|
|
50
|
-
const assetName = 'Asset';
|
|
51
|
-
const assetAtRef = 'local:Asset';
|
|
52
|
-
const assetRefItem = {
|
|
53
|
-
isForeign: false,
|
|
54
|
-
serviceKey: 'local',
|
|
55
|
-
typeName: assetName,
|
|
56
|
-
isValidService: true
|
|
57
|
-
};
|
|
58
|
-
const assetRefSchema = {
|
|
59
|
-
'@ref': assetAtRef
|
|
60
|
-
};
|
|
61
|
-
expect(projectSchemaModel.atRefToRefItem(assetAtRef)).toEqual(assetRefItem);
|
|
62
|
-
expect(projectSchemaModel.refItemToShape(assetRefItem) instanceof ShapeModel).toEqual(true);
|
|
63
|
-
expect(projectSchemaModel.getRef(assetRefSchema)).toEqual(assetRefItem);
|
|
64
|
-
expect(projectSchemaModel.normalizeRefExpression(assetName)).toEqual(assetAtRef);
|
|
65
|
-
expect(projectSchemaModel.refExpressionToRefItem(assetName)).toEqual(assetRefItem);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import shopifySchemaJson from '@/examples/latest/shopify-store-with-widget.json';
|
|
3
|
-
import { ProjectSchema } from "../project-schema.js";
|
|
4
|
-
import { ServiceConfig } from "../service.js";
|
|
5
|
-
const projectSchema = shopifySchemaJson;
|
|
6
|
-
const projectSchemaModel = new ProjectSchema(projectSchema);
|
|
7
|
-
describe('ServiceModel', () => {
|
|
8
|
-
const serviceId = 'gregs-takeshape-store';
|
|
9
|
-
const serviceModel = new ServiceConfig(projectSchemaModel, serviceId);
|
|
10
|
-
test('invalid service id', () => {
|
|
11
|
-
expect(() => new ServiceConfig(projectSchemaModel, 'bogus')).toThrowError(new Error('Could not create service model for bogus'));
|
|
12
|
-
});
|
|
13
|
-
test('basic accessors', () => {
|
|
14
|
-
expect(serviceModel.id).toEqual(serviceId);
|
|
15
|
-
expect(serviceModel.json).toEqual(projectSchema.services[serviceId]);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ProjectSchemaJSON, ShapeJSON } from '../project-schema/index.ts';
|
|
2
|
-
import { type RefItem, type RefItemWithPath } from '../refs.ts';
|
|
3
|
-
import type { SchemaWithRef } from '../types/index.ts';
|
|
4
|
-
import { QueryModel } from './query.ts';
|
|
5
|
-
import { ServiceConfig } from './service.ts';
|
|
6
|
-
import { ShapeModel } from './shape.ts';
|
|
7
|
-
import type { IProjectSchema } from './types.ts';
|
|
8
|
-
/**
|
|
9
|
-
* Model object representing a ProjectSchema.
|
|
10
|
-
* Intended to help make it easier to find the right utils
|
|
11
|
-
* and avoid direct schema json access where a util would be preferred.
|
|
12
|
-
*/
|
|
13
|
-
export declare class ProjectSchema implements IProjectSchema {
|
|
14
|
-
private readonly _projectSchemaJSON;
|
|
15
|
-
private readonly _cache;
|
|
16
|
-
constructor(unfilteredProjectSchema: ProjectSchemaJSON);
|
|
17
|
-
get json(): ProjectSchemaJSON;
|
|
18
|
-
get projectId(): string;
|
|
19
|
-
get $schema(): string | undefined;
|
|
20
|
-
get author(): string | undefined;
|
|
21
|
-
getShapeByName(shapeName: string): ShapeModel | undefined;
|
|
22
|
-
getShapeById(shapeId: string): ShapeModel | undefined;
|
|
23
|
-
getShapeByRef(shapeRef: string): ShapeModel;
|
|
24
|
-
get shapes(): ShapeJSON[];
|
|
25
|
-
get refs(): RefItemWithPath[];
|
|
26
|
-
getQueryByName(queryName: string): QueryModel;
|
|
27
|
-
get queries(): QueryModel[];
|
|
28
|
-
getMutationByName(mutationName: string): QueryModel;
|
|
29
|
-
get mutations(): QueryModel[];
|
|
30
|
-
getServiceById(serviceId: string): ServiceConfig;
|
|
31
|
-
atRefToRefItem(atRef: string, template?: string): RefItem;
|
|
32
|
-
refItemToShape(refItem: RefItem): ShapeModel;
|
|
33
|
-
getRef(refSchema: SchemaWithRef): import("@takeshape/util").Maybe<RefItem>;
|
|
34
|
-
normalizeRefExpression(refExpression: string): string;
|
|
35
|
-
refExpressionToRefItem(refExpression: string): RefItem;
|
|
36
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import omit from 'lodash/omit.js';
|
|
2
|
-
import { atRefToRefItem, getRef, normalizeRefExpression, refExpressionToRefItem, shapeToRefItem } from "../refs.js";
|
|
3
|
-
import { getAllRefs } from "../schema-util.js";
|
|
4
|
-
import { getShape, getShapeById } from "../util/shapes.js";
|
|
5
|
-
import { QueryModel } from "./query.js";
|
|
6
|
-
import { ServiceConfig } from "./service.js";
|
|
7
|
-
import { ShapeModel } from "./shape.js";
|
|
8
|
-
/**
|
|
9
|
-
* Model object representing a ProjectSchema.
|
|
10
|
-
* Intended to help make it easier to find the right utils
|
|
11
|
-
* and avoid direct schema json access where a util would be preferred.
|
|
12
|
-
*/
|
|
13
|
-
export class ProjectSchema {
|
|
14
|
-
_projectSchemaJSON;
|
|
15
|
-
_cache = {};
|
|
16
|
-
constructor(unfilteredProjectSchema) {
|
|
17
|
-
// You can pass a ProjectSchemaCompat in here, but we remove its values so they don't get passed through to getJSON.
|
|
18
|
-
// If you need to use this metadata it should be stored separately.
|
|
19
|
-
this._projectSchemaJSON = omit(unfilteredProjectSchema, ['created', 'updated', 'version']);
|
|
20
|
-
}
|
|
21
|
-
get json() {
|
|
22
|
-
return this._projectSchemaJSON;
|
|
23
|
-
}
|
|
24
|
-
get projectId() {
|
|
25
|
-
return this.json.projectId;
|
|
26
|
-
}
|
|
27
|
-
get $schema() {
|
|
28
|
-
return this.json.$schema;
|
|
29
|
-
}
|
|
30
|
-
get author() {
|
|
31
|
-
return this.json.author;
|
|
32
|
-
}
|
|
33
|
-
getShapeByName(shapeName) {
|
|
34
|
-
const shapeJSON = getShape(this.json, shapeName);
|
|
35
|
-
if (!shapeJSON) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
const shapeRefItem = shapeToRefItem(this.json, shapeJSON);
|
|
39
|
-
return new ShapeModel(this, shapeRefItem);
|
|
40
|
-
}
|
|
41
|
-
getShapeById(shapeId) {
|
|
42
|
-
const shapeJSON = getShapeById(this.json, shapeId);
|
|
43
|
-
if (!shapeJSON) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
const shapeRefItem = shapeToRefItem(this.json, shapeJSON);
|
|
47
|
-
return new ShapeModel(this, shapeRefItem);
|
|
48
|
-
}
|
|
49
|
-
getShapeByRef(shapeRef) {
|
|
50
|
-
return new ShapeModel(this, shapeRef);
|
|
51
|
-
}
|
|
52
|
-
get shapes() {
|
|
53
|
-
this._cache.shapes ??= Object.keys(this.json.shapes).map((name) => new ShapeModel(this, normalizeRefExpression(this.json, name)));
|
|
54
|
-
return this._cache.shapes;
|
|
55
|
-
}
|
|
56
|
-
get refs() {
|
|
57
|
-
this._cache.refs ??= getAllRefs(this.json);
|
|
58
|
-
return this._cache.refs;
|
|
59
|
-
}
|
|
60
|
-
getQueryByName(queryName) {
|
|
61
|
-
return new QueryModel(this, 'query', queryName);
|
|
62
|
-
}
|
|
63
|
-
get queries() {
|
|
64
|
-
this._cache.queries ??= Object.keys(this.json.queries).map((name) => new QueryModel(this, 'query', name));
|
|
65
|
-
return this._cache.queries;
|
|
66
|
-
}
|
|
67
|
-
getMutationByName(mutationName) {
|
|
68
|
-
return new QueryModel(this, 'mutation', mutationName);
|
|
69
|
-
}
|
|
70
|
-
get mutations() {
|
|
71
|
-
this._cache.mutations = Object.keys(this.json.mutations).map((name) => new QueryModel(this, 'mutation', name));
|
|
72
|
-
return this._cache.mutations;
|
|
73
|
-
}
|
|
74
|
-
getServiceById(serviceId) {
|
|
75
|
-
return new ServiceConfig(this, serviceId);
|
|
76
|
-
}
|
|
77
|
-
atRefToRefItem(atRef, template) {
|
|
78
|
-
return atRefToRefItem(this.json, atRef, template);
|
|
79
|
-
}
|
|
80
|
-
refItemToShape(refItem) {
|
|
81
|
-
return new ShapeModel(this, refItem);
|
|
82
|
-
}
|
|
83
|
-
getRef(refSchema) {
|
|
84
|
-
return getRef(this.json, refSchema);
|
|
85
|
-
}
|
|
86
|
-
normalizeRefExpression(refExpression) {
|
|
87
|
-
return normalizeRefExpression(this.json, refExpression);
|
|
88
|
-
}
|
|
89
|
-
refExpressionToRefItem(refExpression) {
|
|
90
|
-
return refExpressionToRefItem(this.json, refExpression);
|
|
91
|
-
}
|
|
92
|
-
}
|
package/dist/models/service.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ServiceConfigJSON } from '../project-schema/index.ts';
|
|
2
|
-
import type { IProjectSchema } from './types.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Create a model object representing a service configuration.
|
|
5
|
-
*/
|
|
6
|
-
export declare class ServiceConfig {
|
|
7
|
-
private readonly _serviceId;
|
|
8
|
-
private readonly _storedServiceConfig;
|
|
9
|
-
constructor(projectSchemaModel: IProjectSchema, _serviceId: string);
|
|
10
|
-
get id(): string;
|
|
11
|
-
get json(): ServiceConfigJSON;
|
|
12
|
-
}
|
package/dist/models/service.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a model object representing a service configuration.
|
|
3
|
-
*/
|
|
4
|
-
export class ServiceConfig {
|
|
5
|
-
_serviceId;
|
|
6
|
-
_storedServiceConfig;
|
|
7
|
-
constructor(projectSchemaModel, _serviceId) {
|
|
8
|
-
this._serviceId = _serviceId;
|
|
9
|
-
if (!projectSchemaModel.json.services?.[_serviceId]) {
|
|
10
|
-
throw new Error(`Could not create service model for ${_serviceId}`);
|
|
11
|
-
}
|
|
12
|
-
this._storedServiceConfig = projectSchemaModel.json.services[_serviceId];
|
|
13
|
-
}
|
|
14
|
-
get id() {
|
|
15
|
-
return this._serviceId;
|
|
16
|
-
}
|
|
17
|
-
get json() {
|
|
18
|
-
return this._storedServiceConfig;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
File without changes
|