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