@seedprotocol/sdk 0.2.45 → 0.2.46

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 (80) hide show
  1. package/dist/{Db-BlgPVb_Z.js → Db-5C5VqRWb.js} +5 -2
  2. package/dist/Db-5C5VqRWb.js.map +1 -0
  3. package/dist/{Db-gw_uZA_e.js → Db-Dv890NJZ.js} +4 -3
  4. package/dist/{Db-gw_uZA_e.js.map → Db-Dv890NJZ.js.map} +1 -1
  5. package/dist/{FileManager-BNqJl6Bz.js → FileManager-AhAsy_F_.js} +20 -7
  6. package/dist/{FileManager-BNqJl6Bz.js.map → FileManager-AhAsy_F_.js.map} +1 -1
  7. package/dist/{Item-BO38NUjz.js → Item-BmPvgaG4.js} +4 -3
  8. package/dist/{Item-BO38NUjz.js.map → Item-BmPvgaG4.js.map} +1 -1
  9. package/dist/{ItemProperty-8H7B05zy.js → ItemProperty-BW4k1h0o.js} +4 -3
  10. package/dist/{ItemProperty-8H7B05zy.js.map → ItemProperty-BW4k1h0o.js.map} +1 -1
  11. package/dist/{index-CsbUKGXp.js → index-CGeSKilQ.js} +189 -144
  12. package/dist/index-CGeSKilQ.js.map +1 -0
  13. package/dist/{index-Km3L1_LR.js → index-CPxn1SR4.js} +4 -3
  14. package/dist/index-CPxn1SR4.js.map +1 -0
  15. package/dist/main.js +3 -2
  16. package/dist/main.js.map +1 -1
  17. package/dist/{seed.schema.config-Dn_1QbD7.js → seed.schema.config-BXWvwsZQ.js} +10 -9
  18. package/dist/seed.schema.config-BXWvwsZQ.js.map +1 -0
  19. package/dist/src/BaseItem.ts +1 -1
  20. package/dist/src/BaseItemProperty.ts +7 -6
  21. package/dist/src/actors.ts +1 -1
  22. package/dist/src/client.ts +12 -0
  23. package/dist/src/configureFs.ts +1 -1
  24. package/dist/src/createMetadata.ts +11 -4
  25. package/dist/src/download.ts +1 -1
  26. package/dist/src/files.ts +15 -4
  27. package/dist/src/getItemProperties.ts +9 -19
  28. package/dist/src/getPublishPayload.ts +15 -8
  29. package/dist/src/getPublishUploads.ts +1 -1
  30. package/dist/src/gql.ts +9 -4
  31. package/dist/src/graphql.ts +12 -4
  32. package/dist/src/helpers.ts +14 -3
  33. package/dist/src/hydrateFromDb.ts +1 -1
  34. package/dist/src/metadataLatest.ts +34 -0
  35. package/dist/src/migrate.ts +1 -1
  36. package/dist/src/property.ts +10 -7
  37. package/dist/src/resolveRelatedValue.ts +1 -1
  38. package/dist/src/resolveRemoteStorage.ts +1 -1
  39. package/dist/src/saveImageSrc.ts +2 -2
  40. package/dist/src/saveItemStorage.ts +1 -1
  41. package/dist/src/updateItemPropertyValue.ts +1 -1
  42. package/dist/src/validate.ts +1 -1
  43. package/dist/src/waitForDb.ts +12 -9
  44. package/dist/types/src/Item/queries.d.ts +2 -2
  45. package/dist/types/src/Item/queries.d.ts.map +1 -1
  46. package/dist/types/src/Item/service/actors/fetchDataFromEas.d.ts +1 -2
  47. package/dist/types/src/Item/service/actors/fetchDataFromEas.d.ts.map +1 -1
  48. package/dist/types/src/Item/service/actors/waitForDb.d.ts +3 -1
  49. package/dist/types/src/Item/service/actors/waitForDb.d.ts.map +1 -1
  50. package/dist/types/src/ItemProperty/BaseItemProperty.d.ts +1 -1
  51. package/dist/types/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
  52. package/dist/types/src/ItemProperty/service/actors/waitForDb.d.ts.map +1 -1
  53. package/dist/types/src/ItemProperty/service/propertyMachine.d.ts +6 -6
  54. package/dist/types/src/browser/db/Db.d.ts.map +1 -1
  55. package/dist/types/src/browser/helpers/FileManager.d.ts.map +1 -1
  56. package/dist/types/src/browser/react/property.d.ts +1 -1
  57. package/dist/types/src/browser/react/property.d.ts.map +1 -1
  58. package/dist/types/src/client.d.ts +1 -0
  59. package/dist/types/src/client.d.ts.map +1 -1
  60. package/dist/types/src/db/read/getItemProperties.d.ts.map +1 -1
  61. package/dist/types/src/db/read/getPublishPayload.d.ts.map +1 -1
  62. package/dist/types/src/db/read/subqueries/metadataLatest.d.ts +5 -0
  63. package/dist/types/src/db/read/subqueries/metadataLatest.d.ts.map +1 -0
  64. package/dist/types/src/db/write/createMetadata.d.ts.map +1 -1
  65. package/dist/types/src/graphql/gql/gql.d.ts +12 -5
  66. package/dist/types/src/graphql/gql/gql.d.ts.map +1 -1
  67. package/dist/types/src/graphql/gql/graphql.d.ts +31 -15
  68. package/dist/types/src/graphql/gql/graphql.d.ts.map +1 -1
  69. package/dist/types/src/helpers/files.d.ts.map +1 -1
  70. package/dist/types/src/schema/file/queries.d.ts.map +1 -1
  71. package/dist/types/src/schema/model/index.d.ts.map +1 -1
  72. package/dist/types/src/services/global/globalMachine.d.ts +90 -90
  73. package/dist/types/src/services/internal/helpers.d.ts.map +1 -1
  74. package/package.json +3 -3
  75. package/dist/Db-BlgPVb_Z.js.map +0 -1
  76. package/dist/index-CsbUKGXp.js.map +0 -1
  77. package/dist/index-Km3L1_LR.js.map +0 -1
  78. package/dist/seed.schema.config-Dn_1QbD7.js.map +0 -1
  79. package/dist/types/src/Item/service/actors/saveDataToDb.d.ts +0 -3
  80. package/dist/types/src/Item/service/actors/saveDataToDb.d.ts.map +0 -1
