@seedprotocol/sdk 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/dist/bin.js +182 -111
  2. package/dist/bin.js.map +1 -1
  3. package/dist/main.js +3 -2
  4. package/dist/main.js.map +1 -1
  5. package/dist/node/db/node.app.db.config.ts +7 -26
  6. package/dist/scripts/bin.d.ts +4 -4
  7. package/dist/scripts/bin.d.ts.map +1 -1
  8. package/dist/seedData.json +23 -0
  9. package/dist/src/Item/BaseItem.js +3 -3
  10. package/dist/src/Item/BaseItem.js.map +1 -1
  11. package/dist/src/ItemProperty/BaseItemProperty.d.ts +4 -1
  12. package/dist/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
  13. package/dist/src/ItemProperty/BaseItemProperty.js +65 -21
  14. package/dist/src/ItemProperty/BaseItemProperty.js.map +1 -1
  15. package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
  16. package/dist/src/ItemProperty/service/actors/hydrateFromDb.js +27 -17
  17. package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
  18. package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
  19. package/dist/src/ItemProperty/service/actors/initialize.js +25 -20
  20. package/dist/src/ItemProperty/service/actors/initialize.js.map +1 -1
  21. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +1 -1
  22. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js +1 -1
  23. package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js.map +1 -1
  24. package/dist/src/ItemProperty/service/propertyMachine.d.ts +11 -11
  25. package/dist/src/browser/Item/Item.js +0 -1
  26. package/dist/src/browser/Item/Item.js.map +1 -1
  27. package/dist/src/browser/ItemProperty/ItemProperty.d.ts.map +1 -1
  28. package/dist/src/browser/ItemProperty/ItemProperty.js +0 -1
  29. package/dist/src/browser/ItemProperty/ItemProperty.js.map +1 -1
  30. package/dist/src/browser/db/Db.d.ts.map +1 -1
  31. package/dist/src/browser/db/Db.js +0 -2
  32. package/dist/src/browser/db/Db.js.map +1 -1
  33. package/dist/src/browser/helpers/FileManager.d.ts +1 -1
  34. package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
  35. package/dist/src/browser/helpers/FileManager.js +4 -4
  36. package/dist/src/browser/helpers/FileManager.js.map +1 -1
  37. package/dist/src/browser/helpers/eas.d.ts +20 -0
  38. package/dist/src/browser/helpers/eas.d.ts.map +1 -0
  39. package/dist/src/browser/helpers/eas.js +89 -0
  40. package/dist/src/browser/helpers/eas.js.map +1 -0
  41. package/dist/src/browser/react/SeedImage.d.ts +11 -0
  42. package/dist/src/browser/react/SeedImage.d.ts.map +1 -0
  43. package/dist/src/browser/react/SeedImage.js +105 -0
  44. package/dist/src/browser/react/SeedImage.js.map +1 -0
  45. package/dist/src/browser/react/item.d.ts +8 -8
  46. package/dist/src/browser/react/item.d.ts.map +1 -1
  47. package/dist/src/browser/react/item.js +9 -53
  48. package/dist/src/browser/react/item.js.map +1 -1
  49. package/dist/src/browser/react/property.d.ts +3 -3
  50. package/dist/src/browser/react/property.d.ts.map +1 -1
  51. package/dist/src/browser/react/property.js.map +1 -1
  52. package/dist/src/browser/react/services.d.ts.map +1 -1
  53. package/dist/src/browser/react/services.js +5 -0
  54. package/dist/src/browser/react/services.js.map +1 -1
  55. package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
  56. package/dist/src/browser/workers/FileDownloader.js +1 -0
  57. package/dist/src/browser/workers/FileDownloader.js.map +1 -1
  58. package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
  59. package/dist/src/browser/workers/ImageResizer.js +1 -0
  60. package/dist/src/browser/workers/ImageResizer.js.map +1 -1
  61. package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
  62. package/dist/src/browser/workers/filesDownload.js +4 -0
  63. package/dist/src/browser/workers/filesDownload.js.map +1 -1
  64. package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
  65. package/dist/src/browser/workers/imageResize.js +4 -1
  66. package/dist/src/browser/workers/imageResize.js.map +1 -1
  67. package/dist/src/client/BaseClientManager.d.ts.map +1 -1
  68. package/dist/src/client/ClientManager.d.ts +173 -20
  69. package/dist/src/client/ClientManager.d.ts.map +1 -1
  70. package/dist/src/client/ClientManager.js +8 -0
  71. package/dist/src/client/ClientManager.js.map +1 -1
  72. package/dist/src/client/actors/initialize.d.ts +2 -2
  73. package/dist/src/client/actors/initialize.d.ts.map +1 -1
  74. package/dist/src/client/actors/initialize.js +9 -0
  75. package/dist/src/client/actors/initialize.js.map +1 -1
  76. package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
  77. package/dist/src/client/actors/saveAppState.js +3 -2
  78. package/dist/src/client/actors/saveAppState.js.map +1 -1
  79. package/dist/src/client/clientManagerMachine.d.ts +86 -10
  80. package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
  81. package/dist/src/client/clientManagerMachine.js +3 -1
  82. package/dist/src/client/clientManagerMachine.js.map +1 -1
  83. package/dist/src/db/read/getModelSchemas.d.ts +1 -2
  84. package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
  85. package/dist/src/db/read/getModelSchemas.js +1 -21
  86. package/dist/src/db/read/getModelSchemas.js.map +1 -1
  87. package/dist/src/db/read/getModels.d.ts +4 -1
  88. package/dist/src/db/read/getModels.d.ts.map +1 -1
  89. package/dist/src/db/read/getModels.js +16 -0
  90. package/dist/src/db/read/getModels.js.map +1 -0
  91. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  92. package/dist/src/db/read/getPublishPayload.js +52 -14
  93. package/dist/src/db/read/getPublishPayload.js.map +1 -1
  94. package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
  95. package/dist/src/db/read/getPublishUploads.js +34 -3
  96. package/dist/src/db/read/getPublishUploads.js.map +1 -1
  97. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  98. package/dist/src/events/item/syncDbWithEas.js +9 -28
  99. package/dist/src/events/item/syncDbWithEas.js.map +1 -1
  100. package/dist/src/helpers/constants.d.ts +2 -2
  101. package/dist/src/helpers/constants.d.ts.map +1 -1
  102. package/dist/src/helpers/constants.js +14 -6
  103. package/dist/src/helpers/constants.js.map +1 -1
  104. package/dist/src/helpers/getSegmentedItemProperties.d.ts +1 -0
  105. package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
  106. package/dist/src/helpers/getSegmentedItemProperties.js +6 -2
  107. package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
  108. package/dist/src/helpers/index.d.ts +2 -1
  109. package/dist/src/helpers/index.d.ts.map +1 -1
  110. package/dist/src/helpers/index.js +3 -10
  111. package/dist/src/helpers/index.js.map +1 -1
  112. package/dist/src/helpers/scripts.d.ts +2 -0
  113. package/dist/src/helpers/scripts.d.ts.map +1 -0
  114. package/dist/src/helpers/scripts.js +14 -0
  115. package/dist/src/helpers/scripts.js.map +1 -0
  116. package/dist/src/index.d.ts +4 -2
  117. package/dist/src/index.d.ts.map +1 -1
  118. package/dist/src/interfaces/IItemProperty.d.ts +7 -0
  119. package/dist/src/interfaces/IItemProperty.d.ts.map +1 -1
  120. package/dist/src/node/PathResolver.d.ts +39 -0
  121. package/dist/src/node/PathResolver.d.ts.map +1 -0
  122. package/dist/src/node/PathResolver.js +150 -0
  123. package/dist/src/node/PathResolver.js.map +1 -0
  124. package/dist/src/node/codegen/drizzle.d.ts.map +1 -1
  125. package/dist/src/node/codegen/drizzle.js +25 -4
  126. package/dist/src/node/codegen/drizzle.js.map +1 -1
  127. package/dist/src/node/constants.d.ts +0 -11
  128. package/dist/src/node/constants.d.ts.map +1 -1
  129. package/dist/src/node/constants.js +1 -32
  130. package/dist/src/node/constants.js.map +1 -1
  131. package/dist/src/node/db/node.app.db.config.d.ts.map +1 -1
  132. package/dist/src/schema/image/model.d.ts +8 -0
  133. package/dist/src/schema/image/model.d.ts.map +1 -0
  134. package/dist/src/schema/image/model.js +29 -0
  135. package/dist/src/schema/image/model.js.map +1 -0
  136. package/dist/src/schema/model/index.d.ts +8 -8
  137. package/dist/src/schema/property/index.d.ts +33 -45
  138. package/dist/src/schema/property/index.d.ts.map +1 -1
  139. package/dist/src/schema/property/index.js +0 -1
  140. package/dist/src/schema/property/index.js.map +1 -1
  141. package/dist/src/seedSchema/ConfigSchema.js +18 -0
  142. package/dist/src/seedSchema/ConfigSchema.js.map +1 -0
  143. package/dist/src/services/db/actors/migrate.js +1 -1
  144. package/dist/src/services/db/actors/migrate.js.map +1 -1
  145. package/dist/src/services/global/globalMachine.d.ts +90 -90
  146. package/dist/src/stores/eas.d.ts +12 -5
  147. package/dist/src/stores/eas.d.ts.map +1 -1
  148. package/dist/src/stores/eas.js +13 -8
  149. package/dist/src/stores/eas.js.map +1 -1
  150. package/dist/src/stores/modelClass.d.ts.map +1 -1
  151. package/dist/src/stores/modelClass.js.map +1 -1
  152. package/package.json +2 -1
  153. package/dist/src/Item/index.d.ts +0 -5
  154. package/dist/src/Item/index.d.ts.map +0 -1
  155. package/dist/src/Item/index.js +0 -4
  156. package/dist/src/Item/index.js.map +0 -1
  157. package/dist/src/ItemProperty/index.d.ts +0 -5
  158. package/dist/src/ItemProperty/index.d.ts.map +0 -1
  159. package/dist/src/ItemProperty/index.js +0 -4
  160. package/dist/src/ItemProperty/index.js.map +0 -1
  161. package/dist/src/ItemProperty/service/actors/index.d.ts +0 -4
  162. package/dist/src/ItemProperty/service/actors/index.d.ts.map +0 -1
  163. package/dist/src/browser/Item/index.d.ts +0 -2
  164. package/dist/src/browser/Item/index.d.ts.map +0 -1
  165. package/dist/src/browser/Item/index.js +0 -2
  166. package/dist/src/browser/Item/index.js.map +0 -1
  167. package/dist/src/browser/ItemProperty/index.d.ts +0 -2
  168. package/dist/src/browser/ItemProperty/index.d.ts.map +0 -1
