@takeshape/schema 11.73.0 → 11.76.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.
Files changed (109) hide show
  1. package/dist/builtin-schema.js +1 -0
  2. package/dist/models/runtime-schema.js +1 -0
  3. package/dist/project-schema/latest.d.ts +6 -1
  4. package/dist/project-schema/v3.48.0.d.ts +6 -1
  5. package/dist/project-schema/v3.49.0.d.ts +6 -1
  6. package/dist/project-schema/v3.50.0.d.ts +6 -1
  7. package/dist/project-schema/v3.51.0.d.ts +6 -1
  8. package/dist/project-schema/v3.52.0.d.ts +6 -1
  9. package/dist/project-schema/v3.53.0.d.ts +6 -1
  10. package/dist/project-schema/v3.54.0.d.ts +6 -1
  11. package/dist/schemas/project-schema/experimental.json +20 -0
  12. package/dist/util/expressions.js +2 -2
  13. package/package.json +6 -6
  14. package/dist/__tests__/_examples.test.d.ts +0 -1
  15. package/dist/__tests__/_examples.test.js +0 -77
  16. package/dist/__tests__/agents.test.d.ts +0 -1
  17. package/dist/__tests__/agents.test.js +0 -163
  18. package/dist/__tests__/api-version.test.d.ts +0 -1
  19. package/dist/__tests__/api-version.test.js +0 -24
  20. package/dist/__tests__/builtin-schema.test.d.ts +0 -1
  21. package/dist/__tests__/builtin-schema.test.js +0 -18
  22. package/dist/__tests__/content-schema-transform.test.d.ts +0 -1
  23. package/dist/__tests__/content-schema-transform.test.js +0 -522
  24. package/dist/__tests__/create-input-schema.test.d.ts +0 -1
  25. package/dist/__tests__/create-input-schema.test.js +0 -184
  26. package/dist/__tests__/enum.test.d.ts +0 -1
  27. package/dist/__tests__/enum.test.js +0 -36
  28. package/dist/__tests__/flatten-templates.test.d.ts +0 -1
  29. package/dist/__tests__/flatten-templates.test.js +0 -40
  30. package/dist/__tests__/get-is-leaf.test.d.ts +0 -1
  31. package/dist/__tests__/get-is-leaf.test.js +0 -50
  32. package/dist/__tests__/interfaces.test.d.ts +0 -1
  33. package/dist/__tests__/interfaces.test.js +0 -219
  34. package/dist/__tests__/migration.test.d.ts +0 -1
  35. package/dist/__tests__/migration.test.js +0 -34
  36. package/dist/__tests__/mocks.test.d.ts +0 -1
  37. package/dist/__tests__/mocks.test.js +0 -24
  38. package/dist/__tests__/refs.test.d.ts +0 -1
  39. package/dist/__tests__/refs.test.js +0 -813
  40. package/dist/__tests__/relationships.test.d.ts +0 -1
  41. package/dist/__tests__/relationships.test.js +0 -638
  42. package/dist/__tests__/schema-transform.test.d.ts +0 -1
  43. package/dist/__tests__/schema-transform.test.js +0 -205
  44. package/dist/__tests__/schema-util.test.d.ts +0 -1
  45. package/dist/__tests__/schema-util.test.js +0 -1731
  46. package/dist/__tests__/service-dependencies.test.d.ts +0 -1
  47. package/dist/__tests__/service-dependencies.test.js +0 -360
  48. package/dist/__tests__/unions.test.d.ts +0 -1
  49. package/dist/__tests__/unions.test.js +0 -44
  50. package/dist/__tests__/validate.test.d.ts +0 -1
  51. package/dist/__tests__/validate.test.js +0 -1980
  52. package/dist/__tests__/workflows.test.d.ts +0 -3
  53. package/dist/__tests__/workflows.test.js +0 -149
  54. package/dist/layers/__tests__/layers.test.d.ts +0 -1
  55. package/dist/layers/__tests__/layers.test.js +0 -38
  56. package/dist/migration/to/__tests__/v3.10.0.test.d.ts +0 -1
  57. package/dist/migration/to/__tests__/v3.10.0.test.js +0 -90
  58. package/dist/migration/to/__tests__/v3.12.3.test.d.ts +0 -1
  59. package/dist/migration/to/__tests__/v3.12.3.test.js +0 -103
  60. package/dist/migration/to/__tests__/v3.17.test.d.ts +0 -1
  61. package/dist/migration/to/__tests__/v3.17.test.js +0 -71
  62. package/dist/migration/to/__tests__/v3.34.0.test.d.ts +0 -1
  63. package/dist/migration/to/__tests__/v3.34.0.test.js +0 -240
  64. package/dist/migration/to/__tests__/v3.39.0.test.d.ts +0 -1
  65. package/dist/migration/to/__tests__/v3.39.0.test.js +0 -116
  66. package/dist/migration/to/__tests__/v3.46.0.test.d.ts +0 -1
  67. package/dist/migration/to/__tests__/v3.46.0.test.js +0 -59
  68. package/dist/models/__tests__/fixtures.d.ts +0 -15
  69. package/dist/models/__tests__/fixtures.js +0 -56
  70. package/dist/models/__tests__/query.test.d.ts +0 -1
  71. package/dist/models/__tests__/query.test.js +0 -19
  72. package/dist/models/__tests__/runtime-schema.test.d.ts +0 -1
  73. package/dist/models/__tests__/runtime-schema.test.js +0 -43
  74. package/dist/models/__tests__/shape.test.d.ts +0 -1
  75. package/dist/models/__tests__/shape.test.js +0 -24
  76. package/dist/resolvers/ai/__tests__/rag-query.test.d.ts +0 -1
  77. package/dist/resolvers/ai/__tests__/rag-query.test.js +0 -49
  78. package/dist/services/__tests__/services.test.d.ts +0 -1
  79. package/dist/services/__tests__/services.test.js +0 -113
  80. package/dist/template-shapes/__tests__/index.test.d.ts +0 -1
  81. package/dist/template-shapes/__tests__/index.test.js +0 -40
  82. package/dist/template-shapes/__tests__/names.test.d.ts +0 -1
  83. package/dist/template-shapes/__tests__/names.test.js +0 -19
  84. package/dist/template-shapes/__tests__/templates.test.d.ts +0 -1
  85. package/dist/template-shapes/__tests__/templates.test.js +0 -80
  86. package/dist/template-shapes/__tests__/where.test.d.ts +0 -1
  87. package/dist/template-shapes/__tests__/where.test.js +0 -218
  88. package/dist/types/__tests__/utils.test.d.ts +0 -1
  89. package/dist/types/__tests__/utils.test.js +0 -159
  90. package/dist/util/__tests__/api-indexing.test.d.ts +0 -1
  91. package/dist/util/__tests__/api-indexing.test.js +0 -129
  92. package/dist/util/__tests__/detect-cycles.test.d.ts +0 -1
  93. package/dist/util/__tests__/detect-cycles.test.js +0 -193
  94. package/dist/util/__tests__/expressions.test.d.ts +0 -1
  95. package/dist/util/__tests__/expressions.test.js +0 -172
  96. package/dist/util/__tests__/find-shape-at-path.test.d.ts +0 -1
  97. package/dist/util/__tests__/find-shape-at-path.test.js +0 -41
  98. package/dist/util/__tests__/form-config.test.d.ts +0 -1
  99. package/dist/util/__tests__/form-config.test.js +0 -196
  100. package/dist/util/__tests__/get-return-shape.test.d.ts +0 -1
  101. package/dist/util/__tests__/get-return-shape.test.js +0 -27
  102. package/dist/util/__tests__/has-args.test.d.ts +0 -1
  103. package/dist/util/__tests__/has-args.test.js +0 -46
  104. package/dist/util/__tests__/merge.test.d.ts +0 -1
  105. package/dist/util/__tests__/merge.test.js +0 -1074
  106. package/dist/util/__tests__/patch-schema.test.d.ts +0 -1
  107. package/dist/util/__tests__/patch-schema.test.js +0 -82
  108. package/dist/util/__tests__/shapes.test.d.ts +0 -1
  109. package/dist/util/__tests__/shapes.test.js +0 -30
