dynamo-document-builder 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -2
- package/dist/attributes/attribute-map.cjs +114 -0
- package/dist/attributes/attribute-map.cjs.map +1 -0
- package/dist/attributes/attribute-map.d.ts +32 -0
- package/dist/attributes/attribute-map.mjs +112 -0
- package/dist/attributes/attribute-map.mjs.map +1 -0
- package/dist/attributes/index.cjs +8 -0
- package/dist/attributes/index.cjs.map +1 -0
- package/dist/attributes/index.d.ts +1 -0
- package/dist/attributes/index.mjs +2 -0
- package/dist/attributes/index.mjs.map +1 -0
- package/dist/commands/base-command.cjs +3 -0
- package/dist/commands/base-command.cjs.map +1 -0
- package/dist/commands/base-command.d.ts +24 -0
- package/dist/commands/base-command.mjs +2 -0
- package/dist/commands/base-command.mjs.map +1 -0
- package/dist/commands/batch-get.cjs +55 -0
- package/dist/commands/batch-get.cjs.map +1 -0
- package/dist/commands/batch-get.d.ts +17 -0
- package/dist/commands/batch-get.mjs +53 -0
- package/dist/commands/batch-get.mjs.map +1 -0
- package/dist/commands/batch-write.cjs +94 -0
- package/dist/commands/batch-write.cjs.map +1 -0
- package/dist/commands/batch-write.d.ts +34 -0
- package/dist/commands/batch-write.mjs +92 -0
- package/dist/commands/batch-write.mjs.map +1 -0
- package/dist/commands/condition-check.cjs +24 -0
- package/dist/commands/condition-check.cjs.map +1 -0
- package/dist/commands/condition-check.d.ts +16 -0
- package/dist/commands/condition-check.mjs +22 -0
- package/dist/commands/condition-check.mjs.map +1 -0
- package/dist/commands/conditional-delete.cjs +53 -0
- package/dist/commands/conditional-delete.cjs.map +1 -0
- package/dist/commands/conditional-delete.d.ts +21 -0
- package/dist/commands/conditional-delete.mjs +51 -0
- package/dist/commands/conditional-delete.mjs.map +1 -0
- package/dist/commands/conditional-put.cjs +63 -0
- package/dist/commands/conditional-put.cjs.map +1 -0
- package/dist/commands/conditional-put.d.ts +22 -0
- package/dist/commands/conditional-put.mjs +61 -0
- package/dist/commands/conditional-put.mjs.map +1 -0
- package/dist/commands/conditional-update.cjs +57 -0
- package/dist/commands/conditional-update.cjs.map +1 -0
- package/dist/commands/conditional-update.d.ts +21 -0
- package/dist/commands/conditional-update.mjs +55 -0
- package/dist/commands/conditional-update.mjs.map +1 -0
- package/dist/commands/delete.cjs +59 -0
- package/dist/commands/delete.cjs.map +1 -0
- package/dist/commands/delete.d.ts +20 -0
- package/dist/commands/delete.mjs +57 -0
- package/dist/commands/delete.mjs.map +1 -0
- package/dist/commands/get.cjs +46 -0
- package/dist/commands/get.cjs.map +1 -0
- package/dist/commands/get.d.ts +16 -0
- package/dist/commands/get.mjs +44 -0
- package/dist/commands/get.mjs.map +1 -0
- package/dist/commands/index.cjs +40 -0
- package/dist/commands/index.cjs.map +1 -0
- package/dist/commands/index.d.ts +18 -0
- package/dist/commands/index.mjs +18 -0
- package/dist/commands/index.mjs.map +1 -0
- package/dist/commands/projected-get.cjs +50 -0
- package/dist/commands/projected-get.cjs.map +1 -0
- package/dist/commands/projected-get.d.ts +18 -0
- package/dist/commands/projected-get.mjs +48 -0
- package/dist/commands/projected-get.mjs.map +1 -0
- package/dist/commands/projected-query.cjs +118 -0
- package/dist/commands/projected-query.cjs.map +1 -0
- package/dist/commands/projected-query.d.ts +26 -0
- package/dist/commands/projected-query.mjs +116 -0
- package/dist/commands/projected-query.mjs.map +1 -0
- package/dist/commands/projected-scan.cjs +98 -0
- package/dist/commands/projected-scan.cjs.map +1 -0
- package/dist/commands/projected-scan.d.ts +26 -0
- package/dist/commands/projected-scan.mjs +96 -0
- package/dist/commands/projected-scan.mjs.map +1 -0
- package/dist/commands/put.cjs +69 -0
- package/dist/commands/put.cjs.map +1 -0
- package/dist/commands/put.d.ts +21 -0
- package/dist/commands/put.mjs +67 -0
- package/dist/commands/put.mjs.map +1 -0
- package/dist/commands/query.cjs +117 -0
- package/dist/commands/query.cjs.map +1 -0
- package/dist/commands/query.d.ts +33 -0
- package/dist/commands/query.mjs +115 -0
- package/dist/commands/query.mjs.map +1 -0
- package/dist/commands/scan.cjs +96 -0
- package/dist/commands/scan.cjs.map +1 -0
- package/dist/commands/scan.d.ts +34 -0
- package/dist/commands/scan.mjs +94 -0
- package/dist/commands/scan.mjs.map +1 -0
- package/dist/commands/transact-get.cjs +60 -0
- package/dist/commands/transact-get.cjs.map +1 -0
- package/dist/commands/transact-get.d.ts +15 -0
- package/dist/commands/transact-get.mjs +58 -0
- package/dist/commands/transact-get.mjs.map +1 -0
- package/dist/commands/transact-write.cjs +42 -0
- package/dist/commands/transact-write.cjs.map +1 -0
- package/dist/commands/transact-write.d.ts +20 -0
- package/dist/commands/transact-write.mjs +40 -0
- package/dist/commands/transact-write.mjs.map +1 -0
- package/dist/commands/update.cjs +53 -0
- package/dist/commands/update.cjs.map +1 -0
- package/dist/commands/update.d.ts +22 -0
- package/dist/commands/update.mjs +51 -0
- package/dist/commands/update.mjs.map +1 -0
- package/dist/conditions/and.cjs +14 -0
- package/dist/conditions/and.cjs.map +1 -0
- package/dist/conditions/and.d.ts +2 -0
- package/dist/conditions/and.mjs +12 -0
- package/dist/conditions/and.mjs.map +1 -0
- package/dist/conditions/begins-with.cjs +13 -0
- package/dist/conditions/begins-with.cjs.map +1 -0
- package/dist/conditions/begins-with.d.ts +2 -0
- package/dist/conditions/begins-with.mjs +11 -0
- package/dist/conditions/begins-with.mjs.map +1 -0
- package/dist/conditions/between.cjs +14 -0
- package/dist/conditions/between.cjs.map +1 -0
- package/dist/conditions/between.d.ts +2 -0
- package/dist/conditions/between.mjs +12 -0
- package/dist/conditions/between.mjs.map +1 -0
- package/dist/conditions/condition-parser.cjs +194 -0
- package/dist/conditions/condition-parser.cjs.map +1 -0
- package/dist/conditions/condition-parser.d.ts +7 -0
- package/dist/conditions/condition-parser.mjs +192 -0
- package/dist/conditions/condition-parser.mjs.map +1 -0
- package/dist/conditions/condition-symbols.cjs +43 -0
- package/dist/conditions/condition-symbols.cjs.map +1 -0
- package/dist/conditions/condition-symbols.d.ts +14 -0
- package/dist/conditions/condition-symbols.mjs +31 -0
- package/dist/conditions/condition-symbols.mjs.map +1 -0
- package/dist/conditions/condition-types.cjs +3 -0
- package/dist/conditions/condition-types.cjs.map +1 -0
- package/dist/conditions/condition-types.d.ts +85 -0
- package/dist/conditions/condition-types.mjs +2 -0
- package/dist/conditions/condition-types.mjs.map +1 -0
- package/dist/conditions/contains.cjs +13 -0
- package/dist/conditions/contains.cjs.map +1 -0
- package/dist/conditions/contains.d.ts +3 -0
- package/dist/conditions/contains.mjs +11 -0
- package/dist/conditions/contains.mjs.map +1 -0
- package/dist/conditions/equals.cjs +14 -0
- package/dist/conditions/equals.cjs.map +1 -0
- package/dist/conditions/equals.d.ts +2 -0
- package/dist/conditions/equals.mjs +12 -0
- package/dist/conditions/equals.mjs.map +1 -0
- package/dist/conditions/exists.cjs +12 -0
- package/dist/conditions/exists.cjs.map +1 -0
- package/dist/conditions/exists.d.ts +2 -0
- package/dist/conditions/exists.mjs +10 -0
- package/dist/conditions/exists.mjs.map +1 -0
- package/dist/conditions/greater-than-or-equal.cjs +14 -0
- package/dist/conditions/greater-than-or-equal.cjs.map +1 -0
- package/dist/conditions/greater-than-or-equal.d.ts +2 -0
- package/dist/conditions/greater-than-or-equal.mjs +12 -0
- package/dist/conditions/greater-than-or-equal.mjs.map +1 -0
- package/dist/conditions/greater-than.cjs +14 -0
- package/dist/conditions/greater-than.cjs.map +1 -0
- package/dist/conditions/greater-than.d.ts +2 -0
- package/dist/conditions/greater-than.mjs +12 -0
- package/dist/conditions/greater-than.mjs.map +1 -0
- package/dist/conditions/index.cjs +42 -0
- package/dist/conditions/index.cjs.map +1 -0
- package/dist/conditions/index.d.ts +19 -0
- package/dist/conditions/index.mjs +19 -0
- package/dist/conditions/index.mjs.map +1 -0
- package/dist/conditions/is-in.cjs +13 -0
- package/dist/conditions/is-in.cjs.map +1 -0
- package/dist/conditions/is-in.d.ts +2 -0
- package/dist/conditions/is-in.mjs +11 -0
- package/dist/conditions/is-in.mjs.map +1 -0
- package/dist/conditions/less-than-or-equal.cjs +14 -0
- package/dist/conditions/less-than-or-equal.cjs.map +1 -0
- package/dist/conditions/less-than-or-equal.d.ts +2 -0
- package/dist/conditions/less-than-or-equal.mjs +12 -0
- package/dist/conditions/less-than-or-equal.mjs.map +1 -0
- package/dist/conditions/less-than.cjs +14 -0
- package/dist/conditions/less-than.cjs.map +1 -0
- package/dist/conditions/less-than.d.ts +2 -0
- package/dist/conditions/less-than.mjs +12 -0
- package/dist/conditions/less-than.mjs.map +1 -0
- package/dist/conditions/not-equals.cjs +14 -0
- package/dist/conditions/not-equals.cjs.map +1 -0
- package/dist/conditions/not-equals.d.ts +2 -0
- package/dist/conditions/not-equals.mjs +12 -0
- package/dist/conditions/not-equals.mjs.map +1 -0
- package/dist/conditions/not-exists.cjs +13 -0
- package/dist/conditions/not-exists.cjs.map +1 -0
- package/dist/conditions/not-exists.d.ts +2 -0
- package/dist/conditions/not-exists.mjs +11 -0
- package/dist/conditions/not-exists.mjs.map +1 -0
- package/dist/conditions/not.cjs +13 -0
- package/dist/conditions/not.cjs.map +1 -0
- package/dist/conditions/not.d.ts +2 -0
- package/dist/conditions/not.mjs +11 -0
- package/dist/conditions/not.mjs.map +1 -0
- package/dist/conditions/or.cjs +14 -0
- package/dist/conditions/or.cjs.map +1 -0
- package/dist/conditions/or.d.ts +2 -0
- package/dist/conditions/or.mjs +12 -0
- package/dist/conditions/or.mjs.map +1 -0
- package/dist/conditions/size.cjs +13 -0
- package/dist/conditions/size.cjs.map +1 -0
- package/dist/conditions/size.d.ts +2 -0
- package/dist/conditions/size.mjs +11 -0
- package/dist/conditions/size.mjs.map +1 -0
- package/dist/conditions/type-is.cjs +13 -0
- package/dist/conditions/type-is.cjs.map +1 -0
- package/dist/conditions/type-is.d.ts +2 -0
- package/dist/conditions/type-is.mjs +11 -0
- package/dist/conditions/type-is.mjs.map +1 -0
- package/dist/core/core-types.cjs +3 -0
- package/dist/core/core-types.cjs.map +1 -0
- package/dist/core/core-types.d.ts +41 -0
- package/dist/core/core-types.mjs +2 -0
- package/dist/core/core-types.mjs.map +1 -0
- package/dist/core/entity.cjs +146 -0
- package/dist/core/entity.cjs.map +1 -0
- package/dist/core/entity.d.ts +39 -0
- package/dist/core/entity.mjs +144 -0
- package/dist/core/entity.mjs.map +1 -0
- package/dist/core/index.cjs +12 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.mjs +4 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/key.cjs +8 -0
- package/dist/core/key.cjs.map +1 -0
- package/dist/core/key.d.ts +12 -0
- package/dist/core/key.mjs +6 -0
- package/dist/core/key.mjs.map +1 -0
- package/dist/core/table.cjs +44 -0
- package/dist/core/table.cjs.map +1 -0
- package/dist/core/table.d.ts +22 -0
- package/dist/core/table.mjs +42 -0
- package/dist/core/table.mjs.map +1 -0
- package/dist/errors.cjs +7 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.mjs +5 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal-constants.cjs +20 -0
- package/dist/internal-constants.cjs.map +1 -0
- package/dist/internal-constants.d.ts +8 -0
- package/dist/internal-constants.mjs +11 -0
- package/dist/internal-constants.mjs.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.cjs +92 -0
- package/dist/node_modules/tslib/tslib.es6.cjs.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.mjs +84 -0
- package/dist/node_modules/tslib/tslib.es6.mjs.map +1 -0
- package/dist/projections/index.cjs +8 -0
- package/dist/projections/index.cjs.map +1 -0
- package/dist/projections/index.d.ts +2 -0
- package/dist/projections/index.mjs +2 -0
- package/dist/projections/index.mjs.map +1 -0
- package/dist/projections/projection-parser.cjs +19 -0
- package/dist/projections/projection-parser.cjs.map +1 -0
- package/dist/projections/projection-parser.d.ts +7 -0
- package/dist/projections/projection-parser.mjs +17 -0
- package/dist/projections/projection-parser.mjs.map +1 -0
- package/dist/projections/projection-types.cjs +3 -0
- package/dist/projections/projection-types.cjs.map +1 -0
- package/dist/projections/projection-types.d.ts +1 -0
- package/dist/projections/projection-types.mjs +2 -0
- package/dist/projections/projection-types.mjs.map +1 -0
- package/dist/updates/add-to-set.cjs +14 -0
- package/dist/updates/add-to-set.cjs.map +1 -0
- package/dist/updates/add-to-set.d.ts +3 -0
- package/dist/updates/add-to-set.mjs +12 -0
- package/dist/updates/add-to-set.mjs.map +1 -0
- package/dist/updates/add.cjs +14 -0
- package/dist/updates/add.cjs.map +1 -0
- package/dist/updates/add.d.ts +2 -0
- package/dist/updates/add.mjs +12 -0
- package/dist/updates/add.mjs.map +1 -0
- package/dist/updates/append.cjs +14 -0
- package/dist/updates/append.cjs.map +1 -0
- package/dist/updates/append.d.ts +3 -0
- package/dist/updates/append.mjs +12 -0
- package/dist/updates/append.mjs.map +1 -0
- package/dist/updates/delete.cjs +13 -0
- package/dist/updates/delete.cjs.map +1 -0
- package/dist/updates/delete.d.ts +3 -0
- package/dist/updates/delete.mjs +11 -0
- package/dist/updates/delete.mjs.map +1 -0
- package/dist/updates/index.cjs +24 -0
- package/dist/updates/index.cjs.map +1 -0
- package/dist/updates/index.d.ts +10 -0
- package/dist/updates/index.mjs +10 -0
- package/dist/updates/index.mjs.map +1 -0
- package/dist/updates/prepend.cjs +14 -0
- package/dist/updates/prepend.cjs.map +1 -0
- package/dist/updates/prepend.d.ts +3 -0
- package/dist/updates/prepend.mjs +12 -0
- package/dist/updates/prepend.mjs.map +1 -0
- package/dist/updates/ref.cjs +14 -0
- package/dist/updates/ref.cjs.map +1 -0
- package/dist/updates/ref.d.ts +3 -0
- package/dist/updates/ref.mjs +12 -0
- package/dist/updates/ref.mjs.map +1 -0
- package/dist/updates/remove.cjs +12 -0
- package/dist/updates/remove.cjs.map +1 -0
- package/dist/updates/remove.d.ts +2 -0
- package/dist/updates/remove.mjs +10 -0
- package/dist/updates/remove.mjs.map +1 -0
- package/dist/updates/subtract.cjs +14 -0
- package/dist/updates/subtract.cjs.map +1 -0
- package/dist/updates/subtract.d.ts +2 -0
- package/dist/updates/subtract.mjs +12 -0
- package/dist/updates/subtract.mjs.map +1 -0
- package/dist/updates/update-parser.cjs +157 -0
- package/dist/updates/update-parser.cjs.map +1 -0
- package/dist/updates/update-parser.d.ts +7 -0
- package/dist/updates/update-parser.mjs +155 -0
- package/dist/updates/update-parser.mjs.map +1 -0
- package/dist/updates/update-symbols.cjs +30 -0
- package/dist/updates/update-symbols.cjs.map +1 -0
- package/dist/updates/update-symbols.d.ts +13 -0
- package/dist/updates/update-symbols.mjs +19 -0
- package/dist/updates/update-symbols.mjs.map +1 -0
- package/dist/updates/update-types.cjs +3 -0
- package/dist/updates/update-types.cjs.map +1 -0
- package/dist/updates/update-types.d.ts +42 -0
- package/dist/updates/update-types.mjs +2 -0
- package/dist/updates/update-types.mjs.map +1 -0
- package/package.json +142 -22
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -7
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var conditions_conditionSymbols = require('./condition-symbols.cjs');
|
|
4
|
+
var attributes_attributeMap = require('../attributes/attribute-map.cjs');
|
|
5
|
+
var errors = require('../errors.cjs');
|
|
6
|
+
|
|
7
|
+
function isSizeExpression(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null && 'type' in value && value.type === conditions_conditionSymbols.$size;
|
|
9
|
+
}
|
|
10
|
+
function parseSizeExpression(map, expr) {
|
|
11
|
+
const namePath = parseAttributePath(map, expr.attribute);
|
|
12
|
+
return `size(${namePath})`;
|
|
13
|
+
}
|
|
14
|
+
function parseAttributePath(map, path) {
|
|
15
|
+
const parts = path.split('.');
|
|
16
|
+
return parts.map(part => map.addName(part)).join('.');
|
|
17
|
+
}
|
|
18
|
+
function parseValueExpression(map, value) {
|
|
19
|
+
if (isSizeExpression(value)) {
|
|
20
|
+
return parseSizeExpression(map, value);
|
|
21
|
+
}
|
|
22
|
+
return map.addValue(value);
|
|
23
|
+
}
|
|
24
|
+
function parseComparisonExpression(map, expr) {
|
|
25
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
26
|
+
const value = parseValueExpression(map, expr.value);
|
|
27
|
+
return `${operand} ${expr.operator} ${value}`;
|
|
28
|
+
}
|
|
29
|
+
function parseLogicalExpression(map, expr) {
|
|
30
|
+
if (expr.subConditions.length < 1) {
|
|
31
|
+
throw new errors.DocumentBuilderError('Invalid Condition: Logical expression must have at least one sub-condition');
|
|
32
|
+
}
|
|
33
|
+
const conditions = expr.subConditions.map(c => {
|
|
34
|
+
let parsed;
|
|
35
|
+
if (isConditionTemplate(c)) {
|
|
36
|
+
parsed = parseConditionTemplate(map, c);
|
|
37
|
+
// Only wrap templates with multiple conditions in parentheses
|
|
38
|
+
const templateKeys = Object.keys(c);
|
|
39
|
+
if (templateKeys.length > 1) {
|
|
40
|
+
return `(${parsed})`;
|
|
41
|
+
}
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
parsed = parseConditionExpression(map, c);
|
|
46
|
+
// Wrap logical expressions in parentheses to preserve precedence
|
|
47
|
+
if (c.type === conditions_conditionSymbols.$logical) {
|
|
48
|
+
return `(${parsed})`;
|
|
49
|
+
}
|
|
50
|
+
return parsed;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return conditions.join(` ${expr.operator} `);
|
|
54
|
+
}
|
|
55
|
+
function parseBetweenExpression(map, expr) {
|
|
56
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
57
|
+
const lower = isSizeExpression(expr.lowerValue)
|
|
58
|
+
? parseSizeExpression(map, expr.lowerValue)
|
|
59
|
+
: parseValueExpression(map, expr.lowerValue);
|
|
60
|
+
const upper = isSizeExpression(expr.upperValue)
|
|
61
|
+
? parseSizeExpression(map, expr.upperValue)
|
|
62
|
+
: parseValueExpression(map, expr.upperValue);
|
|
63
|
+
return `${operand} BETWEEN ${lower} AND ${upper}`;
|
|
64
|
+
}
|
|
65
|
+
function parseInExpression(map, expr) {
|
|
66
|
+
if (expr.values.length < 1) {
|
|
67
|
+
throw new errors.DocumentBuilderError('InvalidCondition: IN expression must have at least one value');
|
|
68
|
+
}
|
|
69
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
70
|
+
const values = expr.values.map(v => parseValueExpression(map, v)).join(', ');
|
|
71
|
+
return `${operand} IN (${values})`;
|
|
72
|
+
}
|
|
73
|
+
function parseNotExpression(map, expr) {
|
|
74
|
+
let condition;
|
|
75
|
+
if (isConditionTemplate(expr.condition)) {
|
|
76
|
+
condition = parseConditionTemplate(map, expr.condition);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
condition = parseConditionExpression(map, expr.condition);
|
|
80
|
+
}
|
|
81
|
+
return `NOT (${condition})`;
|
|
82
|
+
}
|
|
83
|
+
function parseExistsExpression(map, expr) {
|
|
84
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
85
|
+
if (expr.not) {
|
|
86
|
+
return `attribute_not_exists(${operand})`;
|
|
87
|
+
}
|
|
88
|
+
return `attribute_exists(${operand})`;
|
|
89
|
+
}
|
|
90
|
+
function parseTypeCheckExpression(map, expr) {
|
|
91
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
92
|
+
const typeValue = parseValueExpression(map, expr.attributeType);
|
|
93
|
+
return `attribute_type(${operand}, ${typeValue})`;
|
|
94
|
+
}
|
|
95
|
+
function parseBeginsWithExpression(map, expr) {
|
|
96
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
97
|
+
const prefix = parseValueExpression(map, expr.prefix);
|
|
98
|
+
return `begins_with(${operand}, ${prefix})`;
|
|
99
|
+
}
|
|
100
|
+
function parseContainsExpression(map, expr) {
|
|
101
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
102
|
+
const value = parseValueExpression(map, expr.substringOrElement);
|
|
103
|
+
return `contains(${operand}, ${value})`;
|
|
104
|
+
}
|
|
105
|
+
function parseConditionExpression(map, expr) {
|
|
106
|
+
if (!('type' in expr)) {
|
|
107
|
+
throw new errors.DocumentBuilderError('Unknown condition expression');
|
|
108
|
+
}
|
|
109
|
+
switch (expr.type) {
|
|
110
|
+
case conditions_conditionSymbols.$comparison:
|
|
111
|
+
return parseComparisonExpression(map, expr);
|
|
112
|
+
case conditions_conditionSymbols.$logical:
|
|
113
|
+
return parseLogicalExpression(map, expr);
|
|
114
|
+
case conditions_conditionSymbols.$between:
|
|
115
|
+
return parseBetweenExpression(map, expr);
|
|
116
|
+
case conditions_conditionSymbols.$in:
|
|
117
|
+
return parseInExpression(map, expr);
|
|
118
|
+
case conditions_conditionSymbols.$not:
|
|
119
|
+
return parseNotExpression(map, expr);
|
|
120
|
+
case conditions_conditionSymbols.$exists:
|
|
121
|
+
return parseExistsExpression(map, expr);
|
|
122
|
+
case conditions_conditionSymbols.$type:
|
|
123
|
+
return parseTypeCheckExpression(map, expr);
|
|
124
|
+
case conditions_conditionSymbols.$beginsWith:
|
|
125
|
+
return parseBeginsWithExpression(map, expr);
|
|
126
|
+
case conditions_conditionSymbols.$contains:
|
|
127
|
+
return parseContainsExpression(map, expr);
|
|
128
|
+
default:
|
|
129
|
+
throw new errors.DocumentBuilderError('Unknown expression type');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function isConditionTemplate(value) {
|
|
133
|
+
if (typeof value !== 'object' || value === null) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if ('type' in value && typeof value.type === 'symbol') {
|
|
137
|
+
return !conditions_conditionSymbols.isConditionSymbol(value.type);
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
function isConditionExpression(value) {
|
|
142
|
+
if (typeof value !== 'object' || value === null) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return 'type' in value && typeof value.type === 'symbol' && conditions_conditionSymbols.isConditionSymbol(value.type);
|
|
146
|
+
}
|
|
147
|
+
function parseConditionTemplate(map, template) {
|
|
148
|
+
const conditions = [];
|
|
149
|
+
for (const [operand, value] of Object.entries(template)) {
|
|
150
|
+
if (typeof value === 'object' && value !== null && 'type' in value) {
|
|
151
|
+
const expr = Object.assign(Object.assign({}, value), { operand });
|
|
152
|
+
conditions.push(parseConditionExpression(map, expr));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const namePlaceholder = parseAttributePath(map, operand);
|
|
156
|
+
const valuePlaceholder = isSizeExpression(value)
|
|
157
|
+
? parseValueExpression(map, value)
|
|
158
|
+
: parseValueExpression(map, value);
|
|
159
|
+
conditions.push(`${namePlaceholder} = ${valuePlaceholder}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return conditions.join(' AND ');
|
|
163
|
+
}
|
|
164
|
+
function parseCondition(condition, attributeExpressionMap = new attributes_attributeMap.AttributeExpressionMap()) {
|
|
165
|
+
let conditionExpression;
|
|
166
|
+
if (Array.isArray(condition)) {
|
|
167
|
+
const expressions = condition.map(c => {
|
|
168
|
+
if (isConditionTemplate(c)) {
|
|
169
|
+
return parseConditionTemplate(attributeExpressionMap, c);
|
|
170
|
+
}
|
|
171
|
+
else if (isConditionExpression(c)) {
|
|
172
|
+
return parseConditionExpression(attributeExpressionMap, c);
|
|
173
|
+
}
|
|
174
|
+
throw new errors.DocumentBuilderError('Invalid condition');
|
|
175
|
+
});
|
|
176
|
+
conditionExpression = expressions.join(' AND ');
|
|
177
|
+
}
|
|
178
|
+
else if (isConditionTemplate(condition)) {
|
|
179
|
+
conditionExpression = parseConditionTemplate(attributeExpressionMap, condition);
|
|
180
|
+
}
|
|
181
|
+
else if (isConditionExpression(condition)) {
|
|
182
|
+
conditionExpression = parseConditionExpression(attributeExpressionMap, condition);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
throw new errors.DocumentBuilderError('Invalid condition');
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
conditionExpression,
|
|
189
|
+
attributeExpressionMap,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
exports.parseCondition = parseCondition;
|
|
194
|
+
//# sourceMappingURL=condition-parser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-parser.cjs","sources":["../../src/conditions/condition-parser.ts"],"sourcesContent":[null],"names":["$size","DocumentBuilderError","$logical","$comparison","$between","$in","$not","$exists","$type","$beginsWith","$contains","isConditionSymbol","AttributeExpressionMap"],"mappings":";;;;;;AAiCA,SAAS,gBAAgB,CAAC,KAAc,EAAA;AACtC,IAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAKA,iCAAK;AAC/F;AAEA,SAAS,mBAAmB,CAAC,GAA2B,EAAE,IAAoB,EAAA;IAC5E,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;IACxD,OAAO,CAAA,KAAA,EAAQ,QAAQ,CAAA,CAAA,CAAG;AAC5B;AAEA,SAAS,kBAAkB,CAAC,GAA2B,EAAE,IAAY,EAAA;IACnE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC7B,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;AACvD;AAEA,SAAS,oBAAoB,CAAC,GAA2B,EAAE,KAAsB,EAAA;AAC/E,IAAA,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE;AAC3B,QAAA,OAAO,mBAAmB,CAAC,GAAG,EAAE,KAAK,CAAC;IACxC;AACA,IAAA,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+
import { AttributeExpressionMap } from '@/attributes/attribute-map';
|
|
3
|
+
export type ConditionParserResult = {
|
|
4
|
+
conditionExpression: string;
|
|
5
|
+
attributeExpressionMap: AttributeExpressionMap;
|
|
6
|
+
};
|
|
7
|
+
export declare function parseCondition(condition: Condition, attributeExpressionMap?: AttributeExpressionMap): ConditionParserResult;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { isConditionSymbol, $contains, $beginsWith, $type, $exists, $not, $in, $between, $logical, $comparison, $size } from './condition-symbols.mjs';
|
|
2
|
+
import { AttributeExpressionMap } from '../attributes/attribute-map.mjs';
|
|
3
|
+
import { DocumentBuilderError } from '../errors.mjs';
|
|
4
|
+
|
|
5
|
+
function isSizeExpression(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && 'type' in value && value.type === $size;
|
|
7
|
+
}
|
|
8
|
+
function parseSizeExpression(map, expr) {
|
|
9
|
+
const namePath = parseAttributePath(map, expr.attribute);
|
|
10
|
+
return `size(${namePath})`;
|
|
11
|
+
}
|
|
12
|
+
function parseAttributePath(map, path) {
|
|
13
|
+
const parts = path.split('.');
|
|
14
|
+
return parts.map(part => map.addName(part)).join('.');
|
|
15
|
+
}
|
|
16
|
+
function parseValueExpression(map, value) {
|
|
17
|
+
if (isSizeExpression(value)) {
|
|
18
|
+
return parseSizeExpression(map, value);
|
|
19
|
+
}
|
|
20
|
+
return map.addValue(value);
|
|
21
|
+
}
|
|
22
|
+
function parseComparisonExpression(map, expr) {
|
|
23
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
24
|
+
const value = parseValueExpression(map, expr.value);
|
|
25
|
+
return `${operand} ${expr.operator} ${value}`;
|
|
26
|
+
}
|
|
27
|
+
function parseLogicalExpression(map, expr) {
|
|
28
|
+
if (expr.subConditions.length < 1) {
|
|
29
|
+
throw new DocumentBuilderError('Invalid Condition: Logical expression must have at least one sub-condition');
|
|
30
|
+
}
|
|
31
|
+
const conditions = expr.subConditions.map(c => {
|
|
32
|
+
let parsed;
|
|
33
|
+
if (isConditionTemplate(c)) {
|
|
34
|
+
parsed = parseConditionTemplate(map, c);
|
|
35
|
+
// Only wrap templates with multiple conditions in parentheses
|
|
36
|
+
const templateKeys = Object.keys(c);
|
|
37
|
+
if (templateKeys.length > 1) {
|
|
38
|
+
return `(${parsed})`;
|
|
39
|
+
}
|
|
40
|
+
return parsed;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
parsed = parseConditionExpression(map, c);
|
|
44
|
+
// Wrap logical expressions in parentheses to preserve precedence
|
|
45
|
+
if (c.type === $logical) {
|
|
46
|
+
return `(${parsed})`;
|
|
47
|
+
}
|
|
48
|
+
return parsed;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return conditions.join(` ${expr.operator} `);
|
|
52
|
+
}
|
|
53
|
+
function parseBetweenExpression(map, expr) {
|
|
54
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
55
|
+
const lower = isSizeExpression(expr.lowerValue)
|
|
56
|
+
? parseSizeExpression(map, expr.lowerValue)
|
|
57
|
+
: parseValueExpression(map, expr.lowerValue);
|
|
58
|
+
const upper = isSizeExpression(expr.upperValue)
|
|
59
|
+
? parseSizeExpression(map, expr.upperValue)
|
|
60
|
+
: parseValueExpression(map, expr.upperValue);
|
|
61
|
+
return `${operand} BETWEEN ${lower} AND ${upper}`;
|
|
62
|
+
}
|
|
63
|
+
function parseInExpression(map, expr) {
|
|
64
|
+
if (expr.values.length < 1) {
|
|
65
|
+
throw new DocumentBuilderError('InvalidCondition: IN expression must have at least one value');
|
|
66
|
+
}
|
|
67
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
68
|
+
const values = expr.values.map(v => parseValueExpression(map, v)).join(', ');
|
|
69
|
+
return `${operand} IN (${values})`;
|
|
70
|
+
}
|
|
71
|
+
function parseNotExpression(map, expr) {
|
|
72
|
+
let condition;
|
|
73
|
+
if (isConditionTemplate(expr.condition)) {
|
|
74
|
+
condition = parseConditionTemplate(map, expr.condition);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
condition = parseConditionExpression(map, expr.condition);
|
|
78
|
+
}
|
|
79
|
+
return `NOT (${condition})`;
|
|
80
|
+
}
|
|
81
|
+
function parseExistsExpression(map, expr) {
|
|
82
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
83
|
+
if (expr.not) {
|
|
84
|
+
return `attribute_not_exists(${operand})`;
|
|
85
|
+
}
|
|
86
|
+
return `attribute_exists(${operand})`;
|
|
87
|
+
}
|
|
88
|
+
function parseTypeCheckExpression(map, expr) {
|
|
89
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
90
|
+
const typeValue = parseValueExpression(map, expr.attributeType);
|
|
91
|
+
return `attribute_type(${operand}, ${typeValue})`;
|
|
92
|
+
}
|
|
93
|
+
function parseBeginsWithExpression(map, expr) {
|
|
94
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
95
|
+
const prefix = parseValueExpression(map, expr.prefix);
|
|
96
|
+
return `begins_with(${operand}, ${prefix})`;
|
|
97
|
+
}
|
|
98
|
+
function parseContainsExpression(map, expr) {
|
|
99
|
+
const operand = parseAttributePath(map, expr.operand);
|
|
100
|
+
const value = parseValueExpression(map, expr.substringOrElement);
|
|
101
|
+
return `contains(${operand}, ${value})`;
|
|
102
|
+
}
|
|
103
|
+
function parseConditionExpression(map, expr) {
|
|
104
|
+
if (!('type' in expr)) {
|
|
105
|
+
throw new DocumentBuilderError('Unknown condition expression');
|
|
106
|
+
}
|
|
107
|
+
switch (expr.type) {
|
|
108
|
+
case $comparison:
|
|
109
|
+
return parseComparisonExpression(map, expr);
|
|
110
|
+
case $logical:
|
|
111
|
+
return parseLogicalExpression(map, expr);
|
|
112
|
+
case $between:
|
|
113
|
+
return parseBetweenExpression(map, expr);
|
|
114
|
+
case $in:
|
|
115
|
+
return parseInExpression(map, expr);
|
|
116
|
+
case $not:
|
|
117
|
+
return parseNotExpression(map, expr);
|
|
118
|
+
case $exists:
|
|
119
|
+
return parseExistsExpression(map, expr);
|
|
120
|
+
case $type:
|
|
121
|
+
return parseTypeCheckExpression(map, expr);
|
|
122
|
+
case $beginsWith:
|
|
123
|
+
return parseBeginsWithExpression(map, expr);
|
|
124
|
+
case $contains:
|
|
125
|
+
return parseContainsExpression(map, expr);
|
|
126
|
+
default:
|
|
127
|
+
throw new DocumentBuilderError('Unknown expression type');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isConditionTemplate(value) {
|
|
131
|
+
if (typeof value !== 'object' || value === null) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
if ('type' in value && typeof value.type === 'symbol') {
|
|
135
|
+
return !isConditionSymbol(value.type);
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
function isConditionExpression(value) {
|
|
140
|
+
if (typeof value !== 'object' || value === null) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return 'type' in value && typeof value.type === 'symbol' && isConditionSymbol(value.type);
|
|
144
|
+
}
|
|
145
|
+
function parseConditionTemplate(map, template) {
|
|
146
|
+
const conditions = [];
|
|
147
|
+
for (const [operand, value] of Object.entries(template)) {
|
|
148
|
+
if (typeof value === 'object' && value !== null && 'type' in value) {
|
|
149
|
+
const expr = Object.assign(Object.assign({}, value), { operand });
|
|
150
|
+
conditions.push(parseConditionExpression(map, expr));
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const namePlaceholder = parseAttributePath(map, operand);
|
|
154
|
+
const valuePlaceholder = isSizeExpression(value)
|
|
155
|
+
? parseValueExpression(map, value)
|
|
156
|
+
: parseValueExpression(map, value);
|
|
157
|
+
conditions.push(`${namePlaceholder} = ${valuePlaceholder}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return conditions.join(' AND ');
|
|
161
|
+
}
|
|
162
|
+
function parseCondition(condition, attributeExpressionMap = new AttributeExpressionMap()) {
|
|
163
|
+
let conditionExpression;
|
|
164
|
+
if (Array.isArray(condition)) {
|
|
165
|
+
const expressions = condition.map(c => {
|
|
166
|
+
if (isConditionTemplate(c)) {
|
|
167
|
+
return parseConditionTemplate(attributeExpressionMap, c);
|
|
168
|
+
}
|
|
169
|
+
else if (isConditionExpression(c)) {
|
|
170
|
+
return parseConditionExpression(attributeExpressionMap, c);
|
|
171
|
+
}
|
|
172
|
+
throw new DocumentBuilderError('Invalid condition');
|
|
173
|
+
});
|
|
174
|
+
conditionExpression = expressions.join(' AND ');
|
|
175
|
+
}
|
|
176
|
+
else if (isConditionTemplate(condition)) {
|
|
177
|
+
conditionExpression = parseConditionTemplate(attributeExpressionMap, condition);
|
|
178
|
+
}
|
|
179
|
+
else if (isConditionExpression(condition)) {
|
|
180
|
+
conditionExpression = parseConditionExpression(attributeExpressionMap, condition);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
throw new DocumentBuilderError('Invalid condition');
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
conditionExpression,
|
|
187
|
+
attributeExpressionMap,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { parseCondition };
|
|
192
|
+
//# sourceMappingURL=condition-parser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-parser.mjs","sources":["../../src/conditions/condition-parser.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAiCA,SAAS,gBAAgB,CAAC,KAAc,EAAA;AACtC,IAAA,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK;AAC/F;AAEA,SAAS,mBAAmB,CAAC,GAA2B,EAAE,IAAoB,EAAA;IAC5E,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC;IACxD,OAAO,CAAA,KAAA,EAAQ,QAAQ,CAAA,CAAA,CAAG;AAC5B;AAEA,SAAS,kBAAkB,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BAAsB,CAAC,sBAAsB,EAAE,SAAS,CAAC;IACjF;AAAO,SAAA,IAAI,qBAAqB,CAAC,SAAS,CAAC,EAAE;AAC3C,QAAA,mBAAmB,GAAG,wBAAwB,CAAC,sBAAsB,EAAE,SAAS,CAAC;IACnF;SAAO;AACL,QAAA,MAAM,IAAI,oBAAoB,CAAC,mBAAmB,CAAC;IACrD;IAEA,OAAO;QACL,mBAAmB;QACnB,sBAAsB;KACvB;AACH;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Internal symbols used to identify different types of conditions.
|
|
5
|
+
*/
|
|
6
|
+
const $comparison = Symbol('comparison');
|
|
7
|
+
const $logical = Symbol('logical');
|
|
8
|
+
const $between = Symbol('between');
|
|
9
|
+
const $in = Symbol('in');
|
|
10
|
+
const $not = Symbol('not');
|
|
11
|
+
const $exists = Symbol('exists');
|
|
12
|
+
const $type = Symbol('type');
|
|
13
|
+
const $beginsWith = Symbol('begins');
|
|
14
|
+
const $contains = Symbol('contains');
|
|
15
|
+
const $size = Symbol('size');
|
|
16
|
+
function isConditionSymbol(value) {
|
|
17
|
+
return (typeof value === 'symbol' &&
|
|
18
|
+
[
|
|
19
|
+
$comparison,
|
|
20
|
+
$logical,
|
|
21
|
+
$between,
|
|
22
|
+
$in,
|
|
23
|
+
$not,
|
|
24
|
+
$exists,
|
|
25
|
+
$type,
|
|
26
|
+
$beginsWith,
|
|
27
|
+
$contains,
|
|
28
|
+
$size,
|
|
29
|
+
].includes(value));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.$beginsWith = $beginsWith;
|
|
33
|
+
exports.$between = $between;
|
|
34
|
+
exports.$comparison = $comparison;
|
|
35
|
+
exports.$contains = $contains;
|
|
36
|
+
exports.$exists = $exists;
|
|
37
|
+
exports.$in = $in;
|
|
38
|
+
exports.$logical = $logical;
|
|
39
|
+
exports.$not = $not;
|
|
40
|
+
exports.$size = $size;
|
|
41
|
+
exports.$type = $type;
|
|
42
|
+
exports.isConditionSymbol = isConditionSymbol;
|
|
43
|
+
//# sourceMappingURL=condition-symbols.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-symbols.cjs","sources":["../../src/conditions/condition-symbols.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;AAEG;MAEU,WAAW,GAAG,MAAM,CAAC,YAAY;MACjC,QAAQ,GAAG,MAAM,CAAC,SAAS;MAC3B,QAAQ,GAAG,MAAM,CAAC,SAAS;MAC3B,GAAG,GAAG,MAAM,CAAC,IAAI;MACjB,IAAI,GAAG,MAAM,CAAC,KAAK;MACnB,OAAO,GAAG,MAAM,CAAC,QAAQ;MACzB,KAAK,GAAG,MAAM,CAAC,MAAM;MACrB,WAAW,GAAG,MAAM,CAAC,QAAQ;MAC7B,SAAS,GAAG,MAAM,CAAC,UAAU;MAC7B,KAAK,GAAG,MAAM,CAAC,MAAM;AAE5B,SAAU,iBAAiB,CAAC,KAAc,EAAA;AAC9C,IAAA,QACE,OAAO,KAAK,KAAK,QAAQ;AACzB,QAAA;YACE,WAAW;YACX,QAAQ;YACR,QAAQ;YACR,GAAG;YACH,IAAI;YACJ,OAAO;YACP,KAAK;YACL,WAAW;YACX,SAAS;YACT,KAAK;AACN,SAAA,CAAC,QAAQ,CAAC,KAAK,CAAC;AAErB;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal symbols used to identify different types of conditions.
|
|
3
|
+
*/
|
|
4
|
+
export declare const $comparison: unique symbol;
|
|
5
|
+
export declare const $logical: unique symbol;
|
|
6
|
+
export declare const $between: unique symbol;
|
|
7
|
+
export declare const $in: unique symbol;
|
|
8
|
+
export declare const $not: unique symbol;
|
|
9
|
+
export declare const $exists: unique symbol;
|
|
10
|
+
export declare const $type: unique symbol;
|
|
11
|
+
export declare const $beginsWith: unique symbol;
|
|
12
|
+
export declare const $contains: unique symbol;
|
|
13
|
+
export declare const $size: unique symbol;
|
|
14
|
+
export declare function isConditionSymbol(value: unknown): boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal symbols used to identify different types of conditions.
|
|
3
|
+
*/
|
|
4
|
+
const $comparison = Symbol('comparison');
|
|
5
|
+
const $logical = Symbol('logical');
|
|
6
|
+
const $between = Symbol('between');
|
|
7
|
+
const $in = Symbol('in');
|
|
8
|
+
const $not = Symbol('not');
|
|
9
|
+
const $exists = Symbol('exists');
|
|
10
|
+
const $type = Symbol('type');
|
|
11
|
+
const $beginsWith = Symbol('begins');
|
|
12
|
+
const $contains = Symbol('contains');
|
|
13
|
+
const $size = Symbol('size');
|
|
14
|
+
function isConditionSymbol(value) {
|
|
15
|
+
return (typeof value === 'symbol' &&
|
|
16
|
+
[
|
|
17
|
+
$comparison,
|
|
18
|
+
$logical,
|
|
19
|
+
$between,
|
|
20
|
+
$in,
|
|
21
|
+
$not,
|
|
22
|
+
$exists,
|
|
23
|
+
$type,
|
|
24
|
+
$beginsWith,
|
|
25
|
+
$contains,
|
|
26
|
+
$size,
|
|
27
|
+
].includes(value));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { $beginsWith, $between, $comparison, $contains, $exists, $in, $logical, $not, $size, $type, isConditionSymbol };
|
|
31
|
+
//# sourceMappingURL=condition-symbols.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-symbols.mjs","sources":["../../src/conditions/condition-symbols.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;AAEG;MAEU,WAAW,GAAG,MAAM,CAAC,YAAY;MACjC,QAAQ,GAAG,MAAM,CAAC,SAAS;MAC3B,QAAQ,GAAG,MAAM,CAAC,SAAS;MAC3B,GAAG,GAAG,MAAM,CAAC,IAAI;MACjB,IAAI,GAAG,MAAM,CAAC,KAAK;MACnB,OAAO,GAAG,MAAM,CAAC,QAAQ;MACzB,KAAK,GAAG,MAAM,CAAC,MAAM;MACrB,WAAW,GAAG,MAAM,CAAC,QAAQ;MAC7B,SAAS,GAAG,MAAM,CAAC,UAAU;MAC7B,KAAK,GAAG,MAAM,CAAC,MAAM;AAE5B,SAAU,iBAAiB,CAAC,KAAc,EAAA;AAC9C,IAAA,QACE,OAAO,KAAK,KAAK,QAAQ;AACzB,QAAA;YACE,WAAW;YACX,QAAQ;YACR,QAAQ;YACR,GAAG;YACH,IAAI;YACJ,OAAO;YACP,KAAK;YACL,WAAW;YACX,SAAS;YACT,KAAK;AACN,SAAA,CAAC,QAAQ,CAAC,KAAK,CAAC;AAErB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-types.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { NativeAttributeValue } from '@aws-sdk/lib-dynamodb';
|
|
2
|
+
import type { $beginsWith, $between, $comparison, $contains, $exists, $in, $logical, $not, $size, $type } from '@/conditions/condition-symbols';
|
|
3
|
+
/**
|
|
4
|
+
* These are the basic building block types for constructing DynamoDB condition expressions.
|
|
5
|
+
*
|
|
6
|
+
* https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Represends a top-level attribute in a Dynamo item OR a nested attribute using dot notation.
|
|
10
|
+
*
|
|
11
|
+
* {@link https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html#Expressions.OperatorsAndFunctions.Syntax}
|
|
12
|
+
*/
|
|
13
|
+
export type Operand = string;
|
|
14
|
+
export type ComparisonOperator = '=' | '<>' | '<' | '<=' | '>' | '>=';
|
|
15
|
+
export type LogicalOperator = 'AND' | 'OR';
|
|
16
|
+
export type DynamoAttributeType = 'B' | 'BOOL' | 'BS' | 'L' | 'M' | 'N' | 'NS' | 'NULL' | 'S' | 'SS';
|
|
17
|
+
export type ValueExpression = NativeAttributeValue | SizeExpression;
|
|
18
|
+
export type ComparisonExpression = {
|
|
19
|
+
type: typeof $comparison;
|
|
20
|
+
operand: Operand;
|
|
21
|
+
operator: ComparisonOperator;
|
|
22
|
+
value: ValueExpression;
|
|
23
|
+
};
|
|
24
|
+
export type ComparisonExpressionTemplate = Omit<ComparisonExpression, 'operand'>;
|
|
25
|
+
export type LogicalExpression = {
|
|
26
|
+
type: typeof $logical;
|
|
27
|
+
operator: LogicalOperator;
|
|
28
|
+
subConditions: ConditionExpressionTemplate[];
|
|
29
|
+
};
|
|
30
|
+
export type BetweenExpression = {
|
|
31
|
+
type: typeof $between;
|
|
32
|
+
operand: Operand;
|
|
33
|
+
lowerValue: ValueExpression;
|
|
34
|
+
upperValue: ValueExpression;
|
|
35
|
+
};
|
|
36
|
+
export type BetweenExpressionTemplate = Omit<BetweenExpression, 'operand'>;
|
|
37
|
+
export type InExpression = {
|
|
38
|
+
type: typeof $in;
|
|
39
|
+
operand: Operand;
|
|
40
|
+
values: ValueExpression[];
|
|
41
|
+
};
|
|
42
|
+
export type InExpressionTemplate = Omit<InExpression, 'operand'>;
|
|
43
|
+
export type NotExpression = {
|
|
44
|
+
type: typeof $not;
|
|
45
|
+
condition: ConditionExpressionTemplate;
|
|
46
|
+
};
|
|
47
|
+
export type ExistsExpression = {
|
|
48
|
+
type: typeof $exists;
|
|
49
|
+
operand: Operand;
|
|
50
|
+
not?: true;
|
|
51
|
+
};
|
|
52
|
+
export type ExistsExpressionTemplate = Omit<ExistsExpression, 'operand'>;
|
|
53
|
+
export type TypeCheckExpression = {
|
|
54
|
+
type: typeof $type;
|
|
55
|
+
operand: Operand;
|
|
56
|
+
attributeType: DynamoAttributeType;
|
|
57
|
+
};
|
|
58
|
+
export type TypeCheckExpressionTemplate = Omit<TypeCheckExpression, 'operand'>;
|
|
59
|
+
export type BeginsWithExpression = {
|
|
60
|
+
type: typeof $beginsWith;
|
|
61
|
+
operand: Operand;
|
|
62
|
+
prefix: string;
|
|
63
|
+
};
|
|
64
|
+
export type BeginsWithExpressionTemplate = Omit<BeginsWithExpression, 'operand'>;
|
|
65
|
+
export type ContainsExpression = {
|
|
66
|
+
type: typeof $contains;
|
|
67
|
+
operand: Operand;
|
|
68
|
+
substringOrElement: NativeAttributeValue;
|
|
69
|
+
};
|
|
70
|
+
export type ContainsExpressionTemplate = Omit<ContainsExpression, 'operand'>;
|
|
71
|
+
export type SizeExpression = {
|
|
72
|
+
type: typeof $size;
|
|
73
|
+
attribute: Operand;
|
|
74
|
+
};
|
|
75
|
+
export type BooleanExpression = ExistsExpression | TypeCheckExpression | BeginsWithExpression | ContainsExpression;
|
|
76
|
+
export type FunctionExpression = BooleanExpression | SizeExpression;
|
|
77
|
+
export type TemplateExpression = Omit<ComparisonExpression | BetweenExpression | InExpression | BooleanExpression, 'operand'>;
|
|
78
|
+
/**
|
|
79
|
+
* Implicit AND between all attributes in the template
|
|
80
|
+
* This is an object where keys are operands and values are either values or template expressions
|
|
81
|
+
*/
|
|
82
|
+
export type ConditionTemplate = Record<Operand, ValueExpression | TemplateExpression>;
|
|
83
|
+
export type ConditionExpression = ComparisonExpression | LogicalExpression | BetweenExpression | InExpression | NotExpression | BooleanExpression;
|
|
84
|
+
export type ConditionExpressionTemplate = ConditionExpression | ConditionTemplate;
|
|
85
|
+
export type Condition = ConditionExpressionTemplate | ConditionExpressionTemplate[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var conditions_conditionSymbols = require('./condition-symbols.cjs');
|
|
4
|
+
|
|
5
|
+
function contains(substringOrElement) {
|
|
6
|
+
return {
|
|
7
|
+
type: conditions_conditionSymbols.$contains,
|
|
8
|
+
substringOrElement,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.contains = contains;
|
|
13
|
+
//# sourceMappingURL=contains.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contains.cjs","sources":["../../src/conditions/contains.ts"],"sourcesContent":[null],"names":["$contains"],"mappings":";;;;AAIM,SAAU,QAAQ,CAAC,kBAAwC,EAAA;IAC/D,OAAO;AACL,QAAA,IAAI,EAAEA,qCAAS;QACf,kBAAkB;KACnB;AACH;;;;"}
|