jsonbadger 0.5.0 → 0.6.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/README.md +36 -18
- package/docs/api/connection.md +144 -0
- package/docs/api/delta-tracker.md +106 -0
- package/docs/api/document.md +77 -0
- package/docs/api/field-types.md +329 -0
- package/docs/api/index.md +35 -0
- package/docs/api/model.md +392 -0
- package/docs/api/query-builder.md +81 -0
- package/docs/api/schema.md +204 -0
- package/docs/architecture-flow.md +397 -0
- package/docs/examples.md +495 -218
- package/docs/jsonb-ops.md +171 -0
- package/docs/lifecycle/model-compilation.md +111 -0
- package/docs/lifecycle.md +146 -0
- package/docs/query-translation.md +11 -10
- package/package.json +10 -3
- package/src/connection/connect.js +12 -17
- package/src/connection/connection.js +128 -0
- package/src/connection/server-capabilities.js +60 -59
- package/src/constants/defaults.js +32 -19
- package/src/constants/{id-strategies.js → id-strategy.js} +28 -29
- package/src/constants/intake-mode.js +8 -0
- package/src/debug/debug-logger.js +17 -15
- package/src/errors/model-overwrite-error.js +25 -0
- package/src/errors/query-error.js +25 -23
- package/src/errors/validation-error.js +25 -23
- package/src/field-types/base-field-type.js +137 -140
- package/src/field-types/builtins/advanced.js +365 -365
- package/src/field-types/builtins/index.js +579 -585
- package/src/field-types/field-type-namespace.js +9 -0
- package/src/field-types/registry.js +149 -122
- package/src/index.js +26 -36
- package/src/migration/ensure-index.js +157 -154
- package/src/migration/ensure-schema.js +27 -15
- package/src/migration/ensure-table.js +44 -31
- package/src/migration/schema-indexes-resolver.js +8 -6
- package/src/model/document-instance.js +29 -540
- package/src/model/document.js +60 -0
- package/src/model/factory/constants.js +36 -0
- package/src/model/factory/index.js +58 -0
- package/src/model/model.js +875 -0
- package/src/model/operations/delete-one.js +39 -0
- package/src/model/operations/insert-one.js +35 -0
- package/src/model/operations/query-builder.js +132 -0
- package/src/model/operations/update-one.js +333 -0
- package/src/model/state.js +34 -0
- package/src/schema/field-definition-parser.js +213 -218
- package/src/schema/path-introspection.js +87 -82
- package/src/schema/schema-compiler.js +126 -212
- package/src/schema/schema.js +621 -138
- package/src/sql/index.js +17 -0
- package/src/sql/jsonb/ops.js +153 -0
- package/src/{query → sql/jsonb}/path-parser.js +54 -43
- package/src/sql/jsonb/read/elem-match.js +133 -0
- package/src/{query → sql/jsonb/read}/operators/contains.js +13 -7
- package/src/sql/jsonb/read/operators/elem-match.js +9 -0
- package/src/{query → sql/jsonb/read}/operators/has-all-keys.js +17 -11
- package/src/{query → sql/jsonb/read}/operators/has-any-keys.js +18 -11
- package/src/sql/jsonb/read/operators/has-key.js +12 -0
- package/src/{query → sql/jsonb/read}/operators/jsonpath-exists.js +22 -15
- package/src/{query → sql/jsonb/read}/operators/jsonpath-match.js +22 -15
- package/src/{query → sql/jsonb/read}/operators/size.js +23 -16
- package/src/sql/parameter-binder.js +18 -13
- package/src/sql/read/build-count-query.js +12 -0
- package/src/sql/read/build-find-query.js +25 -0
- package/src/sql/read/limit-skip.js +21 -0
- package/src/sql/read/sort.js +85 -0
- package/src/sql/read/where/base-fields.js +310 -0
- package/src/sql/read/where/casting.js +90 -0
- package/src/sql/read/where/context.js +79 -0
- package/src/sql/read/where/field-clause.js +58 -0
- package/src/sql/read/where/index.js +38 -0
- package/src/sql/read/where/operator-entries.js +29 -0
- package/src/{query → sql/read/where}/operators/all.js +16 -10
- package/src/sql/read/where/operators/eq.js +12 -0
- package/src/{query → sql/read/where}/operators/gt.js +23 -16
- package/src/{query → sql/read/where}/operators/gte.js +23 -16
- package/src/{query → sql/read/where}/operators/in.js +18 -12
- package/src/sql/read/where/operators/index.js +40 -0
- package/src/{query → sql/read/where}/operators/lt.js +23 -16
- package/src/{query → sql/read/where}/operators/lte.js +23 -16
- package/src/sql/read/where/operators/ne.js +12 -0
- package/src/{query → sql/read/where}/operators/nin.js +18 -12
- package/src/{query → sql/read/where}/operators/regex.js +14 -8
- package/src/sql/read/where/operators.js +126 -0
- package/src/sql/read/where/text-operators.js +83 -0
- package/src/sql/run.js +46 -0
- package/src/sql/write/build-delete-query.js +33 -0
- package/src/sql/write/build-insert-query.js +42 -0
- package/src/sql/write/build-update-query.js +65 -0
- package/src/utils/assert.js +34 -27
- package/src/utils/delta-tracker/.archive/1 tracker-redesign-codex-v2.md +250 -0
- package/src/utils/delta-tracker/.archive/1 tracker-redesign-gemini.md +101 -0
- package/src/utils/delta-tracker/.archive/2 evaluation by gemini.txt +65 -0
- package/src/utils/delta-tracker/.archive/2 evaluation by grok.txt +39 -0
- package/src/utils/delta-tracker/.archive/3 gemini evaluate grok.txt +37 -0
- package/src/utils/delta-tracker/.archive/3 grok evaluate gemini.txt +63 -0
- package/src/utils/delta-tracker/.archive/4 gemini veredict.txt +16 -0
- package/src/utils/delta-tracker/.archive/index.1.js +587 -0
- package/src/utils/delta-tracker/.archive/index.2.js +612 -0
- package/src/utils/delta-tracker/index.js +592 -0
- package/src/utils/dirty-tracker/inline.js +335 -0
- package/src/utils/dirty-tracker/instance.js +414 -0
- package/src/utils/dirty-tracker/static.js +343 -0
- package/src/utils/json-safe.js +13 -9
- package/src/utils/object-path.js +227 -33
- package/src/utils/object.js +408 -168
- package/src/utils/string.js +55 -0
- package/src/utils/value.js +169 -30
- package/docs/api.md +0 -152
- package/src/connection/disconnect.js +0 -16
- package/src/connection/pool-store.js +0 -46
- package/src/model/model-factory.js +0 -555
- package/src/query/limit-skip-compiler.js +0 -31
- package/src/query/operators/elem-match.js +0 -3
- package/src/query/operators/eq.js +0 -6
- package/src/query/operators/has-key.js +0 -6
- package/src/query/operators/index.js +0 -60
- package/src/query/operators/ne.js +0 -6
- package/src/query/query-builder.js +0 -93
- package/src/query/sort-compiler.js +0 -30
- package/src/query/where-compiler.js +0 -477
- package/src/sql/sql-runner.js +0 -31
|
@@ -1,218 +1,213 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function is_plain_object(value) {
|
|
217
|
-
return value !== null && typeof value === 'object' && is_not_array(value);
|
|
218
|
-
}
|
|
1
|
+
import {default_field_type_registry} from '#src/field-types/registry.js';
|
|
2
|
+
import {is_array, is_not_array} from '#src/utils/array.js';
|
|
3
|
+
import {is_plain_object} from '#src/utils/value.js';
|
|
4
|
+
|
|
5
|
+
function field_definition_parser(schema_definition, registry_instance) {
|
|
6
|
+
const parse_state = {
|
|
7
|
+
field_types: Object.create(null),
|
|
8
|
+
object_paths: new Set()
|
|
9
|
+
};
|
|
10
|
+
const schema_root = schema_definition || {};
|
|
11
|
+
const field_registry = registry_instance || default_field_type_registry;
|
|
12
|
+
|
|
13
|
+
parse_schema_object(schema_root, '', field_registry, parse_state);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
field_types: parse_state.field_types,
|
|
17
|
+
object_paths: parse_state.object_paths
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function parse_schema_object(schema_object, parent_path, field_registry, parse_state) {
|
|
22
|
+
if(!is_plain_object(schema_object)) {
|
|
23
|
+
throw new Error('Schema definition must be an object');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const schema_entries = Object.entries(schema_object);
|
|
27
|
+
let entry_index = 0;
|
|
28
|
+
|
|
29
|
+
while(entry_index < schema_entries.length) {
|
|
30
|
+
const schema_entry = schema_entries[entry_index];
|
|
31
|
+
const path_segment = schema_entry[0];
|
|
32
|
+
const field_definition = schema_entry[1];
|
|
33
|
+
const path_value = parent_path ? parent_path + '.' + path_segment : path_segment;
|
|
34
|
+
const parsed_field = parse_field_definition(path_value, field_definition, field_registry);
|
|
35
|
+
|
|
36
|
+
if(parsed_field.kind === 'field_type') {
|
|
37
|
+
parse_state.field_types[path_value] = parsed_field.field_type;
|
|
38
|
+
entry_index += 1;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
parse_state.object_paths.add(path_value);
|
|
43
|
+
parse_schema_object(parsed_field.nested_schema, path_value, field_registry, parse_state);
|
|
44
|
+
entry_index += 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parse_field_definition(path_value, field_definition, field_registry) {
|
|
49
|
+
if(is_array(field_definition)) {
|
|
50
|
+
return {
|
|
51
|
+
kind: 'field_type',
|
|
52
|
+
field_type: create_array_field_type(path_value, field_definition, {}, field_registry)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if(field_registry.has_field_type(field_definition)) {
|
|
57
|
+
return {
|
|
58
|
+
kind: 'field_type',
|
|
59
|
+
field_type: field_registry.create(path_value, field_definition, {})
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if(is_plain_object(field_definition)) {
|
|
64
|
+
const definition_keys = Object.keys(field_definition);
|
|
65
|
+
|
|
66
|
+
if(definition_keys.length === 0) {
|
|
67
|
+
return {
|
|
68
|
+
kind: 'field_type',
|
|
69
|
+
field_type: field_registry.create(path_value, 'Mixed', {})
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if(should_use_explicit_type(field_definition, field_registry)) {
|
|
74
|
+
return {
|
|
75
|
+
kind: 'field_type',
|
|
76
|
+
field_type: create_explicit_field_type(path_value, field_definition, field_registry)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Plain objects without an explicit supported `type` key become nested schema branches.
|
|
81
|
+
return {
|
|
82
|
+
kind: 'nested',
|
|
83
|
+
nested_schema: field_definition
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw new Error('Invalid field definition at path "' + path_value + '"');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function should_use_explicit_type(field_definition, field_registry) {
|
|
91
|
+
if(!Object.prototype.hasOwnProperty.call(field_definition, 'type')) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const type_key = field_definition.type;
|
|
96
|
+
|
|
97
|
+
if(is_array(type_key)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return field_registry.has_field_type(type_key);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function create_explicit_field_type(path_value, field_definition, field_registry) {
|
|
105
|
+
const type_key = field_definition.type;
|
|
106
|
+
const of_definition = field_definition.of;
|
|
107
|
+
const field_options = Object.assign({}, field_definition);
|
|
108
|
+
|
|
109
|
+
// Remove schema-definition syntax keys after extracting them.
|
|
110
|
+
// Runtime FieldType instances should receive internal option keys (for example, `of_field_type`),
|
|
111
|
+
// not parser syntax keys like `type` or `of`.
|
|
112
|
+
delete field_options.type;
|
|
113
|
+
delete field_options.of;
|
|
114
|
+
|
|
115
|
+
if(is_array(type_key)) {
|
|
116
|
+
return create_array_field_type(path_value, type_key, field_options, field_registry);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const type_name = field_registry.resolve(type_key);
|
|
120
|
+
|
|
121
|
+
if(!type_name) {
|
|
122
|
+
throw new Error('Unsupported field type at path "' + path_value + '"');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if(type_name === 'Array') {
|
|
126
|
+
const explicit_array_definition = of_definition !== undefined ? [of_definition] : [];
|
|
127
|
+
return create_array_field_type(path_value, explicit_array_definition, field_options, field_registry);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if(type_name === 'Map') {
|
|
131
|
+
field_options.of_field_type = create_of_field_type(path_value, of_definition, field_registry);
|
|
132
|
+
return field_registry.create(path_value, type_name, field_options);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if(type_name === 'Union') {
|
|
136
|
+
field_options.of_field_types = create_union_field_types(path_value, of_definition, field_registry);
|
|
137
|
+
return field_registry.create(path_value, type_name, field_options);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return field_registry.create(path_value, type_name, field_options);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function create_array_field_type(path_value, array_definition, field_options, field_registry) {
|
|
144
|
+
if(array_definition.length > 1) {
|
|
145
|
+
throw new Error('Array type definition at path "' + path_value + '" must contain at most one item type');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const array_options = Object.assign({}, field_options);
|
|
149
|
+
const item_definition = array_definition.length === 1 ? array_definition[0] : undefined;
|
|
150
|
+
|
|
151
|
+
array_options.of_field_type = create_of_field_type(path_value, item_definition, field_registry);
|
|
152
|
+
return field_registry.create(path_value, 'Array', array_options);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function create_union_field_types(path_value, union_of_definition, field_registry) {
|
|
156
|
+
if(is_not_array(union_of_definition) || union_of_definition.length === 0) {
|
|
157
|
+
throw new Error('Union type definition at path "' + path_value + '" must define a non-empty "of" array');
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const union_field_types = [];
|
|
161
|
+
let type_index = 0;
|
|
162
|
+
|
|
163
|
+
while(type_index < union_of_definition.length) {
|
|
164
|
+
union_field_types.push(create_union_candidate_field_type(path_value, union_of_definition[type_index], field_registry));
|
|
165
|
+
type_index += 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return union_field_types;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function create_union_candidate_field_type(path_value, union_definition, field_registry) {
|
|
172
|
+
if(is_array(union_definition)) {
|
|
173
|
+
return create_array_field_type(path_value, union_definition, {}, field_registry);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if(field_registry.has_field_type(union_definition)) {
|
|
177
|
+
return field_registry.create(path_value, union_definition, {});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if(is_plain_object(union_definition) && should_use_explicit_type(union_definition, field_registry)) {
|
|
181
|
+
return create_explicit_field_type(path_value, union_definition, field_registry);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
throw new Error('Unsupported union type at path "' + path_value + '"');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function create_of_field_type(path_value, of_definition, field_registry) {
|
|
188
|
+
const item_path = path_value + '.$';
|
|
189
|
+
|
|
190
|
+
if(of_definition === undefined) {
|
|
191
|
+
return field_registry.create(item_path, 'Mixed', {});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if(is_array(of_definition)) {
|
|
195
|
+
return create_array_field_type(item_path, of_definition, {}, field_registry);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if(field_registry.has_field_type(of_definition)) {
|
|
199
|
+
return field_registry.create(item_path, of_definition, {});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if(is_plain_object(of_definition)) {
|
|
203
|
+
if(should_use_explicit_type(of_definition, field_registry)) {
|
|
204
|
+
return create_explicit_field_type(item_path, of_definition, field_registry);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return field_registry.create(item_path, 'Mixed', {});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
throw new Error('Unsupported "of" definition at path "' + path_value + '"');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export default field_definition_parser;
|
|
@@ -1,82 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
1
|
+
function create_path_introspection(parsed_schema) {
|
|
2
|
+
const parsed_value = parsed_schema ?? {};
|
|
3
|
+
|
|
4
|
+
// Parent object paths do not have FieldType instances, so track them separately.
|
|
5
|
+
const field_types = get_paths_map(parsed_value);
|
|
6
|
+
const object_paths = resolve_object_paths(parsed_value);
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
field_types,
|
|
10
|
+
object_paths
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function get_path_field_type(path_introspection, path_name) {
|
|
15
|
+
if(!path_introspection || !path_name) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const field_types = get_paths_map(path_introspection);
|
|
20
|
+
return field_types[path_name] ?? null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function get_path_type(path_introspection, path_name) {
|
|
24
|
+
const field_type = get_path_field_type(path_introspection, path_name);
|
|
25
|
+
|
|
26
|
+
if(field_type) {
|
|
27
|
+
return field_type.instance;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const object_paths = resolve_object_paths(path_introspection);
|
|
31
|
+
|
|
32
|
+
if(object_paths.has(path_name)) {
|
|
33
|
+
return 'object';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function is_array_root(path_introspection, path_name) {
|
|
40
|
+
if(!path_introspection || !path_name) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const root_path = String(path_name).split('.')[0];
|
|
45
|
+
const root_field_type = get_path_field_type(path_introspection, root_path);
|
|
46
|
+
|
|
47
|
+
if(!root_field_type) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return root_field_type.instance === 'Array';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function get_paths_map(value) {
|
|
55
|
+
if(!value || typeof value !== 'object') {
|
|
56
|
+
return Object.create(null);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const field_types = value.field_types;
|
|
60
|
+
|
|
61
|
+
if(field_types && typeof field_types === 'object') {
|
|
62
|
+
return field_types;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return Object.create(null);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function resolve_object_paths(value) {
|
|
69
|
+
if(!value) {
|
|
70
|
+
return new Set();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const object_paths = value.object_paths;
|
|
74
|
+
|
|
75
|
+
if(object_paths instanceof Set) {
|
|
76
|
+
return object_paths;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return new Set();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
create_path_introspection,
|
|
84
|
+
get_path_field_type,
|
|
85
|
+
get_path_type,
|
|
86
|
+
is_array_root
|
|
87
|
+
};
|