@@ -1,10 +1,11 @@
1
- export { I as Item } from './index-CsbUKGXp.js';
1
+ export { I as Item } from './index-CGeSKilQ.js';
2
2
  import 'immer';
3
3
  import 'reflect-metadata';
4
4
  import '@sinclair/typebox';
5
5
  import 'xstate';
6
6
  import './constants-Dgv-tSO3.js';
7
7
  import '@ethereum-attestation-service/eas-sdk';
8
+ import 'debug';
8
9
  import 'pluralize';
9
10
  import 'drizzle-orm/sqlite-core';
10
11
  import 'drizzle-orm';
@@ -12,14 +13,14 @@ import 'eventemitter3';
12
13
  import 'nanoid';
13
14
  import 'nanoid-dictionary';
14
15
  import '@zenfs/core';
15
- import 'debug';
16
16
  import 'lodash-es';
17
17
  import '@statelyai/inspect';
18
18
  import 'node:fs';
19
19
  import 'path';
20
20
  import 'arweave';
21
21
  import 'rxjs';
22
+ import 'drizzle-orm/casing';
22
23
  import 'react';
23
24
  import 'use-immer';
24
25
  import '@xstate/react';
25
- //# sourceMappingURL=index-Km3L1_LR.js.map
26
+ //# sourceMappingURL=index-CPxn1SR4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CPxn1SR4.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/main.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import 'immer';
2
2
  import 'reflect-metadata';
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, v 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, t as withSeed } from './index-CsbUKGXp.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, v 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, t as withSeed } from './index-CGeSKilQ.js';
4
4
  export { B as BaseArweaveClient, a as BaseEasClient, c as BaseFileManager, b as BaseQueryClient } from './constants-Dgv-tSO3.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'xstate';
7
+ import 'debug';
7
8
  import 'pluralize';
8
9
  import 'drizzle-orm/sqlite-core';
9
10
  import 'drizzle-orm';
@@ -11,13 +12,13 @@ import 'eventemitter3';
11
12
  import 'nanoid';
12
13
  import 'nanoid-dictionary';
13
14
  import '@zenfs/core';
14
- import 'debug';
15
15
  import 'lodash-es';
16
16
  import '@statelyai/inspect';
17
17
  import 'node:fs';
18
18
  import 'path';
19
19
  import 'arweave';
20
20
  import 'rxjs';
21
+ import 'drizzle-orm/casing';
21
22
  import '@ethereum-attestation-service/eas-sdk';
22
23
  import 'react';
23
24
  import 'use-immer';
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,11 +1,12 @@
1
1
  import { __decorate, __metadata } from 'tslib';
2
2
  import 'reflect-metadata';
3
- import { T as Text, M as Model } from './index-CsbUKGXp.js';
3
+ import { T as Text, M as Model } from './index-CGeSKilQ.js';
4
4
  import 'immer';
5
5
  import '@sinclair/typebox';
6
6
  import 'xstate';
7
7
  import './constants-Dgv-tSO3.js';
8
8
  import '@ethereum-attestation-service/eas-sdk';
9
+ import 'debug';
9
10
  import 'pluralize';
10
11
  import 'drizzle-orm/sqlite-core';
11
12
  import 'drizzle-orm';
@@ -13,13 +14,13 @@ import 'eventemitter3';
13
14
  import 'nanoid';
