@shwfed/nuxt 0.7.8 → 0.7.10

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 (174) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/app.d.vue.ts +7 -58
  3. package/dist/runtime/components/app.vue +18 -411
  4. package/dist/runtime/components/app.vue.d.ts +7 -58
  5. package/dist/runtime/components/fields.d.vue.ts +177 -0
  6. package/dist/runtime/components/fields.vue +47 -0
  7. package/dist/runtime/components/fields.vue.d.ts +177 -0
  8. package/dist/runtime/components/table.d.vue.ts +63 -59
  9. package/dist/runtime/components/table.vue +52 -617
  10. package/dist/runtime/components/table.vue.d.ts +63 -59
  11. package/dist/runtime/components/ui/app/App.d.vue.ts +86 -0
  12. package/dist/runtime/components/ui/app/App.vue +414 -0
  13. package/dist/runtime/components/ui/app/App.vue.d.ts +86 -0
  14. package/dist/runtime/components/ui/button-group/ButtonGroupSeparator.vue +1 -1
  15. package/dist/runtime/components/ui/button-group/ButtonGroupText.vue +1 -1
  16. package/dist/runtime/components/ui/calendar/Calendar.d.vue.ts +5 -12
  17. package/dist/runtime/components/ui/calendar/Calendar.vue +77 -92
  18. package/dist/runtime/components/ui/calendar/Calendar.vue.d.ts +5 -12
  19. package/dist/runtime/components/ui/calendar/CalendarCellTrigger.vue +1 -1
  20. package/dist/runtime/components/ui/calendar/index.d.ts +1 -1
  21. package/dist/runtime/components/ui/checkbox/Checkbox.vue +6 -2
  22. package/dist/runtime/components/ui/command/CommandGroup.vue +4 -0
  23. package/dist/runtime/components/ui/dialog/DialogOverlay.vue +1 -1
  24. package/dist/runtime/components/ui/dropdown-menu/DropdownMenuCheckboxItem.vue +1 -1
  25. package/dist/runtime/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
  26. package/dist/runtime/components/ui/expression-editor/ExpressionEditor.d.vue.ts +30 -0
  27. package/dist/runtime/components/ui/expression-editor/ExpressionEditor.vue +87 -0
  28. package/dist/runtime/components/ui/expression-editor/ExpressionEditor.vue.d.ts +30 -0
  29. package/dist/runtime/components/ui/expression-editor/index.d.ts +1 -0
  30. package/dist/runtime/components/ui/expression-editor/index.js +1 -0
  31. package/dist/runtime/components/ui/field/FieldContent.vue +1 -1
  32. package/dist/runtime/components/ui/field/FieldDescription.vue +1 -1
  33. package/dist/runtime/components/ui/field/FieldError.vue +2 -2
  34. package/dist/runtime/components/ui/field/FieldLabel.vue +1 -1
  35. package/dist/runtime/components/ui/field/FieldSeparator.vue +1 -1
  36. package/dist/runtime/components/ui/field/index.js +7 -5
  37. package/dist/runtime/components/ui/fields/Fields.d.vue.ts +376 -0
  38. package/dist/runtime/components/ui/fields/Fields.vue +441 -0
  39. package/dist/runtime/components/ui/fields/Fields.vue.d.ts +376 -0
  40. package/dist/runtime/components/ui/fields-configurator/FieldsConfiguratorDialog.d.vue.ts +163 -0
  41. package/dist/runtime/components/ui/fields-configurator/FieldsConfiguratorDialog.vue +363 -0
  42. package/dist/runtime/components/ui/fields-configurator/FieldsConfiguratorDialog.vue.d.ts +163 -0
  43. package/dist/runtime/components/ui/input/Input.d.vue.ts +1 -0
  44. package/dist/runtime/components/ui/input/Input.vue +3 -1
  45. package/dist/runtime/components/ui/input/Input.vue.d.ts +1 -0
  46. package/dist/runtime/components/ui/input-group/InputGroup.vue +3 -0
  47. package/dist/runtime/components/ui/input-group/InputGroupAddon.vue +4 -1
  48. package/dist/runtime/components/ui/input-group/InputGroupCombobox.d.vue.ts +11 -3
  49. package/dist/runtime/components/ui/input-group/InputGroupCombobox.vue +16 -5
  50. package/dist/runtime/components/ui/input-group/InputGroupCombobox.vue.d.ts +11 -3
  51. package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.d.vue.ts +8 -1
  52. package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.vue +12 -1
  53. package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.vue.d.ts +8 -1
  54. package/dist/runtime/components/ui/input-group/InputGroupInput.vue +1 -1
  55. package/dist/runtime/components/ui/input-group/InputGroupNumberField.d.vue.ts +5 -2
  56. package/dist/runtime/components/ui/input-group/InputGroupNumberField.vue +10 -4
  57. package/dist/runtime/components/ui/input-group/InputGroupNumberField.vue.d.ts +5 -2
  58. package/dist/runtime/components/ui/input-group/InputGroupText.vue +1 -1
  59. package/dist/runtime/components/ui/input-group/InputGroupTextarea.vue +1 -1
  60. package/dist/runtime/components/ui/input-group/index.js +2 -2
  61. package/dist/runtime/components/ui/label/Label.vue +1 -1
  62. package/dist/runtime/components/ui/locale/Locale.d.vue.ts +20 -0
  63. package/dist/runtime/components/ui/locale/Locale.vue +291 -0
  64. package/dist/runtime/components/ui/locale/Locale.vue.d.ts +20 -0
  65. package/dist/runtime/components/ui/locale/index.d.ts +1 -0
  66. package/dist/runtime/components/ui/locale/index.js +1 -0
  67. package/dist/runtime/components/ui/native-select/NativeSelect.vue +3 -3
  68. package/dist/runtime/components/ui/native-select/NativeSelectOption.d.vue.ts +1 -0
  69. package/dist/runtime/components/ui/native-select/NativeSelectOption.vue +4 -1
  70. package/dist/runtime/components/ui/native-select/NativeSelectOption.vue.d.ts +1 -0
  71. package/dist/runtime/components/ui/navigation-menu/NavigationMenuLink.vue +1 -1
  72. package/dist/runtime/components/ui/navigation-menu/NavigationMenuViewport.vue +1 -1
  73. package/dist/runtime/components/ui/number-field/NumberFieldInput.vue +1 -1
  74. package/dist/runtime/components/ui/range-calendar/RangeCalendarCell.vue +1 -1
  75. package/dist/runtime/components/ui/range-calendar/RangeCalendarCellTrigger.vue +1 -1
  76. package/dist/runtime/components/ui/sheet/SheetOverlay.vue +1 -1
  77. package/dist/runtime/components/ui/switch/Switch.d.vue.ts +24 -0
  78. package/dist/runtime/components/ui/switch/Switch.vue +46 -0
  79. package/dist/runtime/components/ui/switch/Switch.vue.d.ts +24 -0
  80. package/dist/runtime/components/ui/switch/index.d.ts +1 -0
  81. package/dist/runtime/components/ui/switch/index.js +1 -0
  82. package/dist/runtime/components/ui/table/Table.d.vue.ts +81 -0
  83. package/dist/runtime/components/ui/table/Table.vue +792 -0
  84. package/dist/runtime/components/ui/table/Table.vue.d.ts +81 -0
  85. package/dist/runtime/components/ui/table/schema.d.ts +48 -0
  86. package/dist/runtime/components/ui/table/schema.js +126 -0
  87. package/dist/runtime/components/ui/table-configurator/TableConfiguratorDialog.d.vue.ts +62 -0
  88. package/dist/runtime/components/ui/table-configurator/TableConfiguratorDialog.vue +2233 -0
  89. package/dist/runtime/components/ui/table-configurator/TableConfiguratorDialog.vue.d.ts +62 -0
  90. package/dist/runtime/components/ui/table-configurator/menu.d.ts +37 -0
  91. package/dist/runtime/components/ui/table-configurator/menu.js +227 -0
  92. package/dist/runtime/components/ui/tabs/Tabs.d.vue.ts +24 -0
  93. package/dist/runtime/components/ui/tabs/Tabs.vue +30 -0
  94. package/dist/runtime/components/ui/tabs/Tabs.vue.d.ts +24 -0
  95. package/dist/runtime/components/ui/tabs/TabsContent.d.vue.ts +18 -0
  96. package/dist/runtime/components/ui/tabs/TabsContent.vue +23 -0
  97. package/dist/runtime/components/ui/tabs/TabsContent.vue.d.ts +18 -0
  98. package/dist/runtime/components/ui/tabs/TabsList.d.vue.ts +18 -0
  99. package/dist/runtime/components/ui/tabs/TabsList.vue +25 -0
  100. package/dist/runtime/components/ui/tabs/TabsList.vue.d.ts +18 -0
  101. package/dist/runtime/components/ui/tabs/TabsTrigger.d.vue.ts +18 -0
  102. package/dist/runtime/components/ui/tabs/TabsTrigger.vue +27 -0
  103. package/dist/runtime/components/ui/tabs/TabsTrigger.vue.d.ts +18 -0
  104. package/dist/runtime/components/ui/tabs/index.d.ts +4 -0
  105. package/dist/runtime/components/ui/tabs/index.js +4 -0
  106. package/dist/runtime/components/ui/textarea/Textarea.d.vue.ts +1 -0
  107. package/dist/runtime/components/ui/textarea/Textarea.vue +4 -2
  108. package/dist/runtime/components/ui/textarea/Textarea.vue.d.ts +1 -0
  109. package/dist/runtime/components/ui/toggle/Toggle.d.vue.ts +34 -0
  110. package/dist/runtime/components/ui/toggle/Toggle.vue +32 -0
  111. package/dist/runtime/components/ui/toggle/Toggle.vue.d.ts +34 -0
  112. package/dist/runtime/components/ui/toggle/index.d.ts +7 -0
  113. package/dist/runtime/components/ui/toggle/index.js +22 -0
  114. package/dist/runtime/composables/useTableRenderers.d.ts +2 -1
  115. package/dist/runtime/composables/useTableRenderers.js +2 -1
  116. package/dist/runtime/plugins/cel/env.d.ts +2 -2
  117. package/dist/runtime/plugins/cel/env.js +5 -4
  118. package/dist/runtime/plugins/cel/index.d.ts +3 -3
  119. package/dist/runtime/plugins/cel/index.js +7 -3
  120. package/dist/runtime/plugins/markdown/index.d.ts +1 -1
  121. package/dist/runtime/style.css +1 -1
  122. package/dist/runtime/table-renderers/builtins.js +213 -98
  123. package/dist/runtime/table-renderers/registry.d.ts +1 -0
  124. package/dist/runtime/table-renderers/registry.js +3 -0
  125. package/dist/runtime/utils/coders.d.ts +32 -0
  126. package/dist/runtime/utils/coders.js +64 -0
  127. package/dist/runtime/vendor/cel/index.d.ts +17 -0
  128. package/dist/runtime/vendor/cel/index.js +10 -0
  129. package/dist/runtime/vendor/cel-js/LICENSE +21 -0
  130. package/dist/runtime/vendor/cel-js/UPSTREAM.md +17 -0
  131. package/dist/runtime/vendor/cel-js/lib/errors.d.ts +21 -0
  132. package/dist/runtime/vendor/cel-js/lib/errors.js +97 -0
  133. package/dist/runtime/vendor/cel-js/lib/evaluator.d.ts +4 -0
  134. package/dist/runtime/vendor/cel-js/lib/evaluator.js +192 -0
  135. package/dist/runtime/vendor/cel-js/lib/functions.d.ts +53 -0
  136. package/dist/runtime/vendor/cel-js/lib/functions.js +513 -0
  137. package/dist/runtime/vendor/cel-js/lib/globals.d.ts +27 -0
  138. package/dist/runtime/vendor/cel-js/lib/globals.js +33 -0
  139. package/dist/runtime/vendor/cel-js/lib/index.d.ts +469 -0
  140. package/dist/runtime/vendor/cel-js/lib/index.js +18 -0
  141. package/dist/runtime/vendor/cel-js/lib/macros.d.ts +1 -0
  142. package/dist/runtime/vendor/cel-js/lib/macros.js +230 -0
  143. package/dist/runtime/vendor/cel-js/lib/operators.d.ts +117 -0
  144. package/dist/runtime/vendor/cel-js/lib/operators.js +739 -0
  145. package/dist/runtime/vendor/cel-js/lib/optional.d.ts +14 -0
  146. package/dist/runtime/vendor/cel-js/lib/optional.js +161 -0
  147. package/dist/runtime/vendor/cel-js/lib/options.d.ts +23 -0
  148. package/dist/runtime/vendor/cel-js/lib/options.js +47 -0
  149. package/dist/runtime/vendor/cel-js/lib/overloads.d.ts +1 -0
  150. package/dist/runtime/vendor/cel-js/lib/overloads.js +214 -0
  151. package/dist/runtime/vendor/cel-js/lib/parser.d.ts +56 -0
  152. package/dist/runtime/vendor/cel-js/lib/parser.js +827 -0
  153. package/dist/runtime/vendor/cel-js/lib/registry.d.ts +279 -0
  154. package/dist/runtime/vendor/cel-js/lib/registry.js +1596 -0
  155. package/dist/runtime/vendor/cel-js/lib/serialize.d.ts +1 -0
  156. package/dist/runtime/vendor/cel-js/lib/serialize.js +259 -0
  157. package/dist/runtime/vendor/cel-js/lib/type-checker.d.ts +26 -0
  158. package/dist/runtime/vendor/cel-js/lib/type-checker.js +81 -0
  159. package/package.json +9 -4
  160. package/dist/runtime/components/locale.d.vue.ts +0 -14
  161. package/dist/runtime/components/locale.vue +0 -89
  162. package/dist/runtime/components/locale.vue.d.ts +0 -14
  163. package/dist/runtime/components/query.d.vue.ts +0 -30
  164. package/dist/runtime/components/query.vue +0 -266
  165. package/dist/runtime/components/query.vue.d.ts +0 -30
  166. package/dist/runtime/utilities/query-config/global.d.ts +0 -4
  167. package/dist/runtime/utilities/query-config/global.js +0 -18
  168. package/dist/runtime/utilities/query-config/index.d.ts +0 -3
  169. package/dist/runtime/utilities/query-config/index.js +0 -14
  170. package/dist/runtime/utilities/query-config/schema.d.ts +0 -96
  171. package/dist/runtime/utilities/query-config/schema.js +0 -51
  172. /package/dist/runtime/components/{logo.d.vue.ts → ui/logo/Logo.d.vue.ts} +0 -0
  173. /package/dist/runtime/components/{logo.vue → ui/logo/Logo.vue} +0 -0
  174. /package/dist/runtime/components/{logo.vue.d.ts → ui/logo/Logo.vue.d.ts} +0 -0
