@seedprotocol/sdk 0.2.31 → 0.2.32

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 (95) hide show
  1. package/dist/{ArweaveClient-C-HZgUWJ.js → ArweaveClient-BXD_aTsx.js} +2 -2
  2. package/dist/{ArweaveClient-rTTCUjiu.js.map → ArweaveClient-BXD_aTsx.js.map} +1 -1
  3. package/dist/{ArweaveClient-rTTCUjiu.js → ArweaveClient-CkcZD_QE.js} +2 -2
  4. package/dist/{ArweaveClient-C-HZgUWJ.js.map → ArweaveClient-CkcZD_QE.js.map} +1 -1
  5. package/dist/{Db-CPpw7pPl.js → Db-BKm58Z1E.js} +11 -9
  6. package/dist/{Db-CPpw7pPl.js.map → Db-BKm58Z1E.js.map} +1 -1
  7. package/dist/Db-xO-g5pKA.js +390 -0
  8. package/dist/Db-xO-g5pKA.js.map +1 -0
  9. package/dist/{EasClient-CKv5Eyao.js → EasClient-BNwSwDTO.js} +2 -2
  10. package/dist/{EasClient-nvmz2kCc.js.map → EasClient-BNwSwDTO.js.map} +1 -1
  11. package/dist/{EasClient-nvmz2kCc.js → EasClient-epqE9aWI.js} +2 -2
  12. package/dist/{EasClient-CKv5Eyao.js.map → EasClient-epqE9aWI.js.map} +1 -1
  13. package/dist/{FileManager-EGwM_VHY.js → FileManager-CXk83EW5.js} +4 -4
  14. package/dist/FileManager-CXk83EW5.js.map +1 -0
  15. package/dist/{FileManager-Bm_fGCH1.js → FileManager-DXi-X7r5.js} +2 -2
  16. package/dist/{FileManager-Bm_fGCH1.js.map → FileManager-DXi-X7r5.js.map} +1 -1
  17. package/dist/{Item-DJFIzrGb.js → Item-DCdD-972.js} +5 -9
  18. package/dist/{Item-DJFIzrGb.js.map → Item-DCdD-972.js.map} +1 -1
  19. package/dist/{ItemProperty-DabiYJLq.js → ItemProperty-BlE3BrNc.js} +5 -9
  20. package/dist/{ItemProperty-DabiYJLq.js.map → ItemProperty-BlE3BrNc.js.map} +1 -1
  21. package/dist/{QueryClient-CkqXe8Nk.js → QueryClient-Ckl99FYC.js} +2 -2
  22. package/dist/{QueryClient-CkqXe8Nk.js.map → QueryClient-Ckl99FYC.js.map} +1 -1
  23. package/dist/{QueryClient-pzZAYWa0.js → QueryClient-Do0C7Jnt.js} +2 -2
  24. package/dist/{QueryClient-pzZAYWa0.js.map → QueryClient-Do0C7Jnt.js.map} +1 -1
  25. package/dist/bin.js +6 -5
  26. package/dist/bin.js.map +1 -1
  27. package/dist/{constants-BjOTXEgm.js → constants-BakHTrB9.js} +2 -2
  28. package/dist/{constants-BjOTXEgm.js.map → constants-BakHTrB9.js.map} +1 -1
  29. package/dist/{index-D3qJ54jj.js → index-B2ovknu0.js} +50 -292
  30. package/dist/index-B2ovknu0.js.map +1 -0
  31. package/dist/{index-MhbsovAK.js → index-D3j5ZJGe.js} +5 -9
  32. package/dist/index-D3j5ZJGe.js.map +1 -0
  33. package/dist/main.js +6 -10
  34. package/dist/main.js.map +1 -1
  35. package/dist/{seed.schema.config-DCFBkB3M.js → seed.schema.config-DQalKJ_d.js} +5 -9
  36. package/dist/seed.schema.config-DQalKJ_d.js.map +1 -0
  37. package/dist/src/BaseDb.ts +4 -0
  38. package/dist/src/BaseItem.ts +4 -0
  39. package/dist/src/Db.ts +5 -0
  40. package/dist/src/FileManager.ts +2 -2
  41. package/dist/src/IItem.ts +2 -1
  42. package/dist/src/SeedProtocolSdk.d.ts +0 -15
  43. package/dist/src/content-hash.ts +30 -0
  44. package/dist/src/create.ts +2 -2
  45. package/dist/src/download.ts +1 -1
  46. package/dist/src/getItem.ts +2 -3
  47. package/dist/src/getPublishPayload.ts +2 -8
  48. package/dist/src/image-resize.ts +28 -0
  49. package/dist/src/migrate.ts +3 -241
  50. package/dist/src/preparePublishRequestData.ts +2 -2
  51. package/dist/src/requestAll.ts +3 -3
  52. package/dist/src/saveImageSrc.ts +4 -0
  53. package/dist/src/upload.ts +2 -2
  54. package/dist/types/src/Item/BaseItem.d.ts +11 -1
  55. package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
  56. package/dist/types/src/ItemProperty/service/actors/saveValueToDb/saveImageSrc.d.ts.map +1 -1
  57. package/dist/types/src/browser/db/Db.d.ts +2 -0
  58. package/dist/types/src/browser/db/Db.d.ts.map +1 -1
  59. package/dist/types/src/browser/index.d.ts.map +1 -1
  60. package/dist/types/src/browser/react/item.d.ts +3 -2
  61. package/dist/types/src/browser/react/item.d.ts.map +1 -1
  62. package/dist/types/src/browser/workers/content-hash.d.ts +2 -0
  63. package/dist/types/src/browser/workers/content-hash.d.ts.map +1 -0
  64. package/dist/types/src/browser/workers/image-resize.d.ts +2 -0
  65. package/dist/types/src/browser/workers/image-resize.d.ts.map +1 -0
  66. package/dist/types/src/db/Db/BaseDb.d.ts +1 -0
  67. package/dist/types/src/db/Db/BaseDb.d.ts.map +1 -1
  68. package/dist/types/src/db/read/getItem.d.ts.map +1 -1
  69. package/dist/types/src/db/read/getPublishPayload.d.ts +2 -2
  70. package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
  71. package/dist/types/src/helpers/ArweaveClient/queries.d.ts.map +1 -0
  72. package/dist/types/src/helpers/index.d.ts +1 -3
  73. package/dist/types/src/helpers/index.d.ts.map +1 -1
  74. package/dist/types/src/index.d.ts +1 -0
  75. package/dist/types/src/index.d.ts.map +1 -1
  76. package/dist/types/src/interfaces/IItem.d.ts +1 -0
  77. package/dist/types/src/interfaces/IItem.d.ts.map +1 -1
  78. package/dist/types/src/node/db/Db.d.ts +3 -0
  79. package/dist/types/src/node/db/Db.d.ts.map +1 -1
  80. package/dist/types/src/services/db/actors/migrate.d.ts +0 -1
  81. package/dist/types/src/services/db/actors/migrate.d.ts.map +1 -1
  82. package/dist/types/src/types/index.d.ts +0 -31
  83. package/dist/types/src/types/index.d.ts.map +1 -1
  84. package/package.json +7 -14
  85. package/dist/Db-DW4cvius.js +0 -138
  86. package/dist/Db-DW4cvius.js.map +0 -1
  87. package/dist/FileManager-EGwM_VHY.js.map +0 -1
  88. package/dist/index-D3qJ54jj.js.map +0 -1
  89. package/dist/index-MhbsovAK.js.map +0 -1
  90. package/dist/seed.schema.config-DCFBkB3M.js.map +0 -1
  91. package/dist/src/logger.ts +0 -33
  92. package/dist/types/src/browser/arweave/queries.d.ts.map +0 -1
  93. package/dist/types/src/helpers/logger.d.ts +0 -7
  94. package/dist/types/src/helpers/logger.d.ts.map +0 -1
  95. /package/dist/types/src/{browser/arweave → helpers/ArweaveClient}/queries.d.ts +0 -0
