@seedprotocol/sdk 0.3.4 → 0.3.6

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 (40) hide show
  1. package/dist/addModel.js +89 -0
  2. package/dist/addModel.js.map +1 -0
  3. package/dist/bin.js +71 -29
  4. package/dist/bin.js.map +1 -1
  5. package/dist/db/configs/browser.app.db.config.ts +1 -0
  6. package/dist/db/configs/node.app.db.config.ts +1 -0
  7. package/dist/main.js +1 -1
  8. package/dist/main.js.map +1 -1
  9. package/dist/node/codegen/templates/model.njk +14 -0
  10. package/dist/scripts/addModel.d.ts +3 -0
  11. package/dist/scripts/addModel.d.ts.map +1 -0
  12. package/dist/scripts/bin.d.ts.map +1 -1
  13. package/dist/src/db/configs/browser.app.db.config.d.ts.map +1 -1
  14. package/dist/src/db/configs/node.app.db.config.d.ts.map +1 -1
  15. package/dist/src/helpers/constants.d.ts +1 -0
  16. package/dist/src/helpers/constants.d.ts.map +1 -1
  17. package/dist/src/helpers/constants.js +2 -1
  18. package/dist/src/helpers/constants.js.map +1 -1
  19. package/dist/src/index.d.ts +1 -1
  20. package/dist/src/index.d.ts.map +1 -1
  21. package/dist/src/node/codegen/drizzle.d.ts +4 -1
  22. package/dist/src/node/codegen/drizzle.d.ts.map +1 -1
  23. package/dist/src/node/codegen/drizzle.js +37 -9
  24. package/dist/src/node/codegen/drizzle.js.map +1 -1
  25. package/dist/src/node/constants.d.ts.map +1 -1
  26. package/dist/src/node/constants.js +12 -4
  27. package/dist/src/node/constants.js.map +1 -1
  28. package/dist/src/node/helpers/index.d.ts.map +1 -1
  29. package/dist/src/node/helpers/index.js +19 -8
  30. package/dist/src/node/helpers/index.js.map +1 -1
  31. package/dist/src/node/webpack/index.d.ts.map +1 -1
  32. package/dist/src/node/webpack/index.js +7 -0
  33. package/dist/src/node/webpack/index.js.map +1 -1
  34. package/dist/src/schema/index.d.ts.map +1 -1
  35. package/dist/src/schema/model/index.d.ts +8 -8
  36. package/dist/src/schema/property/index.d.ts +58 -32
  37. package/dist/src/schema/property/index.d.ts.map +1 -1
  38. package/dist/src/schema/property/index.js +13 -6
  39. package/dist/src/schema/property/index.js.map +1 -1
  40. package/package.json +3 -2
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import { generateModelCode } from './src/node/codegen/drizzle.js';
4
+
5
+ // Parse command line arguments
6
+ const args = process.argv.slice(2);
7
+ const sourceSchemaFilePath = args[0];
8
+ const outputFilePath = args[1];
9
+ const jsonString = args[2];
10
+ if (!sourceSchemaFilePath || !outputFilePath || !jsonString) {
11
+ console.error('Usage: npx tsx bin/addModel.ts <source-schema-file-path> <output-file-path> <json-string>');
12
+ process.exit(1);
13
+ }
14
+ // Read the contents of the file
15
+ let fileContents;
16
+ try {
17
+ fileContents = fs.readFileSync(sourceSchemaFilePath, 'utf-8');
18
+ }
19
+ catch (error) {
20
+ console.error(`Error reading file at ${sourceSchemaFilePath}:`, error);
21
+ process.exit(1);
22
+ }
23
+ // Parse the JSON string
24
+ let jsonModel;
25
+ try {
26
+ jsonModel = JSON.parse(jsonString);
27
+ }
28
+ catch (error) {
29
+ console.error('Invalid JSON string:', error);
30
+ process.exit(1);
31
+ }
32
+ /**
33
+ * Simple function to inject a new model after the last model class and update the models object
34
+ * @param {string} schemaContent - The content of the schema file
35
+ * @param {string} newModelCode - The code for the new model to inject
36
+ * @returns {string} The updated schema content
37
+ */
38
+ const injectModel = (schemaContent, newModelCode) => {
39
+ // Extract the model name from the new code
40
+ const modelNameMatch = newModelCode.match(/class\s+(\w+)/);
41
+ if (!modelNameMatch) {
42
+ throw new Error("Could not extract model name from provided code");
43
+ }
44
+ const modelName = modelNameMatch[1];
45
+ // Find the 'const models' position
46
+ const modelsPos = schemaContent.indexOf('const models');
47
+ if (modelsPos === -1) {
48
+ throw new Error("Could not find 'const models' in the schema");
49
+ }
50
+ // Find the position of the last model class before 'const models'
51
+ const lastClassPos = schemaContent.lastIndexOf('@Model', modelsPos);
52
+ if (lastClassPos === -1) {
53
+ throw new Error("Could not find any model declarations in the schema");
54
+ }
55
+ // Find the end of the last class
56
+ const classEndPos = schemaContent.indexOf('}', lastClassPos);
57
+ if (classEndPos === -1) {
58
+ throw new Error("Could not find closing brace of the last model class");
59
+ }
60
+ // Find the position after the last class's closing brace
61
+ const insertModelPos = schemaContent.indexOf('\n', classEndPos) + 1;
62
+ // Insert the new model
63
+ let updatedSchema = schemaContent.slice(0, insertModelPos) +
64
+ "\n" + newModelCode + "\n\n" +
65
+ schemaContent.slice(insertModelPos);
66
+ // Find the closing brace of the models object
67
+ const modelsClosingBracePos = updatedSchema.indexOf('}', updatedSchema.indexOf('const models'));
68
+ // Add the new model to the models object
69
+ updatedSchema =
70
+ updatedSchema.slice(0, modelsClosingBracePos) +
71
+ ` ${modelName},\n` +
72
+ updatedSchema.slice(modelsClosingBracePos);
73
+ return updatedSchema;
74
+ };
75
+ const newModelCode = generateModelCode({
76
+ modelName: jsonModel.name,
77
+ properties: jsonModel.properties,
78
+ });
79
+ const updatedSchema = injectModel(fileContents, newModelCode);
80
+ // Write the new table file
81
+ try {
82
+ fs.writeFileSync(outputFilePath, updatedSchema, 'utf-8');
83
+ console.log(`Wrote updated schema file to ${outputFilePath}`);
84
+ }
85
+ catch (error) {
86
+ console.error('Error writing Drizzle table file:', error);
87
+ process.exit(1);
88
+ }
89
+ //# sourceMappingURL=addModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addModel.js","sources":["../../scripts/addModel.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from 'fs';\nimport { createDrizzleSchemaFilesFromConfig, generateModelCode } from '../src/node/codegen/drizzle';\n\n// Parse command line arguments\nconst args = process.argv.slice(2);\nconst sourceSchemaFilePath = args[0];\nconst outputFilePath = args[1];\nconst jsonString = args[2];\n\nif (!sourceSchemaFilePath || !outputFilePath || !jsonString) {\n console.error('Usage: npx tsx bin/addModel.ts <source-schema-file-path> <output-file-path> <json-string>');\n process.exit(1);\n}\n\n// Read the contents of the file\nlet fileContents;\ntry {\n fileContents = fs.readFileSync(sourceSchemaFilePath, 'utf-8');\n} catch (error) {\n console.error(`Error reading file at ${sourceSchemaFilePath}:`, error);\n process.exit(1);\n}\n\n// Parse the JSON string\nlet jsonModel;\ntry {\n jsonModel = JSON.parse(jsonString);\n} catch (error) {\n console.error('Invalid JSON string:', error);\n process.exit(1);\n}\n\n/**\n * Simple function to inject a new model after the last model class and update the models object\n * @param {string} schemaContent - The content of the schema file\n * @param {string} newModelCode - The code for the new model to inject\n * @returns {string} The updated schema content\n */\nconst injectModel = (schemaContent: string, newModelCode: string) => {\n // Extract the model name from the new code\n const modelNameMatch = newModelCode.match(/class\\s+(\\w+)/);\n if (!modelNameMatch) {\n throw new Error(\"Could not extract model name from provided code\");\n }\n const modelName = modelNameMatch[1];\n\n // Find the 'const models' position\n const modelsPos = schemaContent.indexOf('const models');\n if (modelsPos === -1) {\n throw new Error(\"Could not find 'const models' in the schema\");\n }\n\n // Find the position of the last model class before 'const models'\n const lastClassPos = schemaContent.lastIndexOf('@Model', modelsPos);\n if (lastClassPos === -1) {\n throw new Error(\"Could not find any model declarations in the schema\");\n }\n\n // Find the end of the last class\n const classEndPos = schemaContent.indexOf('}', lastClassPos);\n if (classEndPos === -1) {\n throw new Error(\"Could not find closing brace of the last model class\");\n }\n\n // Find the position after the last class's closing brace\n const insertModelPos = schemaContent.indexOf('\\n', classEndPos) + 1;\n \n // Insert the new model\n let updatedSchema = \n schemaContent.slice(0, insertModelPos) + \n \"\\n\" + newModelCode + \"\\n\\n\" + \n schemaContent.slice(insertModelPos);\n \n // Find the closing brace of the models object\n const modelsClosingBracePos = updatedSchema.indexOf('}', updatedSchema.indexOf('const models'));\n \n // Add the new model to the models object\n updatedSchema = \n updatedSchema.slice(0, modelsClosingBracePos) + \n ` ${modelName},\\n` + \n updatedSchema.slice(modelsClosingBracePos);\n \n return updatedSchema;\n}\n\nconst newModelCode = generateModelCode({\n modelName: jsonModel.name,\n properties: jsonModel.properties,\n});\n\nconst updatedSchema = injectModel(fileContents, newModelCode);\n\n// Write the new table file\ntry {\n fs.writeFileSync(outputFilePath, updatedSchema, 'utf-8');\n console.log(`Wrote updated schema file to ${outputFilePath}`);\n} catch (error) {\n console.error('Error writing Drizzle table file:', error);\n process.exit(1);\n} \n"],"names":[],"mappings":";;;;AAKA;AACA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,MAAM,oBAAoB,GAAG,IAAI,CAAC,CAAC,CAAC;AACpC,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;AAE1B,IAAI,CAAC,oBAAoB,IAAI,CAAC,cAAc,IAAI,CAAC,UAAU,EAAE;AAC3D,IAAA,OAAO,CAAC,KAAK,CAAC,2FAA2F,CAAC;AAC1G,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;AACA,IAAI,YAAY;AAChB,IAAI;IACF,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,oBAAoB,EAAE,OAAO,CAAC;AAC/D;AAAE,OAAO,KAAK,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,CAAA,sBAAA,EAAyB,oBAAoB,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC;AACtE,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;AACA,IAAI,SAAS;AACb,IAAI;AACF,IAAA,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;AACpC;AAAE,OAAO,KAAK,EAAE;AACd,IAAA,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC;AAC5C,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;;;;;AAKG;AACH,MAAM,WAAW,GAAG,CAAC,aAAqB,EAAE,YAAoB,KAAI;;I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,CAAC;AAE5C,IAAA,OAAO,aAAa;AACtB,CAAC;AAED,MAAM,YAAY,GAAG,iBAAiB,CAAC;IACrC,SAAS,EAAE,SAAS,CAAC,IAAI;IACzB,UAAU,EAAE,SAAS,CAAC,UAAU;AACjC,CAAA,CAAC;AAEF,MAAM,aAAa,GAAG,WAAW,CAAC,YAAY,EAAE,YAAY,CAAC;AAE7D;AACA,IAAI;IACF,EAAE,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,EAAE,OAAO,CAAC;AACxD,IAAA,OAAO,CAAC,GAAG,CAAC,gCAAgC,cAAc,CAAA,CAAE,CAAC;AAC/D;AAAE,OAAO,KAAK,EAAE;AACd,IAAA,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC;AACzD,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB"}
package/dist/bin.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
- import { exec, execSync } from 'child_process';
5
- import { promisify } from 'util';
4
+ import { execSync } from 'child_process';
6
5
  import { pathToFileURL } from 'url';
