@seedprotocol/sdk 0.2.51 → 0.2.52

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 (205) hide show
  1. package/dist/{ArweaveClient-D1TsTBoj.js → ArweaveClient-D5iJisYr.js} +2 -2
  2. package/dist/{ArweaveClient-DpdXUcVJ.js.map → ArweaveClient-D5iJisYr.js.map} +1 -1
  3. package/dist/{ArweaveClient-DpdXUcVJ.js → ArweaveClient-HEIIuOfB.js} +2 -2
  4. package/dist/{ArweaveClient-D1TsTBoj.js.map → ArweaveClient-HEIIuOfB.js.map} +1 -1
  5. package/dist/{Db-quJxmvHH.js → Db-D-BsZYlN.js} +3 -3
  6. package/dist/{Db-quJxmvHH.js.map → Db-D-BsZYlN.js.map} +1 -1
  7. package/dist/{Db-DMJ0v3gO.js → Db-Dpsbk_T7.js} +3 -3
  8. package/dist/{Db-DMJ0v3gO.js.map → Db-Dpsbk_T7.js.map} +1 -1
  9. package/dist/{EasClient-ClZDuT3o.js → EasClient-D3wKgt0o.js} +2 -2
  10. package/dist/{EasClient-DfnGY_2X.js.map → EasClient-D3wKgt0o.js.map} +1 -1
  11. package/dist/{EasClient-DfnGY_2X.js → EasClient-jqkT2ZBt.js} +2 -2
  12. package/dist/{EasClient-ClZDuT3o.js.map → EasClient-jqkT2ZBt.js.map} +1 -1
  13. package/dist/{FileManager-texI7UwL.js → FileManager-4mWYO3Mt.js} +3 -5
  14. package/dist/FileManager-4mWYO3Mt.js.map +1 -0
  15. package/dist/{Item-D4n439Ei.js → Item-CqWdJsyg.js} +3 -3
  16. package/dist/{Item-D4n439Ei.js.map → Item-CqWdJsyg.js.map} +1 -1
  17. package/dist/{ItemProperty-Be5ymRVT.js → ItemProperty-BpBW3IWx.js} +3 -3
  18. package/dist/{ItemProperty-Be5ymRVT.js.map → ItemProperty-BpBW3IWx.js.map} +1 -1
  19. package/dist/{QueryClient-B1HkAaJo.js → QueryClient-CBOP3OoU.js} +2 -2
  20. package/dist/{QueryClient-B1HkAaJo.js.map → QueryClient-CBOP3OoU.js.map} +1 -1
  21. package/dist/{QueryClient-BPoc9eBn.js → QueryClient-bKb3SB0W.js} +2 -2
  22. package/dist/{QueryClient-BPoc9eBn.js.map → QueryClient-bKb3SB0W.js.map} +1 -1
  23. package/dist/bin.js +5 -5
  24. package/dist/{constants-5PxfAeqj.js → constants-CIDbABDz.js} +2 -2
  25. package/dist/{constants-5PxfAeqj.js.map → constants-CIDbABDz.js.map} +1 -1
  26. package/dist/{index-BeKRizLf.js → index-BRxO1tLl.js} +257 -145
  27. package/dist/index-BRxO1tLl.js.map +1 -0
  28. package/dist/{index-BLla2o05.js → index-d8Qsot6w.js} +3 -3
  29. package/dist/index-d8Qsot6w.js.map +1 -0
  30. package/dist/main.js +2 -2
  31. package/dist/package.json +189 -0
  32. package/dist/{seed.schema.config-CMpV_hyS.js → seed.schema.config-CPRn6KVL.js} +3 -3
  33. package/dist/{seed.schema.config-CMpV_hyS.js.map → seed.schema.config-CPRn6KVL.js.map} +1 -1
  34. package/dist/types/src/client/BaseClientManager.d.ts +7 -0
  35. package/dist/types/src/client/BaseClientManager.d.ts.map +1 -0
  36. package/dist/types/src/client/actions/setAddresses.d.ts +2 -0
  37. package/dist/types/src/client/actions/setAddresses.d.ts.map +1 -0
  38. package/dist/types/src/client/actors/initialize.d.ts +4 -0
  39. package/dist/types/src/client/actors/initialize.d.ts.map +1 -0
  40. package/dist/types/src/client/actors/saveAppState.d.ts +5 -0
  41. package/dist/types/src/client/actors/saveAppState.d.ts.map +1 -0
  42. package/dist/types/src/client/clientManagerMachine.d.ts +19 -0
  43. package/dist/types/src/client/clientManagerMachine.d.ts.map +1 -0
  44. package/dist/types/src/client/index.d.ts +41 -0
  45. package/dist/types/src/client/index.d.ts.map +1 -0
  46. package/dist/types/src/client.d.ts.map +1 -1
  47. package/dist/types/src/node/helpers/FileManager.d.ts.map +1 -1
  48. package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
  49. package/dist/types/src/types/machines.d.ts +5 -0
  50. package/dist/types/src/types/machines.d.ts.map +1 -1
  51. package/package.json +2 -2
  52. package/dist/FileManager-texI7UwL.js.map +0 -1
  53. package/dist/index-BLla2o05.js.map +0 -1
  54. package/dist/index-BeKRizLf.js.map +0 -1
  55. package/dist/src/AppStateSchema.ts +0 -10
  56. package/dist/src/ArweaveClient.ts +0 -13
  57. package/dist/src/Attestation.ts +0 -21
  58. package/dist/src/BaseArweaveClient.ts +0 -13
  59. package/dist/src/BaseDb.ts +0 -35
  60. package/dist/src/BaseEasClient.ts +0 -13
  61. package/dist/src/BaseFileManager.ts +0 -56
  62. package/dist/src/BaseItem.ts +0 -413
  63. package/dist/src/BaseItemProperty.ts +0 -416
  64. package/dist/src/BaseQueryClient.ts +0 -13
  65. package/dist/src/ConfigSchema.ts +0 -15
  66. package/dist/src/Db.ts +0 -78
  67. package/dist/src/EasClient.ts +0 -13
  68. package/dist/src/FileDownloader.ts +0 -63
  69. package/dist/src/FileManager.ts +0 -57
  70. package/dist/src/IDb.ts +0 -7
  71. package/dist/src/IEasClient.ts +0 -2
  72. package/dist/src/IItem.ts +0 -26
  73. package/dist/src/IItemProperty.ts +0 -28
  74. package/dist/src/IQueryClient.ts +0 -4
  75. package/dist/src/ImageResizer.ts +0 -81
  76. package/dist/src/Item.ts +0 -12
  77. package/dist/src/ItemProperty.ts +0 -9
  78. package/dist/src/MetadataSchema.ts +0 -28
  79. package/dist/src/ModelSchema.ts +0 -46
  80. package/dist/src/ModelUidSchema.ts +0 -16
  81. package/dist/src/PropertyUidSchema.ts +0 -16
  82. package/dist/src/QueryClient.ts +0 -22
  83. package/dist/src/Schema.ts +0 -17
  84. package/dist/src/SeedProtocolSdk.d.ts +0 -19
  85. package/dist/src/SeedSchema.ts +0 -29
  86. package/dist/src/VersionSchema.ts +0 -16
  87. package/dist/src/actors.ts +0 -295
  88. package/dist/src/addModelsToDb.ts +0 -152
  89. package/dist/src/allItems.ts +0 -31
  90. package/dist/src/analyzeInput.ts +0 -144
  91. package/dist/src/browser.app.db.config.ts +0 -27
  92. package/dist/src/browser.ts +0 -30
  93. package/dist/src/checkStatus.ts +0 -50
  94. package/dist/src/client.ts +0 -148
  95. package/dist/src/configureFs.ts +0 -94
  96. package/dist/src/connectToDb.ts +0 -41
  97. package/dist/src/connectionManager.ts +0 -67
  98. package/dist/src/constants.ts +0 -125
  99. package/dist/src/content-hash.ts +0 -30
  100. package/dist/src/create.ts +0 -39
  101. package/dist/src/createMetadata.ts +0 -77
  102. package/dist/src/createNewItem.ts +0 -61
  103. package/dist/src/createPublishAttempt.ts +0 -16
  104. package/dist/src/createSeed.ts +0 -31
  105. package/dist/src/createSeeds.ts +0 -24
  106. package/dist/src/createVersion.ts +0 -33
  107. package/dist/src/dbMachine.ts +0 -182
  108. package/dist/src/deleteItem.ts +0 -19
  109. package/dist/src/download.ts +0 -202
  110. package/dist/src/drizzle.ts +0 -78
  111. package/dist/src/eas.ts +0 -40
  112. package/dist/src/environment.ts +0 -35
  113. package/dist/src/eventBus.ts +0 -5
  114. package/dist/src/events.ts +0 -14
  115. package/dist/src/fetchDataFromEas.ts +0 -94
  116. package/dist/src/fetchDbData.ts +0 -19
  117. package/dist/src/fetchRelatedItems.ts +0 -184
  118. package/dist/src/fetchSeeds.ts +0 -52
  119. package/dist/src/fetchVersions.ts +0 -49
  120. package/dist/src/files.ts +0 -81
  121. package/dist/src/filesDownload.ts +0 -326
  122. package/dist/src/fragment-masking.ts +0 -87
  123. package/dist/src/getExistingItem.ts +0 -60
  124. package/dist/src/getItem.ts +0 -32
  125. package/dist/src/getItemData.ts +0 -99
  126. package/dist/src/getItemProperties.ts +0 -56
  127. package/dist/src/getItemProperty.ts +0 -34
  128. package/dist/src/getItems.ts +0 -70
  129. package/dist/src/getMetadata.ts +0 -40
  130. package/dist/src/getModelSchemas.ts +0 -89
  131. package/dist/src/getPropertyData.ts +0 -50
  132. package/dist/src/getPublishPayload.ts +0 -355
  133. package/dist/src/getPublishUploads.ts +0 -207
  134. package/dist/src/getRelationValueData.ts +0 -27
  135. package/dist/src/getSchemaForItemProperty.ts +0 -68
  136. package/dist/src/getSchemaForModel.ts +0 -42
  137. package/dist/src/getSchemaUidForModel.ts +0 -32
  138. package/dist/src/getSeedData.ts +0 -34
  139. package/dist/src/getSegmentedItemProperties.ts +0 -65
  140. package/dist/src/getStorageTransactionIdForSeedUid.ts +0 -38
  141. package/dist/src/getVersionData.ts +0 -46
  142. package/dist/src/getVersionsForVersionUids.ts +0 -39
  143. package/dist/src/globalMachine.ts +0 -280
  144. package/dist/src/gql.ts +0 -118
  145. package/dist/src/graphql.ts +0 -3209
  146. package/dist/src/helpers.ts +0 -273
  147. package/dist/src/hydrateExistingItem.ts +0 -137
  148. package/dist/src/hydrateFromDb.ts +0 -270
  149. package/dist/src/hydrateNewItem.ts +0 -34
  150. package/dist/src/imageResize.ts +0 -507
  151. package/dist/src/index.d.ts +0 -5
  152. package/dist/src/index.ts +0 -4
  153. package/dist/src/initialize.ts +0 -124
  154. package/dist/src/internalMachine.ts +0 -238
  155. package/dist/src/itemMachineAll.ts +0 -157
  156. package/dist/src/itemMachineSingle.ts +0 -158
  157. package/dist/src/loadAppDb.ts +0 -47
  158. package/dist/src/machines.ts +0 -60
  159. package/dist/src/metadataLatest.ts +0 -34
  160. package/dist/src/migrate.ts +0 -53
  161. package/dist/src/model.ts +0 -72
  162. package/dist/src/modelClass.ts +0 -19
  163. package/dist/src/node.app.db.config.ts +0 -41
  164. package/dist/src/prepareDb.ts +0 -29
  165. package/dist/src/preparePublishRequestData.ts +0 -81
  166. package/dist/src/processItems.ts +0 -74
  167. package/dist/src/property.ts +0 -156
  168. package/dist/src/propertyMachine.ts +0 -202
  169. package/dist/src/publish.ts +0 -28
  170. package/dist/src/publishMachine.ts +0 -77
  171. package/dist/src/queries.ts +0 -13
  172. package/dist/src/recoverDeletedItem.ts +0 -14
  173. package/dist/src/reload.ts +0 -33
  174. package/dist/src/request.ts +0 -45
  175. package/dist/src/requestAll.ts +0 -157
  176. package/dist/src/resolveRelatedValue.ts +0 -367
  177. package/dist/src/resolveRemoteStorage.ts +0 -88
  178. package/dist/src/saveAppState.ts +0 -19
  179. package/dist/src/saveConfig.ts +0 -88
  180. package/dist/src/saveDataToDb.ts +0 -145
  181. package/dist/src/saveImageSrc.ts +0 -242
  182. package/dist/src/saveItemStorage.ts +0 -156
  183. package/dist/src/saveMetadata.ts +0 -18
  184. package/dist/src/savePublishService.ts +0 -30
  185. package/dist/src/saveRelation.ts +0 -112
  186. package/dist/src/seed.schema.config.ts +0 -25
  187. package/dist/src/seed.ts +0 -10
  188. package/dist/src/seedProtocol.ts +0 -17
  189. package/dist/src/services.ts +0 -365
  190. package/dist/src/sqlWasmClient.ts +0 -88
  191. package/dist/src/syncDbWithEas.ts +0 -628
  192. package/dist/src/trash.ts +0 -29
  193. package/dist/src/ts-to-proto.ts +0 -101
  194. package/dist/src/types.ts +0 -12
  195. package/dist/src/updateItemPropertyValue.ts +0 -243
  196. package/dist/src/updateMachineContext.ts +0 -21
  197. package/dist/src/updateMetadata.ts +0 -59
  198. package/dist/src/upload.ts +0 -86
  199. package/dist/src/validate.ts +0 -45
  200. package/dist/src/validateInput.ts +0 -47
  201. package/dist/src/validateItemData.ts +0 -20
  202. package/dist/src/versionData.ts +0 -24
  203. package/dist/src/waitForDb.ts +0 -25
  204. package/dist/src/waitForFiles.ts +0 -34
  205. package/dist/src/wasm.d.ts +0 -8300
