@seedprotocol/sdk 0.1.46 → 0.1.48

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 (147) hide show
  1. package/dist/bin.js.map +1 -1
  2. package/dist/constants-BLctWkrn.js.map +1 -1
  3. package/dist/{index-BEzB8REh.js → index-DMIKRod-.js} +3684 -3660
  4. package/dist/index-DMIKRod-.js.map +1 -0
  5. package/dist/{index-ChGsdGPJ.js → index-wKss7188.js} +10 -10
  6. package/dist/index-wKss7188.js.map +1 -0
  7. package/dist/main.js +7 -7
  8. package/dist/{seed.schema.config-jKpK-lR6.js → seed.schema.config-C0M8Rcti.js} +7 -7
  9. package/dist/seed.schema.config-C0M8Rcti.js.map +1 -0
  10. package/dist/src/AppStateSchema.ts +10 -0
  11. package/dist/src/Attestation.ts +21 -0
  12. package/dist/src/ConfigSchema.ts +15 -0
  13. package/dist/src/ItemProperty.ts +383 -0
  14. package/dist/src/MetadataSchema.ts +28 -0
  15. package/dist/src/ModelSchema.ts +46 -0
  16. package/dist/src/ModelUidSchema.ts +16 -0
  17. package/dist/src/PropertyUidSchema.ts +16 -0
  18. package/dist/src/Schema.ts +17 -0
  19. package/dist/src/SeedSchema.ts +29 -0
  20. package/dist/src/VersionSchema.ts +16 -0
  21. package/dist/src/actors.ts +10 -0
  22. package/dist/src/addModelsToDb.ts +150 -0
  23. package/dist/src/allItems.ts +23 -0
  24. package/dist/src/arweave.ts +37 -0
  25. package/dist/src/browser.app.db.config.ts +27 -0
  26. package/dist/src/browser.seed.db.config.ts +33 -0
  27. package/dist/src/browser.ts +30 -0
  28. package/dist/src/checkStatus.ts +50 -0
  29. package/dist/src/client.ts +85 -0
  30. package/dist/src/configureFs.ts +81 -0
  31. package/dist/src/connectToDb.ts +74 -0
  32. package/dist/src/connectionManager.ts +67 -0
  33. package/dist/src/constants.ts +118 -0
  34. package/dist/src/create.ts +39 -0
  35. package/dist/src/createItem.ts +15 -0
  36. package/dist/src/createItemMachine.ts +37 -0
  37. package/dist/src/createPublishAttempt.ts +16 -0
  38. package/dist/src/createSeeds.ts +24 -0
  39. package/dist/src/createVersion.ts +33 -0
  40. package/dist/src/db.ts +247 -0
  41. package/dist/src/dbMachine.ts +181 -0
  42. package/dist/src/deleteItem.ts +19 -0
  43. package/dist/src/download.ts +289 -0
  44. package/dist/src/drizzle.ts +82 -0
  45. package/dist/src/environment.ts +15 -0
  46. package/dist/src/eventBus.ts +5 -0
  47. package/dist/src/events.ts +14 -0
  48. package/dist/src/fetchDataFromEas.ts +90 -0
  49. package/dist/src/fetchDbData.ts +16 -0
  50. package/dist/src/fetchRelatedItems.ts +179 -0
  51. package/dist/src/fetchSeeds.ts +44 -0
  52. package/dist/src/fetchVersions.ts +41 -0
  53. package/dist/src/files.ts +16 -0
  54. package/dist/src/fragment-masking.ts +87 -0
  55. package/dist/src/fsProxy.ts +36 -0
  56. package/dist/src/getItem.ts +189 -0
  57. package/dist/src/getItemProperties.ts +162 -0
  58. package/dist/src/getItems.ts +75 -0
  59. package/dist/src/getMetadata.ts +40 -0
  60. package/dist/src/getModelSchemas.ts +88 -0
  61. package/dist/src/getSchemaForModel.ts +42 -0
  62. package/dist/src/getSeedData.ts +34 -0
  63. package/dist/src/getVersionData.ts +58 -0
  64. package/dist/src/getVersionsForVersionUids.ts +39 -0
  65. package/dist/src/globalMachine.ts +259 -0
  66. package/dist/src/gql.ts +113 -0
  67. package/dist/src/graphql.ts +3201 -0
  68. package/dist/src/helpers.ts +150 -0
  69. package/dist/src/hydrateExistingItem.ts +137 -0
  70. package/dist/src/hydrateFromDb.ts +254 -0
  71. package/dist/src/hydrateNewItem.ts +34 -0
  72. package/dist/src/index.d.ts +5 -0
  73. package/dist/src/index.ts +21 -0
  74. package/dist/src/init.ts +61 -0
  75. package/dist/src/initialize.ts +127 -0
  76. package/dist/src/internalMachine.ts +220 -0
  77. package/dist/src/item.ts +324 -0
  78. package/dist/src/itemMachineAll.ts +158 -0
  79. package/dist/src/itemMachineSingle.ts +175 -0
  80. package/dist/src/loadAppDb.ts +47 -0
  81. package/dist/src/logger.ts +33 -0
  82. package/dist/src/machine.ts +55 -0
  83. package/dist/src/machines.ts +58 -0
  84. package/dist/src/migrate.ts +288 -0
  85. package/dist/src/model.ts +71 -0
  86. package/dist/src/modelClass.ts +19 -0
  87. package/dist/src/node.app.db.config.ts +40 -0
  88. package/dist/src/prepareDb.ts +34 -0
  89. package/dist/src/preparePublishRequestData.ts +81 -0
  90. package/dist/src/processItems.ts +71 -0
  91. package/dist/src/property.ts +161 -0
  92. package/dist/src/propertyMachine.ts +154 -0
  93. package/dist/src/publish.ts +31 -0
  94. package/dist/src/publishMachine.ts +77 -0
  95. package/dist/src/queries.ts +13 -0
  96. package/dist/src/read.ts +174 -0
  97. package/dist/src/recoverDeletedItem.ts +14 -0
  98. package/dist/src/request.ts +54 -0
  99. package/dist/src/requestAll.ts +157 -0
  100. package/dist/src/resolveRelatedValue.ts +348 -0
  101. package/dist/src/resolveRemoteStorage.ts +87 -0
  102. package/dist/src/save.ts +183 -0
  103. package/dist/src/saveConfig.ts +79 -0
  104. package/dist/src/saveDataToDb.ts +145 -0
  105. package/dist/src/saveMetadata.ts +18 -0
  106. package/dist/src/saveValueToDb.ts +94 -0
  107. package/dist/src/seed.schema.config.ts +25 -0
  108. package/dist/src/seed.ts +37 -0
  109. package/dist/src/seedData.ts +0 -0
  110. package/dist/src/seedProtocol.ts +17 -0
  111. package/dist/src/services.ts +359 -0
  112. package/dist/src/sqlWasmClient.ts +88 -0
  113. package/dist/src/syncDbWithEas.ts +686 -0
  114. package/dist/src/trash.ts +29 -0
  115. package/dist/src/ts-to-proto.ts +101 -0
  116. package/dist/src/types.ts +12 -0
  117. package/dist/src/upload.ts +86 -0
  118. package/dist/src/validate.ts +42 -0
  119. package/dist/src/validateInput.ts +33 -0
  120. package/dist/src/validateItemData.ts +20 -0
  121. package/dist/src/waitForDb.ts +23 -0
  122. package/dist/src/wasm.d.ts +8300 -0
  123. package/dist/src/write.ts +366 -0
  124. package/dist/types/src/browser/db/read/getModelSchemas.d.ts.map +1 -1
  125. package/dist/types/src/browser/events/item/create.d.ts.map +1 -1
  126. package/dist/types/src/browser/events/item/publish.d.ts.map +1 -1
  127. package/dist/types/src/browser/events/item/requestAll.d.ts.map +1 -1
  128. package/dist/types/src/browser/events/item/syncDbWithEas.d.ts.map +1 -1
  129. package/dist/types/src/browser/item/single/actors/hydrateExistingItem.d.ts +3 -1
  130. package/dist/types/src/browser/item/single/actors/hydrateExistingItem.d.ts.map +1 -1
  131. package/dist/types/src/browser/item/single/actors/saveDataToDb.d.ts +3 -3
  132. package/dist/types/src/browser/item/single/itemMachineSingle.d.ts +3 -3
  133. package/dist/types/src/browser/property/ItemProperty.d.ts +7 -7
  134. package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
  135. package/dist/types/src/browser/property/actors/hydrateFromDb.d.ts.map +1 -1
  136. package/dist/types/src/browser/property/actors/initialize.d.ts.map +1 -1
  137. package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +3 -3
  138. package/dist/types/src/browser/react/trash.d.ts +1 -1
  139. package/dist/types/src/browser/react/trash.d.ts.map +1 -1
  140. package/dist/types/src/browser/services/db/dbMachine.d.ts +6 -6
  141. package/dist/types/src/browser/services/publish/publishMachine.d.ts +17 -17
  142. package/dist/types/src/types/machines.d.ts +4 -0
  143. package/dist/types/src/types/machines.d.ts.map +1 -1
  144. package/package.json +1 -1
  145. package/dist/index-BEzB8REh.js.map +0 -1
  146. package/dist/index-ChGsdGPJ.js.map +0 -1
  147. package/dist/seed.schema.config-jKpK-lR6.js.map +0 -1
