@seedprotocol/sdk 0.3.8 → 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.
- package/dist/addModel.js +4 -0
- package/dist/addModel.js.map +1 -1
- package/dist/bin.js +182 -111
- package/dist/bin.js.map +1 -1
- package/dist/main.js +13 -1
- package/dist/main.js.map +1 -1
- package/dist/node/db/node.app.db.config.ts +7 -26
- package/dist/scripts/bin.d.ts +4 -4
- package/dist/scripts/bin.d.ts.map +1 -1
- package/dist/seedData.json +23 -0
- package/dist/src/Item/BaseItem.js +3 -3
- package/dist/src/Item/BaseItem.js.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.d.ts +4 -1
- package/dist/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.js +65 -21
- package/dist/src/ItemProperty/BaseItemProperty.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js +27 -17
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.js +25 -20
- package/dist/src/ItemProperty/service/actors/initialize.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +11 -11
- package/dist/src/browser/Item/Item.js +0 -1
- package/dist/src/browser/Item/Item.js.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js +0 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js.map +1 -1
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/db/Db.js +35 -10
- package/dist/src/browser/db/Db.js.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts +3 -1
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.js +24 -12
- package/dist/src/browser/helpers/FileManager.js.map +1 -1
- package/dist/src/browser/helpers/eas.d.ts +20 -0
- package/dist/src/browser/helpers/eas.d.ts.map +1 -0
- package/dist/src/browser/helpers/eas.js +89 -0
- package/dist/src/browser/helpers/eas.js.map +1 -0
- package/dist/src/browser/index.d.ts +0 -1
- package/dist/src/browser/index.d.ts.map +1 -1
- package/dist/src/browser/react/SeedImage.d.ts +11 -0
- package/dist/src/browser/react/SeedImage.d.ts.map +1 -0
- package/dist/src/browser/react/SeedImage.js +105 -0
- package/dist/src/browser/react/SeedImage.js.map +1 -0
- package/dist/src/browser/react/index.d.ts +2 -1
- package/dist/src/browser/react/index.d.ts.map +1 -1
- package/dist/src/browser/react/item.d.ts +8 -8
- package/dist/src/browser/react/item.d.ts.map +1 -1
- package/dist/src/browser/react/item.js +9 -53
- package/dist/src/browser/react/item.js.map +1 -1
- package/dist/src/browser/react/model.d.ts +7 -0
- package/dist/src/browser/react/model.d.ts.map +1 -0
- package/dist/src/browser/react/model.js +20 -0
- package/dist/src/browser/react/model.js.map +1 -0
- package/dist/src/browser/react/property.d.ts +3 -3
- package/dist/src/browser/react/property.d.ts.map +1 -1
- package/dist/src/browser/react/property.js.map +1 -1
- package/dist/src/browser/react/services.d.ts.map +1 -1
- package/dist/src/browser/react/services.js +6 -1
- package/dist/src/browser/react/services.js.map +1 -1
- package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
- package/dist/src/browser/workers/FileDownloader.js +4 -1
- package/dist/src/browser/workers/FileDownloader.js.map +1 -1
- package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/src/browser/workers/ImageResizer.js +1 -0
- package/dist/src/browser/workers/ImageResizer.js.map +1 -1
- package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
- package/dist/src/browser/workers/filesDownload.js +4 -0
- package/dist/src/browser/workers/filesDownload.js.map +1 -1
- package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
- package/dist/src/browser/workers/imageResize.js +4 -1
- package/dist/src/browser/workers/imageResize.js.map +1 -1
- package/dist/src/client/BaseClientManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +184 -22
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.js +29 -0
- package/dist/src/client/ClientManager.js.map +1 -1
- package/dist/src/client/actors/initialize.d.ts +2 -2
- package/dist/src/client/actors/initialize.d.ts.map +1 -1
- package/dist/src/client/actors/initialize.js +9 -0
- package/dist/src/client/actors/initialize.js.map +1 -1
- package/dist/src/client/actors/saveAppState.js +3 -3
- package/dist/src/client/actors/saveAppState.js.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts +86 -10
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.js +3 -1
- package/dist/src/client/clientManagerMachine.js.map +1 -1
- package/dist/src/db/read/getModelSchemas.d.ts +1 -2
- package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/src/db/read/getModelSchemas.js +1 -21
- package/dist/src/db/read/getModelSchemas.js.map +1 -1
- package/dist/src/db/read/getModels.d.ts +5 -0
- package/dist/src/db/read/getModels.d.ts.map +1 -0
- package/dist/src/db/read/getModels.js +16 -0
- package/dist/src/db/read/getModels.js.map +1 -0
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.js +52 -14
- package/dist/src/db/read/getPublishPayload.js.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.js +34 -3
- package/dist/src/db/read/getPublishUploads.js.map +1 -1
- package/dist/src/events/files/download.d.ts.map +1 -1
- package/dist/src/events/files/download.js +0 -1
- package/dist/src/events/files/download.js.map +1 -1
- package/dist/src/events/files/index.d.ts.map +1 -1
- package/dist/src/events/files/index.js +0 -1
- package/dist/src/events/files/index.js.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.js +9 -28
- package/dist/src/events/item/syncDbWithEas.js.map +1 -1
- package/dist/src/events/services/allItems.d.ts.map +1 -1
- package/dist/src/events/services/allItems.js +0 -1
- package/dist/src/events/services/allItems.js.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts +2 -0
- package/dist/src/helpers/FileManager/BaseFileManager.d.ts.map +1 -1
- package/dist/src/helpers/FileManager/BaseFileManager.js +6 -0
- package/dist/src/helpers/FileManager/BaseFileManager.js.map +1 -1
- package/dist/src/helpers/constants.d.ts +2 -2
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/constants.js +14 -6
- package/dist/src/helpers/constants.js.map +1 -1
- package/dist/src/helpers/environment.js +1 -1
- package/dist/src/helpers/environment.js.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.d.ts +1 -0
- package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.js +6 -2
- package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
- package/dist/src/helpers/index.d.ts +2 -1
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/index.js +3 -10
- package/dist/src/helpers/index.js.map +1 -1
- package/dist/src/helpers/scripts.d.ts +2 -0
- package/dist/src/helpers/scripts.d.ts.map +1 -0
- package/dist/src/helpers/scripts.js +14 -0
- package/dist/src/helpers/scripts.js.map +1 -0
- package/dist/src/index.d.ts +11 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IItemProperty.d.ts +7 -0
- package/dist/src/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/src/node/PathResolver.d.ts +39 -0
- package/dist/src/node/PathResolver.d.ts.map +1 -0
- package/dist/src/node/PathResolver.js +150 -0
- package/dist/src/node/PathResolver.js.map +1 -0
- package/dist/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/src/node/codegen/drizzle.js +25 -4
- package/dist/src/node/codegen/drizzle.js.map +1 -1
- package/dist/src/node/constants.d.ts +0 -11
- package/dist/src/node/constants.d.ts.map +1 -1
- package/dist/src/node/constants.js +1 -32
- package/dist/src/node/constants.js.map +1 -1
- package/dist/src/node/db/node.app.db.config.d.ts.map +1 -1
- package/dist/src/node/helpers/FileManager.d.ts +2 -0
- package/dist/src/node/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/node/helpers/index.d.ts.map +1 -1
- package/dist/src/node/helpers/index.js +0 -1
- package/dist/src/node/helpers/index.js.map +1 -1
- package/dist/src/schema/image/model.d.ts +8 -0
- package/dist/src/schema/image/model.d.ts.map +1 -0
- package/dist/src/schema/image/model.js +29 -0
- package/dist/src/schema/image/model.js.map +1 -0
- package/dist/src/schema/model/index.d.ts +8 -8
- package/dist/src/schema/property/index.d.ts +33 -45
- package/dist/src/schema/property/index.d.ts.map +1 -1
- package/dist/src/schema/property/index.js +0 -1
- package/dist/src/schema/property/index.js.map +1 -1
- package/dist/src/seedSchema/ConfigSchema.js +18 -0
- package/dist/src/seedSchema/ConfigSchema.js.map +1 -0
- package/dist/src/services/db/actors/migrate.js +2 -2
- package/dist/src/services/db/actors/migrate.js.map +1 -1
- package/dist/src/services/global/globalMachine.d.ts +90 -90
- package/dist/src/services/internal/helpers.js +3 -3
- package/dist/src/services/internal/helpers.js.map +1 -1
- package/dist/src/stores/eas.d.ts +12 -5
- package/dist/src/stores/eas.d.ts.map +1 -1
- package/dist/src/stores/eas.js +13 -8
- package/dist/src/stores/eas.js.map +1 -1
- package/dist/src/stores/modelClass.d.ts.map +1 -1
- package/dist/src/stores/modelClass.js.map +1 -1
- package/dist/src/types/model.d.ts +2 -15
- package/dist/src/types/model.d.ts.map +1 -1
- package/package.json +8 -7
- package/dist/src/Item/index.d.ts +0 -5
- package/dist/src/Item/index.d.ts.map +0 -1
- package/dist/src/Item/index.js +0 -4
- package/dist/src/Item/index.js.map +0 -1
- package/dist/src/ItemProperty/index.d.ts +0 -5
- package/dist/src/ItemProperty/index.d.ts.map +0 -1
- package/dist/src/ItemProperty/service/actors/index.d.ts +0 -4
- package/dist/src/ItemProperty/service/actors/index.d.ts.map +0 -1
- package/dist/src/browser/Item/index.d.ts +0 -2
- package/dist/src/browser/Item/index.d.ts.map +0 -1
- package/dist/src/browser/Item/index.js +0 -2
- package/dist/src/browser/Item/index.js.map +0 -1
- package/dist/src/browser/ItemProperty/index.d.ts +0 -2
- package/dist/src/browser/ItemProperty/index.d.ts.map +0 -1
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
import { fromCallback } from 'xstate';
|
|
2
2
|
import { getSchemaUidForSchemaDefinition } from '../../../stores/eas.js';
|
|
3
3
|
import { BaseFileManager } from '../../../helpers/FileManager/BaseFileManager.js';
|
|
4
|
+
import { INTERNAL_PROPERTY_NAMES } from '../../../helpers/constants.js';
|
|
4
5
|
|
|
5
6
|
const initialize = fromCallback(({ sendBack, input: { context } }) => {
|
|
6
|
-
const { isRelation, propertyName, storageTransactionId } = context;
|
|
7
|
+
const { isRelation, propertyName, storageTransactionId, propertyRecordSchema, } = context;
|
|
7
8
|
let { schemaUid } = context;
|
|
8
|
-
|
|
9
|
-
schemaUid
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const _initialize = async () => {
|
|
10
|
+
if (!schemaUid &&
|
|
11
|
+
!INTERNAL_PROPERTY_NAMES.includes(propertyName) &&
|
|
12
|
+
(!propertyRecordSchema ||
|
|
13
|
+
!propertyRecordSchema.storageType ||
|
|
14
|
+
propertyRecordSchema.storageType !== 'ItemStorage')) {
|
|
15
|
+
schemaUid = await getSchemaUidForSchemaDefinition({ schemaText: propertyName });
|
|
16
|
+
if (schemaUid) {
|
|
17
|
+
sendBack({ type: 'updateContext', schemaUid });
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
sendBack({ type: 'isRelatedProperty' });
|
|
16
|
-
sendBack({ type: 'initializeSuccess' });
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (!isRelation) {
|
|
20
|
-
if ((propertyName !== 'html' && propertyName !== 'json') ||
|
|
21
|
-
!storageTransactionId) {
|
|
20
|
+
if (isRelation) {
|
|
21
|
+
sendBack({ type: 'isRelatedProperty' });
|
|
22
22
|
sendBack({ type: 'initializeSuccess' });
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
if (!isRelation) {
|
|
26
|
+
if ((propertyName !== 'html' && propertyName !== 'json') ||
|
|
27
|
+
!storageTransactionId) {
|
|
28
|
+
sendBack({ type: 'initializeSuccess' });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
26
31
|
if (propertyName === 'html') {
|
|
27
32
|
const htmlFilePath = `/files/html/${storageTransactionId}.html`;
|
|
28
33
|
const exists = await BaseFileManager.pathExists(htmlFilePath);
|
|
@@ -49,11 +54,11 @@ const initialize = fromCallback(({ sendBack, input: { context } }) => {
|
|
|
49
54
|
sendBack({ type: 'updateContext', renderValue });
|
|
50
55
|
return;
|
|
51
56
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
_initialize().then(() => {
|
|
60
|
+
sendBack({ type: 'initializeSuccess' });
|
|
61
|
+
});
|
|
57
62
|
});
|
|
58
63
|
|
|
59
64
|
export { initialize };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sources":["../../../../../../src/ItemProperty/service/actors/initialize.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { getSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\n\nexport const initialize = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { isRelation, propertyName, storageTransactionId } = context\n let { schemaUid } = context\n\n if (!schemaUid) {\n
|
|
1
|
+
{"version":3,"file":"initialize.js","sources":["../../../../../../src/ItemProperty/service/actors/initialize.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { getSchemaUidForSchemaDefinition } from '@/stores/eas'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { INTERNAL_PROPERTY_NAMES } from '@/helpers/constants'\n\n\nexport const initialize = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { \n isRelation, \n propertyName, \n storageTransactionId,\n propertyRecordSchema, \n } = context\n let { schemaUid } = context\n\n const _initialize = async () => {\n if (\n !schemaUid && \n !INTERNAL_PROPERTY_NAMES.includes(propertyName) &&\n (\n !propertyRecordSchema ||\n !propertyRecordSchema.storageType ||\n propertyRecordSchema.storageType !== 'ItemStorage'\n )\n ) {\n schemaUid = await getSchemaUidForSchemaDefinition({ schemaText: propertyName })\n if (schemaUid) {\n sendBack({ type: 'updateContext', schemaUid })\n }\n }\n \n if (isRelation) {\n sendBack({ type: 'isRelatedProperty' })\n sendBack({ type: 'initializeSuccess' })\n return\n }\n \n if (!isRelation) {\n if (\n (propertyName !== 'html' && propertyName !== 'json') ||\n !storageTransactionId\n ) {\n sendBack({ type: 'initializeSuccess' })\n return\n }\n \n if (propertyName === 'html') {\n const htmlFilePath = `/files/html/${storageTransactionId}.html`\n const exists = await BaseFileManager.pathExists(htmlFilePath)\n if (!exists) {\n return\n }\n const renderValue = await BaseFileManager.readFileAsString(htmlFilePath)\n .catch((error) => {\n console.warn('Error reading html file', error)\n })\n sendBack({ type: 'updateContext', renderValue })\n return\n }\n if (propertyName === 'json') {\n const jsonFilePath = `/files/json/${storageTransactionId}.json`\n const exists = await BaseFileManager.pathExists(jsonFilePath)\n if (!exists) {\n return\n }\n const renderValue = await BaseFileManager.readFileAsString(jsonFilePath)\n .catch((error) => {\n console.warn('Error reading json file', error)\n })\n sendBack({ type: 'updateContext', renderValue })\n return\n }\n \n }\n }\n\n _initialize().then(() => {\n sendBack({ type: 'initializeSuccess' })\n })\n})\n"],"names":[],"mappings":";;;;;AAQa,MAAA,UAAU,GAAG,YAAY,CAGpC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;IACrC,MAAM,EACJ,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,oBAAoB,GACrB,GAAG,OAAO;AACX,IAAA,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO;AAE3B,IAAA,MAAM,WAAW,GAAG,YAAW;AAC7B,QAAA,IACE,CAAC,SAAS;AACV,YAAA,CAAC,uBAAuB,CAAC,QAAQ,CAAC,YAAY,CAAC;AAC/C,aACE,CAAC,oBAAoB;gBACrB,CAAC,oBAAoB,CAAC,WAAW;AACjC,gBAAA,oBAAoB,CAAC,WAAW,KAAK,aAAa,CACnD,EACD;YACA,SAAS,GAAG,MAAM,+BAA+B,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;YAC/E,IAAI,SAAS,EAAE;gBACb,QAAQ,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;;;QAIlD,IAAI,UAAU,EAAE;AACd,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;AACvC,YAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC;YACvC;;QAGF,IAAI,CAAC,UAAU,EAAE;YACf,IACE,CAAC,YAAY,KAAK,MAAM,IAAI,YAAY,KAAK,MAAM;gBACnD,CAAC,oBAAoB,EACrB;AACA,gBAAA,QAAQ,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orage.d.ts","sourceRoot":"","sources":["../../../../../src/ItemProperty/service/actors/resolveRemoteStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"resolveRemoteStorage.d.ts","sourceRoot":"","sources":["../../../../../src/ItemProperty/service/actors/resolveRemoteStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,QAAQ,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAMpD,eAAO,MAAM,oBAAoB,oGAmF/B,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fromCallback } from 'xstate';
|
|
2
2
|
import { BaseFileManager } from '../../../helpers/FileManager/BaseFileManager.js';
|
|
3
|
+
import path from 'path';
|
|
3
4
|
|
|
4
5
|
const resolveRemoteStorage = fromCallback(({ sendBack, input: { context } }) => {
|
|
5
6
|
const { propertyInstances } = context;
|
|
@@ -11,7 +12,6 @@ const resolveRemoteStorage = fromCallback(({ sendBack, input: { context } }) =>
|
|
|
11
12
|
}
|
|
12
13
|
const storageTransactionId = propertyInstances.get('storageTransactionId');
|
|
13
14
|
const _resolveRemoteStorage = async () => {
|
|
14
|
-
const path = await import('path-browserify');
|
|
15
15
|
const filesDirExists = await BaseFileManager.pathExists('/files');
|
|
16
16
|
if (!filesDirExists) {
|
|
17
17
|
await BaseFileManager.createDirIfNotExists('/files');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRemoteStorage.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRemoteStorage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\n\n\nexport const resolveRemoteStorage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { propertyInstances } = context\n\n if (!propertyInstances) {\n throw new Error(`propertyInstances not found for ${context.seedLocalId}`)\n }\n\n if (!propertyInstances.has('storageTransactionId')) {\n return\n }\n\n const storageTransactionId = propertyInstances.get('storageTransactionId')\n\n const _resolveRemoteStorage = async (): Promise<void> => {\n
|
|
1
|
+
{"version":3,"file":"resolveRemoteStorage.js","sources":["../../../../../../src/ItemProperty/service/actors/resolveRemoteStorage.ts"],"sourcesContent":["import { EventObject, fromCallback } from 'xstate'\nimport { FromCallbackInput } from '@/types/machines'\nimport { PropertyMachineContext } from '@/types/property'\nimport { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport path from 'path'\n\n\nexport const resolveRemoteStorage = fromCallback<\n EventObject,\n FromCallbackInput<PropertyMachineContext, EventObject>\n>(({ sendBack, input: { context } }) => {\n const { propertyInstances } = context\n\n if (!propertyInstances) {\n throw new Error(`propertyInstances not found for ${context.seedLocalId}`)\n }\n\n if (!propertyInstances.has('storageTransactionId')) {\n return\n }\n\n const storageTransactionId = propertyInstances.get('storageTransactionId')\n\n const _resolveRemoteStorage = async (): Promise<void> => {\n\n const filesDirExists = await BaseFileManager.pathExists('/files')\n\n if (!filesDirExists) {\n await BaseFileManager.createDirIfNotExists('/files')\n }\n\n const htmlDir = path.join('/files', 'html')\n\n const htmlExists = await BaseFileManager.pathExists(htmlDir)\n\n const fs = await BaseFileManager.getFs()\n\n if (htmlExists) {\n const htmlFiles = await fs.promises.readdir(htmlDir)\n const matchingHtmlFile = htmlFiles.find(\n (file: string) => file === `${storageTransactionId}.html`,\n )\n if (matchingHtmlFile) {\n const htmlString = await fs.promises.readFile(\n path.join(htmlDir, matchingHtmlFile),\n 'utf8',\n )\n sendBack({\n type: 'updateValue',\n propertyName: 'html',\n propertyValue: htmlString,\n })\n }\n }\n\n if (!htmlExists) {\n await fs.promises.mkdir(htmlDir)\n }\n\n const jsonDir = path.join('/files', 'json')\n\n const jsonExists = await fs.promises.exists(jsonDir)\n\n if (jsonExists) {\n const jsonFiles = await fs.promises.readdir(jsonDir)\n const matchingJsonFile = jsonFiles.find(\n (file: string) => file === `${storageTransactionId}.json`,\n )\n if (matchingJsonFile) {\n const jsonString = await fs.promises.readFile(\n path.join(jsonDir, matchingJsonFile),\n 'utf8',\n )\n sendBack({\n type: 'updateValue',\n propertyName: 'json',\n propertyValue: jsonString,\n })\n }\n }\n\n if (!jsonExists) {\n await fs.promises.mkdir(jsonDir)\n }\n }\n\n _resolveRemoteStorage().then(() => {\n sendBack({ type: 'resolveRemoteStorageSuccess' })\n return\n })\n})\n"],"names":[],"mappings":";;;;AAOa,MAAA,oBAAoB,GAAG,YAAY,CAG9C,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,KAAI;AACrC,IAAA,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO;IAErC,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,CAAA,gCAAA,EAAmC,OAAO,CAAC,WAAW,CAAE,CAAA,CAAC;;IAG3E,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE;QAClD;;IAGF,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,GAAG,CAAC,sBAAsB,CAAC;AAE1E,IAAA,MAAM,qBAAqB,GAAG,YAA0B;QAEtD,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC;QAEjE,IAAI,CAAC,cAAc,EAAE;AACnB,YAAA,MAAM,eAAe,CAAC,oBAAoB,CAAC,QAAQ,CAAC;;QAGtD,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;QAE3C,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC;AAE5D,QAAA,MAAM,EAA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AAC;AACP,oBAAA,IAAI,EAAE,aAAa;AACnB,oBAAA,YAAY,EAAE,MAAM;AACpB,oBAAA,aAAa,EAAE,UAAU;AAC1B,iBAAA,CAAC;;;QAIN,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;;AAEpC,KAAC;AAED,IAAA,qBAAqB,EAAE,CAAC,IAAI,CAAC,MAAK;AAChC,QAAA,QAAQ,CAAC,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC;QACjD;AACF,KAAC,CAAC;AACJ,CAAC;;;;"}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { PropertyMachineContext } from '@/types';
|
|
2
2
|
export declare const propertyMachine: import("xstate").StateMachine<any, import("xstate").AnyEventObject, {
|
|
3
|
-
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("
|
|
3
|
+
[x: string]: import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("@/types").SaveValueToDbEvent>, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any>, import("xstate").EventObject>> | import("xstate").ActorRefFromLogic<import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("xstate").EventObject>, import("xstate").EventObject>> | undefined;
|
|
4
4
|
}, import("xstate").Values<{
|
|
5
|
-
initialize: {
|
|
6
|
-
src: "initialize";
|
|
7
|
-
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("xstate").EventObject>, import("xstate").EventObject>;
|
|
8
|
-
id: string | undefined;
|
|
9
|
-
};
|
|
10
|
-
waitForDb: {
|
|
11
|
-
src: "waitForDb";
|
|
12
|
-
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any>, import("xstate").EventObject>;
|
|
13
|
-
id: string | undefined;
|
|
14
|
-
};
|
|
15
5
|
saveRelation: {
|
|
16
6
|
src: "saveRelation";
|
|
17
7
|
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("@/types").SaveValueToDbEvent>, import("xstate").EventObject>;
|
|
@@ -27,11 +17,21 @@ export declare const propertyMachine: import("xstate").StateMachine<any, import(
|
|
|
27
17
|
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("@/types").SaveValueToDbEvent>, import("xstate").EventObject>;
|
|
28
18
|
id: string | undefined;
|
|
29
19
|
};
|
|
20
|
+
waitForDb: {
|
|
21
|
+
src: "waitForDb";
|
|
22
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any>, import("xstate").EventObject>;
|
|
23
|
+
id: string | undefined;
|
|
24
|
+
};
|
|
30
25
|
hydrateFromDb: {
|
|
31
26
|
src: "hydrateFromDb";
|
|
32
27
|
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("xstate").EventObject>, import("xstate").EventObject>;
|
|
33
28
|
id: string | undefined;
|
|
34
29
|
};
|
|
30
|
+
initialize: {
|
|
31
|
+
src: "initialize";
|
|
32
|
+
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("xstate").EventObject>, import("xstate").EventObject>;
|
|
33
|
+
id: string | undefined;
|
|
34
|
+
};
|
|
35
35
|
resolveRelatedValue: {
|
|
36
36
|
src: "resolveRelatedValue";
|
|
37
37
|
logic: import("xstate").CallbackActorLogic<import("xstate").EventObject, import("@/types").FromCallbackInput<any, import("xstate").EventObject>, import("xstate").EventObject>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.js","sources":["../../../../../src/browser/Item/Item.ts"],"sourcesContent":["import {\n ModelSchema,\n ModelValues,\n NewItemProps,\n} from '@/types'\nimport { BaseItem } from '@/Item/BaseItem'\nimport { IItem } from '@/interfaces'\n\nexport class Item<T extends ModelValues<ModelSchema>> extends BaseItem<T> implements IItem<T> {\n\n constructor(initialValues: NewItemProps<T>,) {\n super(initialValues,)\n }\n\n}\n
|
|
1
|
+
{"version":3,"file":"Item.js","sources":["../../../../../src/browser/Item/Item.ts"],"sourcesContent":["import {\n ModelSchema,\n ModelValues,\n NewItemProps,\n} from '@/types'\nimport { BaseItem } from '@/Item/BaseItem'\nimport { IItem } from '@/interfaces'\n\nexport class Item<T extends ModelValues<ModelSchema>> extends BaseItem<T> implements IItem<T> {\n\n constructor(initialValues: NewItemProps<T>,) {\n super(initialValues,)\n }\n\n}\n"],"names":[],"mappings":";;AAQM,MAAO,IAAyC,SAAQ,QAAW,CAAA;AAEvE,IAAA,WAAA,CAAY,aAA8B,EAAA;QACxC,KAAK,CAAC,aAAa,CAAE;;AAGxB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemProperty.d.ts","sourceRoot":"","sources":["../../../../src/browser/ItemProperty/ItemProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAGlE,cAAM,YAAa,SAAQ,gBAAgB,CAAC,YAAY,CAAE,YAAW,aAAa,CAAC,YAAY,CAAC;gBAGlF,aAAa,EAAE,OAAO,CAAC,2BAA2B,CAAC;CAIhE;
|
|
1
|
+
{"version":3,"file":"ItemProperty.d.ts","sourceRoot":"","sources":["../../../../src/browser/ItemProperty/ItemProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAGlE,cAAM,YAAa,SAAQ,gBAAgB,CAAC,YAAY,CAAE,YAAW,aAAa,CAAC,YAAY,CAAC;gBAGlF,aAAa,EAAE,OAAO,CAAC,2BAA2B,CAAC;CAIhE;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemProperty.js","sources":["../../../../../src/browser/ItemProperty/ItemProperty.ts"],"sourcesContent":["import { CreatePropertyInstanceProps, PropertyType } from '@/types'\nimport { IItemProperty } from '@/interfaces/IItemProperty'\nimport { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'\n\n\nclass ItemProperty extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {\n\n\n constructor(initialValues: Partial<CreatePropertyInstanceProps>) {\n super(initialValues)\n }\n\n}\n\
|
|
1
|
+
{"version":3,"file":"ItemProperty.js","sources":["../../../../../src/browser/ItemProperty/ItemProperty.ts"],"sourcesContent":["import { CreatePropertyInstanceProps, PropertyType } from '@/types'\nimport { IItemProperty } from '@/interfaces/IItemProperty'\nimport { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'\n\n\nclass ItemProperty extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {\n\n\n constructor(initialValues: Partial<CreatePropertyInstanceProps>) {\n super(initialValues)\n }\n\n}\n\nexport { ItemProperty }\n"],"names":[],"mappings":";;AAKA,MAAM,YAAa,SAAQ,gBAA8B,CAAA;AAGvD,IAAA,WAAA,CAAY,aAAmD,EAAA;QAC7D,KAAK,CAAC,aAAa,CAAC;;AAGvB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../../src/browser/db/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EAAW,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"Db.d.ts","sourceRoot":"","sources":["../../../../src/browser/db/Db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EAAW,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAQzE,cAAM,EAAG,SAAQ,MAAO,YAAW,GAAG;IAEpC,MAAM,CAAC,gBAAgB,EAAE,GAAG,CAAA;IAC5B,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,MAAM,CAAC,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAA;;IAMvE,MAAM,CAAC,QAAQ;IAIf,MAAM,CAAC,YAAY;WAIN,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;WAyE3D,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC;WAwL5D,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE;CAiC7C;AAED,OAAO,EAAE,EAAE,EAAE,CAAA"}
|
|
@@ -6,7 +6,6 @@ import { drizzle } from 'drizzle-orm/sqlite-proxy';
|
|
|
6
6
|
import { migrate } from 'drizzle-orm/sqlite-proxy/migrator';
|
|
7
7
|
import { DB_NAME_APP, BROWSER_FS_TOP_DIR } from '../../services/internal/constants.js';
|
|
8
8
|
import '../../helpers/index.js';
|
|
9
|
-
import { sqlite3Worker1Promiser } from '@sqlite.org/sqlite-wasm';
|
|
10
9
|
import { BaseFileManager } from '../../helpers/FileManager/BaseFileManager.js';
|
|
11
10
|
|
|
12
11
|
const logger = debug('seedSdk:browser:db:Db');
|
|
@@ -25,13 +24,35 @@ class Db extends BaseDb {
|
|
|
25
24
|
return this.dbId;
|
|
26
25
|
}
|
|
27
26
|
this.filesDir = filesDir;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if (typeof document === 'undefined') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let promiser;
|
|
31
|
+
try {
|
|
32
|
+
let sqlite3Worker1Promiser;
|
|
33
|
+
const sqliteWasm = await import('@sqlite.org/sqlite-wasm');
|
|
34
|
+
if (sqliteWasm && sqliteWasm.sqlite3Worker1Promiser) {
|
|
35
|
+
sqlite3Worker1Promiser = sqliteWasm.sqlite3Worker1Promiser;
|
|
36
|
+
}
|
|
37
|
+
if (!sqlite3Worker1Promiser && window.sqlite3Worker1Promiser) {
|
|
38
|
+
sqlite3Worker1Promiser = window.sqlite3Worker1Promiser;
|
|
39
|
+
}
|
|
40
|
+
if (!sqlite3Worker1Promiser) {
|
|
41
|
+
throw new Error('Failed to load sqlite3Worker1Promiser');
|
|
42
|
+
}
|
|
43
|
+
promiser = await new Promise((resolve) => {
|
|
44
|
+
const _promiser = sqlite3Worker1Promiser({
|
|
45
|
+
onready: () => {
|
|
46
|
+
resolve(_promiser);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}).catch((error) => {
|
|
50
|
+
console.error('Error from sqlite proxy server: ', JSON.stringify(error));
|
|
33
51
|
});
|
|
34
|
-
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.error('Error from sqlite proxy server: ', JSON.stringify(e));
|
|
55
|
+
}
|
|
35
56
|
if (!promiser) {
|
|
36
57
|
throw new Error('Failed to create promiser');
|
|
37
58
|
}
|
|
@@ -72,8 +93,6 @@ class Db extends BaseDb {
|
|
|
72
93
|
});
|
|
73
94
|
try {
|
|
74
95
|
const zenfs = await BaseFileManager.getFs();
|
|
75
|
-
const filesInRoot = await zenfs.promises.readdir('/');
|
|
76
|
-
logger('filesInRoot', filesInRoot);
|
|
77
96
|
const migrations = readMigrationFiles({
|
|
78
97
|
migrationsFolder: pathToDbDir,
|
|
79
98
|
});
|
|
@@ -124,7 +143,13 @@ class Db extends BaseDb {
|
|
|
124
143
|
}
|
|
125
144
|
catch (error) {
|
|
126
145
|
await BaseFileManager.waitForFile(`${pathToDbDir}/meta/_journal.json`);
|
|
127
|
-
await
|
|
146
|
+
const journalExists = await BaseFileManager.pathExists(`${pathToDbDir}/meta/_journal.json`);
|
|
147
|
+
if (journalExists) {
|
|
148
|
+
await this.migrate(pathToDbDir, dbName);
|
|
149
|
+
}
|
|
150
|
+
if (!journalExists) {
|
|
151
|
+
throw new Error('Failed to migrate database');
|
|
152
|
+
}
|
|
128
153
|
}
|
|
129
154
|
this.appDb = drizzleDb;
|
|
130
155
|
// const createTempTableQuery = await appDb.run(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Db.js","sources":["../../../../../src/browser/db/Db.ts"],"sourcesContent":["import { BaseDb } from \"@/db/Db/BaseDb\";\nimport { IDb } from \"@/interfaces/IDb\";\nimport debug from \"debug\";\nimport { sql } from \"drizzle-orm\";\nimport { readMigrationFiles } from \"drizzle-orm/migrator\";\nimport { drizzle, SqliteRemoteDatabase } from \"drizzle-orm/sqlite-proxy\";\nimport { migrate as drizzleMigrate } from \"drizzle-orm/sqlite-proxy/migrator\";\nimport { BROWSER_FS_TOP_DIR, DB_NAME_APP } from \"@/services/internal/constants\";\nimport { BaseFileManager } from \"@/helpers\";\nimport { sqlite3Worker1Promiser, } from \"@sqlite.org/sqlite-wasm\";\n\nconst logger = debug('seedSdk:browser:db:Db')\n\n\nclass Db extends BaseDb implements IDb {\n\n static sqliteWasmClient: any\n static filesDir: string | undefined\n static pathToDb: string | undefined\n static dbId: string | undefined\n static appDb: SqliteRemoteDatabase<Record<string, unknown>> | undefined\n\n constructor() {\n super()\n }\n\n static getAppDb() {\n return this.appDb\n }\n\n static isAppDbReady() {\n return !!this.appDb\n }\n\n static async connectToDb(filesDir: string,): Promise<string | undefined> {\n\n if (Db.sqliteWasmClient) {\n return this.dbId\n }\n\n this.filesDir = filesDir\n\n const promiser = await new Promise<(event: string, config: Record<string, unknown>) => Promise<any>>((resolve) => {\n const _promiser = sqlite3Worker1Promiser({\n onready: () => {\n resolve(_promiser);\n },\n });\n });\n\n if (!promiser) {\n throw new Error('Failed to create promiser')\n }\n\n this.sqliteWasmClient = promiser\n\n const responseGet = await this.sqliteWasmClient('config-get', {});\n\n logger('[Db.prepareDb] Running SQLite3 version', responseGet.result.version.libVersion);\n\n const responseOpen = await this.sqliteWasmClient('open', {\n filename: `file:${filesDir}/db/${DB_NAME_APP}.sqlite3?vfs=opfs`,\n });\n const { dbId } = responseOpen;\n logger(\n '[Db.prepareDb] OPFS is available, created persisted database at',\n responseOpen.result.filename.replace(/^file:(.*?)\\?vfs=opfs/, '$1'),\n );\n\n logger('[Db.prepareDb] dbId', dbId) \n\n this.dbId = dbId\n\n return dbId\n }\n\n static async migrate(pathToDbDir: string, dbName: string,): Promise<void> {\n\n const schemaGlobString = `${BROWSER_FS_TOP_DIR}/schema/*`\n\n const drizzleDb = drizzle(\n async (sql, params, method) => {\n try {\n // logger(\n // `executing sql on ${dbName} with id: ${dbId} and method: ${method}`,\n // sql,\n // )\n\n const finalResult = await this.exec(sql, params)\n\n // logger(`finalResult with method: ${method}`, finalResult)\n // Drizzle always waits for {rows: string[][]} or {rows: string[]} for the return value.\n\n // When the method is get, you should return a value as {rows: string[]}.\n // Otherwise, you should return {rows: string[][]}.\n\n return { rows: finalResult }\n } catch (e: any) {\n console.error('Error from sqlite proxy server: ', JSON.stringify(e))\n return { rows: [] }\n }\n },\n {\n schema: schemaGlobString,\n // logger: true,\n },\n )\n\n try {\n const zenfs = await BaseFileManager.getFs()\n\n const filesInRoot = await zenfs.promises.readdir('/')\n logger('filesInRoot', filesInRoot)\n const migrations = readMigrationFiles({\n migrationsFolder: pathToDbDir,\n })\n\n if (migrations.length > 0) {\n const incomingMigrationHashes = migrations.map(\n (migration) => migration.hash,\n )\n\n let existingMigrationHashes\n let rows = []\n\n try {\n\n const queryMigrationsTable = await drizzleDb.run(\n sql.raw(\n `SELECT name \n FROM sqlite_master \n WHERE type='table' \n AND name='__drizzle_migrations';`,\n ),\n )\n\n logger('queryMigrationsTable', queryMigrationsTable)\n\n if (queryMigrationsTable && queryMigrationsTable.rows && queryMigrationsTable.rows.length > 0) {\n const query = await drizzleDb.run(\n sql.raw(\n `SELECT hash, created_at\n FROM main.__drizzle_migrations;`,\n ),\n )\n \n rows = query.rows\n }\n\n } catch (e) {\n rows = []\n }\n\n if (rows && rows.length > 0) {\n existingMigrationHashes = rows.map((row) => row[0])\n }\n\n if (existingMigrationHashes) {\n let shouldRebuildDb = false\n for (const existingHash of existingMigrationHashes) {\n if (!incomingMigrationHashes.includes(existingHash)) {\n shouldRebuildDb = true\n break\n }\n }\n if (shouldRebuildDb) {\n await zenfs.promises.unlink(`${pathToDbDir}/${dbName}.sqlite3`)\n }\n }\n }\n\n await drizzleMigrate(\n drizzleDb,\n async (queriesToRun) => {\n // logger('queriesToRun', queriesToRun)\n for (const query of queriesToRun) {\n // logger('query', query)\n await drizzleDb.run(sql.raw(query))\n }\n },\n {\n migrationsFolder: pathToDbDir,\n },\n )\n } catch (error) {\n\n await BaseFileManager.waitForFile(`${pathToDbDir}/meta/_journal.json`)\n\n await this.migrate(pathToDbDir, dbName,)\n\n }\n\n this.appDb = drizzleDb\n // const createTempTableQuery = await appDb.run(\n // sql.raw(\n // `CREATE TEMP TABLE IF NOT EXISTS temp_last_inserted_id (id INTEGER, table TEXT);`,\n // ),\n // )\n //\n // logger(\n // '[db/actors] [migrate] createTempTableQuery',\n // createTempTableQuery,\n // )\n\n // const triggersQuery = await appDb.run(\n // sql.raw(\n // `SELECT name\n // FROM main.sqlite_master\n // WHERE type = 'trigger';`,\n // ),\n // )\n //\n // logger('[db/actors] [migrate] triggersQuery', triggersQuery)\n //\n // const triggers = triggersQuery.rows.map((row) => row[0])\n //\n // const tablesQuery = await appDb.run(\n // sql.raw(\n // `SELECT name\n // FROM main.sqlite_master\n // WHERE type = 'table';`,\n // ),\n // )\n //\n // logger('[db/actors] [migrate] tablesQuery', tablesQuery)\n //\n // const tableNames = tablesQuery.rows.map((row) => row[0])\n // logger('[db/actors] [migrate] tableNames', tableNames)\n // for (const tableName of tableNames) {\n // const triggerName = `after_insert_${tableName}`\n // if (triggers.includes(triggerName)) {\n // continue\n // }\n // const createTriggerQuery = await appDb.run(\n // sql.raw(\n // `CREATE TRIGGER after_insert_${tableName}\n // AFTER INSERT ON ${tableName}\n // BEGIN\n // DELETE FROM temp_last_inserted_id;\n // INSERT INTO temp_last_inserted_id (id) VALUES (new.id);\n // END;`,\n // ),\n // )\n //\n // logger(\n // '[db/actors] [migrate] createTriggerQuery',\n // createTriggerQuery,\n // )\n // }\n }\n\n static async exec(sql: string, params: any[]) {\n const rowsToReturnRaw: SqliteWasmResult[] = []\n const rowsValues: string[][] = []\n \n // For a single exec command, the callback potentially gets called several times -- once for each row.\n // So we need to collect all rows into a final array to return (execResult).\n const rowsToReturn = await new Promise((resolve, reject) => {\n\n\n this.sqliteWasmClient('exec', {\n dbId:this.dbId,\n sql,\n bind: params,\n callback: (result) => {\n // Checks if this is the final callback of the query\n if (!result || !result.row || !result.rowNumber) {\n const returnResult = []\n for (const currRow of rowsToReturnRaw) {\n returnResult.push(currRow.row)\n }\n resolve(returnResult)\n } else {\n // If not the final response, add this row to the return array\n rowsToReturnRaw.push(result)\n }\n },\n }).catch(async (error) => {\n reject(error)\n })\n })\n \n return rowsToReturn || []\n }\n}\n\nexport { Db }"],"names":["drizzleMigrate"],"mappings":";;;;;;;;;;;AAWA,MAAM,MAAM,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E;;AAE5B;;;;"}
|
|
1
|
+
{"version":3,"file":"Db.js","sources":["../../../../../src/browser/db/Db.ts"],"sourcesContent":["import { BaseDb } from \"@/db/Db/BaseDb\";\nimport { IDb } from \"@/interfaces/IDb\";\nimport debug from \"debug\";\nimport { sql } from \"drizzle-orm\";\nimport { readMigrationFiles } from \"drizzle-orm/migrator\";\nimport { drizzle, SqliteRemoteDatabase } from \"drizzle-orm/sqlite-proxy\";\nimport { migrate as drizzleMigrate } from \"drizzle-orm/sqlite-proxy/migrator\";\nimport { BROWSER_FS_TOP_DIR, DB_NAME_APP } from \"@/services/internal/constants\";\nimport { BaseFileManager } from \"@/helpers\";\n\nconst logger = debug('seedSdk:browser:db:Db')\n\n\nclass Db extends BaseDb implements IDb {\n\n static sqliteWasmClient: any\n static filesDir: string | undefined\n static pathToDb: string | undefined\n static dbId: string | undefined\n static appDb: SqliteRemoteDatabase<Record<string, unknown>> | undefined\n\n constructor() {\n super()\n }\n\n static getAppDb() {\n return this.appDb\n }\n\n static isAppDbReady() {\n return !!this.appDb\n }\n\n static async connectToDb(filesDir: string,): Promise<string | undefined> {\n\n if (Db.sqliteWasmClient) {\n return this.dbId\n }\n\n this.filesDir = filesDir\n\n if (typeof document === 'undefined') {\n return\n }\n\n let promiser\n\n try {\n\n let sqlite3Worker1Promiser\n\n const sqliteWasm = await import('@sqlite.org/sqlite-wasm')\n\n if (sqliteWasm && sqliteWasm.sqlite3Worker1Promiser) {\n sqlite3Worker1Promiser = sqliteWasm.sqlite3Worker1Promiser\n }\n\n if (!sqlite3Worker1Promiser && window.sqlite3Worker1Promiser) {\n sqlite3Worker1Promiser = window.sqlite3Worker1Promiser\n }\n\n if (!sqlite3Worker1Promiser) {\n throw new Error('Failed to load sqlite3Worker1Promiser')\n }\n\n promiser = await new Promise<(event: string, config: Record<string, unknown>) => Promise<any>>((resolve) => {\n const _promiser = sqlite3Worker1Promiser({\n onready: () => {\n resolve(_promiser);\n },\n });\n }).catch((error) => {\n console.error('Error from sqlite proxy server: ', JSON.stringify(error))\n });\n\n } catch ( e ) {\n console.error('Error from sqlite proxy server: ', JSON.stringify(e))\n }\n\n\n if (!promiser) {\n throw new Error('Failed to create promiser')\n }\n\n this.sqliteWasmClient = promiser\n\n const responseGet = await this.sqliteWasmClient('config-get', {});\n\n logger('[Db.prepareDb] Running SQLite3 version', responseGet.result.version.libVersion);\n\n const responseOpen = await this.sqliteWasmClient('open', {\n filename: `file:${filesDir}/db/${DB_NAME_APP}.sqlite3?vfs=opfs`,\n });\n const { dbId } = responseOpen;\n logger(\n '[Db.prepareDb] OPFS is available, created persisted database at',\n responseOpen.result.filename.replace(/^file:(.*?)\\?vfs=opfs/, '$1'),\n );\n\n logger('[Db.prepareDb] dbId', dbId) \n\n this.dbId = dbId\n\n return dbId\n }\n\n static async migrate(pathToDbDir: string, dbName: string,): Promise<void> {\n\n const schemaGlobString = `${BROWSER_FS_TOP_DIR}/schema/*`\n\n const drizzleDb = drizzle(\n async (sql, params, method) => {\n try {\n // logger(\n // `executing sql on ${dbName} with id: ${dbId} and method: ${method}`,\n // sql,\n // )\n\n const finalResult = await this.exec(sql, params)\n\n // logger(`finalResult with method: ${method}`, finalResult)\n // Drizzle always waits for {rows: string[][]} or {rows: string[]} for the return value.\n\n // When the method is get, you should return a value as {rows: string[]}.\n // Otherwise, you should return {rows: string[][]}.\n\n return { rows: finalResult }\n } catch (e: any) {\n console.error('Error from sqlite proxy server: ', JSON.stringify(e))\n return { rows: [] }\n }\n },\n {\n schema: schemaGlobString,\n // logger: true,\n },\n )\n\n try {\n const zenfs = await BaseFileManager.getFs()\n\n const migrations = readMigrationFiles({\n migrationsFolder: pathToDbDir,\n })\n\n if (migrations.length > 0) {\n const incomingMigrationHashes = migrations.map(\n (migration) => migration.hash,\n )\n\n let existingMigrationHashes\n let rows = []\n\n try {\n\n const queryMigrationsTable = await drizzleDb.run(\n sql.raw(\n `SELECT name \n FROM sqlite_master \n WHERE type='table' \n AND name='__drizzle_migrations';`,\n ),\n )\n\n logger('queryMigrationsTable', queryMigrationsTable)\n\n if (queryMigrationsTable && queryMigrationsTable.rows && queryMigrationsTable.rows.length > 0) {\n const query = await drizzleDb.run(\n sql.raw(\n `SELECT hash, created_at\n FROM main.__drizzle_migrations;`,\n ),\n )\n \n rows = query.rows\n }\n\n } catch (e) {\n rows = []\n }\n\n if (rows && rows.length > 0) {\n existingMigrationHashes = rows.map((row) => row[0])\n }\n\n if (existingMigrationHashes) {\n let shouldRebuildDb = false\n for (const existingHash of existingMigrationHashes) {\n if (!incomingMigrationHashes.includes(existingHash)) {\n shouldRebuildDb = true\n break\n }\n }\n if (shouldRebuildDb) {\n await zenfs.promises.unlink(`${pathToDbDir}/${dbName}.sqlite3`)\n }\n }\n }\n\n await drizzleMigrate(\n drizzleDb,\n async (queriesToRun) => {\n // logger('queriesToRun', queriesToRun)\n for (const query of queriesToRun) {\n // logger('query', query)\n await drizzleDb.run(sql.raw(query))\n }\n },\n {\n migrationsFolder: pathToDbDir,\n },\n )\n } catch (error) {\n\n await BaseFileManager.waitForFile(`${pathToDbDir}/meta/_journal.json`)\n\n const journalExists = await BaseFileManager.pathExists(\n `${pathToDbDir}/meta/_journal.json`,\n )\n\n if (journalExists) {\n await this.migrate(pathToDbDir, dbName,)\n }\n\n if (!journalExists) {\n throw new Error('Failed to migrate database')\n }\n\n\n }\n\n this.appDb = drizzleDb\n // const createTempTableQuery = await appDb.run(\n // sql.raw(\n // `CREATE TEMP TABLE IF NOT EXISTS temp_last_inserted_id (id INTEGER, table TEXT);`,\n // ),\n // )\n //\n // logger(\n // '[db/actors] [migrate] createTempTableQuery',\n // createTempTableQuery,\n // )\n\n // const triggersQuery = await appDb.run(\n // sql.raw(\n // `SELECT name\n // FROM main.sqlite_master\n // WHERE type = 'trigger';`,\n // ),\n // )\n //\n // logger('[db/actors] [migrate] triggersQuery', triggersQuery)\n //\n // const triggers = triggersQuery.rows.map((row) => row[0])\n //\n // const tablesQuery = await appDb.run(\n // sql.raw(\n // `SELECT name\n // FROM main.sqlite_master\n // WHERE type = 'table';`,\n // ),\n // )\n //\n // logger('[db/actors] [migrate] tablesQuery', tablesQuery)\n //\n // const tableNames = tablesQuery.rows.map((row) => row[0])\n // logger('[db/actors] [migrate] tableNames', tableNames)\n // for (const tableName of tableNames) {\n // const triggerName = `after_insert_${tableName}`\n // if (triggers.includes(triggerName)) {\n // continue\n // }\n // const createTriggerQuery = await appDb.run(\n // sql.raw(\n // `CREATE TRIGGER after_insert_${tableName}\n // AFTER INSERT ON ${tableName}\n // BEGIN\n // DELETE FROM temp_last_inserted_id;\n // INSERT INTO temp_last_inserted_id (id) VALUES (new.id);\n // END;`,\n // ),\n // )\n //\n // logger(\n // '[db/actors] [migrate] createTriggerQuery',\n // createTriggerQuery,\n // )\n // }\n }\n\n static async exec(sql: string, params: any[]) {\n const rowsToReturnRaw: SqliteWasmResult[] = []\n const rowsValues: string[][] = []\n \n // For a single exec command, the callback potentially gets called several times -- once for each row.\n // So we need to collect all rows into a final array to return (execResult).\n const rowsToReturn = await new Promise((resolve, reject) => {\n\n\n this.sqliteWasmClient('exec', {\n dbId:this.dbId,\n sql,\n bind: params,\n callback: (result) => {\n // Checks if this is the final callback of the query\n if (!result || !result.row || !result.rowNumber) {\n const returnResult = []\n for (const currRow of rowsToReturnRaw) {\n returnResult.push(currRow.row)\n }\n resolve(returnResult)\n } else {\n // If not the final response, add this row to the return array\n rowsToReturnRaw.push(result)\n }\n },\n }).catch(async (error) => {\n reject(error)\n })\n })\n \n return rowsToReturn || []\n }\n}\n\nexport { Db }\n"],"names":["drizzleMigrate"],"mappings":";;;;;;;;;;AAUA,MAAM,MAAM,GAAG,KAAK,CAAC,uBAAuB,CAAC;AAG7C,MAAM,EAAG,SAAQ,MAAM,CAAA;AAQrB,IAAA,WAAA,GAAA;AACE,QAAA,KAAK,EAAE;;AAGT,IAAA,OAAO,QAAQ,GAAA;QACb,OAAO,IAAI,CAAC,KAAK;;AAGnB,IAAA,OAAO,YAAY,GAAA;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C,MAAM,EAAE;gBAC3B,IAAI,EAAC,IAAI,CAAC,IAAI;gBACd,GAAG;AACH,gBAAA,IAAI,EAAE,MAAM;AACZ,gBAAA,QAAQ,EAAE,CAAC,MAAM,KAAI;;AAEnB,oBAAA,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;wBAC/C,MAAM,YAAY,GAAG,EAAE;AACvB,wBAAA,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE;AACrC,4BAAA,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;;wBAEhC,OAAO,CAAC,YAAY,CAAC;;yBAChB;;AAEL,wBAAA,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC;;iBAE/B;AACF,aAAA,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,KAAI;gBACvB,MAAM,CAAC,KAAK,CAAC;AACf,aAAC,CAAC;AACJ,SAAC,CAAC;QAEF,OAAO,YAAY,IAAI,EAAE;;AAE5B;;;;"}
|
|
@@ -18,8 +18,10 @@ declare class FileManager extends BaseFileManager {
|
|
|
18
18
|
static waitForFile(filePath: string, interval?: number, timeout?: number): Promise<boolean>;
|
|
19
19
|
static saveFile(filePath: string, content: string | Blob | ArrayBuffer): Promise<void>;
|
|
20
20
|
static readFile(filePath: string): Promise<File>;
|
|
21
|
-
static readFileAsBuffer(filePath: string): Promise<
|
|
21
|
+
static readFileAsBuffer(filePath: string): Promise<Blob>;
|
|
22
22
|
static readFileAsString(filePath: string): Promise<string>;
|
|
23
|
+
static getParentDirPath(filePath: string): string;
|
|
24
|
+
static getFilenameFromPath(filePath: string): string;
|
|
23
25
|
}
|
|
24
26
|
export { FileManager };
|
|
25
27
|
//# sourceMappingURL=FileManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileManager.d.ts","sourceRoot":"","sources":["../../../../src/browser/helpers/FileManager.ts"],"names":[],"mappings":"AAAA,O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,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKhE,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIjD,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;CAGrD;AAsDD,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { BaseFileManager } from '../../helpers/FileManager/BaseFileManager.js';
|
|
|
2
2
|
import { FileDownloader } from '../workers/FileDownloader.js';
|
|
3
3
|
import { ImageResizer } from '../workers/ImageResizer.js';
|
|
4
4
|
import debug from 'debug';
|
|
5
|
+
import path from 'path-browserify';
|
|
5
6
|
|
|
6
7
|
const logger = debug('seedSdk:browser:helpers:FileManager');
|
|
7
8
|
class FileManager extends BaseFileManager {
|
|
@@ -101,8 +102,12 @@ class FileManager extends BaseFileManager {
|
|
|
101
102
|
* @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.
|
|
102
103
|
*/
|
|
103
104
|
static async waitForFile(filePath, interval = 1000, timeout = 60000) {
|
|
104
|
-
const fs = await this.getFs()
|
|
105
|
-
const fsNode = await import('node:fs')
|
|
105
|
+
// const fs = await this.getFs()
|
|
106
|
+
// const fsNode = await import('node:fs')
|
|
107
|
+
const pathExists = await this.pathExists(filePath);
|
|
108
|
+
if (pathExists) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
106
111
|
return new Promise((resolve, reject) => {
|
|
107
112
|
const startTime = Date.now();
|
|
108
113
|
let isBusy = false;
|
|
@@ -112,11 +117,12 @@ class FileManager extends BaseFileManager {
|
|
|
112
117
|
return;
|
|
113
118
|
}
|
|
114
119
|
isBusy = true;
|
|
115
|
-
// TODO: Needs to read from OPFS
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
// // TODO: Needs to read from OPFS
|
|
121
|
+
// const exists = await BaseFileManager.pathExists(filePath)
|
|
122
|
+
// if (exists) {
|
|
123
|
+
// stop()
|
|
124
|
+
// resolve(true)
|
|
125
|
+
// }
|
|
120
126
|
const pathExists = await this.pathExists(filePath);
|
|
121
127
|
if (pathExists) {
|
|
122
128
|
stop();
|
|
@@ -244,8 +250,8 @@ class FileManager extends BaseFileManager {
|
|
|
244
250
|
// Get the file and read it as an ArrayBuffer
|
|
245
251
|
const file = await this.readFile(filePath);
|
|
246
252
|
const arrayBuffer = await file.arrayBuffer();
|
|
247
|
-
// Convert ArrayBuffer to
|
|
248
|
-
return
|
|
253
|
+
// Convert ArrayBuffer to Blob
|
|
254
|
+
return new Blob([arrayBuffer]);
|
|
249
255
|
}
|
|
250
256
|
catch (error) {
|
|
251
257
|
console.error(`Error reading from OPFS: ${error.message}`);
|
|
@@ -253,8 +259,14 @@ class FileManager extends BaseFileManager {
|
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
261
|
static async readFileAsString(filePath) {
|
|
256
|
-
const
|
|
257
|
-
return
|
|
262
|
+
const blob = await this.readFileAsBuffer(filePath);
|
|
263
|
+
return blob.text();
|
|
264
|
+
}
|
|
265
|
+
static getParentDirPath(filePath) {
|
|
266
|
+
return path.dirname(filePath);
|
|
267
|
+
}
|
|
268
|
+
static getFilenameFromPath(filePath) {
|
|
269
|
+
return path.basename(filePath);
|
|
258
270
|
}
|
|
259
271
|
}
|
|
260
272
|
class CancelableInterval {
|
|
@@ -278,7 +290,7 @@ class CancelableInterval {
|
|
|
278
290
|
}
|
|
279
291
|
catch (error) {
|
|
280
292
|
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
281
|
-
|
|
293
|
+
logger('Previous task was canceled.');
|
|
282
294
|
}
|
|
283
295
|
else {
|
|
284
296
|
console.error('Task error:', error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileManager.js","sources":["../../../../../src/browser/helpers/FileManager.ts"],"sourcesContent":["import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { FileDownloader } from '../workers/FileDownloader'\nimport { ImageResizer } from '../workers/ImageResizer'\nimport debug from 'debug'\n\nconst logger = debug('seedSdk:browser:helpers:FileManager')\n\nclass FileManager extends BaseFileManager {\n\n static async getFs() {\n const fs = await import('@zenfs/core')\n return fs\n }\n\n static async getContentUrlFromPath( path: string ): Promise<string | undefined> {\n\n const fileExists = await this.pathExists(path)\n if ( fileExists ) {\n const file = await this.readFile(path)\n return URL.createObjectURL(file)\n }\n }\n\n static async initializeFileSystem(): Promise<void> {\n\n const fs = await this.getFs()\n const {WebAccess} = await import('@zenfs/dom')\n const {configureSingle} = fs\n\n const handle = await navigator.storage.getDirectory()\n // await configure({\n // mounts: {\n // '/': {\n // backend: WebAccess,\n // handle,\n // },\n // },\n // disableUpdateOnRead: true,\n // onlySyncOnClose: true,\n // })\n await configureSingle({\n backend: WebAccess,\n handle,\n })\n }\n\n static async downloadAllFiles( {\n transactionIds,\n arweaveHost,\n excludedTransactions,\n }: DownloadAllFilesParams ): Promise<void> {\n const fileDownloader = new FileDownloader()\n await fileDownloader.downloadAll({ transactionIds, arweaveHost, excludedTransactions })\n }\n\n static async resizeImage( { filePath, width, height }: ResizeImageParams ): Promise<void> {\n const imageResizer = new ImageResizer()\n await imageResizer.resize({ filePath, width, height })\n }\n\n static async resizeAllImages( { width, height }: ResizeAllImagesParams ): Promise<void> {\n const imageResizer = new ImageResizer()\n await imageResizer.resizeAll({ width, height })\n }\n\n static async pathExists(filePath: string): Promise<boolean> {\n try {\n // Access the root directory of OPFS\n const root = await navigator.storage.getDirectory();\n \n // Split the path into segments\n const parts = filePath.split('/').filter(Boolean);\n let currentDir = root;\n\n // Traverse each part of the path\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n try {\n const handle = await currentDir.getDirectoryHandle(part, { create: false });\n currentDir = handle; // Move into the directory\n } catch (error) {\n try {\n // If it's not a directory, check if it's a file\n await currentDir.getFileHandle(part, { create: false });\n // If we successfully got a file handle and it's the last part, return true\n return i === parts.length - 1;\n } catch {\n // Neither a directory nor a file exists\n return false;\n }\n }\n }\n\n return true; // Directory exists\n } catch (error) {\n return false; // Any error means the path does not exist\n }\n }\n\n static async createDirIfNotExists(filePath: string): Promise<void> {\n if (!(await this.pathExists(filePath))) {\n try {\n const fs = await this.getFs()\n await fs.promises.mkdir(filePath)\n } catch (error) {\n // This is a no-op. We tried to create a directory that already exists.\n logger('Attempted to create a directory that already exists')\n }\n }\n }\n\n /**\n * Waits for a file to exist at the specified path.\n * @param {string} filePath - The path of the file to check.\n * @param {number} interval - The interval in milliseconds between checks (default: 500ms).\n * @param {number} timeout - The timeout in milliseconds to wait for the file to exist (default: 10s).\n * @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.\n */\n static async waitForFile(filePath: string, interval: number = 1000, timeout: number = 60000): Promise<boolean> {\n\n const fs = await this.getFs()\n const fsNode = await import('node:fs')\n\n return new Promise((resolve, reject) => {\n const startTime = Date.now()\n \n let isBusy = false\n\n const cancelableInterval = new CancelableInterval(async (stop) => {\n logger('waitForFile', filePath)\n if (isBusy) {\n return\n }\n isBusy = true\n // TODO: Needs to read from OPFS\n if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {\n stop()\n resolve(true)\n }\n\n const pathExists = await this.pathExists(filePath)\n if (pathExists) {\n stop()\n resolve(true)\n }\n\n if (Date.now() - startTime >= timeout) {\n stop()\n reject(new Error('Timeout exceeded while waiting for file'))\n }\n isBusy = false\n }, interval)\n\n cancelableInterval.start()\n \n // const _interval = setInterval(async () => {\n // logger('waitForFile', filePath)\n // if (isBusy) {\n // return\n // }\n // isBusy = true\n // // TODO: Needs to read from OPFS\n // if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {\n // clearInterval(_interval)\n // resolve(true)\n // }\n\n // const pathExists = await this.pathExists(filePath)\n // if (pathExists) {\n // clearInterval(_interval)\n // resolve(true)\n // }\n\n // if (Date.now() - startTime >= timeout) {\n // clearInterval(_interval)\n // reject(new Error('Timeout exceeded while waiting for file'))\n // }\n // isBusy = false\n // }, interval)\n \n // retry(\n // {\n // times: Math.ceil(timeout / interval),\n // interval: interval,\n // },\n // (callback: Function) => {\n // if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {\n // return callback(null, true) // File exists, finish with success\n // }\n // if (Date.now() - startTime >= timeout) {\n // return callback(new Error('Timeout exceeded while waiting for file'))\n // }\n // callback(new Error('File does not exist yet')) // Retry with this error\n // },\n // (err: Error, result: boolean) => {\n // if (err) {\n // return resolve(false) // Resolve as false if timeout or error occurs\n // }\n // resolve(result) // Resolve as true if file exists\n // },\n // )\n })\n }\n\n static async saveFile(filePath: string, content: string | Blob | ArrayBuffer): Promise<void> {\n try {\n // Get a handle to the OPFS root directory\n const root = await navigator.storage.getDirectory();\n \n // Split the file path into directory and file name\n const pathParts = filePath.split('/');\n const fileName = pathParts.pop();\n if (!fileName) throw new Error('Invalid file path');\n\n // Traverse directories and create them if they don't exist\n let currentDir = root;\n for (const part of pathParts) {\n if (part !== '') {\n currentDir = await currentDir.getDirectoryHandle(part, { create: true });\n }\n }\n\n // Get the file handle and create the file if it doesn't exist\n const fileHandle = await currentDir.getFileHandle(fileName, { create: true });\n\n // Create a writable stream and write the content\n const writable = await fileHandle.createWritable();\n \n if (typeof content === 'string' || content instanceof Uint8Array) {\n await writable.write(content);\n } else if (content instanceof Blob) {\n await writable.write(content);\n } else if (content instanceof ArrayBuffer) {\n await writable.write(new Blob([content]));\n } else {\n throw new Error('Unsupported content type');\n }\n\n await writable.close();\n logger(`File written successfully: ${filePath}`);\n } catch (error) {\n console.error(`Error writing to OPFS: ${error.message}`);\n }\n }\n\n static async readFile(filePath: string): Promise<File> {\n try {\n // Get a handle to the OPFS root directory\n const root = await navigator.storage.getDirectory();\n \n // Split the file path into directory and file name\n const pathParts = filePath.split('/');\n const fileName = pathParts.pop();\n if (!fileName) throw new Error('Invalid file path');\n \n // Traverse directories to reach the target file\n let currentDir = root;\n for (const part of pathParts) {\n if (part !== '') {\n currentDir = await currentDir.getDirectoryHandle(part, { create: false });\n }\n }\n \n // Get the file handle\n const fileHandle = await currentDir.getFileHandle(fileName, { create: false });\n \n // Get the file and read it as an ArrayBuffer\n return await fileHandle.getFile();\n } catch (error) {\n console.error(`Error reading from OPFS: ${error.message}`);\n throw error;\n }\n }\n\n static async readFileAsBuffer(filePath: string): Promise<Buffer> {\n try {\n\n // Get the file and read it as an ArrayBuffer\n const file = await this.readFile(filePath)\n const arrayBuffer = await file.arrayBuffer();\n\n // Convert ArrayBuffer to Buffer\n return Buffer.from(arrayBuffer);\n } catch (error) {\n console.error(`Error reading from OPFS: ${error.message}`);\n throw error;\n }\n }\n\n static async readFileAsString(filePath: string): Promise<string> {\n const buffer = await this.readFileAsBuffer(filePath)\n return buffer.toString('utf-8')\n }\n}\n\ntype AsyncTask = (stop: () => void) => Promise<void>\n\n\nclass CancelableInterval {\n private intervalId: number | null = null;\n private currentTaskAbortController: AbortController | null = null;\n\n constructor(private task: AsyncTask, private interval: number) {}\n\n start() {\n this.intervalId = window.setInterval(async () => {\n if (this.currentTaskAbortController) {\n // Cancel the previous running task\n this.currentTaskAbortController.abort();\n }\n\n // Create a new abort controller for the current task\n this.currentTaskAbortController = new AbortController();\n const signal = this.currentTaskAbortController.signal;\n\n try {\n await this.taskWithCancellation(signal);\n } catch (error) {\n if (error instanceof DOMException && error.name === 'AbortError') {\n console.log('Previous task was canceled.');\n } else {\n console.error('Task error:', error);\n }\n this.stop()\n }\n }, this.interval);\n }\n\n private async taskWithCancellation(signal: AbortSignal) {\n await this.task(() => this.stop())\n if (signal.aborted) {\n throw new DOMException('Task was aborted', 'AbortError');\n }\n }\n\n stop() {\n if (this.intervalId !== null) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n if (this.currentTaskAbortController) {\n this.currentTaskAbortController.abort();\n }\n }\n}\n\n\nexport { FileManager }\n"],"names":[],"mappings":";;;;;AAKA,MAAM,MAAM,GAAG,KAAK,CAAC,qCAAqC,CAAC;AAE3D,MAAM,WAAY,SAAQ,eAAe,CAAA;I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AAA,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC;;gBAErC,IAAI,CAAC,IAAI,EAAE;;AAEnB,SAAC,EAAE,IAAI,CAAC,QAAQ,CAAC;;IAGb,MAAM,oBAAoB,CAAC,MAAmB,EAAA;AACpD,QAAA,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;AAClC,QAAA,IAAI,MAAM,CAAC,OAAO,EAAE;AAChB,YAAA,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,YAAY,CAAC;;;IAI9D,IAAI,GAAA;AACA,QAAA,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE;AAC1B,YAAA,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC;AAC9B,YAAA,IAAI,CAAC,UAAU,GAAG,IAAI;;AAE1B,QAAA,IAAI,IAAI,CAAC,0BAA0B,EAAE;AACjC,YAAA,IAAI,CAAC,0BAA0B,CAAC,KAAK,EAAE;;;AAGlD;;;;"}
|
|
1
|
+
{"version":3,"file":"FileManager.js","sources":["../../../../../src/browser/helpers/FileManager.ts"],"sourcesContent":["import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager'\nimport { FileDownloader } from '../workers/FileDownloader'\nimport { ImageResizer } from '../workers/ImageResizer'\nimport debug from 'debug'\nimport path from 'path-browserify'\n\nconst logger = debug('seedSdk:browser:helpers:FileManager')\n\nclass FileManager extends BaseFileManager {\n\n static async getFs() {\n const fs = await import('@zenfs/core')\n return fs\n }\n\n static async getContentUrlFromPath( path: string ): Promise<string | undefined> {\n\n const fileExists = await this.pathExists(path)\n if ( fileExists ) {\n const file = await this.readFile(path)\n return URL.createObjectURL(file)\n }\n }\n\n static async initializeFileSystem(): Promise<void> {\n\n const fs = await this.getFs()\n const {WebAccess} = await import('@zenfs/dom')\n const {configureSingle} = fs\n\n const handle = await navigator.storage.getDirectory()\n // await configure({\n // mounts: {\n // '/': {\n // backend: WebAccess,\n // handle,\n // },\n // },\n // disableUpdateOnRead: true,\n // onlySyncOnClose: true,\n // })\n await configureSingle({\n backend: WebAccess,\n handle,\n })\n }\n\n static async downloadAllFiles( {\n transactionIds,\n arweaveHost,\n excludedTransactions,\n }: DownloadAllFilesParams ): Promise<void> {\n const fileDownloader = new FileDownloader()\n await fileDownloader.downloadAll({ transactionIds, arweaveHost, excludedTransactions })\n }\n\n static async resizeImage( { filePath, width, height }: ResizeImageParams ): Promise<void> {\n const imageResizer = new ImageResizer()\n await imageResizer.resize({ filePath, width, height })\n }\n\n static async resizeAllImages( { width, height }: ResizeAllImagesParams ): Promise<void> {\n const imageResizer = new ImageResizer()\n await imageResizer.resizeAll({ width, height })\n }\n\n static async pathExists(filePath: string): Promise<boolean> {\n try {\n // Access the root directory of OPFS\n const root = await navigator.storage.getDirectory();\n \n // Split the path into segments\n const parts = filePath.split('/').filter(Boolean);\n let currentDir = root;\n\n // Traverse each part of the path\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i];\n try {\n const handle = await currentDir.getDirectoryHandle(part, { create: false });\n currentDir = handle; // Move into the directory\n } catch (error) {\n try {\n // If it's not a directory, check if it's a file\n await currentDir.getFileHandle(part, { create: false });\n // If we successfully got a file handle and it's the last part, return true\n return i === parts.length - 1;\n } catch {\n // Neither a directory nor a file exists\n return false;\n }\n }\n }\n\n return true; // Directory exists\n } catch (error) {\n return false; // Any error means the path does not exist\n }\n }\n\n static async createDirIfNotExists(filePath: string): Promise<void> {\n if (!(await this.pathExists(filePath))) {\n try {\n const fs = await this.getFs()\n await fs.promises.mkdir(filePath)\n } catch (error) {\n // This is a no-op. We tried to create a directory that already exists.\n logger('Attempted to create a directory that already exists')\n }\n }\n }\n\n /**\n * Waits for a file to exist at the specified path.\n * @param {string} filePath - The path of the file to check.\n * @param {number} interval - The interval in milliseconds between checks (default: 500ms).\n * @param {number} timeout - The timeout in milliseconds to wait for the file to exist (default: 10s).\n * @returns {Promise<boolean>} - Resolves to true if the file exists within the timeout period, otherwise false.\n */\n static async waitForFile(filePath: string, interval: number = 1000, timeout: number = 60000): Promise<boolean> {\n\n // const fs = await this.getFs()\n // const fsNode = await import('node:fs')\n const pathExists = await this.pathExists(filePath)\n\n if (pathExists) {\n return true\n }\n\n return new Promise((resolve, reject) => {\n const startTime = Date.now()\n\n let isBusy = false\n\n const cancelableInterval = new CancelableInterval(async (stop) => {\n logger('waitForFile', filePath)\n if (isBusy) {\n return\n }\n isBusy = true\n // // TODO: Needs to read from OPFS\n // const exists = await BaseFileManager.pathExists(filePath)\n // if (exists) {\n // stop()\n // resolve(true)\n // }\n\n const pathExists = await this.pathExists(filePath)\n if (pathExists) {\n stop()\n resolve(true)\n }\n\n if (Date.now() - startTime >= timeout) {\n stop()\n reject(new Error('Timeout exceeded while waiting for file'))\n }\n isBusy = false\n }, interval)\n\n cancelableInterval.start()\n \n // const _interval = setInterval(async () => {\n // logger('waitForFile', filePath)\n // if (isBusy) {\n // return\n // }\n // isBusy = true\n // // TODO: Needs to read from OPFS\n // if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {\n // clearInterval(_interval)\n // resolve(true)\n // }\n\n // const pathExists = await this.pathExists(filePath)\n // if (pathExists) {\n // clearInterval(_interval)\n // resolve(true)\n // }\n\n // if (Date.now() - startTime >= timeout) {\n // clearInterval(_interval)\n // reject(new Error('Timeout exceeded while waiting for file'))\n // }\n // isBusy = false\n // }, interval)\n \n // retry(\n // {\n // times: Math.ceil(timeout / interval),\n // interval: interval,\n // },\n // (callback: Function) => {\n // if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {\n // return callback(null, true) // File exists, finish with success\n // }\n // if (Date.now() - startTime >= timeout) {\n // return callback(new Error('Timeout exceeded while waiting for file'))\n // }\n // callback(new Error('File does not exist yet')) // Retry with this error\n // },\n // (err: Error, result: boolean) => {\n // if (err) {\n // return resolve(false) // Resolve as false if timeout or error occurs\n // }\n // resolve(result) // Resolve as true if file exists\n // },\n // )\n })\n }\n\n static async saveFile(filePath: string, content: string | Blob | ArrayBuffer): Promise<void> {\n try {\n // Get a handle to the OPFS root directory\n const root = await navigator.storage.getDirectory();\n \n // Split the file path into directory and file name\n const pathParts = filePath.split('/');\n const fileName = pathParts.pop();\n if (!fileName) throw new Error('Invalid file path');\n\n // Traverse directories and create them if they don't exist\n let currentDir = root;\n for (const part of pathParts) {\n if (part !== '') {\n currentDir = await currentDir.getDirectoryHandle(part, { create: true });\n }\n }\n\n // Get the file handle and create the file if it doesn't exist\n const fileHandle = await currentDir.getFileHandle(fileName, { create: true });\n\n // Create a writable stream and write the content\n const writable = await fileHandle.createWritable();\n \n if (typeof content === 'string' || content instanceof Uint8Array) {\n await writable.write(content);\n } else if (content instanceof Blob) {\n await writable.write(content);\n } else if (content instanceof ArrayBuffer) {\n await writable.write(new Blob([content]));\n } else {\n throw new Error('Unsupported content type');\n }\n\n await writable.close();\n logger(`File written successfully: ${filePath}`);\n } catch (error) {\n console.error(`Error writing to OPFS: ${error.message}`);\n }\n }\n\n static async readFile(filePath: string): Promise<File> {\n try {\n // Get a handle to the OPFS root directory\n const root = await navigator.storage.getDirectory();\n \n // Split the file path into directory and file name\n const pathParts = filePath.split('/');\n const fileName = pathParts.pop();\n if (!fileName) throw new Error('Invalid file path');\n \n // Traverse directories to reach the target file\n let currentDir = root;\n for (const part of pathParts) {\n if (part !== '') {\n currentDir = await currentDir.getDirectoryHandle(part, { create: false });\n }\n }\n \n // Get the file handle\n const fileHandle = await currentDir.getFileHandle(fileName, { create: false });\n \n // Get the file and read it as an ArrayBuffer\n return await fileHandle.getFile();\n } catch (error) {\n console.error(`Error reading from OPFS: ${error.message}`);\n throw error;\n }\n }\n\n static async readFileAsBuffer(filePath: string): Promise<Blob> {\n try {\n\n // Get the file and read it as an ArrayBuffer\n const file = await this.readFile(filePath)\n const arrayBuffer = await file.arrayBuffer();\n\n // Convert ArrayBuffer to Blob\n return new Blob([arrayBuffer]);\n } catch (error) {\n console.error(`Error reading from OPFS: ${error.message}`);\n throw error;\n }\n }\n\n static async readFileAsString(filePath: string): Promise<string> {\n const blob = await this.readFileAsBuffer(filePath)\n return blob.text()\n }\n\n static getParentDirPath(filePath: string): string {\n return path.dirname(filePath)\n }\n\n static getFilenameFromPath(filePath: string): string {\n return path.basename(filePath)\n }\n}\n\ntype AsyncTask = (stop: () => void) => Promise<void>\n\n\nclass CancelableInterval {\n private intervalId: number | null = null;\n private currentTaskAbortController: AbortController | null = null;\n\n constructor(private task: AsyncTask, private interval: number) {}\n\n start() {\n this.intervalId = window.setInterval(async () => {\n if (this.currentTaskAbortController) {\n // Cancel the previous running task\n this.currentTaskAbortController.abort();\n }\n\n // Create a new abort controller for the current task\n this.currentTaskAbortController = new AbortController();\n const signal = this.currentTaskAbortController.signal;\n\n try {\n await this.taskWithCancellation(signal);\n } catch (error) {\n if (error instanceof DOMException && error.name === 'AbortError') {\n logger('Previous task was canceled.');\n } else {\n console.error('Task error:', error);\n }\n this.stop()\n }\n }, this.interval);\n }\n\n private async taskWithCancellation(signal: AbortSignal) {\n await this.task(() => this.stop())\n if (signal.aborted) {\n throw new DOMException('Task was aborted', 'AbortError');\n }\n }\n\n stop() {\n if (this.intervalId !== null) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n if (this.currentTaskAbortController) {\n this.currentTaskAbortController.abort();\n }\n }\n}\n\n\nexport { FileManager }\n"],"names":[],"mappings":";;;;;;AAMA,MAAM,MAAM,GAAG,KAAK,CAAC,qCAAqC,CAAC;AAE3D,MAAM,WAAY,SAAQ,eAAe,CAAA;IAEvC,aAAa,KAAK,GAAA;AAChB,QAAA,MAAM,EAAE,GAAG,MAAM,OAAO,aAAa,CAAC;AACtC,QAAA,OAAO,EAAE;;AAGX,IAAA,aAAa,qBAAqB,CAAE,IAAY,EAAA;QAE9C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAC9C,IAAK,UAAU,EAAG;YAChB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAA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O,EAAE;AAChB,YAAA,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,YAAY,CAAC;;;IAI9D,IAAI,GAAA;AACA,QAAA,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE;AAC1B,YAAA,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC;AAC9B,YAAA,IAAI,CAAC,UAAU,GAAG,IAAI;;AAE1B,QAAA,IAAI,IAAI,CAAC,0BAA0B,EAAE;AACjC,YAAA,IAAI,CAAC,0BAA0B,CAAC,KAAK,EAAE;;;AAGlD;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Attestation, Schema } from "@/graphql/gql/graphql";
|
|
2
|
+
type GetModelSchemasFromEas = () => Promise<Schema[]>;
|
|
3
|
+
export declare const getModelSchemasFromEas: GetModelSchemasFromEas;
|
|
4
|
+
type GetItemVersionsFromEasProps = {
|
|
5
|
+
seedUids: string[];
|
|
6
|
+
};
|
|
7
|
+
type GetItemVersionsFromEas = (props: GetItemVersionsFromEasProps) => Promise<Attestation[]>;
|
|
8
|
+
export declare const getItemVersionsFromEas: GetItemVersionsFromEas;
|
|
9
|
+
type GetItemPropertiesFromEasProps = {
|
|
10
|
+
versionUids: string[];
|
|
11
|
+
};
|
|
12
|
+
type GetItemPropertiesFromEas = (props: GetItemPropertiesFromEasProps) => Promise<Attestation[]>;
|
|
13
|
+
export declare const getItemPropertiesFromEas: GetItemPropertiesFromEas;
|
|
14
|
+
type GetSchemaUidBySchemaNameProps = {
|
|
15
|
+
schemaName: string;
|
|
16
|
+
};
|
|
17
|
+
type GetSchemaUidBySchemaName = (props: GetSchemaUidBySchemaNameProps) => Promise<string>;
|
|
18
|
+
export declare const getSchemaUidBySchemaName: GetSchemaUidBySchemaName;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=eas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eas.d.ts","sourceRoot":"","sources":["../../../../src/browser/helpers/eas.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE3D,KAAK,sBAAsB,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;AAGrD,eAAO,MAAM,sBAAsB,EAAE,sBAyCpC,CAAA;AAED,KAAK,2BAA2B,GAAG;IACjC,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA;AAED,KAAK,sBAAsB,GAAG,CAC5B,KAAK,EAAE,2BAA2B,KAC/B,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;AAG3B,eAAO,MAAM,sBAAsB,EAAE,sBAiBpC,CAAA;AAED,KAAK,6BAA6B,GAAG;IACnC,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB,CAAA;AAED,KAAK,wBAAwB,GAAG,CAC9B,KAAK,EAAE,6BAA6B,KACjC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;AAE3B,eAAO,MAAM,wBAAwB,EAAE,wBAiBtC,CAAA;AAED,KAAK,6BAA6B,GAAG;IACnC,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,wBAAwB,GAAG,CAC9B,KAAK,EAAE,6BAA6B,KACjC,OAAO,CAAC,MAAM,CAAC,CAAA;AAEpB,eAAO,MAAM,wBAAwB,EAAE,wBAqBtC,CAAA"}
|