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.
@@ -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;