@@ -1,31 +1,27 @@
1
- export { I as Item } from './index-D3qJ54jj.js';
1
+ export { I as Item } from './index-B2ovknu0.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
4
  import 'tslib';
5
5
  import '@sinclair/typebox';
6
+ import 'eventemitter3';
6
7
  import 'drizzle-orm';
7
8
  import 'react';
8
- import 'dayjs';
9
9
  import 'nanoid';
10
10
  import 'nanoid-dictionary';
11
11
  import '@zenfs/core';
12
12
  import 'debug';
13
13
  import 'drizzle-orm/sqlite-core';
14
- import './constants-BjOTXEgm.js';
14
+ import './constants-BakHTrB9.js';
15
15
  import '@ethereum-attestation-service/eas-sdk';
16
16
  import 'xstate';
17
17
  import 'pluralize';
18
- import 'eventemitter3';
19
18
  import 'lodash-es';
20
19
  import '@statelyai/inspect';
21
- import 'drizzle-orm/sqlite-proxy';
22
- import 'drizzle-orm/sqlite-proxy/migrator';
23
- import 'drizzle-orm/migrator';
24
20
  import 'node:fs';
25
21
  import '@zenfs/dom';
26
22
  import 'path';
27
23
  import 'arweave';
24
+ import 'rxjs';
28
25
  import 'use-immer';
