@tachybase/schema 0.23.40 → 0.23.47
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/lib/core/effects/index.d.ts +2 -0
- package/lib/core/effects/index.js +23 -0
- package/lib/core/effects/onFieldEffects.d.ts +27 -0
- package/lib/core/effects/onFieldEffects.js +158 -0
- package/lib/core/effects/onFormEffects.d.ts +24 -0
- package/lib/core/effects/onFormEffects.js +117 -0
- package/lib/core/global.d.js +0 -0
- package/lib/core/index.d.ts +4 -0
- package/lib/core/index.js +27 -0
- package/lib/core/models/ArrayField.d.ts +17 -0
- package/lib/core/models/ArrayField.js +145 -0
- package/lib/core/models/BaseField.d.ts +72 -0
- package/lib/core/models/BaseField.js +285 -0
- package/lib/core/models/Field.d.ts +70 -0
- package/lib/core/models/Field.js +426 -0
- package/lib/core/models/Form.d.ts +102 -0
- package/lib/core/models/Form.js +483 -0
- package/lib/core/models/Graph.d.ts +8 -0
- package/lib/core/models/Graph.js +77 -0
- package/lib/core/models/Heart.d.ts +16 -0
- package/lib/core/models/Heart.js +91 -0
- package/lib/core/models/LifeCycle.d.ts +14 -0
- package/lib/core/models/LifeCycle.js +64 -0
- package/lib/core/models/ObjectField.d.ts +12 -0
- package/lib/core/models/ObjectField.js +64 -0
- package/lib/core/models/Query.d.ts +18 -0
- package/lib/core/models/Query.js +105 -0
- package/lib/core/models/VoidField.d.ts +14 -0
- package/lib/core/models/VoidField.js +117 -0
- package/lib/core/models/index.d.ts +9 -0
- package/lib/core/models/index.js +37 -0
- package/lib/core/models/types.d.ts +9 -0
- package/lib/core/models/types.js +15 -0
- package/lib/core/shared/checkers.d.ts +117 -0
- package/lib/core/shared/checkers.js +109 -0
- package/lib/core/shared/constants.d.ts +48 -0
- package/lib/core/shared/constants.js +86 -0
- package/lib/core/shared/effective.d.ts +9 -0
- package/lib/core/shared/effective.js +91 -0
- package/lib/core/shared/externals.d.ts +8 -0
- package/lib/core/shared/externals.js +87 -0
- package/lib/core/shared/internals.d.ts +54 -0
- package/lib/core/shared/internals.js +956 -0
- package/lib/core/types.d.ts +275 -0
- package/lib/core/types.js +76 -0
- package/lib/grid/index.d.ts +67 -0
- package/lib/grid/index.js +378 -0
- package/lib/grid/observer.d.ts +19 -0
- package/lib/grid/observer.js +107 -0
- package/lib/index.d.ts +12 -24
- package/lib/index.js +27 -244
- package/lib/json-schema/compiler.d.ts +8 -0
- package/lib/json-schema/compiler.js +129 -0
- package/lib/json-schema/global.d.js +0 -0
- package/lib/json-schema/index.d.ts +2 -0
- package/lib/json-schema/index.js +23 -0
- package/lib/json-schema/patches.d.ts +5 -0
- package/lib/json-schema/patches.js +68 -0
- package/lib/json-schema/polyfills/SPECIFICATION_1_0.d.ts +2 -0
- package/lib/json-schema/polyfills/SPECIFICATION_1_0.js +132 -0
- package/lib/json-schema/polyfills/index.d.ts +1 -0
- package/lib/json-schema/polyfills/index.js +21 -0
- package/lib/json-schema/schema.d.ts +88 -0
- package/lib/json-schema/schema.js +231 -0
- package/lib/json-schema/shared.d.ts +62 -0
- package/lib/json-schema/shared.js +232 -0
- package/lib/json-schema/transformer.d.ts +4 -0
- package/lib/json-schema/transformer.js +238 -0
- package/lib/json-schema/types.d.ts +119 -0
- package/lib/json-schema/types.js +15 -0
- package/lib/path/contexts.d.ts +10 -0
- package/lib/path/contexts.js +49 -0
- package/lib/path/destructor.d.ts +15 -0
- package/lib/path/destructor.js +151 -0
- package/lib/path/index.d.ts +51 -0
- package/lib/path/index.js +513 -0
- package/lib/path/matcher.d.ts +33 -0
- package/lib/path/matcher.js +197 -0
- package/lib/path/parser.d.ts +33 -0
- package/lib/path/parser.js +379 -0
- package/lib/path/shared.d.ts +13 -0
- package/lib/path/shared.js +121 -0
- package/lib/path/tokenizer.d.ts +27 -0
- package/lib/path/tokenizer.js +269 -0
- package/lib/path/tokens.d.ts +27 -0
- package/lib/path/tokens.js +216 -0
- package/lib/path/types.d.ts +88 -0
- package/lib/path/types.js +63 -0
- package/lib/react/components/ArrayField.d.ts +6 -0
- package/lib/react/components/ArrayField.js +44 -0
- package/lib/react/components/ExpressionScope.d.ts +2 -0
- package/lib/react/components/ExpressionScope.js +35 -0
- package/lib/react/components/Field.d.ts +5 -0
- package/lib/react/components/Field.js +45 -0
- package/lib/react/components/FormConsumer.d.ts +2 -0
- package/lib/react/components/FormConsumer.js +36 -0
- package/lib/react/components/FormProvider.d.ts +2 -0
- package/lib/react/components/FormProvider.js +35 -0
- package/lib/react/components/ObjectField.d.ts +6 -0
- package/lib/react/components/ObjectField.js +39 -0
- package/lib/react/components/ReactiveField.d.ts +11 -0
- package/lib/react/components/ReactiveField.js +115 -0
- package/lib/react/components/RecordScope.d.ts +2 -0
- package/lib/react/components/RecordScope.js +65 -0
- package/lib/react/components/RecordsScope.d.ts +2 -0
- package/lib/react/components/RecordsScope.js +43 -0
- package/lib/react/components/RecursionField.d.ts +2 -0
- package/lib/react/components/RecursionField.js +105 -0
- package/lib/react/components/SchemaField.d.ts +41 -0
- package/lib/react/components/SchemaField.js +154 -0
- package/lib/react/components/VoidField.d.ts +5 -0
- package/lib/react/components/VoidField.js +39 -0
- package/lib/react/components/index.d.ts +11 -0
- package/lib/react/components/index.js +41 -0
- package/lib/react/global.d.js +0 -0
- package/lib/react/hooks/index.d.ts +6 -0
- package/lib/react/hooks/index.js +31 -0
- package/lib/react/hooks/useAttach.d.ts +6 -0
- package/lib/react/hooks/useAttach.js +35 -0
- package/lib/react/hooks/useExpressionScope.d.ts +1 -0
- package/lib/react/hooks/useExpressionScope.js +30 -0
- package/lib/react/hooks/useField.d.ts +2 -0
- package/lib/react/hooks/useField.js +32 -0
- package/lib/react/hooks/useFieldSchema.d.ts +2 -0
- package/lib/react/hooks/useFieldSchema.js +32 -0
- package/lib/react/hooks/useForm.d.ts +2 -0
- package/lib/react/hooks/useForm.js +32 -0
- package/lib/react/hooks/useFormEffects.d.ts +2 -0
- package/lib/react/hooks/useFormEffects.js +42 -0
- package/lib/react/hooks/useParentForm.d.ts +2 -0
- package/lib/react/hooks/useParentForm.js +40 -0
- package/lib/react/index.d.ts +5 -0
- package/lib/react/index.js +29 -0
- package/lib/react/shared/connect.d.ts +9 -0
- package/lib/react/shared/connect.js +118 -0
- package/lib/react/shared/context.d.ts +14 -0
- package/lib/react/shared/context.js +74 -0
- package/lib/react/shared/index.d.ts +2 -0
- package/lib/react/shared/index.js +23 -0
- package/lib/react/shared/render.d.ts +2 -0
- package/lib/react/shared/render.js +69 -0
- package/lib/react/types.d.ts +84 -0
- package/lib/react/types.js +15 -0
- package/lib/reactive/action.d.ts +2 -0
- package/lib/reactive/action.js +48 -0
- package/lib/reactive/annotations/box.d.ts +7 -0
- package/lib/reactive/annotations/box.js +76 -0
- package/lib/reactive/annotations/computed.d.ts +12 -0
- package/lib/reactive/annotations/computed.js +154 -0
- package/lib/reactive/annotations/index.d.ts +5 -0
- package/lib/reactive/annotations/index.js +29 -0
- package/lib/reactive/annotations/observable.d.ts +4 -0
- package/lib/reactive/annotations/observable.js +67 -0
- package/lib/reactive/annotations/ref.d.ts +6 -0
- package/lib/reactive/annotations/ref.js +78 -0
- package/lib/reactive/annotations/shallow.d.ts +2 -0
- package/lib/reactive/annotations/shallow.js +67 -0
- package/lib/reactive/array.d.ts +12 -0
- package/lib/reactive/array.js +83 -0
- package/lib/reactive/autorun.d.ts +7 -0
- package/lib/reactive/autorun.js +155 -0
- package/lib/reactive/batch.d.ts +2 -0
- package/lib/reactive/batch.js +40 -0
- package/lib/reactive/checkers.d.ts +10 -0
- package/lib/reactive/checkers.js +60 -0
- package/lib/reactive/environment.d.ts +28 -0
- package/lib/reactive/environment.js +76 -0
- package/lib/reactive/externals.d.ts +10 -0
- package/lib/reactive/externals.js +156 -0
- package/lib/reactive/global.d.js +0 -0
- package/lib/reactive/handlers.d.ts +4 -0
- package/lib/reactive/handlers.js +246 -0
- package/lib/reactive/index.d.ts +10 -0
- package/lib/reactive/index.js +39 -0
- package/lib/reactive/internals.d.ts +17 -0
- package/lib/reactive/internals.js +139 -0
- package/lib/reactive/model.d.ts +3 -0
- package/lib/reactive/model.js +68 -0
- package/lib/reactive/observable.d.ts +9 -0
- package/lib/reactive/observable.js +50 -0
- package/lib/reactive/observe.d.ts +2 -0
- package/lib/reactive/observe.js +58 -0
- package/lib/reactive/reaction.d.ts +21 -0
- package/lib/reactive/reaction.js +278 -0
- package/lib/reactive/tracker.d.ts +7 -0
- package/lib/reactive/tracker.js +63 -0
- package/lib/reactive/tree.d.ts +25 -0
- package/lib/reactive/tree.js +106 -0
- package/lib/reactive/types.d.ts +79 -0
- package/lib/reactive/types.js +21 -0
- package/lib/reactive/untracked.d.ts +4 -0
- package/lib/reactive/untracked.js +29 -0
- package/lib/reactive-react/hooks/index.d.ts +9 -0
- package/lib/reactive-react/hooks/index.js +48 -0
- package/lib/reactive-react/hooks/useCompatEffect.d.ts +2 -0
- package/lib/reactive-react/hooks/useCompatEffect.js +60 -0
- package/lib/reactive-react/hooks/useCompatFactory.d.ts +3 -0
- package/lib/reactive-react/hooks/useCompatFactory.js +74 -0
- package/lib/reactive-react/hooks/useDidUpdate.d.ts +1 -0
- package/lib/reactive-react/hooks/useDidUpdate.js +38 -0
- package/lib/reactive-react/hooks/useForceUpdate.d.ts +1 -0
- package/lib/reactive-react/hooks/useForceUpdate.js +76 -0
- package/lib/reactive-react/hooks/useLayoutEffect.d.ts +2 -0
- package/lib/reactive-react/hooks/useLayoutEffect.js +28 -0
- package/lib/reactive-react/hooks/useObserver.d.ts +2 -0
- package/lib/reactive-react/hooks/useObserver.js +43 -0
- package/lib/reactive-react/index.d.ts +3 -0
- package/lib/reactive-react/index.js +25 -0
- package/lib/reactive-react/observer.d.ts +8 -0
- package/lib/reactive-react/observer.js +64 -0
- package/lib/reactive-react/shared/gc.d.ts +8 -0
- package/lib/reactive-react/shared/gc.js +59 -0
- package/lib/reactive-react/shared/global.d.ts +1 -0
- package/lib/reactive-react/shared/global.js +50 -0
- package/lib/reactive-react/shared/immediate.d.ts +1 -0
- package/lib/reactive-react/shared/immediate.js +40 -0
- package/lib/reactive-react/shared/index.d.ts +2 -0
- package/lib/reactive-react/shared/index.js +23 -0
- package/lib/reactive-react/types.d.ts +14 -0
- package/lib/reactive-react/types.js +15 -0
- package/lib/shared/array.d.ts +35 -0
- package/lib/shared/array.js +189 -0
- package/lib/shared/case.d.ts +6 -0
- package/lib/shared/case.js +39 -0
- package/lib/shared/checkers.d.ts +21 -0
- package/lib/shared/checkers.js +77 -0
- package/lib/shared/clone.d.ts +2 -0
- package/lib/shared/clone.js +97 -0
- package/lib/shared/compare.d.ts +1 -0
- package/lib/shared/compare.js +129 -0
- package/lib/shared/defaults.d.ts +6 -0
- package/lib/shared/defaults.js +63 -0
- package/lib/shared/deprecate.d.ts +1 -0
- package/lib/shared/deprecate.js +42 -0
- package/lib/shared/global.d.ts +1 -0
- package/lib/shared/global.js +50 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +51 -0
- package/lib/shared/instanceof.d.ts +1 -0
- package/lib/shared/instanceof.js +36 -0
- package/lib/shared/isEmpty.d.ts +3 -0
- package/lib/shared/isEmpty.js +94 -0
- package/lib/shared/merge.d.ts +12 -0
- package/lib/shared/merge.js +214 -0
- package/lib/shared/middleware.d.ts +4 -0
- package/lib/shared/middleware.js +41 -0
- package/lib/shared/path.d.ts +3 -0
- package/lib/shared/path.js +27 -0
- package/lib/shared/string.d.ts +1 -0
- package/lib/shared/string.js +38 -0
- package/lib/shared/subscribable.d.ts +11 -0
- package/lib/shared/subscribable.js +74 -0
- package/lib/shared/uid.d.ts +1 -0
- package/lib/shared/uid.js +35 -0
- package/lib/validator/formats.d.ts +16 -0
- package/lib/validator/formats.js +40 -0
- package/lib/validator/index.d.ts +4 -0
- package/lib/validator/index.js +27 -0
- package/lib/validator/locale.d.ts +219 -0
- package/lib/validator/locale.js +240 -0
- package/lib/validator/parser.d.ts +5 -0
- package/lib/validator/parser.js +153 -0
- package/lib/validator/registry.d.ts +15 -0
- package/lib/validator/registry.js +116 -0
- package/lib/validator/rules.d.ts +3 -0
- package/lib/validator/rules.js +154 -0
- package/lib/validator/template.d.ts +2 -0
- package/lib/validator/template.js +42 -0
- package/lib/validator/types.d.ts +62 -0
- package/lib/validator/types.js +28 -0
- package/lib/validator/validator.d.ts +2 -0
- package/lib/validator/validator.js +63 -0
- package/package.json +16 -10
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var matcher_exports = {};
|
|
20
|
+
__export(matcher_exports, {
|
|
21
|
+
Matcher: () => Matcher
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(matcher_exports);
|
|
24
|
+
var import_shared = require("./shared");
|
|
25
|
+
var import_types = require("./types");
|
|
26
|
+
const _Matcher = class _Matcher {
|
|
27
|
+
constructor(tree, record) {
|
|
28
|
+
this.tree = tree;
|
|
29
|
+
this.stack = [];
|
|
30
|
+
this.excluding = false;
|
|
31
|
+
this.wildcards = [];
|
|
32
|
+
this.record = record;
|
|
33
|
+
}
|
|
34
|
+
next(node, pos) {
|
|
35
|
+
if (node.after) {
|
|
36
|
+
return this.matchNode(node.after, pos);
|
|
37
|
+
}
|
|
38
|
+
if ((0, import_types.isWildcardOperator)(node) && !node.filter) {
|
|
39
|
+
if (this.excluding) {
|
|
40
|
+
return false;
|
|
41
|
+
} else {
|
|
42
|
+
if (pos === 0 || node.optional) return true;
|
|
43
|
+
return !!this.take(pos);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const isLastToken = pos === this.path.length - 1;
|
|
47
|
+
if (isLastToken) {
|
|
48
|
+
return !!this.take(pos);
|
|
49
|
+
} else {
|
|
50
|
+
const wildcard = this.wildcards.pop();
|
|
51
|
+
if (wildcard && wildcard.after) {
|
|
52
|
+
return this.next(wildcard, pos);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
shot() {
|
|
58
|
+
var _a;
|
|
59
|
+
if (((_a = this.record) == null ? void 0 : _a.score) >= 0) {
|
|
60
|
+
this.record.score++;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
take(pos) {
|
|
64
|
+
return String(this.path[pos] ?? "");
|
|
65
|
+
}
|
|
66
|
+
matchExcludeIdentifier(matched, node, pos) {
|
|
67
|
+
const isLastToken = pos === this.path.length - 1;
|
|
68
|
+
const isContainToken = pos < this.path.length;
|
|
69
|
+
if (!node.after) {
|
|
70
|
+
this.excluding = false;
|
|
71
|
+
}
|
|
72
|
+
if (matched) {
|
|
73
|
+
if (node.after) {
|
|
74
|
+
return this.next(node, pos);
|
|
75
|
+
}
|
|
76
|
+
if (isLastToken) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (isLastToken) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return isContainToken;
|
|
84
|
+
}
|
|
85
|
+
matchIdentifier(node, pos) {
|
|
86
|
+
const current = this.take(pos);
|
|
87
|
+
let matched = false;
|
|
88
|
+
if ((0, import_types.isExpandOperator)(node.after)) {
|
|
89
|
+
if (current.indexOf(node.value) === 0) {
|
|
90
|
+
this.shot();
|
|
91
|
+
matched = true;
|
|
92
|
+
}
|
|
93
|
+
if (this.excluding) {
|
|
94
|
+
return this.matchExcludeIdentifier(matched, node.after, pos);
|
|
95
|
+
} else {
|
|
96
|
+
return matched && this.next(node.after, pos);
|
|
97
|
+
}
|
|
98
|
+
} else if (current === node.value) {
|
|
99
|
+
this.shot();
|
|
100
|
+
matched = true;
|
|
101
|
+
}
|
|
102
|
+
if (this.excluding) {
|
|
103
|
+
return this.matchExcludeIdentifier(matched, node, pos);
|
|
104
|
+
} else {
|
|
105
|
+
return matched && this.next(node, pos);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
matchIgnoreExpression(node, pos) {
|
|
109
|
+
return (0, import_shared.isEqual)(node.value, this.take(pos)) && this.next(node, pos);
|
|
110
|
+
}
|
|
111
|
+
matchDestructorExpression(node, pos) {
|
|
112
|
+
return (0, import_shared.isEqual)(node.source, this.take(pos)) && this.next(node, pos);
|
|
113
|
+
}
|
|
114
|
+
matchExpandOperator(node, pos) {
|
|
115
|
+
return this.next(node, pos);
|
|
116
|
+
}
|
|
117
|
+
matchWildcardOperator(node, pos) {
|
|
118
|
+
let matched = false;
|
|
119
|
+
if (node.filter) {
|
|
120
|
+
this.stack.push(node);
|
|
121
|
+
matched = this.matchNode(node.filter, pos);
|
|
122
|
+
this.stack.pop();
|
|
123
|
+
} else {
|
|
124
|
+
matched = this.next(node, pos);
|
|
125
|
+
}
|
|
126
|
+
return matched;
|
|
127
|
+
}
|
|
128
|
+
matchGroupExpression(node, pos) {
|
|
129
|
+
let excluding = false;
|
|
130
|
+
if (node.isExclude) {
|
|
131
|
+
excluding = !this.excluding;
|
|
132
|
+
}
|
|
133
|
+
return (0, import_shared.toArr)(node.value)[excluding ? "every" : "some"]((item) => {
|
|
134
|
+
this.wildcards = this.stack.slice();
|
|
135
|
+
this.excluding = excluding;
|
|
136
|
+
return this.matchNode(item, pos);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
matchRangeExpression(node, pos) {
|
|
140
|
+
const current = Number(this.take(pos));
|
|
141
|
+
if (node.start) {
|
|
142
|
+
if (node.end) {
|
|
143
|
+
return current >= Number(node.start.value) && current <= Number(node.end.value);
|
|
144
|
+
} else {
|
|
145
|
+
return current >= Number(node.start.value);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
if (node.end) {
|
|
149
|
+
return current <= Number(node.end.value);
|
|
150
|
+
} else {
|
|
151
|
+
this.wildcards = this.stack.slice();
|
|
152
|
+
return this.next(node, pos);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
matchNode(node, pos = 0) {
|
|
157
|
+
if ((0, import_types.isDotOperator)(node)) {
|
|
158
|
+
return this.next(node, pos + 1);
|
|
159
|
+
} else if ((0, import_types.isIdentifier)(node)) {
|
|
160
|
+
return this.matchIdentifier(node, pos);
|
|
161
|
+
} else if ((0, import_types.isIgnoreExpression)(node)) {
|
|
162
|
+
return this.matchIgnoreExpression(node, pos);
|
|
163
|
+
} else if ((0, import_types.isDestructorExpression)(node)) {
|
|
164
|
+
return this.matchDestructorExpression(node, pos);
|
|
165
|
+
} else if ((0, import_types.isExpandOperator)(node)) {
|
|
166
|
+
return this.matchExpandOperator(node, pos);
|
|
167
|
+
} else if ((0, import_types.isWildcardOperator)(node)) {
|
|
168
|
+
return this.matchWildcardOperator(node, pos);
|
|
169
|
+
} else if ((0, import_types.isGroupExpression)(node)) {
|
|
170
|
+
return this.matchGroupExpression(node, pos);
|
|
171
|
+
} else if ((0, import_types.isRangeExpression)(node)) {
|
|
172
|
+
return this.matchRangeExpression(node, pos);
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
match(path) {
|
|
177
|
+
this.path = path;
|
|
178
|
+
return { matched: this.matchNode(this.tree), record: this.record };
|
|
179
|
+
}
|
|
180
|
+
static matchSegments(source, target, record) {
|
|
181
|
+
if (source.length !== target.length) return { matched: false, record };
|
|
182
|
+
const match = /* @__PURE__ */ __name((pos = 0) => {
|
|
183
|
+
const current = (0, import_shared.isSegmentEqual)(source[pos], target[pos]);
|
|
184
|
+
if ((record == null ? void 0 : record.score) >= 0) {
|
|
185
|
+
record.score++;
|
|
186
|
+
}
|
|
187
|
+
return current && (pos < source.length - 1 ? match(pos + 1) : true);
|
|
188
|
+
}, "match");
|
|
189
|
+
return { matched: match(), record };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
__name(_Matcher, "Matcher");
|
|
193
|
+
let Matcher = _Matcher;
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
Matcher
|
|
197
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Path } from './index';
|
|
2
|
+
import { Tokenizer } from './tokenizer';
|
|
3
|
+
import { Token } from './tokens';
|
|
4
|
+
import { ArrayPatternNode, DestructorExpressionNode, ExpandOperatorNode, GroupExpressionNode, IdentifierNode, IgnoreExpressionNode, Node, ObjectPatternNode, ObjectPatternPropertyNode, RangeExpressionNode, Segments, WildcardOperatorNode } from './types';
|
|
5
|
+
export declare class Parser extends Tokenizer {
|
|
6
|
+
isMatchPattern: boolean;
|
|
7
|
+
isWildMatchPattern: boolean;
|
|
8
|
+
haveExcludePattern: boolean;
|
|
9
|
+
haveRelativePattern: boolean;
|
|
10
|
+
base: Path;
|
|
11
|
+
relative: string | number;
|
|
12
|
+
data: {
|
|
13
|
+
segments: Segments;
|
|
14
|
+
tree?: Node;
|
|
15
|
+
};
|
|
16
|
+
constructor(input: string, base?: Path);
|
|
17
|
+
parse(): Node;
|
|
18
|
+
append(parent: Node, node: Node): void;
|
|
19
|
+
parseAtom(type: Token): Node;
|
|
20
|
+
pushSegments(key: string | number): void;
|
|
21
|
+
parseIdentifier(): IdentifierNode;
|
|
22
|
+
parseExpandOperator(): ExpandOperatorNode;
|
|
23
|
+
parseWildcardOperator(): WildcardOperatorNode;
|
|
24
|
+
parseDestructorExpression(): DestructorExpressionNode;
|
|
25
|
+
parseArrayPattern(): ArrayPatternNode;
|
|
26
|
+
parseArrayPatternElements(): any[];
|
|
27
|
+
parseObjectPattern(): ObjectPatternNode;
|
|
28
|
+
parseObjectProperties(): ObjectPatternPropertyNode[];
|
|
29
|
+
parseDotOperator(): Node;
|
|
30
|
+
parseIgnoreExpression(): IgnoreExpressionNode;
|
|
31
|
+
parseGroupExpression(parent: Node): GroupExpressionNode;
|
|
32
|
+
parseRangeExpression(parent: Node): RangeExpressionNode;
|
|
33
|
+
}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var parser_exports = {};
|
|
20
|
+
__export(parser_exports, {
|
|
21
|
+
Parser: () => Parser
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(parser_exports);
|
|
24
|
+
var import_contexts = require("./contexts");
|
|
25
|
+
var import_destructor = require("./destructor");
|
|
26
|
+
var import_shared = require("./shared");
|
|
27
|
+
var import_tokenizer = require("./tokenizer");
|
|
28
|
+
var import_tokens = require("./tokens");
|
|
29
|
+
const createTreeBySegments = /* @__PURE__ */ __name((segments = [], afterNode) => {
|
|
30
|
+
const segLen = segments.length;
|
|
31
|
+
const build = /* @__PURE__ */ __name((start = 0) => {
|
|
32
|
+
const after = start < segLen - 1 ? build(start + 1) : afterNode;
|
|
33
|
+
const dot = after && {
|
|
34
|
+
type: "DotOperator",
|
|
35
|
+
after
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
type: "Identifier",
|
|
39
|
+
value: segments[start],
|
|
40
|
+
after: dot
|
|
41
|
+
};
|
|
42
|
+
}, "build");
|
|
43
|
+
return build();
|
|
44
|
+
}, "createTreeBySegments");
|
|
45
|
+
const calculate = /* @__PURE__ */ __name((a, b, operator) => {
|
|
46
|
+
if ((0, import_shared.isNumberLike)(a) && (0, import_shared.isNumberLike)(b)) {
|
|
47
|
+
if (operator === "+") return String(Number(a) + Number(b));
|
|
48
|
+
if (operator === "-") return String(Number(a) - Number(b));
|
|
49
|
+
if (operator === "*") return String(Number(a) * Number(b));
|
|
50
|
+
if (operator === "/") return String(Number(a) / Number(b));
|
|
51
|
+
} else {
|
|
52
|
+
if (operator === "+") return String(a) + String(b);
|
|
53
|
+
if (operator === "-") return "NaN";
|
|
54
|
+
if (operator === "*") return "NaN";
|
|
55
|
+
if (operator === "/") return "NaN";
|
|
56
|
+
}
|
|
57
|
+
return String(Number(b));
|
|
58
|
+
}, "calculate");
|
|
59
|
+
const _Parser = class _Parser extends import_tokenizer.Tokenizer {
|
|
60
|
+
constructor(input, base) {
|
|
61
|
+
super(input);
|
|
62
|
+
this.isMatchPattern = false;
|
|
63
|
+
this.isWildMatchPattern = false;
|
|
64
|
+
this.haveExcludePattern = false;
|
|
65
|
+
this.haveRelativePattern = false;
|
|
66
|
+
this.base = base;
|
|
67
|
+
}
|
|
68
|
+
parse() {
|
|
69
|
+
let node;
|
|
70
|
+
this.data = {
|
|
71
|
+
segments: []
|
|
72
|
+
};
|
|
73
|
+
if (!this.eat(import_tokens.eofTok)) {
|
|
74
|
+
this.next();
|
|
75
|
+
node = this.parseAtom(this.state.type);
|
|
76
|
+
}
|
|
77
|
+
this.data.tree = node;
|
|
78
|
+
return node;
|
|
79
|
+
}
|
|
80
|
+
append(parent, node) {
|
|
81
|
+
if (parent && node) {
|
|
82
|
+
parent.after = node;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
parseAtom(type) {
|
|
86
|
+
switch (type) {
|
|
87
|
+
case import_tokens.braceLTok:
|
|
88
|
+
case import_tokens.bracketLTok:
|
|
89
|
+
if (this.includesContext(import_contexts.destructorContext)) {
|
|
90
|
+
if (type === import_tokens.braceLTok) {
|
|
91
|
+
return this.parseObjectPattern();
|
|
92
|
+
} else {
|
|
93
|
+
return this.parseArrayPattern();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return this.parseDestructorExpression();
|
|
97
|
+
case import_tokens.nameTok:
|
|
98
|
+
return this.parseIdentifier();
|
|
99
|
+
case import_tokens.expandTok:
|
|
100
|
+
return this.parseExpandOperator();
|
|
101
|
+
case import_tokens.dbStarTok:
|
|
102
|
+
case import_tokens.starTok:
|
|
103
|
+
return this.parseWildcardOperator();
|
|
104
|
+
case import_tokens.bracketDLTok:
|
|
105
|
+
return this.parseIgnoreExpression();
|
|
106
|
+
case import_tokens.dotTok:
|
|
107
|
+
return this.parseDotOperator();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
pushSegments(key) {
|
|
111
|
+
this.data.segments.push(key);
|
|
112
|
+
}
|
|
113
|
+
parseIdentifier() {
|
|
114
|
+
const node = {
|
|
115
|
+
type: "Identifier",
|
|
116
|
+
value: this.state.value
|
|
117
|
+
};
|
|
118
|
+
const hasNotInDestructor = !this.includesContext(import_contexts.destructorContext) && !this.isMatchPattern && !this.isWildMatchPattern;
|
|
119
|
+
this.next();
|
|
120
|
+
if (this.includesContext(import_contexts.bracketArrayContext)) {
|
|
121
|
+
if (this.state.type !== import_tokens.bracketRTok) {
|
|
122
|
+
throw this.unexpect();
|
|
123
|
+
} else {
|
|
124
|
+
this.state.context.pop();
|
|
125
|
+
this.next();
|
|
126
|
+
}
|
|
127
|
+
} else if (hasNotInDestructor) {
|
|
128
|
+
this.pushSegments(node.value);
|
|
129
|
+
}
|
|
130
|
+
if (this.state.type === import_tokens.bracketLTok) {
|
|
131
|
+
this.next();
|
|
132
|
+
if (this.state.type !== import_tokens.nameTok) {
|
|
133
|
+
throw this.unexpect();
|
|
134
|
+
}
|
|
135
|
+
this.state.context.push(import_contexts.bracketArrayContext);
|
|
136
|
+
let isNumberKey = false;
|
|
137
|
+
if (/^\d+$/.test(this.state.value)) {
|
|
138
|
+
isNumberKey = true;
|
|
139
|
+
}
|
|
140
|
+
const value = this.state.value;
|
|
141
|
+
this.pushSegments(isNumberKey ? Number(value) : value);
|
|
142
|
+
const after = this.parseAtom(this.state.type);
|
|
143
|
+
if (isNumberKey) {
|
|
144
|
+
after.arrayIndex = true;
|
|
145
|
+
}
|
|
146
|
+
this.append(node, after);
|
|
147
|
+
} else {
|
|
148
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
149
|
+
}
|
|
150
|
+
return node;
|
|
151
|
+
}
|
|
152
|
+
parseExpandOperator() {
|
|
153
|
+
const node = {
|
|
154
|
+
type: "ExpandOperator"
|
|
155
|
+
};
|
|
156
|
+
this.isMatchPattern = true;
|
|
157
|
+
this.isWildMatchPattern = true;
|
|
158
|
+
this.data.segments = [];
|
|
159
|
+
this.next();
|
|
160
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
161
|
+
return node;
|
|
162
|
+
}
|
|
163
|
+
parseWildcardOperator() {
|
|
164
|
+
const node = {
|
|
165
|
+
type: "WildcardOperator"
|
|
166
|
+
};
|
|
167
|
+
if (this.state.type === import_tokens.dbStarTok) {
|
|
168
|
+
node.optional = true;
|
|
169
|
+
}
|
|
170
|
+
this.isMatchPattern = true;
|
|
171
|
+
this.isWildMatchPattern = true;
|
|
172
|
+
this.data.segments = [];
|
|
173
|
+
this.next();
|
|
174
|
+
if (this.state.type === import_tokens.parenLTok) {
|
|
175
|
+
node.filter = this.parseGroupExpression(node);
|
|
176
|
+
} else if (this.state.type === import_tokens.bracketLTok) {
|
|
177
|
+
node.filter = this.parseRangeExpression(node);
|
|
178
|
+
}
|
|
179
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
180
|
+
return node;
|
|
181
|
+
}
|
|
182
|
+
parseDestructorExpression() {
|
|
183
|
+
const node = {
|
|
184
|
+
type: "DestructorExpression"
|
|
185
|
+
};
|
|
186
|
+
this.state.context.push(import_contexts.destructorContext);
|
|
187
|
+
const startPos = this.state.pos - 1;
|
|
188
|
+
node.value = this.state.type === import_tokens.braceLTok ? this.parseObjectPattern() : this.parseArrayPattern();
|
|
189
|
+
const endPos = this.state.pos;
|
|
190
|
+
this.state.context.pop();
|
|
191
|
+
node.source = this.input.substring(startPos, endPos).replace(/\[\s*([+\-*/])?\s*([^,\]\s]*)\s*\]/, (match, operator, target) => {
|
|
192
|
+
if (this.relative !== void 0) {
|
|
193
|
+
if (operator) {
|
|
194
|
+
if (target) {
|
|
195
|
+
return calculate(this.relative, target, operator);
|
|
196
|
+
} else {
|
|
197
|
+
return calculate(this.relative, 1, operator);
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
if (target) {
|
|
201
|
+
return calculate(this.relative, target, "+");
|
|
202
|
+
} else {
|
|
203
|
+
return String(this.relative);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return match;
|
|
208
|
+
}).replace(/\s*\.\s*/g, "").replace(/\s*/g, "");
|
|
209
|
+
if (this.relative === void 0) {
|
|
210
|
+
(0, import_destructor.setDestructor)(node.source, (0, import_destructor.parseDestructorRules)(node));
|
|
211
|
+
}
|
|
212
|
+
this.relative = void 0;
|
|
213
|
+
this.pushSegments(node.source);
|
|
214
|
+
this.next();
|
|
215
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
216
|
+
return node;
|
|
217
|
+
}
|
|
218
|
+
parseArrayPattern() {
|
|
219
|
+
const node = {
|
|
220
|
+
type: "ArrayPattern",
|
|
221
|
+
elements: []
|
|
222
|
+
};
|
|
223
|
+
this.next();
|
|
224
|
+
node.elements = this.parseArrayPatternElements();
|
|
225
|
+
return node;
|
|
226
|
+
}
|
|
227
|
+
parseArrayPatternElements() {
|
|
228
|
+
const nodes = [];
|
|
229
|
+
while (this.state.type !== import_tokens.bracketRTok && this.state.type !== import_tokens.eofTok) {
|
|
230
|
+
nodes.push(this.parseAtom(this.state.type));
|
|
231
|
+
if (this.state.type === import_tokens.bracketRTok) {
|
|
232
|
+
if (this.includesContext(import_contexts.destructorContext)) {
|
|
233
|
+
this.next();
|
|
234
|
+
}
|
|
235
|
+
return nodes;
|
|
236
|
+
}
|
|
237
|
+
this.next();
|
|
238
|
+
}
|
|
239
|
+
return nodes;
|
|
240
|
+
}
|
|
241
|
+
parseObjectPattern() {
|
|
242
|
+
const node = {
|
|
243
|
+
type: "ObjectPattern",
|
|
244
|
+
properties: []
|
|
245
|
+
};
|
|
246
|
+
this.next();
|
|
247
|
+
node.properties = this.parseObjectProperties();
|
|
248
|
+
return node;
|
|
249
|
+
}
|
|
250
|
+
parseObjectProperties() {
|
|
251
|
+
const nodes = [];
|
|
252
|
+
while (this.state.type !== import_tokens.braceRTok && this.state.type !== import_tokens.eofTok) {
|
|
253
|
+
const node = {
|
|
254
|
+
type: "ObjectPatternProperty",
|
|
255
|
+
key: this.parseAtom(this.state.type)
|
|
256
|
+
};
|
|
257
|
+
nodes.push(node);
|
|
258
|
+
if (this.state.type === import_tokens.colonTok) {
|
|
259
|
+
this.next();
|
|
260
|
+
node.value = this.parseAtom(this.state.type);
|
|
261
|
+
}
|
|
262
|
+
if (this.state.type === import_tokens.braceRTok) {
|
|
263
|
+
if (this.includesContext(import_contexts.destructorContext)) {
|
|
264
|
+
this.next();
|
|
265
|
+
}
|
|
266
|
+
return nodes;
|
|
267
|
+
}
|
|
268
|
+
this.next();
|
|
269
|
+
}
|
|
270
|
+
return nodes;
|
|
271
|
+
}
|
|
272
|
+
parseDotOperator() {
|
|
273
|
+
const node = {
|
|
274
|
+
type: "DotOperator"
|
|
275
|
+
};
|
|
276
|
+
const prevToken = this.type_;
|
|
277
|
+
if (!prevToken && this.base) {
|
|
278
|
+
if (this.base.isMatchPattern) {
|
|
279
|
+
throw new Error("Base path must be an absolute path.");
|
|
280
|
+
}
|
|
281
|
+
this.data.segments = this.base.toArr();
|
|
282
|
+
while (this.state.type === import_tokens.dotTok) {
|
|
283
|
+
this.relative = this.data.segments.pop();
|
|
284
|
+
this.haveRelativePattern = true;
|
|
285
|
+
this.next();
|
|
286
|
+
}
|
|
287
|
+
return createTreeBySegments(this.data.segments.slice(), this.parseAtom(this.state.type));
|
|
288
|
+
} else {
|
|
289
|
+
this.next();
|
|
290
|
+
}
|
|
291
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
292
|
+
return node;
|
|
293
|
+
}
|
|
294
|
+
parseIgnoreExpression() {
|
|
295
|
+
this.next();
|
|
296
|
+
const value = String(this.state.value).replace(/\s*/g, "");
|
|
297
|
+
const node = {
|
|
298
|
+
type: "IgnoreExpression",
|
|
299
|
+
value
|
|
300
|
+
};
|
|
301
|
+
this.pushSegments(value);
|
|
302
|
+
this.next();
|
|
303
|
+
this.append(node, this.parseAtom(this.state.type));
|
|
304
|
+
this.next();
|
|
305
|
+
return node;
|
|
306
|
+
}
|
|
307
|
+
parseGroupExpression(parent) {
|
|
308
|
+
const node = {
|
|
309
|
+
type: "GroupExpression",
|
|
310
|
+
value: []
|
|
311
|
+
};
|
|
312
|
+
this.isMatchPattern = true;
|
|
313
|
+
this.data.segments = [];
|
|
314
|
+
this.next();
|
|
315
|
+
loop: while (true) {
|
|
316
|
+
switch (this.state.type) {
|
|
317
|
+
case import_tokens.commaTok:
|
|
318
|
+
this.next();
|
|
319
|
+
break;
|
|
320
|
+
case import_tokens.bangTok:
|
|
321
|
+
node.isExclude = true;
|
|
322
|
+
this.haveExcludePattern = true;
|
|
323
|
+
this.next();
|
|
324
|
+
break;
|
|
325
|
+
case import_tokens.eofTok:
|
|
326
|
+
break loop;
|
|
327
|
+
case import_tokens.parenRTok:
|
|
328
|
+
break loop;
|
|
329
|
+
default:
|
|
330
|
+
node.value.push(this.parseAtom(this.state.type));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
this.next();
|
|
334
|
+
this.append(parent, this.parseAtom(this.state.type));
|
|
335
|
+
return node;
|
|
336
|
+
}
|
|
337
|
+
parseRangeExpression(parent) {
|
|
338
|
+
const node = {
|
|
339
|
+
type: "RangeExpression"
|
|
340
|
+
};
|
|
341
|
+
this.next();
|
|
342
|
+
this.isMatchPattern = true;
|
|
343
|
+
this.data.segments = [];
|
|
344
|
+
let start = false, hasColon = false;
|
|
345
|
+
loop: while (true) {
|
|
346
|
+
switch (this.state.type) {
|
|
347
|
+
case import_tokens.colonTok:
|
|
348
|
+
hasColon = true;
|
|
349
|
+
start = true;
|
|
350
|
+
this.next();
|
|
351
|
+
break;
|
|
352
|
+
case import_tokens.bracketRTok:
|
|
353
|
+
if (!hasColon && !node.end) {
|
|
354
|
+
node.end = node.start;
|
|
355
|
+
}
|
|
356
|
+
break loop;
|
|
357
|
+
case import_tokens.commaTok:
|
|
358
|
+
throw this.unexpect();
|
|
359
|
+
case import_tokens.eofTok:
|
|
360
|
+
break loop;
|
|
361
|
+
default:
|
|
362
|
+
if (!start) {
|
|
363
|
+
node.start = this.parseAtom(this.state.type);
|
|
364
|
+
} else {
|
|
365
|
+
node.end = this.parseAtom(this.state.type);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
this.next();
|
|
370
|
+
this.append(parent, this.parseAtom(this.state.type));
|
|
371
|
+
return node;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
__name(_Parser, "Parser");
|
|
375
|
+
let Parser = _Parser;
|
|
376
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
377
|
+
0 && (module.exports = {
|
|
378
|
+
Parser
|
|
379
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const isFn: (obj: unknown) => obj is (...args: any[]) => any;
|
|
2
|
+
export declare const isArr: (arg: any) => arg is any[];
|
|
3
|
+
export declare const isPlainObj: (obj: unknown) => obj is object;
|
|
4
|
+
export declare const isStr: (obj: unknown) => obj is string;
|
|
5
|
+
export declare const isBool: (obj: unknown) => obj is boolean;
|
|
6
|
+
export declare const isNum: (obj: unknown) => obj is number;
|
|
7
|
+
export declare const isObj: (val: unknown) => val is object;
|
|
8
|
+
export declare const isRegExp: (obj: unknown) => obj is RegExp;
|
|
9
|
+
export declare const isNumberLike: (t: any) => boolean;
|
|
10
|
+
export declare const toArr: <T>(val: T | T[]) => T[];
|
|
11
|
+
export declare const isAssignable: (val: any) => boolean;
|
|
12
|
+
export declare const isEqual: (a: any, b: any) => boolean;
|
|
13
|
+
export declare const isSegmentEqual: (a: any, b: any) => boolean;
|