14
15
  import 'nanoid-dictionary';
15
16
  import '@zenfs/core';
16
- import 'debug';
17
17
  import 'lodash-es';
18
18
  import '@statelyai/inspect';
19
19
  import 'node:fs';
20
20
  import 'path';
21
21
  import 'arweave';
22
22
  import 'rxjs';
23
+ import 'drizzle-orm/casing';
23
24
  import 'react';
24
25
  import 'use-immer';
25
26
  import '@xstate/react';
@@ -29,11 +30,11 @@ let Seed = class Seed {
29
30
  __decorate([
30
31
  Text(),
31
32
  __metadata("design:type", String)
32
- ], Seed.prototype, "uid", void 0);
33
+ ], Seed.prototype, "uid", undefined);
33
34
  __decorate([
34
35
  Text(),
35
36
  __metadata("design:type", String)
36
- ], Seed.prototype, "type", void 0);
37
+ ], Seed.prototype, "type", undefined);
37
38
  Seed = __decorate([
38
39
  Model
39
40
  ], Seed);
@@ -42,11 +43,11 @@ let Version = class Version {
42
43
  __decorate([
43
44
  Text(),
44
45
  __metadata("design:type", String)
45
- ], Version.prototype, "seedUid", void 0);
46
+ ], Version.prototype, "seedUid", undefined);
46
47
  __decorate([
47
48
  Text(),
48
49
  __metadata("design:type", String)
49
- ], Version.prototype, "note", void 0);
50
+ ], Version.prototype, "note", undefined);
50
51
  Version = __decorate([
51
52
  Model
52
53
  ], Version);
@@ -55,11 +56,11 @@ let Metadata = class Metadata {
55
56
  __decorate([
56
57
  Text(),
57
58
  __metadata("design:type", String)
58
- ], Metadata.prototype, "key", void 0);
59
+ ], Metadata.prototype, "key", undefined);
59
60
  __decorate([
60
61
  Text(),
61
62
  __metadata("design:type", String)
62
- ], Metadata.prototype, "value", void 0);
63
+ ], Metadata.prototype, "value", undefined);
63
64
  Metadata = __decorate([
64
65
  Model
65
66
  ], Metadata);
@@ -70,4 +71,4 @@ const models = {
70
71
  };
71
72
 
72
73
  export { models };
73
- //# sourceMappingURL=seed.schema.config-Dn_1QbD7.js.map
74
+ //# sourceMappingURL=seed.schema.config-BXWvwsZQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.schema.config-BXWvwsZQ.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,SAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,IAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,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,SAAA,CAAA;AAChB,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAc,CAAA,EAAA,OAAA,CAAA,SAAA,EAAA,MAAA,EAAA,SAAA,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,SAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAe,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,SAAA,CAAA;AAFlB,QAAQ,GAAA,UAAA,CAAA;IADb;AACK,CAAA,EAAA,QAAQ,CAGb;AAEY,MAAA,MAAM,GAAG;IACpB,IAAI;IACJ,OAAO;IACP,QAAQ;;;;;"}
@@ -110,7 +110,7 @@ export abstract class BaseItem<T extends ModelValues<ModelSchema>> implements II
110
110
  }
111
111
 
112
112
  this._propertiesSubject.next(propertiesObj)
113
- eventEmitter.emit(`item.${modelName}.${seedUid || seedLocalId}.update`)
113
+ // eventEmitter.emit(`item.${modelName}.${seedUid || seedLocalId}.update`)
114
114
  })
115
115
 
116
116
  this._service.start()
@@ -201,12 +201,13 @@ export abstract class BaseItemProperty<PropertyType> implements IItemProperty<Pr
201
201
  }
202
202
 
203
203
  this._subject.next(renderValue)
204
- if (context.seedLocalId) {
205
- eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
206
- }
207
- if (context.seedUid) {
208
- eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
209
- }
204
+ // TODO: Maybe have this only update the property?
205
+ // if (context.seedLocalId) {
206
+ // eventEmitter.emit(`item.${modelName}.${context.seedLocalId}.update`)
207
+ // }
208
+ // if (context.seedUid) {
209
+ // eventEmitter.emit(`item.${modelName}.${context.seedUid}.update`)
210
+ // }
210
211
  },
211
212
  )
212
213
 
@@ -3,7 +3,7 @@ import { fetchAllFilesMachine } from '@/schema/file/fetchAll/index'
3
3
  import { ARWEAVE_HOST } from '@/services/internal/constants'
4
4
  import { GET_FILES_METADATA } from '@/schema/file/queries'
5
5
  import { getArweave } from '@/helpers/ArweaveClient'