29
26
  import '@xstate/react';
30
- import 'rxjs';
31
- //# sourceMappingURL=index-MhbsovAK.js.map
27
+ //# sourceMappingURL=index-D3j5ZJGe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-D3j5ZJGe.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/main.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import 'immer';
2
2
  import 'reflect-metadata';
3
- export { D as Db, d as ImageSrc, e as Item, f as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, x as client, v as eventEmitter, s as getCorrectId, t as getGlobalService, k as useCreateItem, m as useDeleteItem, n as useGlobalServiceStatus, h as useItem, j as useItemProperties, l as useItemProperty, u as useItems, p as usePersistedSnapshots, o as usePublishItem, r as useService, q as useServices, w as withSeed } from './index-D3qJ54jj.js';
3
+ export { D as Db, c as ImageSrc, d as Item, e as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, t as client, r as eventEmitter, p as getCorrectId, q as getGlobalService, h as useCreateItem, j as useDeleteItem, k as useGlobalServiceStatus, f as useItem, g as useItemProperties, i as useItemProperty, u as useItems, m as usePersistedSnapshots, l as usePublishItem, o as useService, n as useServices, s as withSeed } from './index-B2ovknu0.js';
4
+ export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-BakHTrB9.js';
4
5
  import 'tslib';
5
- import 'drizzle-orm';
6
- export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-BjOTXEgm.js';
7
6
  import '@sinclair/typebox';
7
+ import 'eventemitter3';
8
+ import 'drizzle-orm';
8
9
  import 'react';
9
- import 'dayjs';
10
10
  import 'nanoid';
11
11
  import 'nanoid-dictionary';
12
12
  import '@zenfs/core';
@@ -14,18 +14,14 @@ import 'debug';
14
14
  import 'drizzle-orm/sqlite-core';
15
15
  import 'xstate';
16
16
  import 'pluralize';
17
- import 'eventemitter3';
18
17
  import 'lodash-es';
19
18
  import '@statelyai/inspect';
20
- import 'drizzle-orm/sqlite-proxy';
21
- import 'drizzle-orm/sqlite-proxy/migrator';
22
- import 'drizzle-orm/migrator';
23
19
  import 'node:fs';
24
20
  import '@zenfs/dom';
25
21
  import 'path';
26
22
  import 'arweave';
27
- import 'use-immer';
28
- import '@xstate/react';
29
23
  import 'rxjs';
30
24
  import '@ethereum-attestation-service/eas-sdk';
25
+ import 'use-immer';
26
+ import '@xstate/react';
31
27
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"main.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,33 +1,29 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import 'reflect-metadata';
3
- import { T as Text, M as Model } from './index-D3qJ54jj.js';
3
+ import { T as Text, M as Model } from './index-B2ovknu0.js';
4
4
  import 'immer';
5
5
  import '@sinclair/typebox';
6
+ import 'eventemitter3';
6
7
  import 'drizzle-orm';
7
8
  import 'react';
8
- import 'dayjs';
9
9
  import 'nanoid';
10
10
  import 'nanoid-dictionary';
11
11
  import '@zenfs/core';
12
12
  import 'debug';
13
13
  import 'drizzle-orm/sqlite-core';
14
- import './constants-BjOTXEgm.js';
14
+ import './constants-BakHTrB9.js';
15
15
  import '@ethereum-attestation-service/eas-sdk';
16
16
  import 'xstate';
17
17
  import 'pluralize';
18
- import 'eventemitter3';
19
18
  import 'lodash-es';
20
19
  import '@statelyai/inspect';
21
- import 'drizzle-orm/sqlite-proxy';
22
- import 'drizzle-orm/sqlite-proxy/migrator';
23
- import 'drizzle-orm/migrator';
24
20
  import 'node:fs';
25
21
  import '@zenfs/dom';
26
22
  import 'path';
27
23
  import 'arweave';
24
+ import 'rxjs';
28
25
  import 'use-immer';
29
26
  import '@xstate/react';
30
- import 'rxjs';
31
27
 
32
28
  let Seed = class Seed {
33
29
  };
@@ -75,4 +71,4 @@ const models = {
75
71
  };
76
72
 
77
73
  export { models };
