dynamo-bao 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 +333 -0
- package/bin/chokidar-test.js +60 -0
- package/bin/codegen.js +114 -0
- package/bin/dynamo-bao-create-table.js +136 -0
- package/bin/generators/index.js +0 -0
- package/bin/generators/model.js +428 -0
- package/bin/utils/scriptLogger.js +10 -0
- package/bin/watch.js +93 -0
- package/package.json +54 -0
- package/src/config.js +60 -0
- package/src/constants.js +35 -0
- package/src/db.js +21 -0
- package/src/fieldResolver.js +74 -0
- package/src/fields.js +781 -0
- package/src/filter-expression.js +241 -0
- package/src/index.js +127 -0
- package/src/key-condition.js +258 -0
- package/src/mixins/batch-loading-mixin.js +336 -0
- package/src/mixins/mutation-mixin.js +595 -0
- package/src/mixins/query-mixin.js +341 -0
- package/src/mixins/unique-constraint-mixin.js +131 -0
- package/src/mixins/validation-mixin.js +154 -0
- package/src/model-config.js +47 -0
- package/src/model-manager.js +106 -0
- package/src/model.js +689 -0
- package/src/object-not-found.js +44 -0
- package/src/plugin-manager.js +61 -0
- package/src/utils/logger.js +54 -0
- package/src/utils/retry-helper.js +24 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
|
|
4
|
+
class FieldResolver {
|
|
5
|
+
constructor(builtInFieldsPath, customFieldsPath) {
|
|
6
|
+
this.builtInFields = require(builtInFieldsPath);
|
|
7
|
+
this.customFieldsPath = customFieldsPath;
|
|
8
|
+
this.fieldDefinitionCache = new Map();
|
|
9
|
+
|
|
10
|
+
console.log("FieldResolver constructor:", {
|
|
11
|
+
builtInFieldsPath,
|
|
12
|
+
customFieldsPath,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Pre-cache all built-in fields
|
|
16
|
+
Object.entries(this.builtInFields).forEach(([name, definition]) => {
|
|
17
|
+
this.fieldDefinitionCache.set(name, definition);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getFieldDefinition(fieldType) {
|
|
22
|
+
if (this.fieldDefinitionCache.has(fieldType)) {
|
|
23
|
+
return this.fieldDefinitionCache.get(fieldType);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Try custom fields if available
|
|
27
|
+
if (this.customFieldsPath) {
|
|
28
|
+
try {
|
|
29
|
+
// Convert to kebab case for file name
|
|
30
|
+
const baseName = fieldType.replace(/Field$/, "");
|
|
31
|
+
const kebabName = baseName
|
|
32
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
33
|
+
.toLowerCase();
|
|
34
|
+
const fieldPath = path.join(
|
|
35
|
+
this.customFieldsPath,
|
|
36
|
+
`${kebabName}-field.js`,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
console.log("fieldPath", fieldPath);
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync(fieldPath)) {
|
|
42
|
+
console.log("fieldPath exists");
|
|
43
|
+
const customField = require(fieldPath);
|
|
44
|
+
|
|
45
|
+
console.log("customField", customField);
|
|
46
|
+
// Get the field from the exports using the original field type name
|
|
47
|
+
const fieldDefinition = customField[fieldType];
|
|
48
|
+
if (fieldDefinition) {
|
|
49
|
+
this.fieldDefinitionCache.set(fieldType, fieldDefinition);
|
|
50
|
+
return fieldDefinition;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error("Error loading custom field:", err);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Field type '${fieldType}' not found in built-in or custom fields`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
isCustomField(fieldType) {
|
|
64
|
+
if (!this.customFieldsPath) return false;
|
|
65
|
+
const baseName = fieldType.replace(/Field$/, "");
|
|
66
|
+
const kebabName = baseName
|
|
67
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
68
|
+
.toLowerCase();
|
|
69
|
+
const fieldPath = path.join(this.customFieldsPath, `${kebabName}-field.js`);
|
|
70
|
+
return fs.existsSync(fieldPath);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = FieldResolver;
|