@@ -0,0 +1,101 @@
1
+ import { Decorator, Project } from 'ts-morph'
2
+ import { Field, Type } from 'protobufjs'
3
+ import fs from 'fs'
4
+
5
+ type TsToProtoOptions = {
6
+ tsFilePath: string
7
+ tsConfigPath: string
8
+ outputFilePath: string
9
+ }
10
+
11
+ type TsToProto = (options: TsToProtoOptions) => void
12
+
13
+ export const tsToProto: TsToProto = ({
14
+ tsFilePath,
15
+ tsConfigPath,
16
+ outputFilePath,
17
+ }) => {
18
+ // Initialize the TypeScript project
19
+ const project = new Project({
20
+ tsConfigFilePath: tsConfigPath,
21
+ })
22
+
23
+ // Add the source file
24
+ const sourceFile = project.addSourceFileAtPath(tsFilePath)
25
+
26
+ // Helper function to extract decorator arguments
27
+ const getDecoratorArgument = (decorator: Decorator): string => {
28
+ const callExpression = decorator.getCallExpression()
29
+ if (callExpression) {
30
+ const args = callExpression.getArguments()
31
+ if (args.length > 0) {
32
+ return args[0].getText().replace(/['"]/g, '')
33
+ }
34
+ }
35
+ return ''
36
+ }
37
+
38
+ // Process each class
39
+ const classes = sourceFile.getClasses()
40
+ const protoClasses: { [key: string]: Type } = {}
41
+
42
+ classes.forEach((cls) => {
43
+ const className = cls.getName()
44
+ if (!className) {
45
+ throw new Error('Class name not found')
46
+ }
47
+ const type = new Type(className)
48
+
49
+ // Process each property
50
+ cls.getProperties().forEach((prop, index) => {
51
+ const propName = prop.getName()
52
+ const decorators = prop.getDecorators()
53
+
54
+ decorators.forEach((decorator) => {
55
+ const decoratorName = decorator.getName()
56
+ switch (decoratorName) {
57
+ case 'Text':
58
+ type.add(new Field(propName, type.fieldsArray.length + 1, 'string'))
59
+ break
60
+ case 'ImageSrc':
61
+ type.add(new Field(propName, type.fieldsArray.length + 1, 'string'))
62
+ break
63
+ case 'Relation':
64
+ const relatedType = getDecoratorArgument(decorator)
65
+ type.add(
66
+ new Field(propName, type.fieldsArray.length + 1, relatedType),
67
+ )
68
+ break
69
+ case 'List':
70
+ const listType = getDecoratorArgument(decorator)
71
+ type.add(
72
+ new Field(
73
+ propName,
74
+ type.fieldsArray.length + 1,
75
+ listType,
76
+ 'repeated',
77
+ ),
78
+ )
79
+ break
80
+ default:
81
+ break
82
+ }
83
+ })
84
+ })
85
+
86
+ protoClasses[className] = type
87
+ })
88
+
89
+ // Generate .proto content
90
+ let protoContent = 'syntax = "proto3";\n\n'
91
+ Object.values(protoClasses).forEach((type) => {
92
+ protoContent += `message ${type.name} {\n`
93
+ for (const field of type.fieldsArray) {
94
+ protoContent += ` ${field.repeated ? 'repeated' : ''} ${field.type} ${field.name} = ${field.id};\n`
95
+ }
96
+ protoContent += '}\n'
97
+ })
98
+
99
+ // Write to .proto file
100
+ fs.writeFileSync(outputFilePath, protoContent)
101
+ }
@@ -0,0 +1,12 @@
1
+ type SqliteWasmResult = {
2
+ type: string | null
3
+ row: string[] | null
4
+ rowNumber: number | null
5
+ columnNames: string[]
6
+ }
7
+ type SqliteWasmCallback = (result: SqliteWasmResult) => void
8
+
9
+ type ReturnObj = {
10
+ database: string
11
+ [key: string]: string | number | null | undefined | string[]
12
+ }
@@ -0,0 +1,86 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { FromCallbackInput, PublishMachineContext } from '@/types'
3
+ import { Item } from '@/browser'
4
+ import debug from 'debug'
5
+ import { getCorrectId } from '@/browser/helpers'
6
+
7
+ const logger = debug('app:services:publish:actors:upload')
8
+
9
+ type UploadItem = {
10
+ sourceFilePath: string
11
+ fileSize: number
12
+ filename: string
13
+ seedLocalId?: string
14
+ metadataLocalId?: string
15
+ }
16
+
17
+ export const upload = fromCallback<
18
+ EventObject,
19
+ FromCallbackInput<PublishMachineContext>
20
+ >(({ sendBack, input: { context } }) => {
21
+ const { localId } = context
22
+
23
+ const _upload = async () => {
24
+ const item = await Item.find({ seedLocalId: localId })
25
+
26
+ if (!item) {
27
+ logger('no item with localId', localId)
28
+ return false
29
+ }
30
+
31
+ const editedProperties = await item.getEditedProperties()
32
+
33
+ for (const propertyData of editedProperties) {
34
+ if (propertyData.refSeedType === 'image') {
35
+ // Check sha256 of local file against sha256 of remote files
36
+ // If different, add this file to uploadItems
37
+ }
38
+ }
39
+
40
+ const uploadItems = []
41
+
42
+ for (const editedPropertyData of editedProperties) {
43
+ const propertyName = editedPropertyData.propertyName
44
+ const editedProperty = item.properties[propertyName]
45
+
46
+ if (!editedProperty || !editedProperty.propertyDef) {
47
+ continue
48
+ }
49
+
50
+ if (
51
+ editedProperty.propertyDef.refValueType &&
52
+ editedProperty.propertyDef.refValueType === 'ImageSrc'
53
+ ) {
54
+ const context = editedProperty.getService().getSnapshot().context
55
+ const imageSeedId = context.propertyValue
56
+ const { localId, uid } = getCorrectId(imageSeedId)
57
+ }
58
+
59
+ if (
60
+ editedProperty.propertyDef.storageType === 'ItemStorage' &&
61
+ editedProperty.propertyDef.localStorageDir
62
+ ) {
63
+ }
64
+ }
65
+
66
+ if (uploadItems.length === 0) {
67
+ return true
68
+ }
69
+
70
+ // const turbo = TurboFactory.unauthenticated()
71
+
72
+ // turbo.uploadSignedDataItem()
73
+ //
74
+ // const { id, owner, dataCaches, fastFinalityIndexes } = await turbo.uploadFile(() => {
75
+ // fileStreamFactory => () => fs.createReadStream(filePath),
76
+ // fileSizeFactory => () => fileSize,
77
+ // });
78
+ return false
79
+ }
80
+
81
+ _upload().then((isValid) => {
82
+ if (isValid) {
83
+ sendBack({ type: 'uploadSuccess' })
84
+ }
85
+ })
86
+ })
@@ -0,0 +1,42 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { DbServiceContext, FromCallbackInput } from '@/types/machines'
3
+ import { fs } from '@zenfs/core'
4
+ import {
5
+ DB_VALIDATING_SUCCESS,
6
+ DB_VALIDATING_WAIT,
7
+ } from '@/browser/services/internal/constants'
8
+
9
+ export const validate = fromCallback<
10
+ EventObject,
11
+ FromCallbackInput<DbServiceContext>
12
+ >(({ sendBack, input: { context } }) => {
13
+ const { pathToDir, pathToDb } = context
14
+
15
+ const pathsToCheck = [
16
+ pathToDir,
17
+ `${pathToDir}/db`,
18
+ `${pathToDir}/db/meta`,
19
+ `${pathToDir}/db/meta/_journal.json`,
20
+ ]
21
+
22
+ const _validate = async (): Promise<boolean> => {
23
+ // If any of the necessary files don't exist, we wipe them all and recreate
24
+ let exists = false
25
+
26
+ for (const path of pathsToCheck) {
27
+ exists = await fs.promises.exists(path)
28
+ if (!exists) {
29
+ sendBack({
30
+ type: DB_VALIDATING_WAIT,
31
+ })
32
+ return false
33
+ }
34
+ }
35
+ return exists
36
+ }
37
+
38
+ _validate().then(() => {
39
+ sendBack({ type: DB_VALIDATING_SUCCESS, pathToDb, pathToDir })
40
+ return
41
+ })
42
+ })
@@ -0,0 +1,33 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { INTERNAL_VALIDATING_INPUT_SUCCESS } from '@/browser/services/internal/constants'
3
+ import { internalMachine } from '@/browser/services/internal/internalMachine'
4
+
5
+ export const validateInput = fromCallback<EventObject, typeof internalMachine>(
6
+ ({ sendBack, input: { event } }) => {
7
+ const { endpoints, addresses } = event
8
+
9
+ if (typeof window === 'undefined') {
10
+ throw new Error('validateInput called from non-browser context')
11
+ }
12
+
13
+ if (!endpoints || !endpoints.filePaths || !endpoints.files) {
14
+ throw new Error('validateInput called with invalid endpoints')
15
+ }
16
+
17
+ if (!addresses || !addresses.length) {
18
+ throw new Error('validateInput called with invalid addresses')
19
+ }
20
+
21
+ const _validateInput = async (): Promise<void> => {
22
+ sendBack({
23
+ type: INTERNAL_VALIDATING_INPUT_SUCCESS,
24
+ endpoints,
25
+ addresses,
26
+ })
27
+ }
28
+
29
+ _validateInput().then(() => {
30
+ return
31
+ })
32
+ },
33
+ )
@@ -0,0 +1,20 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { FromCallbackInput, PublishMachineContext } from '@/types'
3
+
4
+ export const validateItemData = fromCallback<
5
+ EventObject,
6
+ FromCallbackInput<PublishMachineContext>
7
+ >(({ sendBack, input: { context } }) => {
8
+ const _validateItemData = async () => {
9
+ if (context && context.localId) {
10
+ return true
11
+ }
12
+ return false
13
+ }
14
+
15
+ _validateItemData().then((isValid) => {
16
+ if (isValid) {
17
+ sendBack({ type: 'validateItemDataSuccess' })
18
+ }
19
+ })
20
+ })
@@ -0,0 +1,23 @@
1
+ import { EventObject, fromCallback } from 'xstate'
2
+ import { itemMachineSingle } from '@/browser/item/single/itemMachineSingle'
3
+
4
+ import { getAppDb } from '@/browser/db/sqlWasmClient'
5
+
6
+ export const waitForDb = fromCallback<EventObject, typeof itemMachineSingle>(
7
+ ({ sendBack }) => {
8
+ const _waitForDb = new Promise<void>((resolve) => {
9
+ const interval = setInterval(() => {
10
+ const appDb = getAppDb()
11
+
12
+ if (appDb) {
13
+ clearInterval(interval)
14
+ resolve()
15
+ }
16
+ }, 100)
17
+ })
18
+
19
+ _waitForDb.then(() => {
20
+ sendBack({ type: 'waitForDbSuccess' })
21
+ })
22
+ },
23
+ )