7
6
  import process from 'node:process';
8
7
  import './src/node/helpers/EasClient.js';
@@ -10,21 +9,61 @@ import './src/node/helpers/QueryClient.js';
10
9
  import 'fs/promises';
11
10
  import './src/helpers/FileManager/BaseFileManager.js';
12
11
  import './src/node/helpers/ArweaveClient.js';
13
- import { SCHEMA_TS } from './src/helpers/constants.js';
12
+ import { SCHEMA_TS, INIT_SCRIPT_SUCCESS_MESSAGE } from './src/helpers/constants.js';
14
13
  import { rootWithNodeModules, dotSeedDir, sdkRootDir, drizzleKitPath, appSchemaDir, appMetaDir, drizzleDbConfigPath } from './src/node/constants.js';
15
14
  import { createDrizzleSchemaFilesFromConfig } from './src/node/codegen/drizzle.js';
16
15
  import { rimrafSync } from 'rimraf';
16
+ import { getTsImport } from './src/node/helpers/index.js';
17
17
 
18
- promisify(exec);
19
18
  let a;
20
19
  a = process.argv.splice(2);
20
+ /**
21
+ * Copy a directory and all its contents recursively
22
+ * @param {string} sourceDir - Path to the source directory
23
+ * @param {string} targetDir - Path to the target directory
24
+ */
25
+ function copyDirectoryRecursively(sourceDir, targetDir) {
26
+ // Create the target directory if it doesn't exist
27
+ if (!fs.existsSync(targetDir)) {
28
+ fs.mkdirSync(targetDir, { recursive: true });
29
+ }
30
+ // Read all entries in the source directory
31
+ const entries = fs.readdirSync(sourceDir);
32
+ // Process each entry
33
+ for (const entry of entries) {
34
+ const sourcePath = path.join(sourceDir, entry);
35
+ const targetPath = path.join(targetDir, entry);
36
+ // Check if the entry is a file or directory
37
+ const stats = fs.statSync(sourcePath);
38
+ if (stats.isFile()) {
39
+ // Copy the file directly
40
+ fs.copyFileSync(sourcePath, targetPath);
41
+ console.log(`Copied file: ${sourcePath} → ${targetPath}`);
42
+ }
43
+ else if (stats.isDirectory()) {
44
+ // Recursively copy the subdirectory
45
+ copyDirectoryRecursively(sourcePath, targetPath);
46
+ }
47
+ }
48
+ }
21
49
  const init = (args) => {
22
50
  console.log('args:', args);
23
51
  if (args && args.length && args[0] === 'init') {
24
52
  console.log('[Seed Protocol] Running init script');
25
53
  let appFilesDirPath = args[2] || undefined;
26
- let schemaFileDir = args[1] || rootWithNodeModules;
27
- const schemaFilePath = path.join(schemaFileDir, SCHEMA_TS);
54
+ console.log('appFilesDirPath', appFilesDirPath);
55
+ console.log('rootWithNodeModules', rootWithNodeModules);
56
+ console.log('process.cwd()', process.cwd());
57
+ let schemaFileDir = args[1];
58
+ console.log('args[1]', args[1]);
59
+ if (!schemaFileDir && process.env.IS_PORTAL && !process.cwd().includes('seed-protocol-sdk')) {
60
+ schemaFileDir = process.cwd();
61
+ }
62
+ if (process.env.NODE_ENV === 'test') {
63
+ schemaFileDir = path.join(process.cwd(), '__tests__', '__mocks__', 'node', 'project');
64
+ }
65
+ console.log('schemaFileDir2', schemaFileDir);
66
+ const schemaFilePath = path.join(schemaFileDir || process.cwd(), SCHEMA_TS);
28
67
  // Remove dotSeedDir to start fresh each time
29
68
  if (fs.existsSync(dotSeedDir)) {
30
69
  fs.rmSync(dotSeedDir, { recursive: true, force: true });
@@ -67,38 +106,39 @@ const init = (args) => {
67
106
  console.error(`Error processing directory: ${dirPath}`, error);
68
107
  }
69
108
  };
70
- const copyFiles = (srcDir, destDir) => {
71
- if (!fs.existsSync(destDir)) {
72
- fs.mkdirSync(destDir, { recursive: true });
73
- }
74
- const srcFiles = fs.readdirSync(srcDir);
75
- srcFiles.forEach((file) => {
76
- console.log(`Copying ${srcDir}/${file} to ${destDir}/${file}`);
77
- fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file));
78
- });
79
- };
109
+ // const copyFiles = (srcDir: string, destDir: string) => {
110
+ // if (!fs.existsSync(destDir)) {
111
+ // fs.mkdirSync(destDir, { recursive: true })
112
+ // }
113
+ // const srcFiles = fs.readdirSync(srcDir)
114
+ // srcFiles.forEach((file) => {
115
+ // if (f)
116
+ // console.log(`Copying ${srcDir}/${file} to ${destDir}/${file}`)
117
+ // fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file))
118
+ // })
119
+ // }
80
120
  const copyDotSeedFilesToAppFiles = async (_appFilesDirPath) => {
81
121
  console.log('[Seed Protocol] Copying dot seed files to app files');
82
- const exists = await fs.promises.access(_appFilesDirPath).then(() => true).catch(() => false);
122
+ const { endpoints } = await getTsImport(schemaFilePath);
123
+ const outputDirPath = endpoints.localOutputDir || _appFilesDirPath;
124
+ const exists = await fs.promises.access(outputDirPath).then(() => true).catch(() => false);
83
125
  if (exists) {
84
- await fs.promises.rm(_appFilesDirPath, { recursive: true, force: true });
126
+ await fs.promises.rm(outputDirPath, { recursive: true, force: true });
85
127
  }
86
128
  console.log(`[Seed Protocol] Removed old app files`);
87
- console.log(`[Seed Protocol] making dir at ${_appFilesDirPath}`);
88
- fs.mkdirSync(_appFilesDirPath, { recursive: true });
129
+ console.log(`[Seed Protocol] making dir at ${outputDirPath}`);
130
+ fs.mkdirSync(outputDirPath, { recursive: true });
89
131
  console.log('[Seed Protocol] copying app files');
90
- fs.cpSync(dotSeedDir, _appFilesDirPath, { recursive: true });
132
+ fs.cpSync(dotSeedDir, outputDirPath, { recursive: true });
91
133
  console.log('[Seed Protocol] removing sqlite3 files and index.ts files');
92
- rimrafSync(`${_appFilesDirPath}/**/*.sqlite3`, {
134
+ rimrafSync(`${outputDirPath}/**/*.sqlite3`, {
93
135
  glob: true,
94
136
  });
95
- rimrafSync(`${_appFilesDirPath}/**/index.ts`, {
137
+ rimrafSync(`${outputDirPath}/**/index.ts`, {
96
138
  glob: true,
97
139
  });
98
140
  };
99
141
  const updateSchema = async (pathToConfig, pathToMeta) => {
100
- console.log('pathToMeta:', pathToMeta);
101
- console.log('pathToConfig:', pathToConfig);
102
142
  if (!fs.existsSync(pathToMeta)) {
103
143
  console.log(`${drizzleKitCommand} generate --config=${pathToConfig}`);
104
144
  execSync(`${drizzleKitCommand} generate --config=${pathToConfig}`);
@@ -106,11 +146,13 @@ const init = (args) => {
106
146
  execSync(`${drizzleKitCommand} migrate --config=${pathToConfig}`);
107
147
  };
108
148
  const runCommands = async () => {
109
- await createDrizzleSchemaFilesFromConfig();
149
+ await createDrizzleSchemaFilesFromConfig(schemaFilePath);
110
150
  ensureIndexExports(appSchemaDir);
111
151
  await updateSchema(drizzleDbConfigPath, appMetaDir);
112
152
  };
113
- copyFiles(path.join(sdkRootDir, 'seedSchema'), path.join(dotSeedDir, 'schema'));
153
+ copyDirectoryRecursively(path.join(sdkRootDir, 'seedSchema'), path.join(dotSeedDir, 'schema'));
154
+ copyDirectoryRecursively(path.join(sdkRootDir, 'node', 'codegen'), path.join(dotSeedDir, 'codegen'));
155
+ console.log('copying', schemaFilePath, path.join(dotSeedDir, 'schema.ts'));
114
156
  fs.copyFileSync(schemaFilePath, path.join(dotSeedDir, 'schema.ts'));
115
157
  runCommands()
116
158
  .then(() => {
@@ -122,12 +164,12 @@ const init = (args) => {
122
164
  }
123
165
  })
124
166
  .then(() => {
125
- console.log('[Seed Protocol] Finished running init script');
167
+ console.log(INIT_SCRIPT_SUCCESS_MESSAGE);
126
168
  });
127
169
  }
128
170
  };
129
171
  const calledFrom = pathToFileURL(process.argv[1]).href;
130
- console.log('calledFrom:', calledFrom);
172
+ console.log('calledFrom', calledFrom);
131
173
  if (calledFrom.endsWith('node_modules/.bin/seed') ||
132
174
  import.meta.url.endsWith('@seedprotocol/sdk/node/bin.js') ||
133
175
  import.meta.url.endsWith('scripts/bin.ts')) {
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sources":["../../scripts/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport path from 'path'\nimport fs from 'fs'\nimport { exec as execCallback, execSync, } from 'child_process'\nimport { promisify } from 'util'\nimport { pathToFileURL } from 'url'\nimport process from 'node:process'\nimport '../src/node/helpers/EasClient'\nimport '../src/node/helpers/QueryClient'\nimport '../src/node/helpers/FileManager'\nimport '../src/node/helpers/ArweaveClient'\nimport { SCHEMA_TS } from '../src/helpers/constants'\nimport {\n appMetaDir,\n appSchemaDir,\n dotSeedDir,\n drizzleDbConfigPath,\n drizzleKitPath,\n rootWithNodeModules,\n sdkRootDir,\n} from '../src/node/constants'\nimport { createDrizzleSchemaFilesFromConfig } from '../src/node/codegen'\nimport { rimrafSync } from 'rimraf'\n\nconst exec = promisify(execCallback)\n\nlet a\n\na = process.argv.splice(2)\n\nconst init = (args: string[]) => {\n console.log('args:', args)\n\n if (args && args.length && args[0] === 'init') {\n console.log('[Seed Protocol] Running init script')\n\n let appFilesDirPath = args[2] || undefined\n\n let schemaFileDir = args[1] || rootWithNodeModules\n const schemaFilePath = path.join(schemaFileDir, SCHEMA_TS)\n\n // Remove dotSeedDir to start fresh each time\n if (fs.existsSync(dotSeedDir)) {\n fs.rmSync(dotSeedDir, { recursive: true, force: true })\n }\n\n console.log('[Seed Protocol] dotSeedDir', dotSeedDir)\n console.log('[Seed Protocol] sdkRootDir', sdkRootDir)\n\n const drizzleKitCommand = `npx --yes tsx ${drizzleKitPath}`\n\n const ensureIndexExports = (dirPath: string): void => {\n try {\n // Get all file names in the directory\n const files = fs.readdirSync(dirPath)\n\n // Filter for .ts files excluding index.ts\n const tsFiles = files.filter(\n (file) => file.endsWith('.ts') && file !== 'index.ts',\n )\n\n // Check if index.ts exists\n const indexFilePath = path.join(dirPath, 'index.ts')\n try {\n fs.accessSync(indexFilePath)\n } catch (error) {\n console.error(`index.ts not found in the directory: ${dirPath}`)\n return\n }\n\n // Read the content of index.ts\n const indexContent = fs.readFileSync(indexFilePath, 'utf8')\n\n // Create export statements for each .ts file\n const exportStatements = tsFiles.map(\n (file) => `export * from './${path.basename(file, '.ts')}';`,\n )\n\n // Check if each export statement is already present in index.ts\n const missingExports = exportStatements.filter(\n (statement) => !indexContent.includes(statement),\n )\n\n if (missingExports.length > 0) {\n // Append missing export statements to index.ts\n const newContent =\n indexContent + '\\n' + missingExports.join('\\n') + '\\n'\n fs.writeFileSync(indexFilePath, newContent, 'utf8')\n console.log(\n `Updated index.ts with missing exports:\\n${missingExports.join('\\n')}`,\n )\n } else {\n console.log('All exports are already present in index.ts')\n }\n } catch (error) {\n console.error(`Error processing directory: ${dirPath}`, error)\n }\n }\n\n const copyFiles = (srcDir, destDir) => {\n if (!fs.existsSync(destDir)) {\n fs.mkdirSync(destDir, { recursive: true })\n }\n const srcFiles = fs.readdirSync(srcDir)\n srcFiles.forEach((file) => {\n console.log(`Copying ${srcDir}/${file} to ${destDir}/${file}`)\n fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file))\n })\n }\n\n const copyDotSeedFilesToAppFiles = async (_appFilesDirPath: string) => {\n console.log('[Seed Protocol] Copying dot seed files to app files')\n const exists = await fs.promises.access(_appFilesDirPath).then(() => true).catch(() => false)\n if (exists) {\n await fs.promises.rm(_appFilesDirPath, { recursive: true, force: true })\n }\n console.log(`[Seed Protocol] Removed old app files`)\n console.log(`[Seed Protocol] making dir at ${_appFilesDirPath}`)\n fs.mkdirSync(_appFilesDirPath, { recursive: true })\n console.log('[Seed Protocol] copying app files')\n fs.cpSync(dotSeedDir, _appFilesDirPath, { recursive: true })\n console.log(\n '[Seed Protocol] removing sqlite3 files and index.ts files',\n )\n rimrafSync(`${_appFilesDirPath}/**/*.sqlite3`, {\n glob: true,\n })\n rimrafSync(`${_appFilesDirPath}/**/index.ts`, {\n glob: true,\n })\n }\n\n const updateSchema = async (pathToConfig: string, pathToMeta: string) => {\n console.log('pathToMeta:', pathToMeta)\n console.log('pathToConfig:', pathToConfig)\n if (!fs.existsSync(pathToMeta)) {\n console.log(`${drizzleKitCommand} generate --config=${pathToConfig}`)\n execSync(\n `${drizzleKitCommand} generate --config=${pathToConfig}`,\n )\n }\n execSync(`${drizzleKitCommand} migrate --config=${pathToConfig}`)\n }\n\n const runCommands = async () => {\n await createDrizzleSchemaFilesFromConfig()\n ensureIndexExports(appSchemaDir)\n await updateSchema(drizzleDbConfigPath, appMetaDir)\n }\n\n copyFiles(\n path.join(sdkRootDir, 'seedSchema'),\n path.join(dotSeedDir, 'schema'),\n )\n\n fs.copyFileSync(schemaFilePath, path.join(dotSeedDir, 'schema.ts'))\n\n runCommands()\n .then(() => {\n if (!appFilesDirPath) {\n console.log('[Seed Protocol] Finished running init script')\n } else {\n return copyDotSeedFilesToAppFiles(appFilesDirPath)\n }\n })\n .then(() => {\n console.log('[Seed Protocol] Finished running init script')\n })\n }\n}\n\nconst calledFrom = pathToFileURL(process.argv[1]).href\n\nconsole.log('calledFrom:', calledFrom)\n\nif (\n calledFrom.endsWith('node_modules/.bin/seed') ||\n import.meta.url.endsWith('@seedprotocol/sdk/node/bin.js') ||\n import.meta.url.endsWith('scripts/bin.ts')\n) {\n // module was not imported but called directly\n init(a)\n}\n\nexport { init }\n"],"names":["execCallback"],"mappings":";;;;;;;;;;;;;;;;;AAwBa,SAAS,CAACA,IAAY;AAEnC,IAAI,CAAC;AAEL,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,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gBAAA,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC;;iBACtD;AACL,gBAAA,OAAO,0BAA0B,CAAC,eAAe,CAAC;;AAEtD,SAAC;aACA,IAAI,CAAC,MAAK;AACT,YAAA,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC;AAC7D,SAAC,CAAC;;AAER;AAEA,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;AAEtD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,UAAU,CAAC;AAEtC,IACE,UAAU,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IAC7C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,+BAA+B,CAAC;IACzD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAC1C;;IAEA,IAAI,CAAC,CAAC,CAAC;AACT;;;;"}
1
+ {"version":3,"file":"bin.js","sources":["../../scripts/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport path from 'path'\nimport fs from 'fs'\nimport { execSync, } from 'child_process'\nimport { pathToFileURL } from 'url'\nimport process from 'node:process'\nimport '../src/node/helpers/EasClient'\nimport '../src/node/helpers/QueryClient'\nimport '../src/node/helpers/FileManager'\nimport '../src/node/helpers/ArweaveClient'\nimport { INIT_SCRIPT_SUCCESS_MESSAGE, SCHEMA_TS } from '../src/helpers/constants'\nimport {\n appMetaDir,\n appSchemaDir,\n dotSeedDir,\n drizzleDbConfigPath,\n drizzleKitPath,\n rootWithNodeModules,\n sdkRootDir,\n} from '../src/node/constants'\nimport { createDrizzleSchemaFilesFromConfig } from '../src/node/codegen'\nimport { rimrafSync } from 'rimraf'\nimport { getTsImport } from '@/node/helpers'\nimport { ModelClassType } from '@/types/model'\n\nlet a\n\na = process.argv.splice(2)\n\n/**\n * Copy a directory and all its contents recursively\n * @param {string} sourceDir - Path to the source directory\n * @param {string} targetDir - Path to the target directory\n */\nfunction copyDirectoryRecursively(sourceDir: string, targetDir: string) {\n // Create the target directory if it doesn't exist\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n // Read all entries in the source directory\n const entries = fs.readdirSync(sourceDir);\n\n // Process each entry\n for (const entry of entries) {\n const sourcePath = path.join(sourceDir, entry);\n const targetPath = path.join(targetDir, entry);\n \n // Check if the entry is a file or directory\n const stats = fs.statSync(sourcePath);\n \n if (stats.isFile()) {\n // Copy the file directly\n fs.copyFileSync(sourcePath, targetPath);\n console.log(`Copied file: ${sourcePath} → ${targetPath}`);\n } \n else if (stats.isDirectory()) {\n // Recursively copy the subdirectory\n copyDirectoryRecursively(sourcePath, targetPath);\n }\n }\n}\n\nconst init = (args: string[]) => {\n console.log('args:', args)\n\n if (args && args.length && args[0] === 'init') {\n console.log('[Seed Protocol] Running init script')\n\n let appFilesDirPath = args[2] || undefined\n\n console.log('appFilesDirPath', appFilesDirPath)\n\n console.log('rootWithNodeModules', rootWithNodeModules)\n\n console.log('process.cwd()', process.cwd())\n \n let schemaFileDir = args[1]\n\n console.log('args[1]', args[1])\n\n if (!schemaFileDir && process.env.IS_PORTAL && !process.cwd().includes('seed-protocol-sdk')) {\n schemaFileDir = process.cwd()\n }\n if (process.env.NODE_ENV === 'test') {\n schemaFileDir = path.join(process.cwd(), '__tests__', '__mocks__', 'node', 'project')\n }\n console.log('schemaFileDir2', schemaFileDir)\n const schemaFilePath = path.join(schemaFileDir || process.cwd(), SCHEMA_TS)\n\n // Remove dotSeedDir to start fresh each time\n if (fs.existsSync(dotSeedDir)) {\n fs.rmSync(dotSeedDir, { recursive: true, force: true })\n }\n\n console.log('[Seed Protocol] dotSeedDir', dotSeedDir)\n console.log('[Seed Protocol] sdkRootDir', sdkRootDir)\n\n const drizzleKitCommand = `npx --yes tsx ${drizzleKitPath}`\n\n const ensureIndexExports = (dirPath: string): void => {\n try {\n // Get all file names in the directory\n const files = fs.readdirSync(dirPath)\n\n // Filter for .ts files excluding index.ts\n const tsFiles = files.filter(\n (file) => file.endsWith('.ts') && file !== 'index.ts',\n )\n\n // Check if index.ts exists\n const indexFilePath = path.join(dirPath, 'index.ts')\n try {\n fs.accessSync(indexFilePath)\n } catch (error) {\n console.error(`index.ts not found in the directory: ${dirPath}`)\n return\n }\n\n // Read the content of index.ts\n const indexContent = fs.readFileSync(indexFilePath, 'utf8')\n\n // Create export statements for each .ts file\n const exportStatements = tsFiles.map(\n (file) => `export * from './${path.basename(file, '.ts')}';`,\n )\n\n // Check if each export statement is already present in index.ts\n const missingExports = exportStatements.filter(\n (statement) => !indexContent.includes(statement),\n )\n\n if (missingExports.length > 0) {\n // Append missing export statements to index.ts\n const newContent =\n indexContent + '\\n' + missingExports.join('\\n') + '\\n'\n fs.writeFileSync(indexFilePath, newContent, 'utf8')\n console.log(\n `Updated index.ts with missing exports:\\n${missingExports.join('\\n')}`,\n )\n } else {\n console.log('All exports are already present in index.ts')\n }\n } catch (error) {\n console.error(`Error processing directory: ${dirPath}`, error)\n }\n }\n\n // const copyFiles = (srcDir: string, destDir: string) => {\n // if (!fs.existsSync(destDir)) {\n // fs.mkdirSync(destDir, { recursive: true })\n // }\n // const srcFiles = fs.readdirSync(srcDir)\n // srcFiles.forEach((file) => {\n // if (f)\n // console.log(`Copying ${srcDir}/${file} to ${destDir}/${file}`)\n // fs.copyFileSync(path.join(srcDir, file), path.join(destDir, file))\n // })\n // }\n\n const copyDotSeedFilesToAppFiles = async (_appFilesDirPath: string) => {\n console.log('[Seed Protocol] Copying dot seed files to app files')\n const { endpoints } = await getTsImport<{\n models: Record<string, ModelClassType>, endpoints: Record<string, string>\n }>(schemaFilePath)\n\n const outputDirPath = endpoints.localOutputDir || _appFilesDirPath\n\n const exists = await fs.promises.access(outputDirPath).then(() => true).catch(() => false)\n if (exists) {\n await fs.promises.rm(outputDirPath, { recursive: true, force: true })\n }\n console.log(`[Seed Protocol] Removed old app files`)\n console.log(`[Seed Protocol] making dir at ${outputDirPath}`)\n fs.mkdirSync(outputDirPath, { recursive: true })\n console.log('[Seed Protocol] copying app files')\n fs.cpSync(dotSeedDir, outputDirPath, { recursive: true })\n console.log(\n '[Seed Protocol] removing sqlite3 files and index.ts files',\n )\n rimrafSync(`${outputDirPath}/**/*.sqlite3`, {\n glob: true,\n })\n rimrafSync(`${outputDirPath}/**/index.ts`, {\n glob: true,\n })\n }\n\n const updateSchema = async (pathToConfig: string, pathToMeta: string) => {\n if (!fs.existsSync(pathToMeta)) {\n console.log(`${drizzleKitCommand} generate --config=${pathToConfig}`)\n execSync(\n `${drizzleKitCommand} generate --config=${pathToConfig}`,\n )\n }\n execSync(`${drizzleKitCommand} migrate --config=${pathToConfig}`)\n }\n\n const runCommands = async () => {\n await createDrizzleSchemaFilesFromConfig(schemaFilePath, undefined)\n ensureIndexExports(appSchemaDir)\n await updateSchema(drizzleDbConfigPath, appMetaDir)\n }\n\n copyDirectoryRecursively(\n path.join(sdkRootDir, 'seedSchema'),\n path.join(dotSeedDir, 'schema'),\n )\n\n copyDirectoryRecursively(\n path.join(sdkRootDir, 'node', 'codegen',),\n path.join(dotSeedDir, 'codegen',),\n )\n\n console.log('copying', schemaFilePath, path.join(dotSeedDir, 'schema.ts'))\n\n fs.copyFileSync(schemaFilePath, path.join(dotSeedDir, 'schema.ts'))\n\n runCommands()\n .then(() => {\n if (!appFilesDirPath) {\n console.log('[Seed Protocol] Finished running init script')\n } else {\n return copyDotSeedFilesToAppFiles(appFilesDirPath)\n }\n })\n .then(() => {\n console.log(INIT_SCRIPT_SUCCESS_MESSAGE)\n })\n }\n}\n\nconst calledFrom = pathToFileURL(process.argv[1]).href\n\nconsole.log('calledFrom', calledFrom)\n\nif (\n calledFrom.endsWith('node_modules/.bin/seed') ||\n import.meta.url.endsWith('@seedprotocol/sdk/node/bin.js') ||\n import.meta.url.endsWith('scripts/bin.ts')\n) {\n // module was not imported but called directly\n init(a)\n}\n\nexport { init }\n"],"names":[],"mappings":";;;;;;;;;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AC;AAEnE,QAAA,WAAW;aACR,IAAI,CAAC,MAAK;YACT,IAAI,CAAC,eAAe,EAAE;AACpB,gBAAA,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC;;iBACtD;AACL,gBAAA,OAAO,0BAA0B,CAAC,eAAe,CAAC;;AAEtD,SAAC;aACA,IAAI,CAAC,MAAK;AACT,YAAA,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;AAC1C,SAAC,CAAC;;AAER;AAEA,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;AAEtD,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC;AAErC,IACE,UAAU,CAAC,QAAQ,CAAC,wBAAwB,CAAC;IAC7C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,+BAA+B,CAAC;IACzD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAC1C;;IAEA,IAAI,CAAC,CAAC,CAAC;AACT;;;;"}
@@ -12,6 +12,7 @@ if (process.env.IS_SEED_DEV) {
12
12
  process.cwd(),
13
13
  '__tests__',
14
14
  '__mocks__',
15
+ 'browser',
15
16
  'project',
16
17
  '.seed',
17
18
  )
@@ -12,6 +12,7 @@ if (process.env.IS_SEED_DEV) {
12
12
  process.cwd(),
13
13
  '__tests__',
14
14
  '__mocks__',
15
+ 'browser',
15
16
  'project',
16
17
  '.seed',
17
18
  )
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { enableMapSet } from 'immer';
2
2
  import 'reflect-metadata';
3
3
  export { Model } from './src/schema/model/index.js';
4
- export { ImageSrc, Json, List, Property, Relation, Text } from './src/schema/property/index.js';
4
+ export { Boolean, Date, Image, Json, List, Number, Property, Relation, Text } from './src/schema/property/index.js';
5
5
  export { Item } from './src/Item/index.js';
6
6
  export { useCreateItem, useItem, useItems, usePublishItem } from './src/browser/react/item.js';
7
7
  export { useItemProperties, useItemProperty } from './src/browser/react/property.js';
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableMapSet } from 'immer'\n\nexport {\n Model,\n Property,\n ImageSrc,\n List,\n Text,\n Json,\n Relation,\n} from './schema'\n\n// export { type IItem, type IItemProperty } from './interfaces'\nexport { Item } from './Item'\n// export { ItemProperty } from './ItemProperty'\n// export { Db } from './db/Db'\n\nexport {\n useItems,\n useItem,\n useItemProperties,\n useCreateItem,\n useItemProperty,\n useDeleteItem,\n useGlobalServiceStatus,\n usePublishItem,\n usePersistedSnapshots,\n useServices,\n useService,\n} from './browser/react'\n\n// export { getCorrectId, BaseArweaveClient, BaseEasClient, BaseFileManager, BaseQueryClient, } from './helpers'\nexport { getCorrectId, } from './helpers'\n\n// export { getGlobalService } from './services/global/globalMachine'\n\nexport {\n eventEmitter,\n} from './eventBus'\n\nenableMapSet()\n\nexport { withSeed } from './node/webpack'\n\n\nexport { client } from './client'\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwCA,YAAY,EAAE"}
1
+ {"version":3,"file":"main.js","sources":["../../src/index.ts"],"sourcesContent":["import { enableMapSet } from 'immer'\n\nexport {\n Model,\n Property,\n Image,\n List,\n Text,\n Json,\n Relation,\n Boolean,\n Number,\n Date,\n} from './schema'\n\n// export { type IItem, type IItemProperty } from './interfaces'\nexport { Item } from './Item'\n// export { ItemProperty } from './ItemProperty'\n// export { Db } from './db/Db'\n\nexport {\n useItems,\n useItem,\n useItemProperties,\n useCreateItem,\n useItemProperty,\n useDeleteItem,\n useGlobalServiceStatus,\n usePublishItem,\n usePersistedSnapshots,\n useServices,\n useService,\n} from './browser/react'\n\n// export { getCorrectId, BaseArweaveClient, BaseEasClient, BaseFileManager, BaseQueryClient, } from './helpers'\nexport { getCorrectId, } from './helpers'\n\n// export { getGlobalService } from './services/global/globalMachine'\n\nexport {\n eventEmitter,\n} from './eventBus'\n\nenableMapSet()\n\nexport { withSeed } from './node/webpack'\n\n\nexport { client } from './client'\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2CA,YAAY,EAAE"}
@@ -0,0 +1,14 @@
1
+ @Model
2
+ class {{ modelName }} {
3
+ {% for property in properties -%}
4
+ {% if property.type == 'Relation' -%}
5
+ @Relation('{{ property.targetModel }}') {{ property.name }}!: {{ property.type | seedTypeToJsType }}
6
+ {% elif property.type == 'List' -%}
7
+ @List('{{ property.targetModel or property.ref }}') {{ property.name }}!: {{ property.type | seedTypeToJsType }}
8
+ {% elif property.type == 'File' -%}
9
+ @File('{{ property.storageType }}', '{{ property.storagePath }}') {{ property.name }}!: {{ property.type | seedTypeToJsType }}
10
+ {% else -%}
11
+ @{{ property.type }}() {{ property.name }}!: {{ property.type | seedTypeToJsType }}
12
+ {% endif -%}
13
+ {% endfor -%}
14
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=addModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addModel.d.ts","sourceRoot":"","sources":["../../scripts/addModel.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../scripts/bin.ts"],"names":[],"mappings":";AAOA,OAAO,+BAA+B,CAAA;AACtC,OAAO,iCAAiC,CAAA;AACxC,OAAO,iCAAiC,CAAA;AACxC,OAAO,mCAAmC,CAAA;AAoB1C,QAAA,MAAM,IAAI,SAAU,MAAM,EAAE,SA2I3B,CAAA;AAeD,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../scripts/bin.ts"],"names":[],"mappings":";AAMA,OAAO,+BAA+B,CAAA;AACtC,OAAO,iCAAiC,CAAA;AACxC,OAAO,iCAAiC,CAAA;AACxC,OAAO,mCAAmC,CAAA;AAsD1C,QAAA,MAAM,IAAI,SAAU,MAAM,EAAE,SAuK3B,CAAA;AAeD,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"browser.app.db.config.d.ts","sourceRoot":"","sources":["../../../../src/db/configs/browser.app.db.config.ts"],"names":[],"mappings":";AAmBA,wBAOE"}
1
+ {"version":3,"file":"browser.app.db.config.d.ts","sourceRoot":"","sources":["../../../../src/db/configs/browser.app.db.config.ts"],"names":[],"mappings":";AAoBA,wBAOE"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.app.db.config.d.ts","sourceRoot":"","sources":["../../../../src/db/configs/node.app.db.config.ts"],"names":[],"mappings":";AAmBA,wBAOE"}
1
+ {"version":3,"file":"node.app.db.config.d.ts","sourceRoot":"","sources":["../../../../src/db/configs/node.app.db.config.ts"],"names":[],"mappings":";AAoBA,wBAOE"}
@@ -38,4 +38,5 @@ export declare enum ImageSize {
38
38
  EXTRA_LARGE = 1920
39
39
  }
40
40
  export declare const CLIENT_NOT_INITIALIZED = "ClientManager is not initialized. Please call init() first.";
41
+ export declare const INIT_SCRIPT_SUCCESS_MESSAGE = "[Seed Protocol] Finished running init script";
41
42
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/helpers/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAIvB,MAAM,uCAAuC,CAAA;AAG9C,eAAO,MAAM,UAAU,eAAe,CAAA;AACtC,eAAO,MAAM,SAAS,cAAc,CAAA;AAEpC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;CAyB/B,CAAA;AAED,eAAO,MAAM,qBAAqB,UAqBjC,CAAA;AAED,eAAO,MAAM,mCAAmC,uEACsB,CAAA;AAEtE,eAAO,MAAM,sBAAsB,EAAE,sBAOpC,CAAA;AAED,oBAAY,SAAS;IACnB,WAAW,MAAM;IACjB,KAAK,MAAM;IACX,MAAM,OAAO;IACb,KAAK,OAAO;IACZ,WAAW,OAAO;CACnB;AAED,eAAO,MAAM,sBAAsB,gEAAgE,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/helpers/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAIvB,MAAM,uCAAuC,CAAA;AAG9C,eAAO,MAAM,UAAU,eAAe,CAAA;AACtC,eAAO,MAAM,SAAS,cAAc,CAAA;AAEpC,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;CAyB/B,CAAA;AAED,eAAO,MAAM,qBAAqB,UAqBjC,CAAA;AAED,eAAO,MAAM,mCAAmC,uEACsB,CAAA;AAEtE,eAAO,MAAM,sBAAsB,EAAE,sBAOpC,CAAA;AAED,oBAAY,SAAS;IACnB,WAAW,MAAM;IACjB,KAAK,MAAM;IACX,MAAM,OAAO;IACb,KAAK,OAAO;IACZ,WAAW,OAAO;CACnB;AAED,eAAO,MAAM,sBAAsB,gEAAgE,CAAA;AAEnG,eAAO,MAAM,2BAA2B,iDAAiD,CAAA"}
@@ -68,6 +68,7 @@ var ImageSize;
68
68
  ImageSize[ImageSize["EXTRA_LARGE"] = 1920] = "EXTRA_LARGE";
69
69
  })(ImageSize || (ImageSize = {}));
70
70
  const CLIENT_NOT_INITIALIZED = 'ClientManager is not initialized. Please call init() first.';
71
+ const INIT_SCRIPT_SUCCESS_MESSAGE = '[Seed Protocol] Finished running init script';
71
72
 
72
- export { CLIENT_NOT_INITIALIZED, INTERNAL_DATA_TYPES, ImageSize, SCHEMA_NJK, SCHEMA_TS, VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, defaultAttestationData, internalPropertyNames };
73
+ export { CLIENT_NOT_INITIALIZED, INIT_SCRIPT_SUCCESS_MESSAGE, INTERNAL_DATA_TYPES, ImageSize, SCHEMA_NJK, SCHEMA_TS, VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA, defaultAttestationData, internalPropertyNames };
73
74
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sources":["../../../../src/helpers/constants.ts"],"sourcesContent":["import {\n AttestationRequestData,\n ZERO_BYTES,\n ZERO_BYTES32,\n ZERO_ADDRESS,\n} from '@ethereum-attestation-service/eas-sdk'\n\n\nexport const SCHEMA_NJK = 'schema.njk'\nexport const SCHEMA_TS = 'schema.ts'\n\nexport const INTERNAL_DATA_TYPES = {\n Text: {\n eas: 'string',\n },\n Number: {\n eas: 'uint8',\n },\n ImageSrc: {\n eas: 'string',\n },\n Relation: {\n eas: 'bytes32',\n },\n List: {\n eas: 'bytes32[]',\n },\n FileSrc: {\n eas: 'string',\n },\n Json: {\n eas: 'string',\n },\n Blob: {\n eas: 'bytes32',\n },\n}\n\nexport const internalPropertyNames = [\n 'localId',\n 'uid',\n 'seedLocalId',\n 'seedUid',\n 'schemaUid',\n 'attestationCreatedAt',\n 'createdAt',\n 'updatedAt',\n 'versionsCount',\n 'lastVersionPublishedAt',\n 'latestVersionLocalId',\n 'versionLocalId',\n 'lastLocalUpdateAt',\n 'storageTransactionId',\n 'versionUid',\n 'refSeedType',\n 'refValueType',\n 'refResolvedValue',\n 'refResolvedDisplayValue',\n 'type',\n]\n\nexport const VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA =\n '0x13c0fd59d69dbce40501a41f8b37768d26dd2e2bb0cad64615334d84f7b9bdf6'\n\nexport const defaultAttestationData: AttestationRequestData = {\n recipient: ZERO_ADDRESS,\n revocable: true,\n value: BigInt(0),\n refUID: ZERO_BYTES32,\n expirationTime: BigInt(0),\n data: ZERO_BYTES,\n}\n\nexport enum ImageSize {\n EXTRA_SMALL = 480,\n SMALL = 760,\n MEDIUM = 1024,\n LARGE = 1440,\n EXTRA_LARGE = 1920,\n}\n\nexport const CLIENT_NOT_INITIALIZED = 'ClientManager is not initialized. Please call init() first.'\n"],"names":[],"mappings":";;AAQO,MAAM,UAAU,GAAG;AACnB,MAAM,SAAS,GAAG;AAEZ,MAAA,mBAAmB,GAAG;A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A,GAAA,CAAA,GAAA,OAAW;AACX,IAAA,SAAA,CAAA,SAAA,CAAA,QAAA,CAAA,GAAA,IAAA,CAAA,GAAA,QAAa;AACb,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,IAAA,CAAA,GAAA,OAAY;AACZ,IAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,IAAA,CAAA,GAAA,aAAkB;AACpB,CAAC,EANW,SAAS,KAAT,SAAS,GAMpB,EAAA,CAAA,CAAA;AAEM,MAAM,sBAAsB,GAAG;;;;"}
1
+ {"version":3,"file":"constants.js","sources":["../../../../src/helpers/constants.ts"],"sourcesContent":["import {\n AttestationRequestData,\n ZERO_BYTES,\n ZERO_BYTES32,\n ZERO_ADDRESS,\n} from '@ethereum-attestation-service/eas-sdk'\n\n\nexport const SCHEMA_NJK = 'schema.njk'\nexport const SCHEMA_TS = 'schema.ts'\n\nexport const INTERNAL_DATA_TYPES = {\n Text: {\n eas: 'string',\n },\n Number: {\n eas: 'uint8',\n },\n ImageSrc: {\n eas: 'string',\n },\n Relation: {\n eas: 'bytes32',\n },\n List: {\n eas: 'bytes32[]',\n },\n FileSrc: {\n eas: 'string',\n },\n Json: {\n eas: 'string',\n },\n Blob: {\n eas: 'bytes32',\n },\n}\n\nexport const internalPropertyNames = [\n 'localId',\n 'uid',\n 'seedLocalId',\n 'seedUid',\n 'schemaUid',\n 'attestationCreatedAt',\n 'createdAt',\n 'updatedAt',\n 'versionsCount',\n 'lastVersionPublishedAt',\n 'latestVersionLocalId',\n 'versionLocalId',\n 'lastLocalUpdateAt',\n 'storageTransactionId',\n 'versionUid',\n 'refSeedType',\n 'refValueType',\n 'refResolvedValue',\n 'refResolvedDisplayValue',\n 'type',\n]\n\nexport const VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA =\n '0x13c0fd59d69dbce40501a41f8b37768d26dd2e2bb0cad64615334d84f7b9bdf6'\n\nexport const defaultAttestationData: AttestationRequestData = {\n recipient: ZERO_ADDRESS,\n revocable: true,\n value: BigInt(0),\n refUID: ZERO_BYTES32,\n expirationTime: BigInt(0),\n data: ZERO_BYTES,\n}\n\nexport enum ImageSize {\n EXTRA_SMALL = 480,\n SMALL = 760,\n MEDIUM = 1024,\n LARGE = 1440,\n EXTRA_LARGE = 1920,\n}\n\nexport const CLIENT_NOT_INITIALIZED = 'ClientManager is not initialized. Please call init() first.'\n\nexport const INIT_SCRIPT_SUCCESS_MESSAGE = '[Seed Protocol] Finished running init script'\n"],"names":[],"mappings":";;AAQO,MAAM,UAAU,GAAG;AACnB,MAAM,SAAS,GAAG;AAEZ,MAAA,mBAAmB,GAAG;AACjC,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,MAAM,EAAE;AACN,QAAA,GAAG,EAAE,OAAO;AACb,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,QAAQ,EAAE;AACR,QAAA,GAAG,EAAE,SAAS;AACf,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,WAAW;AACjB,KAAA;AACD,IAAA,OAAO,EAAE;AACP,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,QAAQ;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,GAAG,EAAE,SAAS;AACf,KAAA;;AAGU,MAAA,qBAAqB,GAAG;IACnC,SAAS;IACT,KAAK;IACL,aAAa;IACb,SAAS;IACT,WAAW;IACX,sBAAsB;IACtB,WAAW;IACX,WAAW;IACX,eAAe;IACf,wBAAwB;IACxB,sBAAsB;IACtB,gBAAgB;IAChB,mBAAmB;IACnB,sBAAsB;IACtB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,yBAAyB;IACzB,MAAM;;AAGD,MAAM,mCAAmC,GAC9C;AAEW,MAAA,sBAAsB,GAA2B;AAC5D,IAAA,SAAS,EAAE,YAAY;AACvB,IAAA,SAAS,EAAE,IAAI;AACf,IAAA,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAChB,IAAA,MAAM,EAAE,YAAY;AACpB,IAAA,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;AACzB,IAAA,IAAI,EAAE,UAAU;;IAGN;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,GAAA,CAAA,GAAA,aAAiB;AACjB,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,GAAA,CAAA,GAAA,OAAW;AACX,IAAA,SAAA,CAAA,SAAA,CAAA,QAAA,CAAA,GAAA,IAAA,CAAA,GAAA,QAAa;AACb,IAAA,SAAA,CAAA,SAAA,CAAA,OAAA,CAAA,GAAA,IAAA,CAAA,GAAA,OAAY;AACZ,IAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,IAAA,CAAA,GAAA,aAAkB;AACpB,CAAC,EANW,SAAS,KAAT,SAAS,GAMpB,EAAA,CAAA,CAAA;AAEM,MAAM,sBAAsB,GAAG;AAE/B,MAAM,2BAA2B,GAAG;;;;"}
@@ -1,4 +1,4 @@
1
- export { Model, Property, ImageSrc, List, Text, Json, Relation, } from './schema';
1
+ export { Model, Property, Image, List, Text, Json, Relation, Boolean, Number, Date, } from './schema';
2
2
  export { Item } from './Item';
3
3
  export { useItems, useItem, useItemProperties, useCreateItem, useItemProperty, useDeleteItem, useGlobalServiceStatus, usePublishItem, usePersistedSnapshots, useServices, useService, } from './browser/react';
4
4
  export { getCorrectId, } from './helpers';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,GACT,MAAM,UAAU,CAAA;AAGjB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAI7B,OAAO,EACL,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,UAAU,GACX,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,YAAY,GAAG,MAAM,WAAW,CAAA;AAIzC,OAAO,EACL,YAAY,GACb,MAAM,YAAY,CAAA;AAInB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,GACL,MAAM,UAAU,CAAA;AAGjB,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAI7B,OAAO,EACL,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,UAAU,GACX,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,YAAY,GAAG,MAAM,WAAW,CAAA;AAIzC,OAAO,EACL,YAAY,GACb,MAAM,YAAY,CAAA;AAInB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAGzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA"}
@@ -1,2 +1,5 @@
1
- export declare const createDrizzleSchemaFilesFromConfig: () => Promise<void>;
1
+ import { ModelClassType } from '@/types';
2
+ export declare const generateDrizzleSchemaCode: (modelName: string, modelClass: ModelClassType) => string;
3
+ export declare const createDrizzleSchemaFilesFromConfig: (configFilePath: string | undefined, outputDirPath: string | undefined) => Promise<void>;
4
+ export declare const generateModelCode: (values: Record<string, any>) => string;
2
5
  //# sourceMappingURL=drizzle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../../src/node/codegen/drizzle.ts"],"names":[],"mappings":"AA4DA,eAAO,MAAM,kCAAkC,qBAoB9C,CAAA"}
1
+ {"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../../src/node/codegen/drizzle.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAmCxC,eAAO,MAAM,yBAAyB,cACzB,MAAM,cACL,cAAc,KACzB,MAcF,CAAA;AAED,eAAO,MAAM,kCAAkC,mBAC7B,MAAM,GAAG,SAAS,iBACnB,MAAM,GAAG,SAAS,kBAoBlC,CAAA;AA2BD,eAAO,MAAM,iBAAiB,WAAY,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAM/D,CAAC"}
@@ -5,7 +5,6 @@ import * as nunjucks from 'nunjucks';
5
5
  import { SCHEMA_NJK } from '../../helpers/constants.js';
6
6
  import { templatePath, dotSeedDir, appGeneratedSchemaDir } from '../constants.js';
7
7
  import { getTsImport } from '../helpers/index.js';
8
- import { BaseFileManager } from '../../helpers/FileManager/BaseFileManager.js';
9
8
  import fs from 'fs';
10
9
 
11
10
  const TemplateLoader = {
@@ -40,19 +39,48 @@ const generateDrizzleSchemaCode = (modelName, modelClass) => {
40
39
  });
41
40
  return schemaCode;
42
41
  };
43
- const createDrizzleSchemaFilesFromConfig = async () => {
44
- const schemaFilePath = path.join(dotSeedDir, 'schema.ts'); // Developer created file with model definitions
45
- const { models } = await getTsImport(schemaFilePath);
46
- const fs = await BaseFileManager.getFs();
42
+ const createDrizzleSchemaFilesFromConfig = async (configFilePath, outputDirPath) => {
43
+ const schemaFilePath = configFilePath || path.join(dotSeedDir, 'schema.ts'); // Developer created file with model definitions
44
+ const { models, } = await getTsImport(schemaFilePath);
45
+ const writeToDir = appGeneratedSchemaDir;
47
46
  for (const [modelName, modelClass] of Object.entries(models)) {
48
47
  const code = generateDrizzleSchemaCode(modelName, modelClass);
49
- if (!fs.existsSync(appGeneratedSchemaDir)) {
50
- fs.mkdirSync(appGeneratedSchemaDir);
48
+ if (!fs.existsSync(writeToDir)) {
49
+ fs.mkdirSync(writeToDir);
51
50
  }
52
- const filePath = path.join(appGeneratedSchemaDir, `${modelName}Schema.ts`);
51
+ const filePath = path.join(writeToDir, `${modelName}Schema.ts`);
53
52
  await fs.promises.writeFile(filePath, code).catch((e) => console.error(e));
54
53
  }
55
54
  };
55
+ // Helper to determine TypeScript type based on property type
56
+ const seedTypeToJsType = (propertyType) => {
57
+ switch (propertyType) {
58
+ case 'Text':
59
+ return 'string';
60
+ case 'Number':
61
+ return 'number';
62
+ case 'Boolean':
63
+ return 'boolean';
64
+ case 'Date':
65
+ return 'string';
66
+ case 'List':
67
+ return 'string[]';
68
+ case 'Relation':
69
+ return 'string';
70
+ case 'Image':
71
+ return 'string';
72
+ case 'File':
73
+ return 'string';
74
+ default:
75
+ return 'any';
76
+ }
77
+ };
78
+ const generateModelCode = (values) => {
79
+ const { modelName, properties } = values;
80
+ const njkEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatePath));
81
+ njkEnv.addFilter('seedTypeToJsType', seedTypeToJsType);
82
+ return njkEnv.render('model.njk', { modelName, properties });
83
+ };
56
84
 
57
- export { createDrizzleSchemaFilesFromConfig };
85
+ export { createDrizzleSchemaFilesFromConfig, generateDrizzleSchemaCode, generateModelCode };
58
86
  //# sourceMappingURL=drizzle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"drizzle.js","sources":["../../../../../src/node/codegen/drizzle.ts"],"sourcesContent":["import path from 'path'\nimport pluralize from 'pluralize'\nimport { camelCase, snakeCase } from 'lodash-es'\nimport * as nunjucks from 'nunjucks'\nimport { ILoader } from 'nunjucks'\nimport { ModelClassType } from '@/types'\nimport { SCHEMA_NJK } from '@/helpers/constants'\nimport {\n appGeneratedSchemaDir,\n dotSeedDir,\n templatePath,\n} from '@/node/constants'\nimport { getTsImport } from '@/node/helpers'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport fs from 'fs'\n\nconst TemplateLoader: ILoader = {\n getSource: (name: string) => {\n let templateFilePath\n if (name.includes(templatePath)) {\n templateFilePath = name\n } else {\n templateFilePath = path.join(templatePath, path.basename(name))\n }\n const src = fs.readFileSync(templateFilePath, 'utf-8')\n\n return {\n path: name,\n src,\n noCache: false,\n }\n },\n}\n\n// Configure Nunjucks\nconst env = new nunjucks.Environment(TemplateLoader)\n\nenv.addFilter('camelCase', camelCase)\nenv.addFilter('snakeCase', snakeCase)\nenv.addFilter('pluralize', pluralize)\n\nconst generateDrizzleSchemaCode = (\n modelName: string,\n modelClass: ModelClassType,\n): string => {\n const listProperties = Object.entries(modelClass.schema).filter(\n ([key, propertyDef]) => propertyDef?.dataType === 'List',\n )\n\n const filePath = path.join(templatePath, SCHEMA_NJK)\n\n const schemaCode = env.render(filePath, {\n modelName,\n modelClass,\n listProperties,\n })\n\n return schemaCode\n}\n\nexport const createDrizzleSchemaFilesFromConfig = async () => {\n const schemaFilePath = path.join(dotSeedDir, 'schema.ts') // Developer created file with model definitions\n\n const { models } = await getTsImport<{\n models: Record<string, ModelClassType>\n }>(schemaFilePath)\n\n const fs = await BaseFileManager.getFs()\n\n for (const [modelName, modelClass] of Object.entries(models)) {\n const code = generateDrizzleSchemaCode(modelName, modelClass)\n\n if (!fs.existsSync(appGeneratedSchemaDir)) {\n fs.mkdirSync(appGeneratedSchemaDir)\n }\n\n const filePath = path.join(appGeneratedSchemaDir, `${modelName}Schema.ts`)\n\n await fs.promises.writeFile(filePath, code).catch((e) => console.error(e))\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAgBA,MAAM,cAAc,GAAY;AAC9B,IAAA,SAAS,EAAE,CAAC,I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D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,WAAW,CAEjC,cAAc,CAAC;AAElB,IAAA,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,KAAK,EAAE;AAExC,IAAA,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC5D,MAAM,IAAI,GAAG,yBAAyB,CAAC,SAAS,EAAE,UAAU,CAAC;QAE7D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE;AACzC,YAAA,EAAE,CAAC,SAAS,CAAC,qBAAqB,CAAC;;AAGrC,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAG,EAAA,SAAS,CAAW,SAAA,CAAA,CAAC;QAE1E,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;;AAE9E;;;;"}
1
+ {"version":3,"file":"drizzle.js","sources":["../../../../../src/node/codegen/drizzle.ts"],"sourcesContent":["import path from 'path'\nimport pluralize from 'pluralize'\nimport { camelCase, snakeCase } from 'lodash-es'\nimport * as nunjucks from 'nunjucks'\nimport { ILoader } from 'nunjucks'\nimport { ModelClassType } from '@/types'\nimport { SCHEMA_NJK } from '@/helpers/constants'\nimport {\n appGeneratedSchemaDir,\n dotSeedDir,\n templatePath,\n} from '@/node/constants'\nimport { getTsImport } from '@/node/helpers'\nimport fs from 'fs'\n\nconst TemplateLoader: ILoader = {\n getSource: (name: string) => {\n let templateFilePath\n if (name.includes(templatePath)) {\n templateFilePath = name\n } else {\n templateFilePath = path.join(templatePath, path.basename(name))\n }\n const src = fs.readFileSync(templateFilePath, 'utf-8')\n\n return {\n path: name,\n src,\n noCache: false,\n }\n },\n}\n\n// Configure Nunjucks\nconst env = new nunjucks.Environment(TemplateLoader)\n\nenv.addFilter('camelCase', camelCase)\nenv.addFilter('snakeCase', snakeCase)\nenv.addFilter('pluralize', pluralize)\n\nexport const generateDrizzleSchemaCode = (\n modelName: string,\n modelClass: ModelClassType,\n): string => {\n const listProperties = Object.entries(modelClass.schema).filter(\n ([key, propertyDef]) => propertyDef?.dataType === 'List',\n )\n\n const filePath = path.join(templatePath, SCHEMA_NJK)\n\n const schemaCode = env.render(filePath, {\n modelName,\n modelClass,\n listProperties,\n })\n\n return schemaCode\n}\n\nexport const createDrizzleSchemaFilesFromConfig = async (\n configFilePath: string | undefined,\n outputDirPath: string | undefined,\n) => {\n const schemaFilePath = configFilePath || path.join(dotSeedDir, 'schema.ts') // Developer created file with model definitions\n const { models, } = await getTsImport<{\n models: Record<string, ModelClassType>\n }>(schemaFilePath)\n\n const writeToDir = outputDirPath || appGeneratedSchemaDir\n\n for (const [modelName, modelClass] of Object.entries(models)) {\n const code = generateDrizzleSchemaCode(modelName, modelClass)\n\n if (!fs.existsSync(writeToDir)) {\n fs.mkdirSync(writeToDir)\n }\n\n const filePath = path.join(writeToDir, `${modelName}Schema.ts`)\n\n await fs.promises.writeFile(filePath, code).catch((e) => console.error(e))\n }\n}\n\n // Helper to determine TypeScript type based on property type\n const seedTypeToJsType = (propertyType: string): string => {\n switch (propertyType) {\n case 'Text':\n return 'string';\n case 'Number':\n return 'number';\n case 'Boolean':\n return 'boolean';\n case 'Date':\n return 'string';\n case 'List':\n return 'string[]';\n case 'Relation':\n return 'string';\n case 'Image':\n return 'string';\n case 'File':\n return 'string';\n default:\n return 'any';\n }\n};\n\n\nexport const generateModelCode = (values: Record<string, any>): string => {\n const { modelName, properties } = values;\n\n const njkEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatePath))\n njkEnv.addFilter('seedTypeToJsType', seedTypeToJsType)\n return njkEnv.render('model.njk', { modelName, properties })\n};\n"],"names":[],"mappings":";;;;;;;;;AAeA,MAAM,cAAc,GAAY;AAC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GAAG,CAAC,MAA2B,KAAY;AACvE,IAAA,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM;AAExC,IAAA,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACpF,IAAA,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;AACtD,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAC9D;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/node/constants.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,kBAAkB,0BAA0B,CAAA;AAMzD,QAAA,IAAI,mBAAmB,QAAgD,CAAA;AAMvE,QAAA,IAAI,UAAU,QAMb,CAAA;AAMD,QAAA,IAAI,UAAU,QAA0C,CAAA;AAYxD,eAAO,MAAM,cAAc,QAK1B,CAAA;AAGD,eAAO,MAAM,YAAY,QAAkC,CAAA;AAC3D,eAAO,MAAM,QAAQ,QAA8B,CAAA;AACnD,eAAO,MAAM,UAAU,QAA8B,CAAA;AACrD,eAAO,MAAM,qBAAqB,QAAkC,CAAA;AAEpE,eAAO,MAAM,mBAAmB,QAK/B,CAAA;AAED,eAAO,MAAM,YAAY,QAKxB,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/node/constants.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAA;AAGtB,eAAO,MAAM,kBAAkB,0BAA0B,CAAA;AAYzD,QAAA,IAAI,mBAAmB,QAAqC,CAAA;AAY5D,QAAA,IAAI,UAAU,QAMb,CAAA;AAMD,QAAA,IAAI,UAAU,QAA0C,CAAA;AAaxD,eAAO,MAAM,cAAc,QAK1B,CAAA;AAGD,eAAO,MAAM,YAAY,QAAkC,CAAA;AAC3D,eAAO,MAAM,QAAQ,QAA8B,CAAA;AACnD,eAAO,MAAM,UAAU,QAA8B,CAAA;AACrD,eAAO,MAAM,qBAAqB,QAAkC,CAAA;AAEpE,eAAO,MAAM,mBAAmB,QAK/B,CAAA;AAED,eAAO,MAAM,YAAY,QAKxB,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA"}