78
- //# sourceMappingURL=seed.schema.config-DCFBkB3M.js.map
74
+ //# sourceMappingURL=seed.schema.config-DQalKJ_d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.schema.config-DQalKJ_d.js","sources":["../../src/db/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/schema'\n\n@Model\nclass Seed {\n @Text() uid!: string\n @Text() type!: string\n}\n\n@Model\nclass Version {\n @Text() seedUid!: string\n @Text() note!: string\n}\n\n@Model\nclass Metadata {\n @Text() key!: string\n @Text() value!: string\n}\n\nexport const models = {\n Seed,\n Version,\n Metadata,\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAM,IAAI,GAAV,MAAM,IAAI,CAAA;CAGT;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,IAAI,GAAA,UAAA,CAAA;IADT;AACK,CAAA,EAAA,IAAI,CAGT;AAGD,IAAM,OAAO,GAAb,MAAM,OAAO,CAAA;CAGZ;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAiB,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,SAAA,EAAA,KAAA,CAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,CAAA,CAAA;AAFjB,OAAO,GAAA,UAAA,CAAA;IADZ;AACK,CAAA,EAAA,OAAO,CAGZ;AAGD,IAAM,QAAQ,GAAd,MAAM,QAAQ,CAAA;CAGb;AAFS,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,KAAA,CAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
@@ -28,4 +28,8 @@ export abstract class BaseDb implements IDb {
28
28
  return this.PlatformClass.connectToDb(pathToDir, dbName)
29
29
  }
30
30
 
31
+ static async migrate(pathToDbDir: string, dbName: string): Promise<void> {
32
+ return this.PlatformClass.migrate(pathToDbDir, dbName)
33
+ }
34
+
31
35
  }
@@ -388,6 +388,10 @@ export abstract class BaseItem<T extends ModelValues<ModelSchema>> implements II
388
388
  return this._propertiesSubject.value
389
389
  }
390
390
 
391
+ get attestationCreatedAt(): number {
392
+ return this.serviceContext.attestationCreatedAt as number
393
+ }
394
+
391
395
  unload(): void {
392
396
  this._subscription?.unsubscribe()
393
397
  this._service.stop()
package/dist/src/Db.ts CHANGED
@@ -66,6 +66,11 @@ class Db extends BaseDb implements IDb {
66
66
  id: drizzle(nodeDbConfig).$client.name
67
67
  }
68
68
  }
69
+
70
+ static async migrate(pathToDbDir: string, dbName: string) {
71
+ const nodeDbConfig = getConfig(pathToDbDir)
72
+ return drizzle(nodeDbConfig)
73
+ }
69
74
  }
70
75
 
71
76
  BaseDb.setPlatformClass(Db)
@@ -1,9 +1,9 @@
1
- import { promises as fs } from 'fs';
1
+ import * as fsAsync from 'fs/promises';
2
2
  import { BaseFileManager } from '@/helpers/FileManager/BaseFileManager';
3
3
 
4
4
  class FileManager extends BaseFileManager {
5
5
  static async readFileAsBuffer(filePath: string): Promise<Buffer> {
6
- return await fs.readFile(filePath);
6
+ return await fsAsync.readFile(filePath);
7
7
  }
8
8
 
9
9
  }
package/dist/src/IItem.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ActorRefFrom, Subscription } from 'xstate'
2
- import { ModelSchema, ModelValues, NewItemProps, PropertyData } from '@/types'
2
+ import { ModelSchema, ModelValues, PropertyData } from '@/types'
3
3
  import { VersionsType } from '@/seedSchema/VersionSchema'
4
4
  import { IItemProperty } from './IItemProperty'
5
5
 
@@ -19,4 +19,5 @@ export interface IItem<T extends ModelValues<ModelSchema>> {
19
19
  readonly latestVersionUid: VersionsType
20
20
  readonly modelName: string
21
21
  readonly properties: Record<string, IItemProperty<any>>
22
+ readonly attestationCreatedAt: number
22
23
  }