@@ -1,87 +0,0 @@
1
- /* eslint-disable */
2
- import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
3
- import { FragmentDefinitionNode } from 'graphql';
4
- import { Incremental } from './graphql';
5
-
6
-
7
- export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
8
- infer TType,
9
- any
10
- >
11
- ? [TType] extends [{ ' $fragmentName'?: infer TKey }]
12
- ? TKey extends string
13
- ? { ' $fragmentRefs'?: { [key in TKey]: TType } }
14
- : never
15
- : never
16
- : never;
17
-
18
- // return non-nullable if `fragmentType` is non-nullable
19
- export function useFragment<TType>(
20
- _documentNode: DocumentTypeDecoration<TType, any>,
21
- fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
22
- ): TType;
23
- // return nullable if `fragmentType` is undefined
24
- export function useFragment<TType>(
25
- _documentNode: DocumentTypeDecoration<TType, any>,
26
- fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
27
- ): TType | undefined;
28
- // return nullable if `fragmentType` is nullable
29
- export function useFragment<TType>(
30
- _documentNode: DocumentTypeDecoration<TType, any>,
31
- fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
32
- ): TType | null;
33
- // return nullable if `fragmentType` is nullable or undefined
34
- export function useFragment<TType>(
35
- _documentNode: DocumentTypeDecoration<TType, any>,
36
- fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
37
- ): TType | null | undefined;
38
- // return array of non-nullable if `fragmentType` is array of non-nullable
39
- export function useFragment<TType>(
40
- _documentNode: DocumentTypeDecoration<TType, any>,
41
- fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
42
- ): Array<TType>;
43
- // return array of nullable if `fragmentType` is array of nullable
44
- export function useFragment<TType>(
45
- _documentNode: DocumentTypeDecoration<TType, any>,
46
- fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
47
- ): Array<TType> | null | undefined;
48
- // return readonly array of non-nullable if `fragmentType` is array of non-nullable
49
- export function useFragment<TType>(
50
- _documentNode: DocumentTypeDecoration<TType, any>,
51
- fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
52
- ): ReadonlyArray<TType>;
53
- // return readonly array of nullable if `fragmentType` is array of nullable
54
- export function useFragment<TType>(
55
- _documentNode: DocumentTypeDecoration<TType, any>,
56
- fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
57
- ): ReadonlyArray<TType> | null | undefined;
58
- export function useFragment<TType>(
59
- _documentNode: DocumentTypeDecoration<TType, any>,
60
- fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | Array<FragmentType<DocumentTypeDecoration<TType, any>>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
61
- ): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
62
- return fragmentType as any;
63
- }
64
-
65
-
66
- export function makeFragmentData<
67
- F extends DocumentTypeDecoration<any, any>,
68
- FT extends ResultOf<F>
69
- >(data: FT, _fragment: F): FragmentType<F> {
70
- return data as FragmentType<F>;
71
- }
72
- export function isFragmentReady<TQuery, TFrag>(
73
- queryNode: DocumentTypeDecoration<TQuery, any>,
74
- fragmentNode: TypedDocumentNode<TFrag>,
75
- data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
76
- ): data is FragmentType<typeof fragmentNode> {
77
- const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
78
- ?.deferredFields;
79
-
80
- if (!deferredFields) return true;
81
-
82
- const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
83
- const fragName = fragDef?.name?.value;
84
-
85
- const fields = (fragName && deferredFields[fragName]) || [];
86
- return fields.length > 0 && fields.every(field => data && field in data);
87
- }
@@ -1,60 +0,0 @@
1
- import { BaseDb } from '@/db/Db/BaseDb'
2
- import { seeds } from '@/seedSchema'
3
- import { and, eq, isNotNull, not, or } from 'drizzle-orm'
4
-
5
- type GetExistingItemProps = {
6
- seedLocalId: string
7
- seedUid: string
8
- }
9
-
10
- type GetExistingItemReturn = {
11
- seedLocalId: string
12
- seedUid: string
13
- createdAt: string
14
- }
15
-
16
- export const getExistingItem = async ({
17
- seedLocalId,
18
- seedUid,
19
- }: GetExistingItemProps): Promise<GetExistingItemReturn | undefined> => {
20
- const appDb = BaseDb.getAppDb()
21
-
22
- const rows = await appDb
23
- .select({
24
- seedLocalId: seeds.localId,
25
- seedUid: seeds.uid,
26
- createdAt: seeds.createdAt,
27
- })
28
- .from(seeds)
29
- .where(
30
- or(
31
- and(
32
- isNotNull(seeds.uid),
33
- not(eq(seeds.uid, '')),
34
- not(eq(seeds.uid, 'undefined')),
35
- not(eq(seeds.uid, 'null')),
36
- not(eq(seeds.uid, 'false')),
37
- not(eq(seeds.uid, '0')),
38
- eq(seeds.uid, seedUid)
39
- ),
40
- and(
41
- isNotNull(seeds.localId),
42
- not(eq(seeds.localId, '')),
43
- not(eq(seeds.localId, 'undefined')),
44
- not(eq(seeds.localId, 'null')),
45
- not(eq(seeds.localId, 'false')),
46
- not(eq(seeds.localId, '0')),
47
- eq(seeds.localId, seedLocalId)
48
- )
49
- )
50
- )
51
-
52
- if (!rows || rows.length === 0) {
53
- return undefined
54
- }
55
-
56
- const matchingRow = rows.find(row => row.seedUid === seedUid) ||
57
- rows.find(row => row.seedLocalId === seedLocalId)
58
-
59
- return matchingRow
60
- }
@@ -1,32 +0,0 @@
1
- import { getItemData } from './getItemData'
2
- import { GetItem } from '@/types'
3
- import { BaseItem } from '@/Item/BaseItem'
4
- import { startCase } from 'lodash-es'
5
-
6
- export const getItem: GetItem = async ({ modelName, seedLocalId, seedUid }) => {
7
- const itemInitObj = await getItemData({
8
- modelName,
9
- seedLocalId,
10
- seedUid,
11
- })
12
-
13
- if (!itemInitObj) {
14
- console.error(
15
- `[db/queries] [getItem] no itemInitObj modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`,
16
- )
17
- return
18
- }
19
-
20
- if (!itemInitObj.seedLocalId) {
21
- console.error(
22
- `[db/queries] [getItem] no itemInitObj.seedLocalId modelName: ${modelName} seedLocalId: ${seedLocalId} seedUid: ${seedUid}`,
23
- )
24
- return
25
- }
26
-
27
- if (!itemInitObj.modelName && itemInitObj.type) {
28
- itemInitObj.modelName = startCase(itemInitObj.type)
29
- }
30
-
31
- return BaseItem.create(itemInitObj)
32
- }
@@ -1,99 +0,0 @@
1
- import { GetItemData, ItemData } from "@/types"
2
- import debug from "debug"
3
- import { BaseDb } from "../Db/BaseDb"
4
- import { and, eq, getTableColumns, gt, SQL, sql } from "drizzle-orm"
5
- import { getItemProperties } from "./getItemProperties"
6
- import { getVersionData } from "./subqueries/versionData"
7
- import { seeds } from "@/seedSchema"
8
- import { getSeedData } from "./getSeedData"
9
-
10
- const logger = debug('app:db:read:getItemData')
11
-
12
- export const getItemData: GetItemData = async ({
13
- modelName,
14
- seedLocalId,
15
- seedUid,
16
- }) => {
17
- if (!seedLocalId && !seedUid) {
18
- throw new Error('[db/queries] [getItem] no seedLocalId or seedUid')
19
- }
20
-
21
- if (seedUid && !seedLocalId) {
22
- const seedData = await getSeedData({ seedUid })
23
- if (!seedData) {
24
- logger('[db/queries] [getItem] no seedData seedUid', seedUid)
25
- return
26
- }
27
- seedLocalId = seedData.localId
28
- }
29
-
30
- const appDb = BaseDb.getAppDb()
31
-
32
- const { localId, uid, ...rest } = getTableColumns(seeds)
33
-
34
- const whereClauses: SQL[] = []
35
-
36
- if (modelName) {
37
- whereClauses.push(eq(seeds.type, modelName.toLowerCase()))
38
- }
39
-
40
- if (seedUid) {
41
- whereClauses.push(eq(seeds.uid, seedUid))
42
- }
43
-
44
- if (seedLocalId && !seedUid) {
45
- whereClauses.push(eq(seeds.localId, seedLocalId))
46
- }
47
-
48
- const versionData = getVersionData()
49
-
50
- const itemDataRows = await appDb
51
- .with(versionData)
52
- .select({
53
- ...rest,
54
- seedLocalId: seeds.localId,
55
- seedUid: seeds.uid,
56
- versionsCount: versionData.versionsCount,
57
- lastVersionPublishedAt: versionData.lastVersionPublishedAt,
58
- latestVersionUid: versionData.latestVersionUid,
59
- latestVersionLocalId: versionData.latestVersionLocalId,
60
- })
61
- .from(seeds)
62
- .leftJoin(versionData, eq(seeds.localId, versionData.seedLocalId))
63
- .where(and(...whereClauses, gt(versionData.versionsCount, 0)))
64
- .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
65
- .groupBy(seeds.localId) as ItemData[]
66
-
67
- if (!itemDataRows || itemDataRows.length === 0) {
68
- logger('[db/queries] [getItemDataFromDb] no itemDataRows')
69
- return
70
- }
71
-
72
- let itemData = itemDataRows[0] as ItemData & { [key: string]: any }
73
-
74
- const propertiesData = await getItemProperties({
75
- seedLocalId,
76
- seedUid: itemData.seedUid || undefined,
77
- })
78
-
79
- if (!propertiesData || propertiesData.length === 0) {
80
- return itemData
81
- }
82
-
83
- for (const propertyData of propertiesData) {
84
- const propertyName = propertyData.propertyName
85
-
86
- let propertyValue = propertyData.propertyValue
87
-
88
- if (propertyName.endsWith('Id') || propertyName.endsWith('Ids')) {
89
- if (propertyData.refSeedType) {
90
- const propertyNameVariant = propertyName.replace(/Ids?$/, '')
91
- itemData[propertyNameVariant] = propertyValue
92
- }
93
- }
94
-
95
- itemData[propertyName] = propertyValue
96
- }
97
-
98
- if (itemData) return itemData
99
- }
@@ -1,56 +0,0 @@
1
- import { GetItemProperties, PropertyData } from '@/types'
2
- import { metadata, seeds, versions } from '@/seedSchema'
3
- import { and, eq, getTableColumns, isNotNull, isNull, sql, SQL } from 'drizzle-orm'
4
- import { BaseDb } from '@/db/Db/BaseDb'
5
- import { getMetadataLatest } from './subqueries/metadataLatest'
6
-
7
-
8
- export const getItemProperties: GetItemProperties = async ({
9
- seedLocalId,
10
- seedUid,
11
- edited,
12
- }) => {
13
- const appDb = BaseDb.getAppDb()
14
-
15
- const whereClauses: SQL[] = [isNotNull(metadata.propertyName)]
16
-
17
- if (seedUid) {
18
- whereClauses.push(eq(seeds.uid, seedUid))
19
- }
20
-
21
- if (seedLocalId) {
22
- whereClauses.push(eq(seeds.localId, seedLocalId))
23
- }
24
-
25
- whereClauses.push(isNotNull(metadata.propertyName))
26
-
27
- if (typeof edited !== 'undefined') {
28
- if (edited) {
29
- whereClauses.push(isNull(metadata.uid))
30
- }
31
- if (!edited) {
32
- whereClauses.push(isNotNull(metadata.uid))
33
- }
34
- }
35
-
36
- // const metadataColumns = getTableColumns(metadata)
37
-
38
- const metadataLatest = getMetadataLatest({seedLocalId, seedUid})
39
-
40
- const propertiesData = await appDb
41
- .with(metadataLatest)
42
- .select()
43
- .from(metadataLatest)
44
- .where(eq(metadataLatest.rowNum, 1))
45
-
46
- return propertiesData.map(data => ({
47
- ...data,
48
- localId: data.localId || '',
49
- uid: data.uid || '',
50
- propertyName: data.propertyName || '',
51
- propertyValue: data.propertyValue || '',
52
- schemaUid: data.schemaUid || '',
53
- modelType: data.modelType || '',
54
- seedLocalId: data.seedLocalId || '',
55
- })) as PropertyData[]
56
- }
@@ -1,34 +0,0 @@
1
- import { BaseDb } from '@/db/Db/BaseDb'
2
- import { metadata, MetadataType } from '@/seedSchema'
3
- import { and, eq, getTableColumns } from 'drizzle-orm'
4
-
5
- type GetItemPropertyProps = Partial<MetadataType>
6
-
7
- type GetItemPropertyData = (
8
- props: GetItemPropertyProps,
9
- ) => Promise<Partial<MetadataType>>
10
-
11
- export const getItemPropertyData: GetItemPropertyData = async (props) => {
12
- const appDb = BaseDb.getAppDb()
13
-
14
- const whereClauses = []
15
-
16
- const tableColumns = getTableColumns(metadata)
17
-
18
- for (const [propertyName, propertyValue] of Object.entries(props)) {
19
- if (Object.keys(tableColumns).includes(propertyName)) {
20
- whereClauses.push(eq(tableColumns[propertyName], propertyValue))
21
- }
22
- }
23
-
24
- const queryRows = await appDb
25
- .select()
26
- .from(metadata)
27
- .where(and(...whereClauses))
28
-
29
- if (!queryRows || queryRows.length === 0) {
30
- return
31
- }
32
-
33
- return queryRows[0]
34
- }
@@ -1,70 +0,0 @@
1
- import { ItemData } from '@/types'
2
- import { and, eq, gt, isNotNull, isNull, or, SQL, sql } from 'drizzle-orm'
3
- import { seeds } from '@/seedSchema'
4
- import { BaseDb } from '@/db/Db/BaseDb'
5
- import { getVersionData } from './subqueries/versionData'
6
-
7
- type GetItemsDataProps = {
8
- modelName?: string
9
- deleted?: boolean
10
- }
11
-
12
- type GetItemsData = (props: GetItemsDataProps) => Promise<ItemData[]>
13
-
14
- export const getItemsData: GetItemsData = async ({
15
- modelName,
16
- deleted,
17
- }): Promise<ItemData[]> => {
18
- const appDb = BaseDb.getAppDb()
19
-
20
- const conditions: SQL[] = []
21
-
22
- if (modelName) {
23
- conditions.push(eq(seeds.type, modelName.toLowerCase()))
24
- }
25
-
26
- if (deleted) {
27
- conditions.push(
28
- or(
29
- isNotNull(seeds._markedForDeletion),
30
- eq(seeds._markedForDeletion, 1),
31
- ) as SQL,
32
- )
33
- }
34
-
35
- if (!deleted) {
36
- conditions.push(
37
- or(
38
- isNull(seeds._markedForDeletion),
39
- eq(seeds._markedForDeletion, 0),
40
- ) as SQL,
41
- )
42
- }
43
-
44
- const versionData = getVersionData()
45
-
46
- let query = appDb
47
- .with(versionData)
48
- .select({
49
- seedLocalId: seeds.localId,
50
- seedUid: seeds.uid,
51
- schemaUid: seeds.schemaUid,
52
- modelName: sql<string>`${modelName}`,
53
- attestationCreatedAt: seeds.attestationCreatedAt,
54
- versionsCount: versionData.versionsCount,
55
- lastVersionPublishedAt: versionData.lastVersionPublishedAt,
56
- lastLocalUpdateAt: versionData.lastLocalUpdateAt,
57
- latestVersionUid: versionData.latestVersionUid,
58
- latestVersionLocalId: versionData.latestVersionLocalId,
59
- createdAt: seeds.createdAt,
60
- })
61
- .from(seeds)
62
- .leftJoin(versionData, eq(seeds.localId, versionData.seedLocalId))
63
- .where(and(gt(versionData.versionsCount, 0), ...conditions))
64
- .orderBy(sql.raw('COALESCE(attestation_created_at, created_at) DESC'))
65
- .groupBy(seeds.localId)
66
-
67
- const itemsData = (await query) as ItemData[]
68
-
69
- return itemsData
70
- }
@@ -1,40 +0,0 @@
1
- import { BaseDb } from '@/db/Db/BaseDb'
2
- import { and, eq, SQL } from 'drizzle-orm'
3
- import { metadata, MetadataType } from '@/seedSchema'
4
-
5
- type GetMetadataProps =
6
- | {
7
- storageTransactionId?: string
8
- }
9
- | undefined
10
-
11
- type GetMetadata = (
12
- props: GetMetadataProps,
13
- ) => Promise<MetadataType | undefined>
14
-
15
- export const getMetadata: GetMetadata = async (props) => {
16
- const appDb = BaseDb.getAppDb()
17
-
18
- let storageTransactionId: string | undefined
19
- if (props) {
20
- storageTransactionId = props.storageTransactionId
21
- }
22
-
23
- const whereClauses: SQL[] = []
24
-
25
- if (storageTransactionId) {
26
- whereClauses.push(eq(metadata.propertyName, 'storageTransactionId'))
27
- whereClauses.push(eq(metadata.propertyValue, storageTransactionId))
28
- }
29
-
30
- const metadataRows = await appDb
31
- .select()
32
- .from(metadata)
33
- .where(and(...whereClauses))
34
-
35
- if (!metadataRows || metadataRows.length === 0) {
36
- return
37
- }
38
-
39
- return metadataRows[0]
40
- }
@@ -1,89 +0,0 @@
1
- import { getModels } from '@/stores/modelClass'
2
- import { GetSchemasQuery, Schema } from '@/graphql/gql/graphql'
3
- import { BaseDb } from '@/db/Db/BaseDb'
4
- import { models as modelsTable, modelUids } from '@/seedSchema'
5
- import { eq } from 'drizzle-orm'
6
- import pluralize from 'pluralize'
7
- import { toSnakeCase } from '@/helpers'
8
- import { GET_SCHEMAS } from '@/Item/queries'
9
- import { BaseEasClient } from '@/helpers/EasClient/BaseEasClient'
10
- import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
11
-
12
-
13
- type GetModelSchemasReturn = {
14
- modelSchemas: GetSchemasQuery
15
- schemaStringToModelRecord: Map<string, Schema>
16
- modelRecords: Record<string, unknown>
17
- }
18
-
19
- type GetModelSchemas = () => Promise<GetModelSchemasReturn>
20
-
21
- export const getModelSchemas: GetModelSchemas = async () => {
22
- const models = getModels()
23
- const modelRecords = [] as Record<string, unknown>[]
24
-
25
- const schemaStringToModelRecord = new Map<string, Schema>()
26
-
27
- const appDb = BaseDb.getAppDb()
28
-
29
- const OR: Record<string, unknown>[] = []
30
-
31
- for (const [modelName, _] of Object.entries(models)) {
32
- const foundModelQuery = await appDb
33
- .select({
34
- id: modelsTable.id,
35
- name: modelsTable.name,
36
- uid: modelUids.uid,
37
- })
38
- .from(modelsTable)
39
- .leftJoin(modelUids, eq(modelsTable.id, modelUids.modelId))
40
- .where(eq(modelsTable.name, modelName))
41
- .limit(1)
42
-
43
- const foundModel: Schema = { ...foundModelQuery[0] }
44
-
45
- if (!foundModel) {
46
- console.error(
47
- `[item/events] [syncDbWithEas] model ${modelName} not found in SDK DB`,
48
- )
49
- return
50
- }
51
-
52
- foundModel.tableName = pluralize(foundModel.name).toLowerCase()
53
-
54
- modelRecords!.push(foundModel)
55
-
56
- if (modelName === 'Seed' || modelName === 'Version') {
57
- continue
58
- }
59
-
60
- const schemaString = `bytes32 ${toSnakeCase(modelName)}`
61
-
62
- OR.push({
63
- schema: {
64
- equals: `bytes32 ${toSnakeCase(modelName)}`,
65
- },
66
- })
67
-
68
- schemaStringToModelRecord.set(schemaString, foundModel)
69
- }
70
-
71
- const queryClient = BaseQueryClient.getQueryClient()
72
- const easClient = BaseEasClient.getEasClient()
73
-
74
- const modelSchemas = await queryClient.fetchQuery({
75
- queryKey: [`getSchemasAllModels`],
76
- queryFn: async () =>
77
- easClient.request(GET_SCHEMAS, {
78
- where: {
79
- OR,
80
- },
81
- }),
82
- })
83
-
84
- return {
85
- modelSchemas,
86
- schemaStringToModelRecord,
87
- modelRecords,
88
- }
89
- }
@@ -1,50 +0,0 @@
1
- import { PropertyData } from "@/types"
2
- import { BaseDb } from "@/db/Db/BaseDb"
3
- import { metadata, MetadataType } from "@/seedSchema"
4
- import { or, eq, and, sql } from "drizzle-orm"
5
- import { startCase } from "lodash-es"
6
- import { GetPropertyDataOptions } from "@/types/db"
7
-
8
-
9
- export const getPropertyData = async ({
10
- propertyName,
11
- seedLocalId,
12
- seedUid,
13
- }: GetPropertyDataOptions): Promise<PropertyData | undefined> => {
14
- const appDb = BaseDb.getAppDb()
15
-
16
- const whereClauses: any[] = [
17
- or(
18
- eq(metadata.propertyName, propertyName),
19
- eq(metadata.propertyName, propertyName + 'Id'),
20
- eq(metadata.propertyName, propertyName + 'Ids'),
21
- ),
22
- ]
23
-
24
- if (seedLocalId) {
25
- whereClauses.push(eq(metadata.seedLocalId, seedLocalId))
26
- }
27
-
28
- if (seedUid) {
29
- whereClauses.push(eq(metadata.seedUid, seedUid))
30
- }
31
-
32
- const rows = (await appDb
33
- .select()
34
- .from(metadata)
35
- .where(and(...whereClauses))
36
- .orderBy(
37
- sql.raw(`COALESCE(attestation_created_at, created_at) DESC`),
38
- )) as MetadataType[]
39
-
40
- if (!rows || rows.length === 0) {
41
- return
42
- }
43
-
44
- const row = rows[0]
45
-
46
- return {
47
- ...row,
48
- modelName: startCase(row.modelType),
49
- }
50
- }