@seedprotocol/sdk 0.2.19 → 0.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Db-CQyWrG2a.js → Db-B1gJQbux.js} +3 -3
- package/dist/Db-B1gJQbux.js.map +1 -0
- package/dist/{Db-Cv4GVzh1.js → Db-CSgUyick.js} +33 -11
- package/dist/Db-CSgUyick.js.map +1 -0
- package/dist/{Item-UegZbC_j.js → Item-B_ZA4PWq.js} +2 -2
- package/dist/{Item-UegZbC_j.js.map → Item-B_ZA4PWq.js.map} +1 -1
- package/dist/ItemProperty-CQrtYQT7.js +39 -0
- package/dist/ItemProperty-CQrtYQT7.js.map +1 -0
- package/dist/{index-DQrMMoLY.js → index-8LV9Tqv2.js} +2 -2
- package/dist/index-8LV9Tqv2.js.map +1 -0
- package/dist/{index-DNw_v54Y.js → index-Xi0K-lIT.js} +155 -128
- package/dist/index-Xi0K-lIT.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/node/db/node.app.db.config.ts +1 -0
- package/dist/{seed.schema.config-SuJxms_6.js → seed.schema.config-uN0rq0mU.js} +2 -2
- package/dist/{seed.schema.config-SuJxms_6.js.map → seed.schema.config-uN0rq0mU.js.map} +1 -1
- package/dist/src/BaseDb.ts +2 -2
- package/dist/src/BaseItem.ts +3 -5
- package/dist/src/Db.ts +37 -3
- package/dist/src/IItem.ts +0 -1
- package/dist/src/IItemProperty.ts +0 -1
- package/dist/src/ItemProperty.ts +9 -0
- package/dist/src/client.ts +4 -2
- package/dist/src/environment.ts +20 -0
- package/dist/src/fetchDbData.ts +1 -1
- package/dist/src/fetchSeeds.ts +1 -1
- package/dist/src/fetchVersions.ts +1 -1
- package/dist/src/globalMachine.ts +6 -2
- package/dist/src/initialize.ts +75 -78
- package/dist/src/internalMachine.ts +2 -0
- package/dist/src/machines.ts +2 -0
- package/dist/src/node.app.db.config.ts +1 -0
- package/dist/src/prepareDb.ts +12 -6
- package/dist/src/processItems.ts +1 -1
- package/dist/src/sqlWasmClient.ts +4 -4
- package/dist/src/updateItemPropertyValue.ts +5 -6
- package/dist/src/validateInput.ts +22 -8
- package/dist/types/src/Item/BaseItem.d.ts +1 -10
- package/dist/types/src/Item/BaseItem.d.ts.map +1 -1
- package/dist/types/src/Item/index.d.ts +2 -2
- package/dist/types/src/Item/index.d.ts.map +1 -1
- package/dist/types/src/Item/service/actors/initialize.d.ts +1 -1
- package/dist/types/src/Item/service/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/ItemProperty/index.d.ts +2 -2
- package/dist/types/src/ItemProperty/index.d.ts.map +1 -1
- package/dist/types/src/browser/db/Db.d.ts +1 -1
- package/dist/types/src/browser/db/Db.d.ts.map +1 -1
- package/dist/types/src/browser/db/sqlWasmClient.d.ts.map +1 -1
- package/dist/types/src/client.d.ts +1 -1
- package/dist/types/src/client.d.ts.map +1 -1
- package/dist/types/src/db/Db/BaseDb.d.ts +1 -1
- package/dist/types/src/db/Db/BaseDb.d.ts.map +1 -1
- package/dist/types/src/db/Db/index.d.ts.map +1 -1
- package/dist/types/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/types/src/helpers/ArweaveClient/index.d.ts.map +1 -1
- package/dist/types/src/helpers/EasClient/index.d.ts.map +1 -1
- package/dist/types/src/helpers/FileManager/index.d.ts.map +1 -1
- package/dist/types/src/helpers/QueryClient/index.d.ts.map +1 -1
- package/dist/types/src/helpers/environment.d.ts +2 -0
- package/dist/types/src/helpers/environment.d.ts.map +1 -1
- package/dist/types/src/interfaces/IItem.d.ts +1 -2
- package/dist/types/src/interfaces/IItem.d.ts.map +1 -1
- package/dist/types/src/interfaces/IItemProperty.d.ts +0 -2
- package/dist/types/src/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/types/src/node/ItemProperty/ItemProperty.d.ts +6 -0
- package/dist/types/src/node/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/node/db/Db.d.ts +1 -1
- package/dist/types/src/node/db/Db.d.ts.map +1 -1
- package/dist/types/src/node/db/node.app.db.config.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/fetchDbData.d.ts +1 -1
- package/dist/types/src/services/allItems/actors/fetchDbData.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts +1 -1
- package/dist/types/src/services/allItems/actors/fetchSeeds.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/fetchVersions.d.ts +1 -1
- package/dist/types/src/services/allItems/actors/fetchVersions.d.ts.map +1 -1
- package/dist/types/src/services/allItems/actors/processItems.d.ts +1 -1
- package/dist/types/src/services/allItems/actors/processItems.d.ts.map +1 -1
- package/dist/types/src/services/allItems/itemMachineAll.d.ts +9 -9
- package/dist/types/src/services/global/actors/initialize.d.ts.map +1 -1
- package/dist/types/src/services/global/globalMachine.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/prepareDb.d.ts +3 -1
- package/dist/types/src/services/internal/actors/prepareDb.d.ts.map +1 -1
- package/dist/types/src/services/internal/actors/validateInput.d.ts +3 -1
- package/dist/types/src/services/internal/actors/validateInput.d.ts.map +1 -1
- package/dist/types/src/services/internal/internalMachine.d.ts +56 -1
- package/dist/types/src/services/internal/internalMachine.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/machines.d.ts +2 -0
- package/dist/types/src/types/machines.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/Db-CQyWrG2a.js.map +0 -1
- package/dist/Db-Cv4GVzh1.js.map +0 -1
- package/dist/ItemProperty-l0sNRNKZ.js +0 -2
- package/dist/ItemProperty-l0sNRNKZ.js.map +0 -1
- package/dist/index-DNw_v54Y.js.map +0 -1
- package/dist/index-DQrMMoLY.js.map +0 -1
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'immer';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
export { D as Db,
|
|
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-Xi0K-lIT.js';
|
|
4
4
|
import 'tslib';
|
|
5
5
|
import 'drizzle-orm';
|
|
6
6
|
export { c as BaseArweaveClient, B as BaseEasClient, b as BaseFileManager, a as BaseQueryClient } from './constants-CuI_qYXt.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-Xi0K-lIT.js';
|
|
4
4
|
import 'immer';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
6
|
import 'drizzle-orm';
|
|
@@ -75,4 +75,4 @@ const models = {
|
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
export { models };
|
|
78
|
-
//# sourceMappingURL=seed.schema.config-
|
|
78
|
+
//# sourceMappingURL=seed.schema.config-uN0rq0mU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.schema.config-
|
|
1
|
+
{"version":3,"file":"seed.schema.config-uN0rq0mU.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;;;;;"}
|
package/dist/src/BaseDb.ts
CHANGED
|
@@ -20,8 +20,8 @@ export abstract class BaseDb implements IDb {
|
|
|
20
20
|
return this.PlatformClass.isAppDbReady()
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
static prepareDb(): Promise<BaseSQLiteDatabase> {
|
|
24
|
-
return this.PlatformClass.prepareDb()
|
|
23
|
+
static prepareDb(filesDir: string): Promise<BaseSQLiteDatabase> {
|
|
24
|
+
return this.PlatformClass.prepareDb(filesDir)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
static connectToDb(pathToDir: string, dbName: string): Promise<unknown> {
|
package/dist/src/BaseItem.ts
CHANGED
|
@@ -27,11 +27,11 @@ import { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'
|
|
|
27
27
|
import { getItemProperties } from '@/db/read/getItemProperties'
|
|
28
28
|
import { getPublishUploads } from '@/db/read/getPublishUploads'
|
|
29
29
|
import { getPublishPayload } from '@/db/read/getPublishPayload'
|
|
30
|
+
import { createNewItem } from '@/db/write/createNewItem'
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
export abstract class BaseItem<T extends ModelValues<ModelSchema>>
|
|
33
|
+
export abstract class BaseItem<T extends ModelValues<ModelSchema>> implements IItem<T> {
|
|
33
34
|
|
|
34
|
-
implements IItem<T> {
|
|
35
35
|
protected static instanceCache: Map<string, { instance: IItem<any>; refCount: number }> = new Map();
|
|
36
36
|
protected _subscription: Subscription | undefined;
|
|
37
37
|
protected readonly _storageTransactionId: string | undefined;
|
|
@@ -39,9 +39,7 @@ export abstract class BaseItem<T extends ModelValues<ModelSchema>>
|
|
|
39
39
|
protected _propertiesSubject: BehaviorSubject<Record<string, IItemProperty<any>>> = new BehaviorSubject({});
|
|
40
40
|
protected readonly _service: ActorRefFrom<typeof itemMachineSingle>;
|
|
41
41
|
|
|
42
|
-
constructor(
|
|
43
|
-
initialValues: NewItemProps<T>,
|
|
44
|
-
) {
|
|
42
|
+
constructor(initialValues: NewItemProps<T>) {
|
|
45
43
|
|
|
46
44
|
const {
|
|
47
45
|
modelName,
|
package/dist/src/Db.ts
CHANGED
|
@@ -2,6 +2,34 @@ import { BaseDb } from "@/db/Db/BaseDb";
|
|
|
2
2
|
import { IDb } from "@/interfaces";
|
|
3
3
|
import nodeAppDbConfig from "./node.app.db.config";
|
|
4
4
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
5
|
+
import { defineConfig } from "drizzle-kit";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { DrizzleConfig } from "drizzle-orm/utils";
|
|
8
|
+
|
|
9
|
+
const getConfig = (filesDir: string) => {
|
|
10
|
+
let sdkRoot = './node_modules/@seedprotocol/sdk'
|
|
11
|
+
|
|
12
|
+
if (process.env.IS_SEED_DEV) {
|
|
13
|
+
sdkRoot = './src'
|
|
14
|
+
}
|
|
15
|
+
const dotSeedDir = path.join(filesDir, '.seed')
|
|
16
|
+
let schemaDir = `${sdkRoot}/dist/seedSchema/*.ts`
|
|
17
|
+
|
|
18
|
+
if (process.env.IS_SEED_DEV) {
|
|
19
|
+
schemaDir = `${sdkRoot}/seedSchema/*.ts`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const nodeDbConfig = defineConfig({
|
|
23
|
+
schema: schemaDir,
|
|
24
|
+
dialect: 'sqlite',
|
|
25
|
+
out: `${dotSeedDir}/db`,
|
|
26
|
+
dbCredentials: {
|
|
27
|
+
url: `${dotSeedDir}/db/app_db.sqlite3`,
|
|
28
|
+
},
|
|
29
|
+
}) as DrizzleConfig
|
|
30
|
+
|
|
31
|
+
return nodeDbConfig
|
|
32
|
+
}
|
|
5
33
|
|
|
6
34
|
export class Db extends BaseDb implements IDb {
|
|
7
35
|
constructor() {
|
|
@@ -16,13 +44,19 @@ export class Db extends BaseDb implements IDb {
|
|
|
16
44
|
return true
|
|
17
45
|
}
|
|
18
46
|
|
|
19
|
-
static async prepareDb() {
|
|
20
|
-
|
|
47
|
+
static async prepareDb(filesDir: string) {
|
|
48
|
+
const nodeDbConfig = getConfig(filesDir)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
return drizzle(nodeDbConfig)
|
|
21
52
|
}
|
|
22
53
|
|
|
23
54
|
static async connectToDb(pathToDir: string, dbName: string) {
|
|
55
|
+
|
|
56
|
+
const nodeDbConfig = getConfig(pathToDir)
|
|
57
|
+
|
|
24
58
|
return {
|
|
25
|
-
id: drizzle(
|
|
59
|
+
id: drizzle(nodeDbConfig).$client.name
|
|
26
60
|
}
|
|
27
61
|
}
|
|
28
62
|
}
|
package/dist/src/IItem.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { IItemProperty } from './IItemProperty'
|
|
|
5
5
|
|
|
6
6
|
export interface IItem<T extends ModelValues<ModelSchema>> {
|
|
7
7
|
|
|
8
|
-
constructor(initialValues: NewItemProps<T>): void
|
|
9
8
|
subscribe(callback: (itemProps: any) => void): Subscription
|
|
10
9
|
getService(): ActorRefFrom<any>
|
|
11
10
|
getEditedProperties(): Promise<PropertyData[]>
|
package/dist/src/ItemProperty.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IItemProperty } from '@/interfaces'
|
|
2
|
+
import { BaseItemProperty } from '@/ItemProperty/BaseItemProperty'
|
|
3
|
+
import { CreatePropertyInstanceProps, ModelSchema, ModelValues, } from '@/types'
|
|
4
|
+
|
|
5
|
+
export class ItemProperty<PropertyType> extends BaseItemProperty<PropertyType> implements IItemProperty<PropertyType> {
|
|
6
|
+
constructor(initialValues: Partial<CreatePropertyInstanceProps>) {
|
|
7
|
+
super(initialValues)
|
|
8
|
+
}
|
|
9
|
+
}
|
package/dist/src/client.ts
CHANGED
|
@@ -20,7 +20,8 @@ import { initFileManager } from './helpers/FileManager'
|
|
|
20
20
|
import { initDb } from './db/Db'
|
|
21
21
|
|
|
22
22
|
const client = {
|
|
23
|
-
init: async (
|
|
23
|
+
init: async (options: SeedConstructorOptions) => {
|
|
24
|
+
const { config, addresses } = options
|
|
24
25
|
|
|
25
26
|
await initItem()
|
|
26
27
|
await initItemProperty()
|
|
@@ -29,7 +30,7 @@ const client = {
|
|
|
29
30
|
await initFileManager()
|
|
30
31
|
await initDb()
|
|
31
32
|
|
|
32
|
-
const { endpoints, models, arweaveDomain } = config
|
|
33
|
+
const { endpoints, models, arweaveDomain, filesDir, } = config
|
|
33
34
|
|
|
34
35
|
if (arweaveDomain) {
|
|
35
36
|
setArweaveDomain(arweaveDomain)
|
|
@@ -54,6 +55,7 @@ const client = {
|
|
|
54
55
|
models,
|
|
55
56
|
addresses,
|
|
56
57
|
arweaveDomain,
|
|
58
|
+
filesDir,
|
|
57
59
|
})
|
|
58
60
|
|
|
59
61
|
const { models: internalModels } = await import('@/db/configs/seed.schema.config')
|
package/dist/src/environment.ts
CHANGED
|
@@ -13,3 +13,23 @@ export const isBrowser = (): boolean => {
|
|
|
13
13
|
export const isReactNative = (): boolean => {
|
|
14
14
|
return typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
export const isElectron = (): boolean => {
|
|
18
|
+
return typeof process !== 'undefined' && process.versions != null && process.versions.electron != null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const getEnvironment = (): string => {
|
|
22
|
+
if (isBrowser()) {
|
|
23
|
+
return 'browser'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isElectron()) {
|
|
27
|
+
return 'electron'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (isReactNative()) {
|
|
31
|
+
return 'react-native'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return 'node'
|
|
35
|
+
}
|
package/dist/src/fetchDbData.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AllItemsMachineContext, FromCallbackInput } from '@/types'
|
|
|
3
3
|
|
|
4
4
|
export const fetchDbData = fromCallback<
|
|
5
5
|
EventObject,
|
|
6
|
-
FromCallbackInput<
|
|
6
|
+
FromCallbackInput<AllItemsMachineContext>
|
|
7
7
|
>(
|
|
8
8
|
({ sendBack, input: { context } }) => {
|
|
9
9
|
const { modelNamePlural, times } = context
|
package/dist/src/fetchSeeds.ts
CHANGED
|
@@ -11,7 +11,7 @@ const logger = debug('app:allItemsActors:fetchSeeds')
|
|
|
11
11
|
|
|
12
12
|
export const fetchSeeds = fromCallback<
|
|
13
13
|
EventObject,
|
|
14
|
-
FromCallbackInput<
|
|
14
|
+
FromCallbackInput<AllItemsMachineContext>
|
|
15
15
|
>(
|
|
16
16
|
({ sendBack, input: { context } }) => {
|
|
17
17
|
const { queryVariables, modelName } = context
|
|
@@ -8,7 +8,7 @@ import { BaseQueryClient } from '@/helpers/QueryClient/BaseQueryClient'
|
|
|
8
8
|
|
|
9
9
|
export const fetchVersions = fromCallback<
|
|
10
10
|
EventObject,
|
|
11
|
-
FromCallbackInput<
|
|
11
|
+
FromCallbackInput<AllItemsMachineContext>
|
|
12
12
|
>(
|
|
13
13
|
({ sendBack, input: { context } }) => {
|
|
14
14
|
const { itemSeeds, modelName } = context
|
|
@@ -61,11 +61,15 @@ const globalMachine = setup({
|
|
|
61
61
|
addedModelRecordsToDb: false,
|
|
62
62
|
models: ({ event }) => event.models,
|
|
63
63
|
endpoints: ({ event }) => event.endpoints,
|
|
64
|
-
|
|
64
|
+
filesDir: ({ event }) => event.filesDir,
|
|
65
|
+
internalService: ({ spawn, event }) => {
|
|
65
66
|
return spawn(internalMachine, {
|
|
66
67
|
systemId: MachineIds.INTERNAL,
|
|
67
68
|
input: {
|
|
68
|
-
endpoints:
|
|
69
|
+
endpoints: event.endpoints,
|
|
70
|
+
filesDir: event.filesDir,
|
|
71
|
+
addresses: event.addresses,
|
|
72
|
+
arweaveDomain: event.arweaveDomain,
|
|
69
73
|
},
|
|
70
74
|
})
|
|
71
75
|
},
|
package/dist/src/initialize.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventObject, fromCallback, Subscription } from 'xstate'
|
|
2
|
-
import {
|
|
2
|
+
import { getEnvironment } from '@/helpers/environment'
|
|
3
3
|
import {
|
|
4
4
|
GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES,
|
|
5
5
|
GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY,
|
|
@@ -18,105 +18,102 @@ export const initialize = fromCallback<
|
|
|
18
18
|
EventObject,
|
|
19
19
|
FromCallbackInput<GlobalMachineContext, EventObject>
|
|
20
20
|
>(({ sendBack, input: { event, context } }) => {
|
|
21
|
-
const { internalService, models, endpoints, arweaveDomain } = context
|
|
21
|
+
const { internalService, models, endpoints, arweaveDomain, addresses, } = context
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let environment = 'browser'
|
|
26
|
-
|
|
27
|
-
if (isNode()) {
|
|
28
|
-
environment = 'node'
|
|
23
|
+
if (!internalService) {
|
|
24
|
+
throw new Error('internalService is required')
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
if (
|
|
32
|
-
|
|
27
|
+
if (!models) {
|
|
28
|
+
throw new Error('models is required')
|
|
33
29
|
}
|
|
34
30
|
|
|
31
|
+
|
|
32
|
+
let environment = getEnvironment()
|
|
33
|
+
|
|
35
34
|
let internalSubscription: Subscription | undefined
|
|
36
35
|
let easSubscription: Subscription | undefined
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
37
|
+
const _initFileSystem = async (): Promise<void> => {
|
|
38
|
+
return
|
|
39
|
+
// return new Promise((resolve) => {
|
|
40
|
+
// })
|
|
41
|
+
}
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
internalService.send({
|
|
54
|
-
type: 'init',
|
|
55
|
-
endpoints,
|
|
56
|
-
addresses,
|
|
57
|
-
arweaveDomain,
|
|
58
|
-
})
|
|
43
|
+
const _initInternal = async (): Promise<void> => {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
internalSubscription = internalService.subscribe((snapshot) => {
|
|
46
|
+
logger('[sdk] [internal] snapshot', snapshot)
|
|
47
|
+
if (snapshot.value === 'ready') {
|
|
48
|
+
resolve()
|
|
49
|
+
}
|
|
59
50
|
})
|
|
60
|
-
|
|
51
|
+
internalService.send({
|
|
52
|
+
type: 'init',
|
|
53
|
+
endpoints,
|
|
54
|
+
addresses,
|
|
55
|
+
arweaveDomain,
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const _initAllItemsServices = async (): Promise<void> => {
|
|
61
|
+
const appDb = BaseDb.getAppDb()
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
const rows = await appDb
|
|
64
|
+
.select()
|
|
65
|
+
.from(appState)
|
|
66
|
+
.where(like(appState.key, 'snapshot__%'))
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
const payloadObj = {
|
|
69
|
+
create: {},
|
|
70
|
+
restore: {},
|
|
71
|
+
}
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
const modelNamesRestored: string[] = []
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
75
|
+
if (rows && rows.length > 0) {
|
|
76
|
+
for (const row of rows) {
|
|
77
|
+
const modelName = row.key.replace('snapshot__', '')
|
|
78
|
+
payloadObj.restore[modelName] = JSON.parse(row.value)
|
|
79
|
+
modelNamesRestored.push(modelName)
|
|
83
80
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
}
|
|
82
|
+
for (const [modelName, ModelClass] of Object.entries(models)) {
|
|
83
|
+
if (!modelNamesRestored.includes(modelName)) {
|
|
84
|
+
payloadObj.create[modelName] = ModelClass
|
|
88
85
|
}
|
|
89
|
-
sendBack({
|
|
90
|
-
type: GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES,
|
|
91
|
-
...payloadObj,
|
|
92
|
-
})
|
|
93
86
|
}
|
|
87
|
+
sendBack({
|
|
88
|
+
type: GLOBAL_INITIALIZING_CREATE_ALL_ITEMS_SERVICES,
|
|
89
|
+
...payloadObj,
|
|
90
|
+
})
|
|
91
|
+
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
const _initEas = async (): Promise<void> => {
|
|
94
|
+
await fetchSchemaUids()
|
|
95
|
+
}
|
|
98
96
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
_initFileSystem().then(() => {
|
|
98
|
+
logger('[global/actors] File system initialized')
|
|
99
|
+
})
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
_initInternal()
|
|
102
|
+
.then(() => {
|
|
103
|
+
return _initAllItemsServices()
|
|
104
|
+
})
|
|
105
|
+
.then(() => {
|
|
106
|
+
return _initEas()
|
|
107
|
+
})
|
|
108
|
+
.then(() => {
|
|
109
|
+
logger('[global/actors] Internal initialized')
|
|
110
|
+
sendBack({ type: GLOBAL_INITIALIZING_INTERNAL_SERVICE_READY })
|
|
111
|
+
internalSubscription?.unsubscribe()
|
|
112
|
+
})
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
114
|
+
// _initEas().then(() => {
|
|
115
|
+
// logger('EAS initialized')
|
|
116
|
+
// })
|
|
120
117
|
|
|
121
118
|
sendBack({ type: GLOBAL_INITIALIZING_SEND_CONFIG, environment })
|
|
122
119
|
|
|
@@ -85,6 +85,8 @@ export const internalMachine = setup({
|
|
|
85
85
|
actions: assign({
|
|
86
86
|
endpoints: ({ event }) => event.endpoints,
|
|
87
87
|
addresses: ({ event }) => event.addresses,
|
|
88
|
+
filesDir: ({ event }) => event.filesDir,
|
|
89
|
+
arweaveDomain: ({ event }) => event.arweaveDomain,
|
|
88
90
|
}),
|
|
89
91
|
},
|
|
90
92
|
},
|
package/dist/src/machines.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type InternalMachineContext = {
|
|
|
18
18
|
error?: string
|
|
19
19
|
endpoints: Endpoints
|
|
20
20
|
addresses: string[]
|
|
21
|
+
filesDir?: string
|
|
21
22
|
arweaveDomain?: string
|
|
22
23
|
environment: string
|
|
23
24
|
hasFiles: boolean
|
|
@@ -36,6 +37,7 @@ export type GlobalMachineContext = {
|
|
|
36
37
|
internalService?: ActorRefFrom<any>
|
|
37
38
|
publishItemService?: ActorRefFrom<any>
|
|
38
39
|
arweaveDomain?: string
|
|
40
|
+
filesDir?: string
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export type PublishMachineContext = PublishRequestData & {
|
package/dist/src/prepareDb.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { BaseDb } from '@/db/Db/BaseDb'
|
|
2
|
+
import { InternalMachineContext } from '@/types'
|
|
3
|
+
import { FromCallbackInput } from '@/types'
|
|
2
4
|
import { EventObject, fromCallback } from 'xstate'
|
|
3
5
|
|
|
4
6
|
|
|
5
|
-
export const prepareDb = fromCallback<
|
|
7
|
+
export const prepareDb = fromCallback<
|
|
8
|
+
EventObject,
|
|
9
|
+
FromCallbackInput<InternalMachineContext>
|
|
10
|
+
>(({ sendBack, input: { context } }) => {
|
|
11
|
+
const { filesDir } = context
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
13
|
+
if (!filesDir) {
|
|
14
|
+
throw new Error('filesDir is required')
|
|
15
|
+
}
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
const _prepareDb = async (): Promise<void> => {
|
|
18
|
+
const manager = await BaseDb.prepareDb(filesDir)
|
|
13
19
|
if (manager) {
|
|
14
20
|
sendBack({ type: 'prepareDbSuccess', manager })
|
|
15
21
|
}
|
package/dist/src/processItems.ts
CHANGED
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
} from 'drizzle-orm/sqlite-proxy'
|
|
6
6
|
import { sql } from 'drizzle-orm'
|
|
7
7
|
|
|
8
|
-
let sqlite3InitModule
|
|
9
|
-
let sqliteWasmClient
|
|
8
|
+
let sqlite3InitModule: any
|
|
9
|
+
let sqliteWasmClient: any
|
|
10
10
|
let manager: SqliteConnectionManager | undefined
|
|
11
11
|
let isPreparing = false
|
|
12
12
|
|
|
13
|
-
export const setSqliteWasmClient = (client) => {
|
|
13
|
+
export const setSqliteWasmClient = (client: any) => {
|
|
14
14
|
sqliteWasmClient = client
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -58,7 +58,7 @@ export const getManager = () => {
|
|
|
58
58
|
return manager
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export const setManager = (m) => {
|
|
61
|
+
export const setManager = (m: any) => {
|
|
62
62
|
manager = m
|
|
63
63
|
}
|
|
64
64
|
let appDb: SqliteRemoteDatabase<Record<string, unknown>> | undefined
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { escapeSqliteString } from '@/helpers/db'
|
|
2
|
-
import { getAppDb, runQueryForStatement } from '@/browser'
|
|
3
2
|
import { metadata, MetadataType } from '@/seedSchema'
|
|
4
3
|
import { and, eq, sql } from 'drizzle-orm'
|
|
5
4
|
import { getSeedData } from '@/db/read/getSeedData'
|
|
@@ -7,7 +6,7 @@ import { getVersionData } from '@/db/read/getVersionData'
|
|
|
7
6
|
import { generateId } from '@/helpers'
|
|
8
7
|
import debug from 'debug'
|
|
9
8
|
import { eventEmitter } from '@/eventBus'
|
|
10
|
-
|
|
9
|
+
import { BaseDb } from '@/db/Db/BaseDb'
|
|
11
10
|
const logger = debug('app:write:updateItemPropertyValue')
|
|
12
11
|
|
|
13
12
|
const sendItemUpdateEvent = ({ modelName, seedLocalId, seedUid }) => {
|
|
@@ -51,7 +50,7 @@ export const updateItemPropertyValue: UpdateItemPropertyValue = async ({
|
|
|
51
50
|
safeNewValue = escapeSqliteString(newValue)
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
const appDb = getAppDb()
|
|
53
|
+
const appDb = BaseDb.getAppDb()
|
|
55
54
|
|
|
56
55
|
const rows = await appDb
|
|
57
56
|
.select()
|
|
@@ -123,7 +122,7 @@ export const updateItemPropertyValue: UpdateItemPropertyValue = async ({
|
|
|
123
122
|
updated_at = ${Date.now()}
|
|
124
123
|
WHERE local_id = '${localId}';`
|
|
125
124
|
|
|
126
|
-
await
|
|
125
|
+
await appDb.run(sql.raw(updatePropertyStatement))
|
|
127
126
|
|
|
128
127
|
sendItemUpdateEvent({ modelName, seedLocalId, seedUid })
|
|
129
128
|
|
|
@@ -167,7 +166,7 @@ export const updateItemPropertyValue: UpdateItemPropertyValue = async ({
|
|
|
167
166
|
${localStorageDir ? `'${localStorageDir}'` : 'NULL'},
|
|
168
167
|
${Date.now()});`
|
|
169
168
|
|
|
170
|
-
await
|
|
169
|
+
await appDb.run(sql.raw(newPropertyStatement))
|
|
171
170
|
|
|
172
171
|
sendItemUpdateEvent({ modelName, seedLocalId, seedUid })
|
|
173
172
|
|
|
@@ -221,7 +220,7 @@ export const updateItemPropertyValue: UpdateItemPropertyValue = async ({
|
|
|
221
220
|
${localStorageDir ? `'${localStorageDir}'` : 'NULL'},
|
|
222
221
|
${Date.now()});`
|
|
223
222
|
|
|
224
|
-
await
|
|
223
|
+
await appDb.run(sql.raw(newPropertyStatement))
|
|
225
224
|
|
|
226
225
|
sendItemUpdateEvent({ modelName, seedLocalId, seedUid })
|
|
227
226
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { EventObject, fromCallback } from 'xstate'
|
|
2
|
-
import { INTERNAL_VALIDATING_INPUT_SUCCESS } from '@/services/internal/constants'
|
|
3
|
-
import {
|
|
2
|
+
import { INTERNAL_VALIDATING_INPUT_SUCCESS, ARWEAVE_HOST } from '@/services/internal/constants'
|
|
3
|
+
import { FromCallbackInput, InternalMachineContext } from '@/types'
|
|
4
|
+
import { isBrowser, isNode } from '@/helpers/environment'
|
|
4
5
|
|
|
5
|
-
export const validateInput = fromCallback<
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export const validateInput = fromCallback<
|
|
7
|
+
EventObject,
|
|
8
|
+
FromCallbackInput<InternalMachineContext>
|
|
9
|
+
>(
|
|
10
|
+
({ sendBack, input: { context } }) => {
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
+
const { endpoints, addresses, arweaveDomain } = context
|
|
13
|
+
let { filesDir } = context
|
|
12
14
|
|
|
13
15
|
if (!endpoints || !endpoints.filePaths || !endpoints.files) {
|
|
14
16
|
throw new Error('validateInput called with invalid endpoints')
|
|
@@ -18,11 +20,23 @@ export const validateInput = fromCallback<EventObject, typeof internalMachine>(
|
|
|
18
20
|
throw new Error('validateInput called with invalid addresses')
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
if (!filesDir) {
|
|
24
|
+
if (isBrowser()) {
|
|
25
|
+
filesDir = '/'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!isBrowser()) {
|
|
29
|
+
throw new Error('validateInput called with invalid filesDir')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
const _validateInput = async (): Promise<void> => {
|
|
22
34
|
sendBack({
|
|
23
35
|
type: INTERNAL_VALIDATING_INPUT_SUCCESS,
|
|
24
36
|
endpoints,
|
|
25
37
|
addresses,
|
|
38
|
+
filesDir,
|
|
39
|
+
arweaveDomain: arweaveDomain || ARWEAVE_HOST,
|
|
26
40
|
})
|
|
27
41
|
}
|
|
28
42
|
|