6
- import { fs } from '@zenfs/core'
6
+ import fs from '@zenfs/core'
7
7
  import {
8
8
  getDataTypeFromString,
9
9
  getMimeType,
@@ -18,9 +18,21 @@ import { initEasClient } from './helpers/EasClient'
18
18
  import { initQueryClient } from './helpers/QueryClient'
19
19
  import { initFileManager } from './helpers/FileManager'
20
20
  import { initDb } from './db/Db'
21
+ import debug from 'debug'
22
+
23
+ const logger = debug('app:client')
21
24
 
22
25
  const client = {
26
+ isInitialized: false,
23
27
  init: async (options: SeedConstructorOptions) => {
28
+ logger('init client')
29
+
30
+ if (client.isInitialized) {
31
+ return
32
+ }
33
+
34
+ client.isInitialized = true
35
+
24
36
  const { config, addresses } = options
25
37
 
26
38
  await initItem()
@@ -6,7 +6,7 @@ import {
6
6
  DB_WAITING_FOR_FILES_RECEIVED,
7
7
  INTERNAL_CONFIGURING_FS_SUCCESS,
8
8
  } from '@/services/internal/constants'
9
- import { fs } from '@zenfs/core'
9
+ import fs from '@zenfs/core'
10
10
  import debug from 'debug'
11
11
  import { FromCallbackInput, InternalMachineContext } from '@/types'
12
12
 
@@ -2,8 +2,10 @@ import { metadata, MetadataType } from '@/seedSchema'
2
2
  import { BaseEasClient, BaseQueryClient, generateId } from '@/helpers'
3
3
  import { PropertyType } from '@/types'
4
4
  import { BaseDb } from '../Db/BaseDb'
5
- import { GET_SCHEMA_BY_NAME, GET_SCHEMAS } from '@/Item/queries'
5
+ import { GET_SCHEMA_BY_NAME, } from '@/Item/queries'
6
6
  import { INTERNAL_DATA_TYPES } from '@/helpers/constants'
7
+ import { toSnakeCase } from 'drizzle-orm/casing'
8
+ import { Schema } from '@/graphql/gql/graphql'
7
9
 
8
10
  type CreateMetadata = (
9
11
  metadataValues: Partial<MetadataType>,
@@ -38,20 +40,25 @@ export const createMetadata: CreateMetadata = async (
38
40
  const easClient = BaseEasClient.getEasClient()
39
41
 
40
42
  const easDataType = INTERNAL_DATA_TYPES[propertyRecordSchema.dataType].eas
43
+
44
+ const propertyNameSnakeCase = toSnakeCase(metadataValues.propertyName)
41
45
 
42
46
  const queryResult = await queryClient.fetchQuery({
43
47
  queryKey: [`getSchemaByName${metadataValues.propertyName}`],
44
- queryFn: async () =>
48
+ queryFn: async (): Promise<{schemas: Schema[]}> =>
45
49
  easClient.request(GET_SCHEMA_BY_NAME, {
46
50
  where: {
47
51
  schema: {
48
- equals: `${easDataType} ${metadataValues.propertyName}`,
52
+ equals: `${easDataType} ${propertyNameSnakeCase}`,
49
53
  },
50
54
  },
51
55
  }),
52
56
  })
53
57
 
54
- metadataValues.schemaUid = queryResult.data[0].schema
58
+ if (queryResult && queryResult.schemas.length > 0) {
59
+ metadataValues.schemaUid = queryResult.schemas[0].id
60
+ }
61
+
55
62
  }
56
63
 
57
64
  return appDb
@@ -1,6 +1,6 @@
1
1
  import { syncDbFiles } from '@/services/internal/helpers'
2
2
  import { eventEmitter } from '@/eventBus'
3
- import { fs } from '@zenfs/core'
3
+ import fs from '@zenfs/core'
4
4
  import { ARWEAVE_HOST } from '@/services/internal/constants'
5
5
  import { appState } from '@/seedSchema'
6
6
  import { eq } from 'drizzle-orm'
package/dist/src/files.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { fs } from '@zenfs/core'
1
+ import fs from '@zenfs/core'
2
2
  import * as fsNode from 'node:fs'
3
+ import debug from 'debug'
4
+
5
+ const logger = debug('app:helpers:files')
3
6
  // import * as retry from 'async-es/retry'
4
7
 
5
8
  export const listFilesInOPFSRoot = async () => {
@@ -28,13 +31,20 @@ export const listFilesInOPFSRoot = async () => {
28
31
  */
29
32
  export const waitForFile = (
30
33
  filePath: string,
31
- interval: number = 500,
32
- timeout: number = 10000,
34
+ interval: number = 1000,
35
+ timeout: number = 60000,
33
36
  ): Promise<boolean> => {
34
37
  return new Promise((resolve, reject) => {
35
38
  const startTime = Date.now()
36
39
 
37
- const _interval = setInterval(() => {
40
+ let isBusy = false
41
+
42
+ const _interval = setInterval(async () => {
43
+ logger('waitForFile', filePath)
44
+ if (isBusy) {
45
+ return
46
+ }
47
+ isBusy = true
38
48
  if (fs.existsSync(filePath) && fsNode.existsSync(filePath)) {
39
49
  clearInterval(_interval)
40
50
  resolve(true)
@@ -43,6 +53,7 @@ export const waitForFile = (
43
53
  clearInterval(_interval)
44
54
  reject(new Error('Timeout exceeded while waiting for file'))
45
55
  }
56
+ isBusy = false
46
57
  }, interval)
47
58
 
48
59
  // retry(
@@ -1,7 +1,8 @@
1
1
  import { GetItemProperties, PropertyData } from '@/types'
2
2
  import { metadata, seeds, versions } from '@/seedSchema'
3
- import { and, eq, getTableColumns, isNotNull, isNull, SQL } from 'drizzle-orm'
3
+ import { and, eq, getTableColumns, isNotNull, isNull, sql, SQL } from 'drizzle-orm'
4
4
  import { BaseDb } from '@/db/Db/BaseDb'
5
+ import { getMetadataLatest } from './subqueries/metadataLatest'
5
6
 
6
7
 
7
8
  export const getItemProperties: GetItemProperties = async ({
@@ -21,16 +22,7 @@ export const getItemProperties: GetItemProperties = async ({
21
22
  whereClauses.push(eq(seeds.localId, seedLocalId))
22
23
  }
23
24
 
24
- // const uidWhereClause: SQL = seedUid
25
- // ? eq(seeds.uid, seedUid)
26
- // : isNull(seeds.uid)
27
- // const localWhereClause: SQL = seedLocalId
28
- // ? eq(seeds.localId, seedLocalId)
29
- // : isNull(seeds.localId)
30
-
31
- // whereClauses.push(or(localWhereClause, uidWhereClause) as SQL)
32
25
  whereClauses.push(isNotNull(metadata.propertyName))
33
- // whereClauses.push(isNotNull(metadata.easDataType))
34
26
 
35
27
  if (typeof edited !== 'undefined') {
36
28
  if (edited) {
@@ -41,17 +33,15 @@ export const getItemProperties: GetItemProperties = async ({
41
33
  }
42
34
  }
43
35
 
44
- const metadataColumns = getTableColumns(metadata)
36
+ // const metadataColumns = getTableColumns(metadata)
37
+
38
+ const metadataLatest = getMetadataLatest({seedLocalId, seedUid})
45
39
 
46
40
  const propertiesData = await appDb
47
- .select({
48
- ...metadataColumns,
49
- })
50
- .from(seeds)
51
- .leftJoin(metadata, eq(metadata.seedLocalId, seeds.localId))
52
- .leftJoin(versions, eq(versions.localId, seeds.localId))
53
- .where(and(...whereClauses))
54
- .groupBy(metadata.propertyName)
41
+ .with(metadataLatest)
42
+ .select()
43
+ .from(metadataLatest)
44
+ .where(eq(metadataLatest.rowNum, 1))
55
45
 
56
46
  return propertiesData.map(data => ({
57
47
  ...data,
@@ -111,6 +111,7 @@ const processRelationProperty = async (
111
111
  relationProperty: IItemProperty<any>,
112
112
  multiPublishPayload: MultiPublishPayload,
113
113
  uploadedTransactions: UploadedTransaction[],
114
+ originalSeedLocalId: string,
114
115
  ): Promise<MultiPublishPayload> => {
115
116
  const value = relationProperty.getService().getSnapshot()
116
117
  .context.propertyValue
@@ -147,7 +148,7 @@ const processRelationProperty = async (
147
148
  listOfAttestations: [],
148
149
  propertiesToUpdate: [
149
150
  {
150
- publishLocalId: relationProperty.localId,
151
+ publishLocalId: originalSeedLocalId,
151
152
  propertySchemaUid: relationProperty.schemaUid,
152
153
  },
153
154
  ],
@@ -182,6 +183,7 @@ const processRelationProperty = async (
182
183
  const processListProperty = async (
183
184
  listProperty: IItemProperty<any>,
184
185
  multiPublishPayload: MultiPublishPayload,
186
+ originalSeedLocalId: string,
185
187
  ): Promise<MultiPublishPayload> => {
186
188
  let value = listProperty.getService().getSnapshot().context.propertyValue
187
189
  if (!value || listProperty.uid) {
@@ -236,7 +238,7 @@ const processListProperty = async (
236
238
  listOfAttestations: [],
237
239
  propertiesToUpdate: [
238
240
  {
239
- publishLocalId: listProperty.localId,
241
+ publishLocalId: originalSeedLocalId,
240
242
  propertySchemaUid: listProperty.schemaUid,
241
243
  },
242
244
  ],
@@ -325,9 +327,19 @@ export const getPublishPayload = async (
325
327
  relationProperty,
326
328
  multiPublishPayload,
327
329
  uploadedTransactions,
330
+ item.seedLocalId,
328
331
  )
329
332
  itemBasicProperties.push(relationProperty)
330
333
  }
334
+
335
+ for (const listProperty of itemListProperties) {
336
+ multiPublishPayload = await processListProperty(
337
+ listProperty,
338
+ multiPublishPayload,
339
+ item.seedLocalId,
340
+ )
341
+ itemBasicProperties.push(listProperty)
342
+ }
331
343
 
332
344
  itemPublishData = await processBasicProperties(
333
345
  itemBasicProperties,
@@ -337,12 +349,7 @@ export const getPublishPayload = async (
337
349
  multiPublishPayload.push(itemPublishData)
338
350
 
339
351
 
340
- for (const listProperty of itemListProperties) {
341
- multiPublishPayload = await processListProperty(
342
- listProperty,
343
- multiPublishPayload,
344
- )
345
- }
352
+
346
353
 
347
354
  return multiPublishPayload
348
355
  }
@@ -1,7 +1,7 @@
1
1
  import Transaction from 'arweave'
2
2
  import { CreateTransactionInterface } from 'arweave/web'
3
3
  import { getArweave } from '@/helpers/ArweaveClient'
4
- import { fs } from '@zenfs/core'
4
+ import fs from '@zenfs/core'
5
5
  import { getCorrectId } from '@/helpers'
6
6
  import { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'
7
7
  import debug from 'debug'
package/dist/src/gql.ts CHANGED
@@ -14,10 +14,11 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
14
14
  * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
15
15
  */
16
16
  const documents = {
17
- "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n": types.GetTransactionTagsDocument,
18
17
  "\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n": types.AttestationFieldsFragmentDoc,
19
18
  "\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n": types.SchemaFieldsFragmentDoc,
19
+ "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n": types.GetTransactionTagsDocument,
20
20
  "\n query GetSchemas($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n": types.GetSchemasDocument,
21
+ "\n query GetSchemaByName($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n": types.GetSchemaByNameDocument,
21
22
  "\n query GetSeeds($where: AttestationWhereInput!) {\n itemSeeds: attestations(where: $where, orderBy: [{ timeCreated: desc }]) {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n timeCreated\n isOffchain\n }\n }\n": types.GetSeedsDocument,
22
23
  "\n query GetSeedIds($where: AttestationWhereInput!) {\n itemSeedIds: attestations(where: $where, orderBy: [{ timeCreated: desc }]) {\n id\n }\n }\n": types.GetSeedIdsDocument,
23
24
  "\n query GetStorageTransactionId($where: AttestationWhereInput!) {\n storageTransactionId: attestations(\n where: $where\n orderBy: [{ timeCreated: desc }]\n ) {\n id\n decodedDataJson\n }\n }\n": types.GetStorageTransactionIdDocument,
@@ -48,19 +49,23 @@ export function graphql(source: string): unknown;
48
49
  /**
49
50
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
50
51
  */
51
- export function graphql(source: "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"): (typeof documents)["\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"];
52
+ export function graphql(source: "\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"): (typeof documents)["\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"];
52
53
  /**
53
54
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
54
55
  */
55
- export function graphql(source: "\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"): (typeof documents)["\n fragment attestationFields on Attestation {\n id\n decodedDataJson\n attester\n schema {\n schemaNames {\n name\n }\n }\n refUID\n revoked\n schemaId\n txid\n timeCreated\n time\n isOffchain\n }\n"];
56
+ export function graphql(source: "\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"): (typeof documents)["\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"];
56
57
  /**
57
58
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
58
59
  */
59
- export function graphql(source: "\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"): (typeof documents)["\n fragment schemaFields on Schema {\n id\n resolver\n revocable\n schema\n index\n schemaNames {\n name\n }\n time\n txid\n creator\n }\n"];
60
+ export function graphql(source: "\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"): (typeof documents)["\n query GetTransactionTags($transactionId: ID!) {\n tags: transaction(id: $transactionId) {\n id\n tags {\n name\n value\n }\n }\n }\n"];
60
61
  /**
61
62
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
62
63
  */
63
64
  export function graphql(source: "\n query GetSchemas($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"): (typeof documents)["\n query GetSchemas($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"];
65
+ /**
66
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
67
+ */
68
+ export function graphql(source: "\n query GetSchemaByName($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"): (typeof documents)["\n query GetSchemaByName($where: SchemaWhereInput!) {\n schemas: schemata(where: $where) {\n id\n schema\n schemaNames {\n name\n }\n }\n }\n"];
64
69
  /**
65
70
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
66
71
  */
@@ -3072,6 +3072,10 @@ export type TransactionEdge = {
3072
3072
  node: Transaction;
3073
3073
  };
3074
3074
 
3075
+ export type AttestationFieldsFragment = { __typename?: 'Attestation', id: string, decodedDataJson: string, attester: string, refUID: string, revoked: boolean, schemaId: string, txid: string, timeCreated: number, time: number, isOffchain: boolean, schema: { __typename?: 'Schema', schemaNames: Array<{ __typename?: 'SchemaName', name: string }> } } & { ' $fragmentName'?: 'AttestationFieldsFragment' };
3076
+
3077
+ export type SchemaFieldsFragment = { __typename?: 'Schema', id: string, resolver: string, revocable: boolean, schema: string, index: string, time: number, txid: string, creator: string, schemaNames: Array<{ __typename?: 'SchemaName', name: string }> } & { ' $fragmentName'?: 'SchemaFieldsFragment' };
3078
+
3075
3079
  export type GetTransactionTagsQueryVariables = Exact<{
3076
3080
  transactionId: Scalars['ID']['input'];
3077
3081
  }>;
@@ -3079,10 +3083,6 @@ export type GetTransactionTagsQueryVariables = Exact<{
3079
3083
 
3080
3084
  export type GetTransactionTagsQuery = { __typename?: 'Query', tags?: { __typename?: 'Transaction', id: string, tags: Array<{ __typename?: 'Tag', name: string, value: string }> } | null };
3081
3085
 
3082
- export type AttestationFieldsFragment = { __typename?: 'Attestation', id: string, decodedDataJson: string, attester: string, refUID: string, revoked: boolean, schemaId: string, txid: string, timeCreated: number, time: number, isOffchain: boolean, schema: { __typename?: 'Schema', schemaNames: Array<{ __typename?: 'SchemaName', name: string }> } } & { ' $fragmentName'?: 'AttestationFieldsFragment' };
3083
-
3084
- export type SchemaFieldsFragment = { __typename?: 'Schema', id: string, resolver: string, revocable: boolean, schema: string, index: string, time: number, txid: string, creator: string, schemaNames: Array<{ __typename?: 'SchemaName', name: string }> } & { ' $fragmentName'?: 'SchemaFieldsFragment' };
3085
-
3086
3086
  export type GetSchemasQueryVariables = Exact<{
3087
3087
  where: SchemaWhereInput;
3088
3088
  }>;
@@ -3090,6 +3090,13 @@ export type GetSchemasQueryVariables = Exact<{
3090
3090
 
3091
3091
  export type GetSchemasQuery = { __typename?: 'Query', schemas: Array<{ __typename?: 'Schema', id: string, schema: string, schemaNames: Array<{ __typename?: 'SchemaName', name: string }> }> };
3092
3092
 
3093
+ export type GetSchemaByNameQueryVariables = Exact<{
3094
+ where: SchemaWhereInput;
3095
+ }>;
3096
+
3097
+
3098
+ export type GetSchemaByNameQuery = { __typename?: 'Query', schemas: Array<{ __typename?: 'Schema', id: string, schema: string, schemaNames: Array<{ __typename?: 'SchemaName', name: string }> }> };
3099
+
3093
3100
  export type GetSeedsQueryVariables = Exact<{
3094
3101
  where: AttestationWhereInput;
3095
3102
  }>;
@@ -3188,6 +3195,7 @@ export const AttestationFieldsFragmentDoc = {"kind":"Document","definitions":[{"
3188
3195
  export const SchemaFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"schemaFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Schema"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"resolver"}},{"kind":"Field","name":{"kind":"Name","value":"revocable"}},{"kind":"Field","name":{"kind":"Name","value":"schema"}},{"kind":"Field","name":{"kind":"Name","value":"index"}},{"kind":"Field","name":{"kind":"Name","value":"schemaNames"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"time"}},{"kind":"Field","name":{"kind":"Name","value":"txid"}},{"kind":"Field","name":{"kind":"Name","value":"creator"}}]}}]} as unknown as DocumentNode<SchemaFieldsFragment, unknown>;
3189
3196
  export const GetTransactionTagsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTransactionTags"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"transactionId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"tags"},"name":{"kind":"Name","value":"transaction"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"transactionId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"tags"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}}]}}]}}]} as unknown as DocumentNode<GetTransactionTagsQuery, GetTransactionTagsQueryVariables>;
3190
3197
  export const GetSchemasDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSchemas"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SchemaWhereInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"schemas"},"name":{"kind":"Name","value":"schemata"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"schema"}},{"kind":"Field","name":{"kind":"Name","value":"schemaNames"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]} as unknown as DocumentNode<GetSchemasQuery, GetSchemasQueryVariables>;
3198
+ export const GetSchemaByNameDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSchemaByName"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"SchemaWhereInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"schemas"},"name":{"kind":"Name","value":"schemata"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"schema"}},{"kind":"Field","name":{"kind":"Name","value":"schemaNames"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]} as unknown as DocumentNode<GetSchemaByNameQuery, GetSchemaByNameQueryVariables>;
3191
3199
  export const GetSeedsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSeeds"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AttestationWhereInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"itemSeeds"},"name":{"kind":"Name","value":"attestations"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}},{"kind":"Argument","name":{"kind":"Name","value":"orderBy"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"timeCreated"},"value":{"kind":"EnumValue","value":"desc"}}]}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"decodedDataJson"}},{"kind":"Field","name":{"kind":"Name","value":"attester"}},{"kind":"Field","name":{"kind":"Name","value":"schema"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"schemaNames"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"refUID"}},{"kind":"Field","name":{"kind":"Name","value":"revoked"}},{"kind":"Field","name":{"kind":"Name","value":"schemaId"}},{"kind":"Field","name":{"kind":"Name","value":"timeCreated"}},{"kind":"Field","name":{"kind":"Name","value":"isOffchain"}}]}}]}}]} as unknown as DocumentNode<GetSeedsQuery, GetSeedsQueryVariables>;
3192
3200
  export const GetSeedIdsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSeedIds"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AttestationWhereInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"itemSeedIds"},"name":{"kind":"Name","value":"attestations"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}},{"kind":"Argument","name":{"kind":"Name","value":"orderBy"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"timeCreated"},"value":{"kind":"EnumValue","value":"desc"}}]}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<GetSeedIdsQuery, GetSeedIdsQueryVariables>;
3193
3201
  export const GetStorageTransactionIdDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetStorageTransactionId"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AttestationWhereInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"storageTransactionId"},"name":{"kind":"Name","value":"attestations"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}},{"kind":"Argument","name":{"kind":"Name","value":"orderBy"},"value":{"kind":"ListValue","values":[{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"timeCreated"},"value":{"kind":"EnumValue","value":"desc"}}]}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"decodedDataJson"}}]}}]}}]} as unknown as DocumentNode<GetStorageTransactionIdQuery, GetStorageTransactionIdQueryVariables>;
@@ -1,4 +1,4 @@
1
- import { fs } from '@zenfs/core'
1
+ import fs from '@zenfs/core'
2
2
  import path from 'path'
3
3
  import { Endpoints } from '@/types'
4
4
  import { BROWSER_FS_TOP_DIR } from '@/services/internal/constants'
@@ -17,12 +17,23 @@ export const createDirectories = async (dirPath: string) => {
17
17
  }
18
18
 
19
19
  const parentDir = path.dirname(dirPath)
20
- const parentDirExists = await fs.promises.exists(parentDir)
20
+ let parentDirExists = await fs.promises.exists(parentDir)
21
21
  if (!parentDirExists) {
22
22
  await createDirectories(parentDir)
23
23
  }
24
24
 
25
- await fs.promises.mkdir(dirPath, { recursive: true })
25
+ parentDirExists = await fs.promises.exists(parentDir)
26
+ if (parentDirExists) {
27
+ try {
28
+ await fs.promises.mkdir(dirPath)
29
+ } catch (error) {
30
+ logger(`[Error] Failed to create directories for ${dirPath}:`, error)
31
+ }
32
+ }
33
+
34
+ if (!parentDirExists) {
35
+ console.log(fs)
36
+ }
26
37
  }
27
38
 
28
39
  let busy = false
@@ -1,7 +1,7 @@
1
1
  import { EventObject, fromCallback } from 'xstate'
2
2
  import { and, eq, or, sql } from 'drizzle-orm'
3
3
  import debug from 'debug'
4
- import { fs } from '@zenfs/core'
4
+ import fs from '@zenfs/core'
5
5
  import { metadata } from '@/seedSchema'
6
6
  import { BaseDb } from '@/db/Db/BaseDb'
7
7
  import { updateMetadata } from '@/db/write/updateMetadata'
@@ -0,0 +1,34 @@
1
+ import { and, eq, getTableColumns, or, SQL, sql } from 'drizzle-orm'
2
+ import { BaseDb } from '@/db/Db/BaseDb'
3
+ import { metadata } from '@/seedSchema'
4
+
5
+ export const getMetadataLatest = ({seedLocalId, seedUid}: {seedLocalId?: string, seedUid?: string}) => {
6
+ const appDb = BaseDb.getAppDb()
7
+
8
+ const whereClauses: SQL[] = []
9
+
10
+ if (seedLocalId) {
11
+ whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
12
+ }
13
+
14
+ if (seedUid) {
15
+ whereClauses.push(eq(metadata.seedUid, seedUid))
16
+ }
17
+
18
+ const metadataColumns = getTableColumns(metadata)
19
+
20
+ return appDb.$with('metadataLatest').as(
21
+ appDb
22
+ .select({
23
+ ...metadataColumns,
24
+ rowNum: sql.raw(`
25
+ ROW_NUMBER() OVER (
26
+ PARTITION BY property_name
27
+ ORDER BY COALESCE(created_at, attestation_created_at) DESC
28
+ )
29
+ `).as('rowNum')
30
+ })
31
+ .from(metadata)
32
+ .where(and(...whereClauses))
33
+ )
34
+ }