@@ -1,20 +1,5 @@
1
1
  export interface SeedProtocolSdk {
2
- // Exported classes
3
- Item: typeof import('@/browser/Item/Item').Item;
4
- ItemProperty: typeof import('@/browser/property/ItemProperty').ItemProperty;
5
2
 
6
- // Exported hooks
7
- useItems: typeof import('@/browser').useItems;
8
- useItem: typeof import('@/browser').useItem;
9
- useItemProperties: typeof import('@/browser').useItemProperties;
10
- useCreateItem: typeof import('@/browser').useCreateItem;
11
- useItemProperty: typeof import('@/browser').useItemProperty;
12
- useDeleteItem: typeof import('@/browser').useDeleteItem;
13
- useGlobalServiceStatus: typeof import('@/browser').useGlobalServiceStatus;
14
- useServices: typeof import('@/browser').useServices;
15
-
16
- // Exported functions
17
- getGlobalService: typeof import('@/browser').getGlobalService;
18
3
  getCorrectId: typeof import('@/helpers').getCorrectId;
19
4
 
20
5
  // Exported constants
@@ -0,0 +1,30 @@
1
+ const hashLargeString = async ( input: string, ): Promise<string> => {
2
+ // Convert the string to an ArrayBuffer
3
+ const encoder = new TextEncoder()
4
+ const data = encoder.encode(input,)
5
+
6
+ // Hash the data with SHA-256
7
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data,)
8
+
9
+ // Convert the ArrayBuffer to a hex string
10
+ const hashArray = Array.from(new Uint8Array(hashBuffer,),)
11
+ const hashHex = hashArray.map(( b, ) => b.toString(16,).padStart(2, '0',),).join('',)
12
+
13
+ return hashHex
14
+ }
15
+
16
+ onmessage = async (event,) => {
17
+ postMessage('Content hash worker received message',)
18
+ if (!event || !event.data || !event.data.trackingId || !event.data.base64) {
19
+ postMessage('No event data received',)
20
+ return
21
+ }
22
+ const { trackingId, base64, } = event.data
23
+ postMessage('Beginning content hash calculation',)
24
+ const contentHash = await hashLargeString(base64,)
25
+ postMessage('Content hash calculation complete',)
26
+ postMessage({
27
+ trackingId,
28
+ contentHash,
29
+ },)
30
+ }
@@ -1,6 +1,6 @@
1
- import { Item } from '@/browser/Item'
2
1
  import { eventEmitter } from '@/eventBus'
3
2
  import { createItemCacheKey, getItemCache, updateItemCache } from './requestAll'
3
+ import { BaseItem } from '@/Item/BaseItem'
4
4
 