package/dist/bin.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import path from 'path';
3
3
  import fs from 'fs';
4
4
  import { execSync } from 'child_process';
5
- import { pathToFileURL } from 'url';
5
+ import { fileURLToPath, pathToFileURL } from 'url';
6
6
  import process from 'node:process';
7
7
  import './src/node/helpers/EasClient.js';
8
8
  import './src/node/helpers/QueryClient.js';
@@ -10,13 +10,26 @@ import 'fs/promises';
10
10
  import './src/helpers/FileManager/BaseFileManager.js';
11
11
  import './src/node/helpers/ArweaveClient.js';
12
12
  import { SCHEMA_TS, INIT_SCRIPT_SUCCESS_MESSAGE } from './src/helpers/constants.js';
13
- import { rootWithNodeModules, dotSeedDir, sdkRootDir, drizzleKitPath, appSchemaDir, appMetaDir, drizzleDbConfigPath } from './src/node/constants.js';
13
+ import { PathResolver } from './src/node/PathResolver.js';
14
14
  import { createDrizzleSchemaFilesFromConfig } from './src/node/codegen/drizzle.js';
15
15
  import { rimrafSync } from 'rimraf';
16
16
  import { getTsImport } from './src/node/helpers/index.js';
17
+ import { drizzle } from 'drizzle-orm/better-sqlite3';
18
+ import Database from 'better-sqlite3';
19
+ import { appState } from './src/seedSchema/AppStateSchema.js';
20
+ import { config } from './src/seedSchema/ConfigSchema.js';
21
+ import { metadata } from './src/seedSchema/MetadataSchema.js';
22
+ import { models } from './src/seedSchema/ModelSchema.js';
23
+ import { modelUids } from './src/seedSchema/ModelUidSchema.js';
24
+ import { seeds } from './src/seedSchema/SeedSchema.js';
25
+ import { versions } from './src/seedSchema/VersionSchema.js';
26
+ import { commandExists } from './src/helpers/scripts.js';
17
27
 