@@ -0,0 +1,14 @@
1
+ export function toggleOptionalTypes(registry: any, enable: any): void;
2
+ export function register(registry: any): void;
3
+ export class Optional {
4
+ static of(value: any): Readonly<Optional>;
5
+ static none(): Readonly<Optional>;
6
+ constructor(value: any);
7
+ hasValue(): boolean;
8
+ value(): any;
9
+ or(optional: any): Optional;
10
+ orValue(defaultValue: any): any;
11
+ get [Symbol.toStringTag](): string;
12
+ #private;
13
+ }
14
+ export const OPTIONAL_NONE: Readonly<Optional>;
@@ -0,0 +1,161 @@
1
+ import {EvaluationError} from './errors.js'
2
+
3
+ export class Optional {
4
+ #value
5
+
6
+ constructor(value) {
7
+ this.#value = value
8
+ }
9
+
10
+ static of(value) {
11
+ if (value === undefined) return OPTIONAL_NONE
12
+ return new Optional(value)
13
+ }
14
+
15
+ static none() {
16
+ return OPTIONAL_NONE
17
+ }
18
+
19
+ hasValue() {
20
+ return this.#value !== undefined
21
+ }
22
+
23
+ value() {
24
+ if (this.#value === undefined) throw new EvaluationError('Optional value is not present')
25
+ return this.#value
26
+ }
27
+
28
+ or(optional) {
29
+ if (this.#value !== undefined) return this
30
+ if (optional instanceof Optional) return optional
31
+ throw new EvaluationError('Optional.or must be called with an Optional argument')
32
+ }
33
+
34
+ orValue(defaultValue) {
35
+ return this.#value === undefined ? defaultValue : this.#value
36
+ }
37
+
38
+ get [Symbol.toStringTag]() {
39
+ return 'optional'
40
+ }
41
+
42
+ [Symbol.for('nodejs.util.inspect.custom')]() {
43
+ return this.#value === undefined
44
+ ? `Optional { none }`
45
+ : `Optional { value: ${JSON.stringify(this.#value)} }`
46
+ }
47
+ }
48
+
49
+ export const OPTIONAL_NONE = Object.freeze(new Optional())
50
+
51
+ class OptionalNamespace {}
52
+ const optionalNamespace = new OptionalNamespace()
53
+
54
+ export function toggleOptionalTypes(registry, enable) {
55
+ const optionalConstant = enable ? optionalNamespace : undefined
56
+ registry.deleteVariable('optional')
57
+ registry.registerConstant('optional', 'OptionalNamespace', optionalConstant)
58
+ }
59
+
60
+ export function register(registry) {
61
+ const sync = {async: false}
62
+ const functionOverload = (sig, handler) => registry.registerFunctionOverload(sig, handler, sync)
63
+
64
+ const optionalConstant = registry.enableOptionalTypes ? optionalNamespace : undefined
65
+ registry.registerType('OptionalNamespace', OptionalNamespace)
66
+ registry.registerConstant('optional', 'OptionalNamespace', optionalConstant)
67
+ functionOverload('optional.hasValue(): bool', (v) => v.hasValue())
68
+ functionOverload('optional<A>.value(): A', (v) => v.value())
69
+ registry.registerFunctionOverload('OptionalNamespace.none(): optional<T>', () => Optional.none())
70
+ functionOverload('OptionalNamespace.of(A): optional<A>', (_, value) => Optional.of(value))
71
+ function ensureOptional(value, ast, description) {
72
+ if (value instanceof Optional) return value
73
+ throw new EvaluationError(`${description} must be optional`, ast)
74
+ }
75
+
76
+ function evaluateOptional(ev, macro, ctx) {
77
+ const v = ev.eval(macro.receiver, ctx)
78
+ if (v instanceof Promise) return v.then((_v) => handleOptionalResolved(_v, ev, macro, ctx))
79
+ return handleOptionalResolved(v, ev, macro, ctx)
80
+ }
81
+
82
+ function handleOptionalResolved(value, ev, macro, ctx) {
83
+ const optional = ensureOptional(value, macro.receiver, `${macro.functionDesc} receiver`)
84
+ if (optional.hasValue()) return macro.onHasValue(optional)
85
+ return macro.onEmpty(ev, macro, ctx)
86
+ }
87
+
88
+ function ensureOptionalType(checker, node, ctx, description) {
89
+ const type = checker.check(node, ctx)
90
+ if (type.kind === 'optional') return type
91
+ if (type.kind === 'dyn') return checker.getType('optional')
92
+ throw new checker.Error(`${description} must be optional, got '${type}'`, node)
93
+ }
94
+
95
+ function createOptionalMacro({functionDesc, evaluate, typeCheck, onHasValue, onEmpty}) {
96
+ return ({ast, args, receiver}) => ({
97
+ ast,
98
+ functionDesc,
99
+ receiver,
100
+ arg: args[0],
101
+ evaluate,
102
+ typeCheck,
103
+ onHasValue,
104
+ onEmpty
105
+ })
106
+ }
107
+
108
+ const invalidOrValueReceiver = 'optional.orValue() receiver'
109
+ const invalidOrReceiver = 'optional.or(optional) receiver'
110
+ const invalidOrArg = 'optional.or(optional) argument'
111
+ registry.registerFunctionOverload(
112
+ 'optional.or(ast): optional<dyn>',
113
+ createOptionalMacro({
114
+ functionDesc: 'optional.or(optional)',
115
+ evaluate: evaluateOptional,
116
+ typeCheck(check, macro, ctx) {
117
+ const l = ensureOptionalType(check, macro.receiver, ctx, invalidOrReceiver)
118
+ const r = ensureOptionalType(check, macro.arg, ctx, invalidOrArg)
119
+ if (!(macro.receiver.maybeAsync || macro.arg.maybeAsync)) macro.ast.setMeta('async', false)
120
+
121
+ const unified = l.unify(check.registry, r)
122
+ if (unified) return unified
123
+ throw new check.Error(
124
+ `${macro.functionDesc} argument must be compatible type, got '${l}' and '${r}'`,
125
+ macro.arg
126
+ )
127
+ },
128
+ onHasValue: (optional) => optional,
129
+ onEmpty(ev, macro, ctx) {
130
+ const ast = macro.arg
131
+ const v = ev.eval(ast, ctx)
132
+ if (v instanceof Promise) return v.then((_v) => ensureOptional(_v, ast, invalidOrArg))
133
+ return ensureOptional(v, ast, invalidOrArg)
134
+ }
135
+ })
136
+ )
137
+
138
+ registry.registerFunctionOverload(
139
+ 'optional.orValue(ast): dyn',
140
+ createOptionalMacro({
141
+ functionDesc: 'optional.orValue(value)',
142
+ onHasValue: (optionalValue) => optionalValue.value(),
143
+ onEmpty(ev, macro, ctx) {
144
+ return ev.eval(macro.arg, ctx)
145
+ },
146
+ evaluate: evaluateOptional,
147
+ typeCheck(check, macro, ctx) {
148
+ const l = ensureOptionalType(check, macro.receiver, ctx, invalidOrValueReceiver).valueType
149
+ const r = check.check(macro.arg, ctx)
150
+ if (!(macro.receiver.maybeAsync || macro.arg.maybeAsync)) macro.ast.setMeta('async', false)
151
+
152
+ const unified = l.unify(check.registry, r)
153
+ if (unified) return unified
154
+ throw new check.Error(
155
+ `${macro.functionDesc} argument must be compatible type, got '${l}' and '${r}'`,
156
+ macro.arg
157
+ )
158
+ }
159
+ })
160
+ )
161
+ }
@@ -0,0 +1,23 @@
1
+ export function createOptions(opts: any, base?: Readonly<{
2
+ unlistedVariablesAreDyn: false;
3
+ homogeneousAggregateLiterals: true;
4
+ enableOptionalTypes: false;
5
+ limits: Readonly<{
6
+ maxAstNodes: 100000;
7
+ maxDepth: 250;
8
+ maxListElements: 1000;
9
+ maxMapEntries: 1000;
10
+ maxCallArguments: 32;
11
+ }>;
12
+ }>): Readonly<{
13
+ unlistedVariablesAreDyn: boolean;
14
+ homogeneousAggregateLiterals: boolean;
15
+ enableOptionalTypes: boolean;
16
+ limits: Readonly<{
17
+ maxAstNodes: 100000;
18
+ maxDepth: 250;
19
+ maxListElements: 1000;
20
+ maxMapEntries: 1000;
21
+ maxCallArguments: 32;
22
+ }>;
23
+ }>;
@@ -0,0 +1,47 @@
1
+ import {objFreeze, objKeys} from './globals.js'
2
+
3
+ const DEFAULT_LIMITS = objFreeze({
4
+ maxAstNodes: 100000,
5
+ maxDepth: 250,
6
+ maxListElements: 1000,
7
+ maxMapEntries: 1000,
8
+ maxCallArguments: 32
9
+ })
10
+
11
+ const LIMIT_KEYS = new Set(objKeys(DEFAULT_LIMITS))
12
+ function createLimits(overrides, base = DEFAULT_LIMITS) {
13
+ const keys = overrides ? objKeys(overrides) : undefined
14
+ if (!keys?.length) return base
15
+
16
+ const merged = {...base}
17
+ for (const key of keys) {
18
+ if (!LIMIT_KEYS.has(key)) throw new TypeError(`Unknown limits option: ${key}`)
19
+ const value = overrides[key]
20
+ if (typeof value !== 'number') continue
21
+ merged[key] = value
22
+ }
23
+ return objFreeze(merged)
24
+ }
25
+
26
+ const DEFAULT_OPTIONS = objFreeze({
27
+ unlistedVariablesAreDyn: false,
28
+ homogeneousAggregateLiterals: true,
29
+ enableOptionalTypes: false,
30
+ limits: DEFAULT_LIMITS
31
+ })
32
+
33
+ function bool(a, b, key) {
34
+ const value = a?.[key] ?? b?.[key]
35
+ if (typeof value !== 'boolean') throw new TypeError(`Invalid option: ${key}`)
36
+ return value
37
+ }
38
+
39
+ export function createOptions(opts, base = DEFAULT_OPTIONS) {
40
+ if (!opts) return base
41
+ return objFreeze({
42
+ unlistedVariablesAreDyn: bool(opts, base, 'unlistedVariablesAreDyn'),
43
+ homogeneousAggregateLiterals: bool(opts, base, 'homogeneousAggregateLiterals'),
44
+ enableOptionalTypes: bool(opts, base, 'enableOptionalTypes'),
45
+ limits: createLimits(opts.limits, base.limits)
46
+ })
47
+ }
@@ -0,0 +1 @@
1
+ export function registerOverloads(registry: any): void;
@@ -0,0 +1,214 @@
1
+ import {UnsignedInt, Duration} from './functions.js'
2
+ import {EvaluationError} from './errors.js'
3
+ import {isArray, hasOwn, objKeys} from './globals.js'
4
+
5
+ export function registerOverloads(registry) {
6
+ const unaryOverload = (op, t, h, ret) => registry.unaryOverload(op, t, h, ret, false)
7
+ const binaryOverload = (l, op, r, h, ret) => registry.binaryOverload(l, op, r, h, ret, false)
8
+
9
+ const MAX_INT = 9223372036854775807n
10
+ const MIN_INT = -9223372036854775808n
11
+ function verifyInteger(v, ast) {
12
+ if (v <= MAX_INT && v >= MIN_INT) return v
13
+ throw new EvaluationError(`integer overflow: ${v}`, ast)
14
+ }
15
+
16
+ unaryOverload('!', 'bool', (a) => !a)
17
+ unaryOverload('-', 'int', (a) => -a)
18
+ binaryOverload('dyn<int>', `==`, `double`, (a, b) => a == b) // eslint-disable-line eqeqeq
19
+ binaryOverload('dyn<int>', `==`, `uint`, (a, b) => a == b.valueOf()) // eslint-disable-line eqeqeq
20
+ binaryOverload('int', '*', 'int', (a, b, ast) => verifyInteger(a * b, ast))
21
+ binaryOverload('int', '+', 'int', (a, b, ast) => verifyInteger(a + b, ast))
22
+ binaryOverload('int', '-', 'int', (a, b, ast) => verifyInteger(a - b, ast))
23
+ binaryOverload('int', '/', 'int', (a, b, ast) => {
24
+ if (b === 0n) throw new EvaluationError('division by zero', ast)
25
+ return a / b
26
+ })
27
+ binaryOverload('int', '%', 'int', (a, b, ast) => {
28
+ if (b === 0n) throw new EvaluationError('modulo by zero', ast)
29
+ return a % b
30
+ })
31
+
32
+ unaryOverload('-', 'double', (a) => -a)
33
+ binaryOverload('double', '*', 'double', (a, b) => a * b)
34
+ binaryOverload('double', '+', 'double', (a, b) => a + b)
35
+ binaryOverload('double', '-', 'double', (a, b) => a - b)
36
+ binaryOverload('double', '/', 'double', (a, b) => a / b)
37
+
38
+ binaryOverload('string', '+', 'string', (a, b) => a + b)
39
+ binaryOverload('list<V>', '+', 'list<V>', (a, b) => [...a, ...b])
40
+ binaryOverload('bytes', '+', 'bytes', (a, b) => {
41
+ if (!a.length) return b
42
+ if (!b.length) return a
43
+
44
+ const result = new Uint8Array(a.length + b.length)
45
+ result.set(a, 0)
46
+ result.set(b, a.length)
47
+ return result
48
+ })
49
+
50
+ const GPD = 'google.protobuf.Duration'
51
+ binaryOverload(GPD, '+', GPD, (a, b) => a.addDuration(b))
52
+ binaryOverload(GPD, '-', GPD, (a, b) => a.subtractDuration(b))
53
+ binaryOverload(GPD, '==', GPD, (a, b) => a.seconds === b.seconds && a.nanos === b.nanos)
54
+
55
+ const GPT = 'google.protobuf.Timestamp'
56
+ binaryOverload(GPT, '==', GPT, (a, b) => a.getTime() === b.getTime())
57
+ binaryOverload(GPT, '-', GPT, (a, b) => Duration.fromMilliseconds(a.getTime() - b.getTime()), GPD)
58
+ binaryOverload(GPT, '-', GPD, (a, b) => b.subtractTimestamp(a))
59
+ binaryOverload(GPT, '+', GPD, (a, b) => b.extendTimestamp(a))
60
+ binaryOverload(GPD, '+', GPT, (a, b) => a.extendTimestamp(b))
61
+
62
+ function listIncludes(value, list, ast, ev) {
63
+ if (list instanceof Set && list.has(value)) return true
64
+ for (const v of list) if (isEqual(value, v, ast, ev)) return true
65
+ return false
66
+ }
67
+
68
+ function mapIncludes(a, b) {
69
+ if (b instanceof Map) return b.get(a) !== undefined
70
+ return hasOwn(b, a) ? b[a] !== undefined : false
71
+ }
72
+
73
+ function listMembership(value, list, ast, ev) {
74
+ return listIncludes(value, list, ast, ev)
75
+ }
76
+
77
+ binaryOverload('V', 'in', 'list<V>', listMembership)
78
+ binaryOverload('K', 'in', 'map<K, V>', mapIncludes)
79
+
80
+ for (const t of ['type', 'null', 'bool', 'string', 'int', 'double']) {
81
+ binaryOverload(t, '==', t, (a, b) => a === b)
82
+ }
83
+
84
+ binaryOverload('bytes', `==`, 'bytes', (a, b) => {
85
+ if (a === b) return true
86
+
87
+ let i = a.length
88
+ if (i !== b.length) return false
89
+ while (i--) if (a[i] !== b[i]) return false
90
+ return true
91
+ })
92
+
93
+ binaryOverload('list<V>', `==`, 'list<V>', (a, b, ast, ev) => {
94
+ if (a === b) return true
95
+
96
+ if (isArray(a) && isArray(b)) {
97
+ const length = a.length
98
+ if (length !== b.length) return false
99
+ for (let i = 0; i < length; i++) {
100
+ if (!isEqual(a[i], b[i], ast, ev)) return false
101
+ }
102
+ return true
103
+ }
104
+
105
+ if (a instanceof Set && b instanceof Set) {
106
+ if (a.size !== b.size) return false
107
+ for (const value of a) if (!b.has(value)) return false
108
+ return true
109
+ }
110
+
111
+ const arr = a instanceof Set ? b : a
112
+ const set = a instanceof Set ? a : b
113
+ if (!isArray(arr)) return false
114
+ if (arr.length !== set?.size) return false
115
+ for (let i = 0; i < arr.length; i++) if (!set.has(arr[i])) return false
116
+ return true
117
+ })
118
+
119
+ binaryOverload('map<K, V>', `==`, 'map<K, V>', (a, b, ast, ev) => {
120
+ if (a === b) return true
121
+
122
+ if (a instanceof Map && b instanceof Map) {
123
+ if (a.size !== b.size) return false
124
+ for (const [key, value] of a)
125
+ if (!(b.has(key) && isEqual(value, b.get(key), ast, ev))) return false
126
+ return true
127
+ }
128
+
129
+ if (a instanceof Map || b instanceof Map) {
130
+ const obj = a instanceof Map ? b : a
131
+ const map = a instanceof Map ? a : b
132
+ const keysObj = objKeys(obj)
133
+ if (map.size !== keysObj.length) return false
134
+ for (const [key, value] of map) {
135
+ if (!(key in obj && isEqual(value, obj[key], ast, ev))) return false
136
+ }
137
+ return true
138
+ }
139
+
140
+ const keysA = objKeys(a)
141
+ const keysB = objKeys(b)
142
+ if (keysA.length !== keysB.length) return false
143
+
144
+ for (let i = 0; i < keysA.length; i++) {
145
+ const key = keysA[i]
146
+ if (!(key in b && isEqual(a[key], b[key], ast, ev))) return false
147
+ }
148
+ return true
149
+ })
150
+
151
+ binaryOverload('uint', '==', 'uint', (a, b) => a.valueOf() === b.valueOf())
152
+ binaryOverload('dyn<uint>', `==`, `double`, (a, b) => a.valueOf() == b) // eslint-disable-line eqeqeq
153
+
154
+ binaryOverload('uint', '+', 'uint', (a, b) => new UnsignedInt(a.valueOf() + b.valueOf()))
155
+ binaryOverload('uint', '-', 'uint', (a, b) => new UnsignedInt(a.valueOf() - b.valueOf()))
156
+ binaryOverload('uint', '*', 'uint', (a, b) => new UnsignedInt(a.valueOf() * b.valueOf()))
157
+ binaryOverload('uint', '/', 'uint', (a, b, ast) => {
158
+ if (b.valueOf() === 0n) throw new EvaluationError('division by zero', ast)
159
+ return new UnsignedInt(a.valueOf() / b.valueOf())
160
+ })
161
+ binaryOverload('uint', '%', 'uint', (a, b, ast) => {
162
+ if (b.valueOf() === 0n) throw new EvaluationError('modulo by zero', ast)
163
+ return new UnsignedInt(a.valueOf() % b.valueOf())
164
+ })
165
+
166
+ for (const [left, right] of [
167
+ ['bool', 'bool'],
168
+ ['int', 'int'],
169
+ ['uint', 'uint'],
170
+ ['double', 'double'],
171
+ ['string', 'string'],
172
+ ['google.protobuf.Timestamp', 'google.protobuf.Timestamp'],
173
+ ['google.protobuf.Duration', 'google.protobuf.Duration'],
174
+ ['int', 'uint'],
175
+ ['int', 'double'],
176
+ ['double', 'int'],
177
+ ['double', 'uint'],
178
+ ['uint', 'int'],
179
+ ['uint', 'double']
180
+ ]) {
181
+ binaryOverload(left, '<', right, (a, b) => a < b)
182
+ binaryOverload(left, '<=', right, (a, b) => a <= b)
183
+ binaryOverload(left, '>', right, (a, b) => a > b)
184
+ binaryOverload(left, '>=', right, (a, b) => a >= b)
185
+ }
186
+ }
187
+
188
+ function isEqual(a, b, ast, ev) {
189
+ if (a === b) return true
190
+ switch (typeof a) {
191
+ case 'undefined':
192
+ case 'string':
193
+ case 'boolean':
194
+ return false
195
+ case 'bigint':
196
+ // eslint-disable-next-line eqeqeq
197
+ if (typeof b === 'number') return a == b
198
+ return false
199
+ case 'number':
200
+ // eslint-disable-next-line eqeqeq
201
+ if (typeof b === 'bigint') return a == b
202
+ return false
203
+ case 'object':
204
+ if (typeof b !== 'object') return false
205
+ const leftType = ev.debugType(a)
206
+ const rightType = ev.debugType(b)
207
+ if (leftType !== rightType) return false
208
+
209
+ const overload = ev.registry.findBinaryOverload('==', leftType, rightType)
210
+ if (!overload) return false
211
+ return overload.handler(a, b, ast, ev)
212
+ }
213
+ throw new EvaluationError(`Cannot compare values of type ${typeof a}`, ast)
214
+ }
@@ -0,0 +1,56 @@
1
+ export class ASTNode {
2
+ constructor(input: any, pos: any, op: any, args: any);
3
+ op: any;
4
+ args: any;
5
+ clone(op: any, args: any): ASTNode;
6
+ get meta(): {
7
+ input: any;
8
+ pos: any;
9
+ evaluate: any;
10
+ check: any;
11
+ };
12
+ /**
13
+ * Check whether we can optimize away async calling
14
+ * If no ast members includes a function, we can optimize the call
15
+ * for which we want to return true here.
16
+ * @returns {boolean}
17
+ */
18
+ get maybeAsync(): boolean;
19
+ check(chk: any, ast: any, ctx: any): any;
20
+ evaluate(ev: any, ast: any, ctx: any): any;
21
+ setMeta(key: any, value: any): this;
22
+ get input(): any;
23
+ get pos(): any;
24
+ toOldStructure(): any[];
25
+ #private;
26
+ }
27
+ export class Parser {
28
+ constructor(limits: any, registry: any);
29
+ lexer: null;
30
+ input: null;
31
+ maxDepthRemaining: null;
32
+ astNodesRemaining: null;
33
+ type: null;
34
+ pos: null;
35
+ limits: any;
36
+ registry: any;
37
+ get value(): any;
38
+ consume(expectedType: any): null;
39
+ match(type: any): boolean;
40
+ parse(input: any): any;
41
+ parseExpression(): any;
42
+ parseLogicalOr(): any;
43
+ parseLogicalAnd(): any;
44
+ parseEquality(): any;
45
+ parseRelational(): any;
46
+ parseAdditive(): any;
47
+ parseMultiplicative(): any;
48
+ parseUnary(): any;
49
+ parsePostfix(): any;
50
+ parsePrimary(): any;
51
+ parseList(): any;
52
+ parseMap(): any;
53
+ parseProperty(): any[];
54
+ parseArgumentList(): any;
55
+ #private;
56
+ }