5
5
  export const createItemRequestHandler = async (event) => {
6
6
  const { ModelClass, itemData } = event
@@ -18,7 +18,7 @@ export const createItemRequestHandler = async (event) => {
18
18
  return
19
19
  }
20
20
 
21
- const newItem = Item.create({
21
+ const newItem = await BaseItem.create({
22
22
  modelName: ModelClass.originalConstructor.name,
23
23
  ...itemData,
24
24
  })
@@ -16,7 +16,7 @@ import { getGlobalService } from '@/services'
16
16
  import { waitFor } from 'xstate'
17
17
  import { getMetadata } from '@/db/read/getMetadata'
18
18
  import { saveMetadata } from '@/db/write/saveMetadata'
19
- import { GET_TRANSACTION_TAGS } from '@/browser/arweave/queries'
19
+ import { GET_TRANSACTION_TAGS } from '@/helpers/ArweaveClient/queries'
20
20
  import { saveAppState } from '@/db/write/saveAppState'
21
21
  import { BaseDb } from '@/db/Db/BaseDb'
22
22
  import { BaseEasClient, BaseQueryClient, BaseArweaveClient } from '@/helpers'
@@ -1,7 +1,6 @@
1
- import { Item } from '@/browser/Item'
2
1
  import { getItemData } from './getItemData'
3
2
  import { GetItem } from '@/types'
4
-
3
+ import { BaseItem } from '@/Item/BaseItem'
5
4
 
6
5
  export const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {
7
6
  const itemInitObj = await getItemData({
@@ -24,5 +23,5 @@ export const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {
24
23
  return
25
24
  }
26
25
 
27
- return Item.create(itemInitObj)
26
+ return BaseItem.create(itemInitObj)
28
27
  }
@@ -16,10 +16,10 @@ import pluralize from 'pluralize'
16
16
  import { getSchemaUidForModel } from '@/db/read/getSchemaUidForModel'
17
17
  import { getSchemaUidForSchemaDefinition } from '@/stores/eas'
18
18
  import { getCorrectId } from '@/helpers'
19
- import { Item } from '@/browser/Item/Item'
20
19
  import { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'
21
20
  import { IItemProperty } from '@/interfaces'
22
21
  import { IItem } from '@/interfaces'
22
+ import { BaseItem } from '@/Item/BaseItem'
23
23
 
24
24
  const getVersionUid = (item: IItem<any>) => {
25
25
  let versionUid
@@ -272,15 +272,9 @@ type UploadedTransaction = {
272
272
  }
273
273
 
274
274
  export const getPublishPayload = async (
275
- item: Item<any>,
275
+ item: BaseItem<any>,
276
276
  uploadedTransactions: UploadedTransaction[],
277
277
  ): Promise<MultiPublishPayload> => {
278
- if (item.modelName === 'Post') {
279
- item.authors = [
280
- 'Sr0bIx9Fwj',
281
- '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',
282
- ]
283
- }
284
278
 
285
279
  let multiPublishPayload: MultiPublishPayload = []
286
280
 
@@ -0,0 +1,28 @@
1
+ import { readAndCompressImage, } from "@misskey-dev/browser-image-resizer";
2
+
3
+ onmessage = async (e) => {
4
+
5
+ const { filePath, width, height } = e.data;
6
+ console.log('image-resize', filePath, width, height)
7
+
8
+ const root = await navigator.storage.getDirectory();
9
+ const fileHandle = await root.getFileHandle(filePath,);
10
+
11
+ const content = await fileHandle.getFile();
12
+ const resizedBlob = await readAndCompressImage(content, { maxWidth: 300 });
13
+
14
+ // Generate new file name with dimensions appended
15
+ const fileNameParts = filePath.split('.');
16
+ const extension = fileNameParts.pop();
17
+ const baseName = fileNameParts.join('.');
18
+ const newFileName = `${baseName}_${width}x${height}.${extension}`;
19
+
20
+ // Save resized image to OPFS with new name
21
+ const outputFileHandle = await root.getFileHandle(newFileName, { create: true });
22
+ const writable = await outputFileHandle.createWritable();
23
+ await writable.write(resizedBlob);
24
+ await writable.close();
25
+
26
+ self.postMessage(`Image resized and saved as ${newFileName}`);
27
+
28
+ }
@@ -4,85 +4,14 @@ import {
4
4
  BROWSER_FS_TOP_DIR,
5
5
  DB_MIGRATING_SUCCESS,
6
6
  } from '@/services/internal/constants'
7
- import { getSqliteWasmClient, setAppDb } from '@/browser/db/sqlWasmClient'
8
- import { drizzle } from 'drizzle-orm/sqlite-proxy'
9
- import { sql } from 'drizzle-orm'
10
- import { fs } from '@zenfs/core'
11
7
  import debug from 'debug'
12
- import { migrate as drizzleMigrate } from 'drizzle-orm/sqlite-proxy/migrator'
13
- import { readMigrationFiles } from 'drizzle-orm/migrator'
14
- import * as fsNode from 'node:fs'
15
8
  import { waitForFile } from '@/helpers/files'
9
+ import { BaseDb } from '@/db/Db/BaseDb'
10
+ import fs from '@zenfs/core'
16
11
 
17
12
  const logger = debug('app:services:db:actors:migrate')
18
13
 
19
- export const dbExec = async (dbId, params, sql, dbName, retries = 2) => {
20
- const rowsToReturnRaw: SqliteWasmResult[] = []
21
- const rowsValues: string[][] = []
22
14
 
23
- const sqliteWasmClient = await getSqliteWasmClient()
24
-
25
- // For a single exec command, the callback potentially gets called several times -- once for each row.
26
- // So we need to collect all rows into a final array to return (execResult).
27
- const rowsToReturn = await new Promise((resolve, reject) => {
28
- sqliteWasmClient('exec', {
29
- dbId,
30
- sql,
31
- bind: params,
32
- callback: (result) => {
33
- // Checks if this is the final callback of the query
34
- if (!result || !result.row || !result.rowNumber) {
35
- const returnResult = []
36
- // Before returning the array, we process it to match the expected output format
37
- // const rowsToReturnProcessed = rowsToReturnRaw.reduce((acc, curr) => {
38
- // if (
39
- // Array.isArray(curr.row) &&
40
- // curr.row?.length > 0 &&
41
- // curr.columnNames.length > 0
42
- // ) {
43
- // const returnObj: ReturnObj = {
44
- // database: dbName,
45
- // }
46
- //
47
- // const values = []
48
- //
49
- // curr.columnNames.forEach((colName, index: number) => {
50
- // if (curr.row && curr.row[index]) {
51
- // returnObj[colName] = curr.row[index]
52
- // values.push(curr.row[index])
53
- // }
54
- // })
55
- // // rowsValueStrings.push(`(${values.join(', ')})`)
56
- // acc.push(returnObj)
57
- // }
58
- // return acc
59
- // }, [] as string[])
60
- for (const currRow of rowsToReturnRaw) {
61
- // const values: string[] = []
62
- // currRow.columnNames.forEach((colName, index: number) => {
63
- // if (currRow.row) {
64
- // values.push(currRow.row[index])
65
- // }
66
- // })
67
- // logger(`[db/actors] [dbExec] currRow`, currRow)
68
- returnResult.push(currRow.row)
69
- }
70
- resolve(returnResult)
71
- } else {
72
- // If not the final response, add this row to the return array
73
- rowsToReturnRaw.push(result)
74
- }
75
- },
76
- }).catch(async (error) => {
77
- reject(error)
78
- })
79
- })
80
-
81
- // logger(`[db/actors] [dbExec] rowsToReturn`, rowsToReturn)
82
- // logger(`[db/actors] [dbExec] rowsValues`, rowsValues)
83
-
84
- return rowsToReturn || []
85
- }
86
15
 
87
16
  export const migrate = fromCallback<
88
17
  EventObject,
@@ -92,8 +21,6 @@ export const migrate = fromCallback<
92
21
 
93
22
  logger('[db/actors] migrate context', context)
94
23
 
95
- const schemaGlobString = `${BROWSER_FS_TOP_DIR}/schema/*`
96
-
97
24
  let journalExists = false
98
25
 
99
26
  // const _initFs = async (): Promise<void> => {
@@ -112,15 +39,6 @@ export const migrate = fromCallback<
112
39
 
113
40
  journalExists = await fs.promises.exists(journalPath)
114
41
 
115
- const journalExistsAsync = journalExists
116
-
117
- const journalExistsSync = fs.existsSync(journalPath)
118
-
119
- const journalExistsSyncNode = fsNode.existsSync(journalPath)
120
-
121
- console.log('journalExistsAsync', journalExistsAsync)
122
- console.log('journalExistsSync', journalExistsSync)
123
- console.log('journalExistsSyncNode', journalExistsSyncNode)
124
42
 
125
43
  if (!journalExists) {
126
44
  await waitForFile(journalPath)
@@ -142,163 +60,7 @@ export const migrate = fromCallback<
142
60
  }
143
61
 
144
62
  const _migrate = async (): Promise<void> => {
145
- const drizzleDb = drizzle(
146
- async (sql, params, method) => {
147
- try {
148
- // logger(
149
- // `executing sql on ${dbName} with id: ${dbId} and method: ${method}`,
150
- // sql,
151
- // )
152
-
153
- const finalResult = await dbExec(dbId, params, sql, dbName)
154
-
155
- // logger(`finalResult with method: ${method}`, finalResult)
156
- // Drizzle always waits for {rows: string[][]} or {rows: string[]} for the return value.
157
-
158
- // When the method is get, you should return a value as {rows: string[]}.
159
- // Otherwise, you should return {rows: string[][]}.
160
-
161
- return { rows: finalResult }
162
- } catch (e: any) {
163
- console.error('Error from sqlite proxy server: ', JSON.stringify(e))
164
- return { rows: [] }
165
- }
166
- },
167
- {
168
- schema: schemaGlobString,
169
- // logger: true,
170
- },
171
- )
172
-
173
- try {
174
- const migrations = readMigrationFiles({
175
- migrationsFolder: pathToDbDir,
176
- })
177
-
178
- if (migrations.length > 0) {
179
- const incomingMigrationHashes = migrations.map(
180
- (migration) => migration.hash,
181
- )
182
-
183
- let existingMigrationHashes
184
- let rows = []
185
-
186
- try {
187
- const query = await drizzleDb.run(
188
- sql.raw(
189
- `SELECT hash, created_at
190
- FROM main.__drizzle_migrations;`,
191
- ),
192
- )
193
-
194
- rows = query.rows
195
- } catch (e) {
196
- rows = []
197
- }
198
-
199
- if (rows && rows.length > 0) {
200
- existingMigrationHashes = rows.map((row) => row[0])
201
- }
202
-
203
- if (existingMigrationHashes) {
204
- let shouldRebuildDb = false
205
- for (const existingHash of existingMigrationHashes) {
206
- if (!incomingMigrationHashes.includes(existingHash)) {
207
- shouldRebuildDb = true
208
- break
209
- }
210
- }
211
- if (shouldRebuildDb) {
212
- await fs.promises.unlink(`${pathToDbDir}/${dbName}.sqlite3`)
213
- }
214
- }
215
- }
216
-
217
- await drizzleMigrate(
218
- drizzleDb,
219
- async (queriesToRun) => {
220
- // logger('queriesToRun', queriesToRun)
221
- for (const query of queriesToRun) {
222
- // logger('query', query)
223
- await drizzleDb.run(sql.raw(query))
224
- }
225
- },
226
- {
227
- migrationsFolder: pathToDbDir,
228
- },
229
- )
230
- } catch (error) {
231
- // console.error('Error migrating database: ', error)
232
- // window.location.reload()
233
- // const handle = await navigator.storage.getDirectory()
234
- //
235
- // await configureSingle({
236
- // backend: WebAccess,
237
- // handle,
238
- // })
239
-
240
- await waitForFile(`${pathToDbDir}/meta/_journal.json`)
241
-
242
- return _migrate()
243
- }
244
-
245
- setAppDb(drizzleDb)
246
- // const createTempTableQuery = await appDb.run(
247
- // sql.raw(
248
- // `CREATE TEMP TABLE IF NOT EXISTS temp_last_inserted_id (id INTEGER, table TEXT);`,
249
- // ),
250
- // )
251
- //
252
- // logger(
253
- // '[db/actors] [migrate] createTempTableQuery',
254
- // createTempTableQuery,
255
- // )
256
-
257
- // const triggersQuery = await appDb.run(
258
- // sql.raw(
259
- // `SELECT name
260
- // FROM main.sqlite_master
261
- // WHERE type = 'trigger';`,
262
- // ),
263
- // )
264
- //
265
- // logger('[db/actors] [migrate] triggersQuery', triggersQuery)
266
- //
267
- // const triggers = triggersQuery.rows.map((row) => row[0])
268
- //
269
- // const tablesQuery = await appDb.run(
270
- // sql.raw(
271
- // `SELECT name
272
- // FROM main.sqlite_master
273
- // WHERE type = 'table';`,
274
- // ),
275
- // )
276
- //
277
- // logger('[db/actors] [migrate] tablesQuery', tablesQuery)
278
- //
279
- // const tableNames = tablesQuery.rows.map((row) => row[0])
280
- // logger('[db/actors] [migrate] tableNames', tableNames)
281
- // for (const tableName of tableNames) {
282
- // const triggerName = `after_insert_${tableName}`
283
- // if (triggers.includes(triggerName)) {
284
- // continue
285
- // }
286
- // const createTriggerQuery = await appDb.run(
287
- // sql.raw(
288
- // `CREATE TRIGGER after_insert_${tableName}
289
- // AFTER INSERT ON ${tableName}
290
- // BEGIN
291
- // DELETE FROM temp_last_inserted_id;
292
- // INSERT INTO temp_last_inserted_id (id) VALUES (new.id);
293
- // END;`,
294
- // ),
295
- // )
296
- //
297
- // logger(
298
- // '[db/actors] [migrate] createTriggerQuery',
299
- // createTriggerQuery,
300
- // )
301
- // }
63
+ await BaseDb.migrate(pathToDbDir, dbName)
302
64
  }
303
65
 
304
66
  _checkForFiles()
@@ -1,10 +1,10 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
2
  import { FromCallbackInput, PublishMachineContext } from '@/types'
3
- import { Item } from '@/browser/Item'
4
3
  import { models as modelsTable, modelUids } from '@/seedSchema'
5
4
  import { BaseDb } from '@/db/Db/BaseDb'
6
5
  import { eq } from 'drizzle-orm'
7
6
  import { getModelSchemas } from '@/db/read/getModelSchemas'
7
+ import { BaseItem } from '@/Item/BaseItem'
8
8
 
9
9
  export const preparePublishRequestData = fromCallback<
10
10
  EventObject,
@@ -13,7 +13,7 @@ export const preparePublishRequestData = fromCallback<
13
13
  const { localId } = context
14
14
 
15
15
  const _preparePublishRequestData = async () => {
16
- const item = await Item.find({ seedLocalId: localId })
16
+ const item = await BaseItem.find({ seedLocalId: localId })
17
17
 
18
18
  if (!item) {
19
19
  return false
@@ -1,12 +1,12 @@
1
1
  import { eventEmitter } from '@/eventBus'
2
- import { Item } from '@/browser/Item'
3
2
  import { getItemsData } from '@/db/read/getItems'
4
3
  import debug from 'debug'
5
4
  import { getModel } from '@/stores/modelClass'
5
+ import { BaseItem } from '@/Item/BaseItem'
6
6
 
7
7
  const logger = debug('app:events:requestAll')
8
8
 
9
- const cache = new Map<string, Map<string, Item<any>>>()
9
+ const cache = new Map<string, Map<string, BaseItem<any>>>()
10
10
 
11
11
  let modelCount = 0
12
12
 
@@ -44,7 +44,7 @@ const handleRequestAll = async (event) => {
44
44
 
45
45
  for (const itemData of itemsData) {
46
46
  returnItems.push(
47
- await Item.create({
47
+ await BaseItem.create({
48
48
  ...itemData,
49
49
  modelName,
50
50
  }),