@@ -1,3 +0,0 @@
1
- import type { Workflow } from '../project-schema/index.ts';
2
- export declare const simpleWorkflow: Workflow;
3
- export declare const complexWorkflow: Workflow;
@@ -1,149 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import postSchemaJson from '@/examples/latest/post-schema.json';
3
- import { applyDefaultsToSchema } from "../schema-util.js";
4
- import { defaultWorkflow, findWorkflowStep, getLiveStepKeys, getStatusField, getWorkflow, getWorkflowStepKeys, statusFallback } from "../workflows.js";
5
- const postSchema = applyDefaultsToSchema(postSchemaJson);
6
- test('getStatusFieldV3', () => {
7
- const shape = {
8
- name: 'post',
9
- workflow: 'default',
10
- title: 'post',
11
- id: 'post',
12
- schema: {
13
- type: 'object',
14
- properties: {
15
- title: { type: 'string' },
16
- body: { type: 'string' }
17
- },
18
- required: ['title', 'body']
19
- }
20
- };
21
- expect(getStatusField({ default: defaultWorkflow }, shape)).toEqual({
22
- type: 'string',
23
- '@workflow': 'default',
24
- title: 'Status'
25
- });
26
- });
27
- test('getWorkflow', () => {
28
- expect(getWorkflow(postSchema, '<postContentTypeId>')).toEqual(defaultWorkflow);
29
- });
30
- export const simpleWorkflow = {
31
- name: 'simple',
32
- title: 'Simple',
33
- steps: [
34
- {
35
- name: 'live',
36
- title: 'Live',
37
- key: 'ByAgr-BZ8',
38
- color: '#5cd79b',
39
- live: true
40
- }
41
- ]
42
- };
43
- export const complexWorkflow = {
44
- name: 'complex',
45
- title: 'Complex',
46
- steps: [
47
- {
48
- name: 'draft',
49
- title: 'Draft',
50
- key: 'r1uCfi4ZL',
51
- color: '#bdbdbd',
52
- live: false
53
- },
54
- {
55
- name: 'artPhoto',
56
- title: 'Art/Photo',
57
- key: 'rkhRGs4WL',
58
- color: '#5cd79b',
59
- live: false
60
- },
61
- {
62
- name: 'legal',
63
- title: 'Legal',
64
- key: 'SJtxS-rWI',
65
- color: '#5cd79b',
66
- live: false
67
- },
68
- {
69
- name: 'finalReview',
70
- title: 'Final Review',
71
- key: 'B1sxHZBZI',
72
- color: '#5cd79b',
73
- live: false
74
- },
75
- {
76
- name: 'published',
77
- title: 'Published',
78
- key: 'Hk2xBZSbI',
79
- color: '#5cd79b',
80
- live: true
81
- },
82
- {
83
- name: 'homepage',
84
- title: 'Homepage',
85
- key: 'SypgH-S-8',
86
- color: '#5cd79b',
87
- live: true
88
- },
89
- {
90
- name: 'retired',
91
- title: 'Retired',
92
- key: 'ByAgr-BZ8',
93
- color: '#5cd79b',
94
- live: false
95
- }
96
- ]
97
- };
98
- test('findWorkflowStep', () => {
99
- expect(findWorkflowStep(complexWorkflow, 'Hk2xBZSbI')).toEqual({
100
- index: 4,
101
- step: complexWorkflow.steps[4]
102
- });
103
- expect(findWorkflowStep(complexWorkflow, 'bogus')).toBe(undefined);
104
- });
105
- test('statusFallback', () => {
106
- expect(statusFallback(defaultWorkflow, true)).toMatchObject({
107
- name: 'enabled'
108
- });
109
- expect(statusFallback(defaultWorkflow, false)).toMatchObject({
110
- name: 'disabled'
111
- });
112
- expect(statusFallback(simpleWorkflow, true)).toMatchObject({ name: 'live' });
113
- expect(statusFallback(simpleWorkflow, false)).toMatchObject({ name: 'live' });
114
- expect(statusFallback(complexWorkflow, true)).toMatchObject({
115
- name: 'published'
116
- });
117
- expect(statusFallback(complexWorkflow, false)).toMatchObject({
118
- name: 'draft'
119
- });
120
- });
121
- const allKeys = complexWorkflow.steps.map((step) => step.key);
122
- test('getWorkflowStepKeys - gte', () => {
123
- const filteredKeys = getWorkflowStepKeys(complexWorkflow, 'B1sxHZBZI', 'gte');
124
- expect(filteredKeys).toEqual(allKeys.slice(3, 7));
125
- expect(filteredKeys.includes('B1sxHZBZI')).toBe(true);
126
- });
127
- test('getWorkflowStepKeys - gt', () => {
128
- expect(getWorkflowStepKeys(complexWorkflow, 'B1sxHZBZI', 'gt')).toEqual(allKeys.slice(4, 7));
129
- });
130
- test('getWorkflowStepKeys - lte', () => {
131
- const filteredKeys = getWorkflowStepKeys(complexWorkflow, 'B1sxHZBZI', 'lte');
132
- expect(filteredKeys).toEqual(allKeys.slice(0, 4));
133
- expect(filteredKeys.includes('B1sxHZBZI')).toBe(true);
134
- });
135
- test('getWorkflowStepKeys - lt', () => {
136
- expect(getWorkflowStepKeys(complexWorkflow, 'B1sxHZBZI', 'lt')).toEqual(allKeys.slice(0, 3));
137
- });
138
- test('getWorkflowStepKeys - eq', () => {
139
- expect(getWorkflowStepKeys(complexWorkflow, 'B1sxHZBZI', 'eq')).toEqual(['B1sxHZBZI']);
140
- });
141
- test('getWorkflowStepKeys - in', () => {
142
- expect(getWorkflowStepKeys(complexWorkflow, 'B1sxHZBZI', 'in')).toEqual(['B1sxHZBZI']);
143
- });
144
- test('getWorkflowStepKeys - step not found', () => {
145
- expect(() => getWorkflowStepKeys(complexWorkflow, 'bogus', 'lt')).toThrowErrorMatchingInlineSnapshot(`[Error: Cannot find step "bogus" in workflow "Complex"]`);
146
- });
147
- test('getLiveStepKeys', () => {
148
- expect(getLiveStepKeys(complexWorkflow)).toEqual(allKeys.slice(4, 6));
149
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,38 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { expect, test } from 'vitest';
4
- import { flattenSchema } from "../layers.js";
5
- function loadFile(fileName) {
6
- return JSON.parse(fs.readFileSync(fileName, 'utf8'));
7
- }
8
- function getPath(...filePath) {
9
- return path.join(__dirname, '..', '..', '..', 'examples', 'v4_0_0', ...filePath);
10
- }
11
- const layerCache = new Map();
12
- const getLayer = (exampleName) => (layerId) => {
13
- const layerPath = getPath(exampleName, 'layers', `${layerId}.json`);
14
- let layer = layerCache.get(layerPath);
15
- if (!layer) {
16
- layer = loadFile(layerPath);
17
- layerCache.set(layerPath, layer);
18
- }
19
- return layer;
20
- };
21
- function getSchema(exampleName) {
22
- return loadFile(getPath(exampleName, 'schema.json'));
23
- }
24
- function getFlattenedSchema(exampleName) {
25
- return loadFile(getPath(exampleName, 'flattened-schema.json'));
26
- }
27
- test.skip('flattenSchema - rick-and-morty-notes', () => {
28
- const exampleName = 'rick-and-morty-notes';
29
- const schema = getSchema(exampleName);
30
- const flattened = flattenSchema(schema, getLayer(exampleName));
31
- expect(flattened).toEqual(getFlattenedSchema(exampleName));
32
- });
33
- test.skip('flattenSchema - shopify-lookbook', () => {
34
- const exampleName = 'shopify-lookbook';
35
- const schema = getSchema(exampleName);
36
- const flattened = flattenSchema(schema, getLayer(exampleName));
37
- expect(flattened).toEqual(getFlattenedSchema(exampleName));
38
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,90 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import migrateToV3_10 from "../v3.10.0.js";
3
- const context = {
4
- encryptFn: () => '',
5
- decryptFn: () => undefined,
6
- generateDataKeyFn: async () => ''
7
- };
8
- function mockSchema(schema) {
9
- const now = new Date().toISOString();
10
- const projectId = 'project-id';
11
- const dataKey = 'secret';
12
- return {
13
- projectId,
14
- dataKey,
15
- version: 1,
16
- created: now,
17
- updated: now,
18
- defaultLocale: 'en-us',
19
- locales: ['en-us'],
20
- apiVersion: '2',
21
- schemaVersion: '3.9.0',
22
- queries: {},
23
- mutations: {},
24
- shapes: {},
25
- workflows: {},
26
- forms: {},
27
- services: {
28
- supaservice: {
29
- id: 'supaservice',
30
- provider: 'generic',
31
- title: 'Supa Service',
32
- serviceType: 'rest',
33
- namespace: 'Supa',
34
- authenticationType: 'none'
35
- }
36
- },
37
- ...schema
38
- };
39
- }
40
- test('migrateToV3_10', async () => {
41
- const projectSchema = mockSchema({
42
- queries: {
43
- woo: {
44
- shape: {
45
- type: 'array',
46
- items: {
47
- $ref: '#/shapes/Supa_Woo/schema'
48
- }
49
- },
50
- resolver: {
51
- name: 'rest:get',
52
- service: 'supaservice',
53
- path: '/',
54
- options: {}
55
- }
56
- }
57
- }
58
- });
59
- const migrated = await migrateToV3_10(context, projectSchema);
60
- expect(migrated.schemaVersion).toBe('3.10.0');
61
- expect(migrated.queries.woo.shape).toEqual({
62
- type: 'array',
63
- items: { '@ref': 'supaservice:Woo' }
64
- });
65
- });
66
- test('migrateToV3_10 - inline array object unsuported', async () => {
67
- const projectSchema = mockSchema({
68
- queries: {
69
- woo: {
70
- shape: {
71
- type: 'array',
72
- items: {
73
- type: 'object',
74
- properties: {
75
- title: { type: 'string' },
76
- inline: { type: 'boolean', default: true }
77
- }
78
- }
79
- },
80
- resolver: {
81
- name: 'rest:get',
82
- service: 'supaservice',
83
- path: '/',
84
- options: {}
85
- }
86
- }
87
- }
88
- });
89
- await expect(migrateToV3_10(context, projectSchema)).rejects.toMatchInlineSnapshot(`[Error: Query "woo" contains an unsupported shape schema {"type":"array","items":{"type":"object","properties":{"title":{"type":"string"},"inline":{"type":"boolean","default":true}}}}. Please contact support]`);
90
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,103 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import migrateToV3_12_3 from "../v3.12.3.js";
3
- test('3.12.3 migration', async () => {
4
- const context = {
5
- encryptFn: () => '',
6
- decryptFn: () => undefined,
7
- generateDataKeyFn: async () => ''
8
- };
9
- const schema = {
10
- schemaVersion: '3.12.2',
11
- version: 2112,
12
- apiVersion: '2',
13
- projectId: 'project-id',
14
- created: '2020-01-01T00:00:00.000Z',
15
- updated: '2020-01-01T00:00:00.000Z',
16
- dataKey: 'secret',
17
- defaultLocale: 'en-us',
18
- locales: ['en-us'],
19
- mutations: {},
20
- shapes: {},
21
- workflows: {},
22
- indexedShapes: {
23
- Shopify_Product: {
24
- queries: {
25
- all: {
26
- name: 'Shopify_products',
27
- interval: 5,
28
- ignoreFields: ['a', 'b', 'c'],
29
- pagination: {
30
- type: 'cursor',
31
- cursorArg: 'cursorArg',
32
- cursorPath: 'cursorPath',
33
- hasMorePath: 'hasMorePath',
34
- itemsPath: 'itemsPath',
35
- sizeArg: 'sizeArg',
36
- size: 100
37
- }
38
- },
39
- single: {
40
- name: 'Shopify_product',
41
- ignoreFields: ['c', 'd', 'e']
42
- }
43
- }
44
- }
45
- },
46
- queries: {
47
- Shopify_product: {
48
- resolver: {
49
- name: 'name',
50
- service: 'shopify'
51
- }
52
- },
53
- Shopify_products: {
54
- resolver: {
55
- name: 'name',
56
- service: 'shopify'
57
- }
58
- }
59
- },
60
- services: {
61
- shopify: {
62
- provider: 'shopify'
63
- }
64
- }
65
- };
66
- const migrated = await migrateToV3_12_3(context, schema);
67
- expect(migrated).toMatchObject({
68
- schemaVersion: '3.12.3',
69
- indexedShapes: {
70
- Shopify_Product: {
71
- queries: {
72
- list: {
73
- name: 'Shopify_products',
74
- ignoreFields: ['a', 'b', 'c'],
75
- pagination: {
76
- type: 'cursor',
77
- cursorArg: 'cursorArg',
78
- cursorPath: 'cursorPath',
79
- hasMorePath: 'hasMorePath',
80
- itemsToIndexPath: 'itemsPath',
81
- pageSizeArg: 'sizeArg',
82
- pageSize: 100
83
- }
84
- },
85
- get: {
86
- name: 'Shopify_product',
87
- ignoreFields: ['c', 'd', 'e']
88
- }
89
- },
90
- triggers: [
91
- {
92
- type: 'webhook',
93
- query: 'get',
94
- service: 'shopify',
95
- events: ['products/create', 'products/update', 'products/delete']
96
- },
97
- { type: 'schedule', query: 'list', interval: 5 }
98
- ]
99
- }
100
- }
101
- });
102
- expect(migrated.indexedShapes?.Shopify_Product.queries.list).not.toMatchObject({ interval: 5 });
103
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,71 +0,0 @@
1
- import { expect, test, vi } from 'vitest';
2
- import migrateToV3_17_0 from "../v3.17.0.js";
3
- test('migrateToV3_17_0', async () => {
4
- const now = '2022-02-15T15:22:26.250Z';
5
- const projectSchema = {
6
- schemaVersion: '3.16.0',
7
- projectId: 'project-id',
8
- dataKey: 'secret',
9
- version: 1,
10
- created: now,
11
- updated: now,
12
- defaultLocale: 'en-us',
13
- locales: ['en-us'],
14
- apiVersion: '2',
15
- queries: {},
16
- mutations: {},
17
- workflows: {},
18
- forms: {},
19
- shapes: {
20
- Product: {
21
- id: '-3U728po3',
22
- name: 'Product',
23
- title: 'Product',
24
- workflow: 'default',
25
- model: {
26
- type: 'multiple'
27
- },
28
- schema: {
29
- type: 'object',
30
- properties: {
31
- title: {
32
- type: 'string',
33
- minLength: 0,
34
- description: '',
35
- title: 'Title',
36
- '@mapping': 'takeshape:local:Product.AoPnfytzY'
37
- },
38
- _createdBy: {
39
- title: 'Created By',
40
- type: 'string',
41
- '@user': true
42
- }
43
- }
44
- }
45
- }
46
- }
47
- };
48
- const migrated = await migrateToV3_17_0({
49
- generateDataKeyFn: vi.fn(),
50
- encryptFn: vi.fn(),
51
- decryptFn: vi.fn()
52
- }, projectSchema);
53
- expect(migrated.shapes.Product.schema).toEqual({
54
- type: 'object',
55
- properties: {
56
- title: {
57
- type: 'string',
58
- minLength: 0,
59
- description: '',
60
- title: 'Title',
61
- '@mapping': 'takeshape:local:Product.AoPnfytzY'
62
- },
63
- _createdBy: {
64
- title: 'Created By',
65
- '@resolver': { name: 'takeshape:getUser', service: 'takeshape:local' },
66
- '@input': { type: 'string' },
67
- '@ref': 'local:TSUser'
68
- }
69
- }
70
- });
71
- });
@@ -1 +0,0 @@
1
- export {};