28
+ const __filename = fileURLToPath(import.meta.url);
29
+ const __dirname = path.dirname(__filename);
18
30
  let a;
19
31
  a = process.argv.splice(2);
32
+ const pathResolver = PathResolver.getInstance();
20
33
  /**
21
34
  * Copy a directory and all its contents recursively
22
35
  * @param {string} sourceDir - Path to the source directory
@@ -46,126 +59,184 @@ function copyDirectoryRecursively(sourceDir, targetDir) {
46
59
  }
47
60
  }
48
61
  }
49
- const init = (args) => {
50
- console.log('args:', args);
51
- if (args && args.length && args[0] === 'init') {
52
- console.log('[Seed Protocol] Running init script');
53
- let appFilesDirPath = args[2] || undefined;
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();
62
+ const seedDatabase = async (seedDataPath) => {
63
+ console.log('[Seed Protocol] Running seed script');
64
+ try {
65
+ // Read the seed data file
66
+ const seedData = JSON.parse(fs.readFileSync(seedDataPath, 'utf-8'));
67
+ // Connect to the database
68
+ const dotSeedDir = pathResolver.getDotSeedDir();
69
+ const dbPath = path.join(dotSeedDir, 'db', 'app_db.sqlite3');
70
+ const sqlite = new Database(dbPath);
71
+ const db = drizzle(sqlite);
72
+ // Seed each table based on the provided data
73
+ if (seedData.appState && seedData.appState.length > 0) {
74
+ await db.insert(appState).values(seedData.appState);
75
+ console.log('Seeded appState table');
61
76
  }
62
- if (process.env.NODE_ENV === 'test') {
63
- schemaFileDir = path.join(process.cwd(), '__tests__', '__mocks__', 'node', 'project');
77
+ if (seedData.config && seedData.config.length > 0) {
78
+ await db.insert(config).values(seedData.config);
79
+ console.log('Seeded config table');
64
80
  }
65
- console.log('schemaFileDir2', schemaFileDir);
66
- const schemaFilePath = path.join(schemaFileDir || process.cwd(), SCHEMA_TS);
67
- // Remove dotSeedDir to start fresh each time
68
- if (fs.existsSync(dotSeedDir)) {
69
- fs.rmSync(dotSeedDir, { recursive: true, force: true });
81
+ if (seedData.models && seedData.models.length > 0) {
82
+ await db.insert(models).values(seedData.models);
83
+ console.log('Seeded models table');
70
84
  }
71
- console.log('[Seed Protocol] dotSeedDir', dotSeedDir);
72
- console.log('[Seed Protocol] sdkRootDir', sdkRootDir);
73
- const drizzleKitCommand = `npx --yes tsx ${drizzleKitPath}`;
74
- const ensureIndexExports = (dirPath) => {
75
- try {
76
- // Get all file names in the directory
77
- const files = fs.readdirSync(dirPath);
78
- // Filter for .ts files excluding index.ts
79
- const tsFiles = files.filter((file) => file.endsWith('.ts') && file !== 'index.ts');
80
- // Check if index.ts exists
81
- const indexFilePath = path.join(dirPath, 'index.ts');
82
- try {
83
- fs.accessSync(indexFilePath);
85
+ if (seedData.modelUids && seedData.modelUids.length > 0) {
86
+ await db.insert(modelUids).values(seedData.modelUids);
87
+ console.log('Seeded modelUids table');
88
+ }
89
+ if (seedData.metadata && seedData.metadata.length > 0) {
90
+ await db.insert(metadata).values(seedData.metadata);
91
+ console.log('Seeded metadata table');
92
+ }
93
+ if (seedData.seeds && seedData.seeds.length > 0) {
94
+ await db.insert(seeds).values(seedData.seeds);
95
+ console.log('Seeded seeds table');
96
+ }
97
+ if (seedData.versions && seedData.versions.length > 0) {
98
+ await db.insert(versions).values(seedData.versions);
99
+ console.log('Seeded versions table');
100
+ }
101
+ console.log('[Seed Protocol] Successfully seeded database');
102
+ }
103
+ catch (error) {
104
+ console.error('[Seed Protocol] Error seeding database:', error);
105
+ process.exit(1);
106
+ }
107
+ };
108
+ const init = (args) => {
109
+ console.log('args:', args);
110
+ if (args && args.length) {
111
+ if (args[0] === 'init') {
112
+ console.log('[Seed Protocol] Running init script');
113
+ let appFilesDirPath = args[2] || undefined;
114
+ let schemaFileDir = args[1];
115
+ if (schemaFileDir && schemaFileDir.startsWith('.')) {
116
+ const relativePath = schemaFileDir.replace('./', '');
117
+ if (!process.cwd().includes(relativePath)) {
118
+ schemaFileDir = path.resolve(schemaFileDir);
84
119
  }
85
- catch (error) {
86
- console.error(`index.ts not found in the directory: ${dirPath}`);
87
- return;
120
+ if (process.cwd().includes(relativePath)) {
121
+ schemaFileDir = process.cwd();
88
122
  }
89
- // Read the content of index.ts
90
- const indexContent = fs.readFileSync(indexFilePath, 'utf8');
91
- // Create export statements for each .ts file
92
- const exportStatements = tsFiles.map((file) => `export * from './${path.basename(file, '.ts')}';`);
93
- // Check if each export statement is already present in index.ts
94
- const missingExports = exportStatements.filter((statement) => !indexContent.includes(statement));
95
- if (missingExports.length > 0) {
96
- // Append missing export statements to index.ts
97
- const newContent = indexContent + '\n' + missingExports.join('\n') + '\n';
98
- fs.writeFileSync(indexFilePath, newContent, 'utf8');
99
- console.log(`Updated index.ts with missing exports:\n${missingExports.join('\n')}`);
123
+ }
124
+ if (!schemaFileDir && !process.cwd().includes('seed-protocol-sdk')) {
125
+ schemaFileDir = process.cwd();
126
+ }
127
+ console.log('[Seed Protocol] schemaFileDir', schemaFileDir);
128
+ if (!schemaFileDir) {
129
+ const defaultSchemaFilePath = path.join(process.cwd(), 'schema.ts');
130
+ if (fs.existsSync(defaultSchemaFilePath)) {
131
+ schemaFileDir = process.cwd();
100
132
  }
101
133
  else {
102
- console.log('All exports are already present in index.ts');
134
+ console.error('No schema file path provided and no default schema file found.');
135
+ return;
103
136
  }
104
137
  }
105
- catch (error) {
106
- console.error(`Error processing directory: ${dirPath}`, error);
107
- }
108
- };
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
- // }
120
- const copyDotSeedFilesToAppFiles = async (_appFilesDirPath) => {
121
- console.log('[Seed Protocol] Copying dot seed files to app files');
122
- const { endpoints } = await getTsImport(schemaFilePath);
123
- const outputDirPath = endpoints.localOutputDir || _appFilesDirPath;
124
- const exists = await fs.promises.access(outputDirPath).then(() => true).catch(() => false);
125
- if (exists) {
126
- await fs.promises.rm(outputDirPath, { recursive: true, force: true });
138
+ const { dotSeedDir, appSchemaDir, appMetaDir, drizzleDbConfigPath, drizzleKitPath, sdkRootDir, } = pathResolver.getAppPaths(schemaFileDir);
139
+ const schemaFilePath = path.join(schemaFileDir, SCHEMA_TS);
140
+ // Remove dotSeedDir to start fresh each time
141
+ if (fs.existsSync(dotSeedDir)) {
142
+ fs.rmSync(dotSeedDir, { recursive: true, force: true });
127
143
  }
128
- console.log(`[Seed Protocol] Removed old app files`);
129
- console.log(`[Seed Protocol] making dir at ${outputDirPath}`);
130
- fs.mkdirSync(outputDirPath, { recursive: true });
131
- console.log('[Seed Protocol] copying app files');
132
- fs.cpSync(dotSeedDir, outputDirPath, { recursive: true });
133
- console.log('[Seed Protocol] removing sqlite3 files and index.ts files');
134
- rimrafSync(`${outputDirPath}/**/*.sqlite3`, {
135
- glob: true,
136
- });
137
- rimrafSync(`${outputDirPath}/**/index.ts`, {
138
- glob: true,
144
+ console.log('[Seed Protocol] dotSeedDir', dotSeedDir);
145
+ const drizzleKitCommand = `npx --yes tsx ${drizzleKitPath}`;
146
+ const ensureIndexExports = (dirPath) => {
147
+ try {
148
+ // Get all file names in the directory
149
+ const files = fs.readdirSync(dirPath);
150
+ // Filter for .ts files excluding index.ts
151
+ const tsFiles = files.filter((file) => file.endsWith('.ts') && file !== 'index.ts');
152
+ // Check if index.ts exists
153
+ const indexFilePath = path.join(dirPath, 'index.ts');
154
+ try {
155
+ fs.accessSync(indexFilePath);
156
+ }
157
+ catch (error) {
158
+ console.error(`index.ts not found in the directory: ${dirPath}`);
159
+ return;
160
+ }
161
+ // Read the content of index.ts
162
+ const indexContent = fs.readFileSync(indexFilePath, 'utf8');
163
+ // Create export statements for each .ts file
164
+ const exportStatements = tsFiles.map((file) => `export * from './${path.basename(file, '.ts')}';`);
165
+ // Check if each export statement is already present in index.ts
166
+ const missingExports = exportStatements.filter((statement) => !indexContent.includes(statement));
167
+ if (missingExports.length > 0) {
168
+ // Append missing export statements to index.ts
169
+ const newContent = indexContent + '\n' + missingExports.join('\n') + '\n';
170
+ fs.writeFileSync(indexFilePath, newContent, 'utf8');
171
+ console.log(`Updated index.ts with missing exports:\n${missingExports.join('\n')}`);
172
+ }
173
+ else {
174
+ console.log('All exports are already present in index.ts');
175
+ }
176
+ }
177
+ catch (error) {
178
+ console.error(`Error processing directory: ${dirPath}`, error);
179
+ }
180
+ };
181
+ const copyDotSeedFilesToAppFiles = async (_appFilesDirPath) => {
182
+ console.log('[Seed Protocol] Copying dot seed files to app files');
183
+ const { endpoints } = await getTsImport(schemaFilePath);
184
+ const outputDirPath = endpoints.localOutputDir || _appFilesDirPath;
185
+ const exists = await fs.promises.access(outputDirPath).then(() => true).catch(() => false);
186
+ if (exists) {
187
+ await fs.promises.rm(outputDirPath, { recursive: true, force: true });
188
+ }
189
+ console.log(`[Seed Protocol] making dir at ${outputDirPath}`);
190
+ fs.mkdirSync(outputDirPath, { recursive: true });
191
+ console.log('[Seed Protocol] copying app files');
192
+ fs.cpSync(dotSeedDir, outputDirPath, { recursive: true });
193
+ console.log('[Seed Protocol] removing sqlite3 files and index.ts files');
194
+ rimrafSync(`${outputDirPath}/**/*.sqlite3`, { glob: true });
195
+ rimrafSync(`${outputDirPath}/**/index.ts`, { glob: true });
196
+ };
197
+ const updateSchema = async (pathToConfig, pathToMeta) => {
198
+ if (!fs.existsSync(pathToMeta)) {
199
+ console.log(`${drizzleKitCommand} generate --config=${pathToConfig}`);
200
+ execSync(`${drizzleKitCommand} generate --config=${pathToConfig}`);
201
+ }
202
+ execSync(`${drizzleKitCommand} migrate --config=${pathToConfig}`);
203
+ };
204
+ const runCommands = async () => {
205
+ const tsxExists = commandExists('tsx');
206
+ if (!tsxExists) {
207
+ execSync(`npm install -g tsx`, { stdio: 'inherit' });
208
+ }
209
+ await createDrizzleSchemaFilesFromConfig(schemaFilePath, undefined);
210
+ ensureIndexExports(appSchemaDir);
211
+ await updateSchema(drizzleDbConfigPath, appMetaDir);
212
+ const seedDataFilePath = path.join(__dirname, 'seedData.json');
213
+ await seedDatabase(seedDataFilePath);
214
+ };
215
+ copyDirectoryRecursively(path.join(pathResolver.getSdkRootDir(), 'seedSchema'), path.join(dotSeedDir, 'schema'));
216
+ copyDirectoryRecursively(path.join(pathResolver.getSdkRootDir(), 'node', 'codegen'), path.join(dotSeedDir, 'codegen'));
217
+ console.log('copying', schemaFilePath, path.join(dotSeedDir, 'schema.ts'));
218
+ fs.copyFileSync(schemaFilePath, path.join(dotSeedDir, 'schema.ts'));
219
+ runCommands()
220
+ .then(() => {
221
+ if (!appFilesDirPath) {
222
+ console.log('[Seed Protocol] Finished running init script');
223
+ }
224
+ else {
225
+ return copyDotSeedFilesToAppFiles(appFilesDirPath);
226
+ }
227
+ })
228
+ .then(() => {
229
+ console.log(INIT_SCRIPT_SUCCESS_MESSAGE);
139
230
  });
140
- };
141
- const updateSchema = async (pathToConfig, pathToMeta) => {
142
- if (!fs.existsSync(pathToMeta)) {
143
- console.log(`${drizzleKitCommand} generate --config=${pathToConfig}`);
144
- execSync(`${drizzleKitCommand} generate --config=${pathToConfig}`);
145
- }
146
- execSync(`${drizzleKitCommand} migrate --config=${pathToConfig}`);
147
- };
148
- const runCommands = async () => {
149
- await createDrizzleSchemaFilesFromConfig(schemaFilePath);
150
- ensureIndexExports(appSchemaDir);
151
- await updateSchema(drizzleDbConfigPath, appMetaDir);
152
- };
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'));
156
- fs.copyFileSync(schemaFilePath, path.join(dotSeedDir, 'schema.ts'));
157
- runCommands()
158
- .then(() => {
159
- if (!appFilesDirPath) {
160
- console.log('[Seed Protocol] Finished running init script');
161
- }
162
- else {
163
- return copyDotSeedFilesToAppFiles(appFilesDirPath);
164
- }
165
- })
166
- .then(() => {
167
- console.log(INIT_SCRIPT_SUCCESS_MESSAGE);
168
- });
231
+ }
232
+ else if (args[0] === 'seed' && args[1]) {
233
+ seedDatabase(args[1]);
234
+ }
235
+ else {
236
+ console.log('Unknown command. Available commands:');
237
+ console.log('init [schemaPath] [appFilesPath] - Initialize the database');
238
+ console.log('seed [seedDataPath] - Seed the database with data from JSON file');
239
+ }
169
240
  }
170
241
  };
171
242
  const calledFrom = pathToFileURL(process.argv[1]).href;
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 { 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":";;;;;;;;;;;;;;;;;AAyBA,IAAI,CAAC;AAEL,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAE1B;;;;AAIG;AACH,SAAS,wBAAwB,CAAC,SAAiB,EAAE,SAAiB,EAAA;;IAEpE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;;IAI9C,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;;AAGzC,IAAA,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;QAC3B,MAAM,UAA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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;;;;"}
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 { fileURLToPath, pathToFileURL } from 'url'\nimport process from 'node:process'\nimport '@/node/helpers/EasClient'\nimport '@/node/helpers/QueryClient'\nimport '@/node/helpers/FileManager'\nimport '@/node/helpers/ArweaveClient'\nimport { INIT_SCRIPT_SUCCESS_MESSAGE, SCHEMA_TS } from '@/helpers/constants'\nimport { PathResolver } from '@/node/PathResolver'\nimport { createDrizzleSchemaFilesFromConfig } from '@/node/codegen'\nimport { rimrafSync } from 'rimraf'\nimport { getTsImport } from '@/node/helpers'\nimport { ModelClassType } from '@/types/model'\nimport { drizzle } from 'drizzle-orm/better-sqlite3'\nimport Database from 'better-sqlite3'\nimport { appState } from '@/seedSchema/AppStateSchema'\nimport { config } from '@/seedSchema/ConfigSchema'\nimport { metadata } from '@/seedSchema/MetadataSchema'\nimport { models } from '@/seedSchema/ModelSchema'\nimport { modelUids } from '@/seedSchema/ModelUidSchema'\nimport { seeds } from '@/seedSchema/SeedSchema'\nimport { versions } from '@/seedSchema/VersionSchema'\nimport { commandExists } from '@/helpers/scripts'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\nlet a\n\na = process.argv.splice(2)\nconst pathResolver = PathResolver.getInstance()\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 seedDatabase = async (seedDataPath: string) => {\n console.log('[Seed Protocol] Running seed script')\n\n try {\n // Read the seed data file\n const seedData = JSON.parse(fs.readFileSync(seedDataPath, 'utf-8'))\n \n // Connect to the database\n const dotSeedDir = pathResolver.getDotSeedDir()\n const dbPath = path.join(dotSeedDir, 'db', 'app_db.sqlite3')\n const sqlite = new Database(dbPath)\n const db = drizzle(sqlite)\n \n // Seed each table based on the provided data\n if (seedData.appState && seedData.appState.length > 0) {\n await db.insert(appState).values(seedData.appState)\n console.log('Seeded appState table')\n }\n \n if (seedData.config && seedData.config.length > 0) {\n await db.insert(config).values(seedData.config)\n console.log('Seeded config table')\n }\n \n if (seedData.models && seedData.models.length > 0) {\n await db.insert(models).values(seedData.models)\n console.log('Seeded models table')\n }\n \n if (seedData.modelUids && seedData.modelUids.length > 0) {\n await db.insert(modelUids).values(seedData.modelUids)\n console.log('Seeded modelUids table')\n }\n \n if (seedData.metadata && seedData.metadata.length > 0) {\n await db.insert(metadata).values(seedData.metadata)\n console.log('Seeded metadata table')\n }\n \n if (seedData.seeds && seedData.seeds.length > 0) {\n await db.insert(seeds).values(seedData.seeds)\n console.log('Seeded seeds table')\n }\n \n if (seedData.versions && seedData.versions.length > 0) {\n await db.insert(versions).values(seedData.versions)\n console.log('Seeded versions table')\n }\n \n console.log('[Seed Protocol] Successfully seeded database')\n } catch (error) {\n console.error('[Seed Protocol] Error seeding database:', error)\n process.exit(1)\n }\n}\n\nconst init = (args: string[],) => {\n console.log('args:', args)\n\n if (args && args.length) {\n if (args[0] === 'init') {\n console.log('[Seed Protocol] Running init script')\n\n let appFilesDirPath = args[2] || undefined\n let schemaFileDir = args[1]\n\n if (schemaFileDir && schemaFileDir.startsWith('.')) {\n const relativePath = schemaFileDir.replace('./', '')\n if (!process.cwd().includes(relativePath)) {\n schemaFileDir = path.resolve(schemaFileDir,)\n }\n if (process.cwd().includes(relativePath)) {\n schemaFileDir = process.cwd()\n }\n }\n\n if (!schemaFileDir && !process.cwd().includes('seed-protocol-sdk')) {\n schemaFileDir = process.cwd()\n }\n\n console.log('[Seed Protocol] schemaFileDir', schemaFileDir)\n\n if (!schemaFileDir) {\n const defaultSchemaFilePath = path.join(process.cwd(), 'schema.ts')\n if (fs.existsSync(defaultSchemaFilePath)) {\n schemaFileDir = process.cwd()\n } else {\n console.error('No schema file path provided and no default schema file found.')\n return\n }\n }\n\n const {\n dotSeedDir,\n appSchemaDir,\n appMetaDir,\n drizzleDbConfigPath,\n drizzleKitPath,\n sdkRootDir,\n } = pathResolver.getAppPaths(schemaFileDir)\n\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\n const tsconfigArg = `--tsconfig ${sdkRootDir}/tsconfig.json`\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 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>,\n 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 \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('[Seed Protocol] removing sqlite3 files and index.ts files')\n rimrafSync(`${outputDirPath}/**/*.sqlite3`, { glob: true })\n rimrafSync(`${outputDirPath}/**/index.ts`, { glob: true })\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 const tsxExists = commandExists('tsx')\n if (!tsxExists) {\n execSync(`npm install -g tsx`, {stdio: 'inherit'})\n }\n\n await createDrizzleSchemaFilesFromConfig(schemaFilePath, undefined)\n ensureIndexExports(appSchemaDir!)\n await updateSchema(drizzleDbConfigPath, appMetaDir!)\n const seedDataFilePath = path.join(__dirname, 'seedData.json')\n await seedDatabase(seedDataFilePath)\n }\n\n copyDirectoryRecursively(\n path.join(pathResolver.getSdkRootDir(), 'seedSchema'),\n path.join(dotSeedDir, 'schema'),\n )\n\n copyDirectoryRecursively(\n path.join(pathResolver.getSdkRootDir(), '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 } else if (args[0] === 'seed' && args[1]) {\n seedDatabase(args[1])\n } else {\n console.log('Unknown command. Available commands:')\n console.log('init [schemaPath] [appFilesPath] - Initialize the database')\n console.log('seed [seedDataPath] - Seed the database with data from JSON file')\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AACjD,MAAM,SAAS,GAAG,IA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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;;;;"}
package/dist/main.js CHANGED
@@ -1,9 +1,10 @@
1
+ export { default as SeedImage } from './src/browser/react/SeedImage.js';
1
2
  import { enableMapSet } from 'immer';
2
3
  import 'reflect-metadata';
3
4
  export { Model } from './src/schema/model/index.js';
4
5
  export { Boolean, Date, Image, Json, List, Number, Property, Relation, Text } from './src/schema/property/index.js';
5
- export { Item } from './src/Item/index.js';
6
- export { ItemProperty } from './src/ItemProperty/index.js';
6
+ export { BaseItem as Item } from './src/Item/BaseItem.js';
7
+ export { BaseItemProperty as ItemProperty } from './src/ItemProperty/BaseItemProperty.js';
7
8
  export { useCreateItem, useItem, useItems, usePublishItem } from './src/browser/react/item.js';
8
9
  export { useItemProperties, useItemProperty } from './src/browser/react/property.js';
9
10
  export { useGlobalServiceStatus, usePersistedSnapshots, useService, useServices } from './src/browser/react/services.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 Image,\n List,\n Text,\n Json,\n Relation,\n Boolean,\n Number,\n Date,\n} from './schema'\n\nexport { Item } from './Item'\nexport { ItemProperty } from './ItemProperty'\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 useModels,\n} from './browser/react'\n\nexport {FileManager as FileManagerBrowser} from './browser/helpers/FileManager'\nexport {Db as DbBrowser} from './browser/db/Db'\n\nexport {models, versions, seeds, metadata, } from './seedSchema'\n\nexport {getModels, getModel, getModelNames,} from './stores/modelClass'\n\nexport { getCorrectId, } from './helpers'\n\nexport {\n eventEmitter,\n} from './eventBus'\n\nenableMapSet()\n\nexport { withSeed } from './node/webpack'\n\nexport type { PublishUpload } from './db/read/getPublishUploads'\n\n\nexport { client } from './client'\n\nexport * from './types'\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,YAAY,EAAE"}
1
+ {"version":3,"file":"main.js","sources":["../../src/index.ts"],"sourcesContent":["import SeedImage from './browser/react/SeedImage'\nimport { 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\nexport { BaseItem as Item } from './Item/BaseItem'\nexport { BaseItemProperty as ItemProperty } from './ItemProperty/BaseItemProperty'\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 useModels,\n} from './browser/react'\n\n\nexport { SeedImage }\n\nexport {FileManager as FileManagerBrowser} from './browser/helpers/FileManager'\nexport {Db as DbBrowser} from './browser/db/Db'\n\nexport {models, versions, seeds, metadata, } from './seedSchema'\n\nexport {getModels, getModel, getModelNames,} from './stores/modelClass'\n\nexport { getCorrectId, } from './helpers'\n\nexport {\n eventEmitter,\n} from './eventBus'\n\nenableMapSet()\n\nexport { withSeed } from './node/webpack'\n\nexport type { PublishUpload } from './db/read/getPublishUploads'\n\n\nexport { client } from './client'\n\nexport * from './types'\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,YAAY,EAAE"}
@@ -1,38 +1,19 @@
1
1
  import { defineConfig } from 'drizzle-kit'
2
2
  import dotenv from 'dotenv'
3
- import process from 'node:process'
4
- import path from 'path'
5
3
  import { DrizzleConfig } from 'drizzle-orm'
4
+ import { PathResolver } from '../PathResolver'
6
5
 
7
6
  dotenv.config()
8
7
 
9
- let sdkRoot = './node_modules/@seedprotocol/sdk'
8
+ const pathResolver = PathResolver.getInstance()
10
9
 
11
- if (process.env.IS_SEED_DEV) {
12
- sdkRoot = './src'
13
- }
14
-
15
- let dotSeedDir = path.join(process.cwd(), '.seed')
16
-
17
- if (process.env.IS_SEED_DEV) {
18
- dotSeedDir = path.join(
19
- process.cwd(),
20
- '__tests__',
21
- '__mocks__',
22
- 'node',
23
- 'project',
24
- '.seed',
25
- )
26
- }
27
-
28
- let schemaDir = `${sdkRoot}/dist/seedSchema/*.ts`
29
-
30
- if (process.env.IS_SEED_DEV) {
31
- schemaDir = `${sdkRoot}/seedSchema/*.ts`
32
- }
10
+ const {
11
+ appSchemaDir,
12
+ dotSeedDir,
13
+ } = pathResolver.getAppPaths()
33
14
 
34
15
  export default defineConfig({
35
- schema: schemaDir,
16
+ schema: appSchemaDir,
36
17
  dialect: 'sqlite',
37
18
  out: `${dotSeedDir}/db`,
38
19
  dbCredentials: {
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import '../src/node/helpers/EasClient';
3
- import '../src/node/helpers/QueryClient';
4
- import '../src/node/helpers/FileManager';
5
- import '../src/node/helpers/ArweaveClient';
2
+ import '@/node/helpers/EasClient';
3
+ import '@/node/helpers/QueryClient';
4
+ import '@/node/helpers/FileManager';
5
+ import '@/node/helpers/ArweaveClient';
6
6
  declare const init: (args: string[]) => void;
7
7
  export { init };
8
8
  //# sourceMappingURL=bin.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../scripts/bin.ts"],"names":[],"mappings":";AAMA,OAAO,0BAA0B,CAAA;AACjC,OAAO,4BAA4B,CAAA;AACnC,OAAO,4BAA4B,CAAA;AACnC,OAAO,8BAA8B,CAAA;AAoHrC,QAAA,MAAM,IAAI,SAAU,MAAM,EAAE,SAyL3B,CAAA;AAeD,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,23 @@
1
+ {
2
+ "appState": [
3
+ ],
4
+ "config": [
5
+ ],
6
+ "models": [
7
+ {
8
+ "name": "Image"
9
+ }
10
+ ],
11
+ "modelUids": [
12
+ {
13
+ "uid": "0x5442a1004fe4152a06ed806367a989942f7051bad21bbed5b98d855509f79aed",
14
+ "modelId": 1
15
+ }
16
+ ],
17
+ "metadata": [
18
+ ],
19
+ "seeds": [
20
+ ],
21
+ "versions": [
22
+ ]
23
+ }
@@ -1,5 +1,5 @@
1
1
  import { itemMachineSingle } from './service/itemMachineSingle.js';
2
- import { internalPropertyNames } from '../helpers/constants.js';
2
+ import { INTERNAL_PROPERTY_NAMES } from '../helpers/constants.js';
3
3
  import { getModel } from '../stores/modelClass.js';
4
4
  import { immerable } from 'immer';
5
5
  import { BehaviorSubject } from 'rxjs';
@@ -80,7 +80,7 @@ class BaseItem {
80
80
  }
81
81
  const propertiesObj = {};
82
82
  for (const [key, propertyInstance] of context.propertyInstances) {
83
- if (typeof key !== 'string' || internalPropertyNames.includes(key)) {
83
+ if (typeof key !== 'string' || INTERNAL_PROPERTY_NAMES.includes(key)) {
84
84
  propertiesObj[key.toString()] = propertyInstance;
85
85
  continue;
86
86
  }
@@ -107,7 +107,7 @@ class BaseItem {
107
107
  seedUid,
108
108
  versionLocalId: latestVersionLocalId,
109
109
  versionUid: latestVersionUid,
110
- modelName: modelName,
110
+ modelName,
111
111
  };
112
112
  if (ModelClass && ModelClass.schema) {
113
113
  const schema = ModelClass.schema;