@seedprotocol/sdk 0.1.47 → 0.1.49
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/bin.js.map +1 -1
- package/dist/constants-BLctWkrn.js.map +1 -1
- package/dist/{index-DWf9Ls94.js → index-DMIKRod-.js} +3995 -3995
- package/dist/index-DMIKRod-.js.map +1 -0
- package/dist/{index-B2WbNudj.js → index-wKss7188.js} +10 -10
- package/dist/index-wKss7188.js.map +1 -0
- package/dist/main.js +7 -7
- package/dist/{seed.schema.config-mBqth17w.js → seed.schema.config-C0M8Rcti.js} +7 -7
- package/dist/seed.schema.config-C0M8Rcti.js.map +1 -0
- package/dist/src/AppStateSchema.ts +10 -0
- package/dist/src/Attestation.ts +21 -0
- package/dist/src/ConfigSchema.ts +15 -0
- package/dist/src/ItemProperty.ts +383 -0
- package/dist/src/MetadataSchema.ts +28 -0
- package/dist/src/ModelSchema.ts +46 -0
- package/dist/src/ModelUidSchema.ts +16 -0
- package/dist/src/PropertyUidSchema.ts +16 -0
- package/dist/src/Schema.ts +17 -0
- package/dist/src/SeedSchema.ts +29 -0
- package/dist/src/VersionSchema.ts +16 -0
- package/dist/src/actors.ts +280 -0
- package/dist/src/addModelsToDb.ts +150 -0
- package/dist/src/allItems.ts +23 -0
- package/dist/src/arweave.ts +37 -0
- package/dist/src/browser.app.db.config.ts +27 -0
- package/dist/src/browser.seed.db.config.ts +33 -0
- package/dist/src/browser.ts +30 -0
- package/dist/src/checkStatus.ts +50 -0
- package/dist/src/client.ts +85 -0
- package/dist/src/configureFs.ts +81 -0
- package/dist/src/connectToDb.ts +74 -0
- package/dist/src/connectionManager.ts +67 -0
- package/dist/src/constants.ts +118 -0
- package/dist/src/create.ts +39 -0
- package/dist/src/createItem.ts +15 -0
- package/dist/src/createItemMachine.ts +37 -0
- package/dist/src/createPublishAttempt.ts +16 -0
- package/dist/src/createSeeds.ts +24 -0
- package/dist/src/createVersion.ts +33 -0
- package/dist/src/db.ts +247 -0
- package/dist/src/dbMachine.ts +181 -0
- package/dist/src/deleteItem.ts +19 -0
- package/dist/src/download.ts +289 -0
- package/dist/src/drizzle.ts +82 -0
- package/dist/src/environment.ts +15 -0
- package/dist/src/eventBus.ts +5 -0
- package/dist/src/events.ts +14 -0
- package/dist/src/fetchDataFromEas.ts +90 -0
- package/dist/src/fetchDbData.ts +16 -0
- package/dist/src/fetchRelatedItems.ts +179 -0
- package/dist/src/fetchSeeds.ts +44 -0
- package/dist/src/fetchVersions.ts +41 -0
- package/dist/src/files.ts +16 -0
- package/dist/src/fragment-masking.ts +87 -0
- package/dist/src/fsProxy.ts +36 -0
- package/dist/src/getItem.ts +189 -0
- package/dist/src/getItemProperties.ts +162 -0
- package/dist/src/getItems.ts +75 -0
- package/dist/src/getMetadata.ts +40 -0
- package/dist/src/getModelSchemas.ts +88 -0
- package/dist/src/getSchemaForModel.ts +42 -0
- package/dist/src/getSeedData.ts +34 -0
- package/dist/src/getVersionData.ts +58 -0
- package/dist/src/getVersionsForVersionUids.ts +39 -0
- package/dist/src/globalMachine.ts +259 -0
- package/dist/src/gql.ts +113 -0
- package/dist/src/graphql.ts +3201 -0
- package/dist/src/helpers.ts +150 -0
- package/dist/src/hydrateExistingItem.ts +137 -0
- package/dist/src/hydrateFromDb.ts +254 -0
- package/dist/src/hydrateNewItem.ts +34 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.ts +73 -0
- package/dist/src/init.ts +61 -0
- package/dist/src/initialize.ts +127 -0
- package/dist/src/internalMachine.ts +220 -0
- package/dist/src/item.ts +324 -0
- package/dist/src/itemMachineAll.ts +158 -0
- package/dist/src/itemMachineSingle.ts +175 -0
- package/dist/src/loadAppDb.ts +47 -0
- package/dist/src/logger.ts +33 -0
- package/dist/src/machine.ts +55 -0
- package/dist/src/machines.ts +58 -0
- package/dist/src/migrate.ts +288 -0
- package/dist/src/model.ts +71 -0
- package/dist/src/modelClass.ts +19 -0
- package/dist/src/node.app.db.config.ts +40 -0
- package/dist/src/prepareDb.ts +34 -0
- package/dist/src/preparePublishRequestData.ts +81 -0
- package/dist/src/processItems.ts +71 -0
- package/dist/src/property.ts +161 -0
- package/dist/src/propertyMachine.ts +154 -0
- package/dist/src/publish.ts +31 -0
- package/dist/src/publishMachine.ts +77 -0
- package/dist/src/queries.ts +13 -0
- package/dist/src/read.ts +174 -0
- package/dist/src/recoverDeletedItem.ts +14 -0
- package/dist/src/request.ts +54 -0
- package/dist/src/requestAll.ts +157 -0
- package/dist/src/resolveRelatedValue.ts +348 -0
- package/dist/src/resolveRemoteStorage.ts +87 -0
- package/dist/src/save.ts +183 -0
- package/dist/src/saveConfig.ts +79 -0
- package/dist/src/saveDataToDb.ts +145 -0
- package/dist/src/saveMetadata.ts +18 -0
- package/dist/src/saveValueToDb.ts +94 -0
- package/dist/src/seed.schema.config.ts +25 -0
- package/dist/src/seed.ts +37 -0
- package/dist/src/seedData.ts +0 -0
- package/dist/src/seedProtocol.ts +17 -0
- package/dist/src/services.ts +359 -0
- package/dist/src/sqlWasmClient.ts +88 -0
- package/dist/src/syncDbWithEas.ts +686 -0
- package/dist/src/trash.ts +29 -0
- package/dist/src/ts-to-proto.ts +101 -0
- package/dist/src/types.ts +12 -0
- package/dist/src/upload.ts +86 -0
- package/dist/src/validate.ts +42 -0
- package/dist/src/validateInput.ts +33 -0
- package/dist/src/validateItemData.ts +20 -0
- package/dist/src/waitForDb.ts +23 -0
- package/dist/src/wasm.d.ts +8300 -0
- package/dist/src/write.ts +366 -0
- package/dist/types/src/browser/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/types/src/browser/item/single/actors/hydrateExistingItem.d.ts +3 -1
- package/dist/types/src/browser/item/single/actors/hydrateExistingItem.d.ts.map +1 -1
- package/dist/types/src/browser/item/single/actors/saveDataToDb.d.ts +3 -3
- package/dist/types/src/browser/item/single/itemMachineSingle.d.ts +3 -3
- package/dist/types/src/browser/property/ItemProperty.d.ts +7 -7
- package/dist/types/src/browser/property/ItemProperty.d.ts.map +1 -1
- package/dist/types/src/browser/property/actors/resolveRemoteStorage.d.ts +3 -3
- package/dist/types/src/browser/react/trash.d.ts +1 -1
- package/dist/types/src/browser/react/trash.d.ts.map +1 -1
- package/dist/types/src/browser/services/db/dbMachine.d.ts +6 -6
- package/dist/types/src/browser/services/publish/publishMachine.d.ts +17 -17
- package/dist/types/src/types/machines.d.ts +4 -0
- package/dist/types/src/types/machines.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/index-B2WbNudj.js.map +0 -1
- package/dist/index-DWf9Ls94.js.map +0 -1
- package/dist/seed.schema.config-mBqth17w.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { f as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, e as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SEEDS, b as GET_SEED_IDS, c as GET_STORAGE_TRANSACTION_ID, d as GET_VERSIONS, I as Item, g as itemMachineAll, i as itemMachineSingle } from './index-
|
|
1
|
+
export { f as GET_ALL_PROPERTIES_FOR_ALL_VERSIONS, e as GET_PROPERTIES, G as GET_SCHEMAS, a as GET_SEEDS, b as GET_SEED_IDS, c as GET_STORAGE_TRANSACTION_ID, d as GET_VERSIONS, I as Item, g as itemMachineAll, i as itemMachineSingle } from './index-DMIKRod-.js';
|
|
2
2
|
import './constants-BLctWkrn.js';
|
|
3
3
|
import 'path';
|
|
4
4
|
import 'reflect-metadata';
|
|
@@ -13,18 +13,18 @@ import 'debug';
|
|
|
13
13
|
import 'lodash-es';
|
|
14
14
|
import 'drizzle-orm/sqlite-core';
|
|
15
15
|
import 'eventemitter3';
|
|
16
|
-
import 'react';
|
|
17
|
-
import 'rxjs';
|
|
18
|
-
import 'immer';
|
|
19
|
-
import 'pluralize';
|
|
20
16
|
import '@tanstack/react-query';
|
|
21
17
|
import 'graphql-request';
|
|
22
18
|
import '@tanstack/query-sync-storage-persister';
|
|
23
19
|
import '@tanstack/react-query-persist-client';
|
|
24
|
-
import '
|
|
25
|
-
import '
|
|
20
|
+
import 'rxjs';
|
|
21
|
+
import 'immer';
|
|
22
|
+
import 'pluralize';
|
|
26
23
|
import '@statelyai/inspect';
|
|
27
|
-
import 'arweave';
|
|
28
|
-
import '@zenfs/dom';
|
|
29
24
|
import 'drizzle-orm/sqlite-proxy';
|
|
30
|
-
|
|
25
|
+
import '@zenfs/dom';
|
|
26
|
+
import 'arweave';
|
|
27
|
+
import 'react';
|
|
28
|
+
import 'use-immer';
|
|
29
|
+
import '@xstate/react';
|
|
30
|
+
//# sourceMappingURL=index-wKss7188.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-wKss7188.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { h as ImageSrc, I as Item, j as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, s as client, t as getCorrectId, r as getGlobalService, m as useCreateItem, o as useDeleteItem, p as useGlobalServiceStatus, k as useItem, l as useItemProperties, n as useItemProperty, u as useItems, q as useServices, w as withSeed } from './index-
|
|
1
|
+
export { h as ImageSrc, I as Item, j as ItemProperty, J as Json, L as List, M as Model, P as Property, R as Relation, T as Text, s as client, t as getCorrectId, r as getGlobalService, m as useCreateItem, o as useDeleteItem, p as useGlobalServiceStatus, k as useItem, l as useItemProperties, n as useItemProperty, u as useItems, q as useServices, w as withSeed } from './index-DMIKRod-.js';
|
|
2
2
|
import 'immer';
|
|
3
3
|
import 'reflect-metadata';
|
|
4
4
|
import './constants-BLctWkrn.js';
|
|
@@ -15,16 +15,16 @@ import 'debug';
|
|
|
15
15
|
import 'lodash-es';
|
|
16
16
|
import 'drizzle-orm/sqlite-core';
|
|
17
17
|
import 'eventemitter3';
|
|
18
|
-
import 'react';
|
|
19
|
-
import 'rxjs';
|
|
20
|
-
import 'pluralize';
|
|
21
18
|
import '@tanstack/react-query';
|
|
22
19
|
import 'graphql-request';
|
|
23
20
|
import '@tanstack/query-sync-storage-persister';
|
|
24
21
|
import '@tanstack/react-query-persist-client';
|
|
25
|
-
import '
|
|
26
|
-
import '
|
|
22
|
+
import 'rxjs';
|
|
23
|
+
import 'pluralize';
|
|
27
24
|
import '@statelyai/inspect';
|
|
28
|
-
import '@zenfs/dom';
|
|
29
25
|
import 'drizzle-orm/sqlite-proxy';
|
|
26
|
+
import '@zenfs/dom';
|
|
27
|
+
import 'react';
|
|
28
|
+
import 'use-immer';
|
|
29
|
+
import '@xstate/react';
|
|
30
30
|
//# sourceMappingURL=main.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as __decorate, a as __metadata } from './constants-BLctWkrn.js';
|
|
2
2
|
import 'drizzle-orm';
|
|
3
|
-
import { T as Text, M as Model } from './index-
|
|
3
|
+
import { T as Text, M as Model } from './index-DMIKRod-.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'reflect-metadata';
|
|
6
6
|
import 'xstate';
|
|
@@ -16,17 +16,17 @@ import 'debug';
|
|
|
16
16
|
import 'lodash-es';
|
|
17
17
|
import 'drizzle-orm/sqlite-core';
|
|
18
18
|
import 'eventemitter3';
|
|
19
|
-
import 'rxjs';
|
|
20
|
-
import 'immer';
|
|
21
|
-
import 'pluralize';
|
|
22
19
|
import '@tanstack/react-query';
|
|
23
20
|
import 'graphql-request';
|
|
24
21
|
import '@tanstack/query-sync-storage-persister';
|
|
25
22
|
import '@tanstack/react-query-persist-client';
|
|
26
|
-
import '
|
|
27
|
-
import '
|
|
23
|
+
import 'rxjs';
|
|
24
|
+
import 'immer';
|
|
25
|
+
import 'pluralize';
|
|
28
26
|
import '@statelyai/inspect';
|
|
29
27
|
import 'drizzle-orm/sqlite-proxy';
|
|
28
|
+
import 'use-immer';
|
|
29
|
+
import '@xstate/react';
|
|
30
30
|
|
|
31
31
|
let Seed = class Seed {
|
|
32
32
|
};
|
|
@@ -74,4 +74,4 @@ const models = {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
export { models };
|
|
77
|
-
//# sourceMappingURL=seed.schema.config-
|
|
77
|
+
//# sourceMappingURL=seed.schema.config-C0M8Rcti.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed.schema.config-C0M8Rcti.js","sources":["../../src/shared/configs/seed.schema.config.ts"],"sourcesContent":["import { Model, Text } from '@/browser'\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;;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
|
|
3
|
+
export const appState = sqliteTable('appState', {
|
|
4
|
+
key: text('key').unique(),
|
|
5
|
+
value: text('value'),
|
|
6
|
+
createdAt: int('created_at'),
|
|
7
|
+
updatedAt: int('updated_at'),
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export type appStateType = appState.$inferSelect
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { graphql, } from '../gql'
|
|
2
|
+
|
|
3
|
+
export const ATTESTATION_FIELDS = graphql(/* GraphQL */ `
|
|
4
|
+
fragment attestationFields on Attestation {
|
|
5
|
+
id
|
|
6
|
+
decodedDataJson
|
|
7
|
+
attester
|
|
8
|
+
schema {
|
|
9
|
+
schemaNames {
|
|
10
|
+
name
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
refUID
|
|
14
|
+
revoked
|
|
15
|
+
schemaId
|
|
16
|
+
txid
|
|
17
|
+
timeCreated
|
|
18
|
+
time
|
|
19
|
+
isOffchain
|
|
20
|
+
}
|
|
21
|
+
`,)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { blob, int, sqliteTable, text, check, } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { sql } from 'drizzle-orm'
|
|
3
|
+
|
|
4
|
+
export const config = sqliteTable('config', {
|
|
5
|
+
id: int('id').primaryKey({ autoIncrement: true }),
|
|
6
|
+
key: text('key').notNull(),
|
|
7
|
+
text: text('text'),
|
|
8
|
+
json: text('json', {mode: 'json'}),
|
|
9
|
+
blob: blob('blob', {mode: 'buffer'}),
|
|
10
|
+
}, () => {
|
|
11
|
+
return {
|
|
12
|
+
// Add a custom check constraint
|
|
13
|
+
atLeastOneNotNull: check('hasValue', sql`key IS NOT NULL OR text IS NOT NULL OR json IS NOT NULL OR blob IS NOT NULL`),
|
|
14
|
+
}
|
|
15
|
+
})
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { ItemPropertyProps, PropertyMachineContext } from '@/types'
|
|
2
|
+
import { ActorRefFrom, createActor, Subscription, waitFor } from 'xstate'
|
|
3
|
+
import { BehaviorSubject, Subscriber } from 'rxjs'
|
|
4
|
+
import { propertyMachine } from './propertyMachine'
|
|
5
|
+
import { immerable } from 'immer'
|
|
6
|
+
import pluralize from 'pluralize'
|
|
7
|
+
import { eventEmitter } from '@/eventBus'
|
|
8
|
+
import { getPropertyData } from '@/browser/db/read'
|
|
9
|
+
import { internalPropertyNames } from '@/shared/helpers/constants'
|
|
10
|
+
import debug from 'debug'
|
|
11
|
+
import { getModel } from '@/browser/stores/modelClass'
|
|
12
|
+
import { getCorrectId } from '@/browser/helpers'
|
|
13
|
+
import { Static } from '@sinclair/typebox'
|
|
14
|
+
import { TProperty } from '@/browser/property'
|
|
15
|
+
|
|
16
|
+
const logger = debug('app:property:class')
|
|
17
|
+
|
|
18
|
+
type ItemPropertyFindProps = {
|
|
19
|
+
propertyName: string
|
|
20
|
+
propertyLocalId?: string
|
|
21
|
+
seedLocalId?: string
|
|
22
|
+
seedUid?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const namesThatEndWithId: string[] = []
|
|
26
|
+
|
|
27
|
+
export class ItemProperty<PropertyType> {
|
|
28
|
+
private static instanceCache: Map<
|
|
29
|
+
string,
|
|
30
|
+
{ instance: ItemProperty<any>; refCount: number }
|
|
31
|
+
> = new Map()
|
|
32
|
+
private readonly _service: ActorRefFrom<typeof propertyMachine>
|
|
33
|
+
private _subject: BehaviorSubject<any>
|
|
34
|
+
private readonly _isRelation: boolean = false
|
|
35
|
+
private readonly _isList: boolean = false
|
|
36
|
+
private readonly _alias: string | undefined
|
|
37
|
+
private _subscription: Subscription
|
|
38
|
+
private _dataType: string | undefined
|
|
39
|
+
private _schemaUid: string | undefined
|
|
40
|
+
private _updateResponseEvent: string | undefined;
|
|
41
|
+
[immerable] = true
|
|
42
|
+
|
|
43
|
+
// private constructor(localIdOrUid) {
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
constructor({
|
|
47
|
+
propertyValue,
|
|
48
|
+
seedUid,
|
|
49
|
+
seedLocalId,
|
|
50
|
+
itemModelName,
|
|
51
|
+
propertyName,
|
|
52
|
+
storageTransactionId,
|
|
53
|
+
schemaUid,
|
|
54
|
+
}: ItemPropertyProps) {
|
|
55
|
+
const ModelClass = getModel(itemModelName)
|
|
56
|
+
|
|
57
|
+
if (!ModelClass) {
|
|
58
|
+
throw new Error(`Model ${itemModelName} not found`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!propertyName) {
|
|
62
|
+
throw new Error(`Property name not provided`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this._lastRenderedValue = propertyValue
|
|
66
|
+
|
|
67
|
+
const serviceInput: Partial<PropertyMachineContext> = {
|
|
68
|
+
propertyValue,
|
|
69
|
+
seedUid,
|
|
70
|
+
propertyName,
|
|
71
|
+
seedLocalId,
|
|
72
|
+
itemModelName,
|
|
73
|
+
storageTransactionId,
|
|
74
|
+
propertyRecordSchema: ModelClass.schema[propertyName],
|
|
75
|
+
schemaUid,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!internalPropertyNames.includes(propertyName)) {
|
|
79
|
+
let propertyNameWithoutId
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
propertyName.endsWith('Id') &&
|
|
83
|
+
!namesThatEndWithId.includes(propertyName)
|
|
84
|
+
) {
|
|
85
|
+
propertyNameWithoutId = propertyName.slice(0, -2)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const propertyRecordSchema =
|
|
89
|
+
ModelClass.schema[propertyNameWithoutId || propertyName]
|
|
90
|
+
if (propertyRecordSchema) {
|
|
91
|
+
this._dataType = propertyRecordSchema.dataType
|
|
92
|
+
|
|
93
|
+
serviceInput.propertyRecordSchema = propertyRecordSchema
|
|
94
|
+
|
|
95
|
+
if (propertyRecordSchema.dataType === 'Relation') {
|
|
96
|
+
this._isRelation = true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
propertyRecordSchema.dataType === 'List' &&
|
|
101
|
+
propertyRecordSchema.ref
|
|
102
|
+
) {
|
|
103
|
+
this._isList = true
|
|
104
|
+
this._isRelation = true
|
|
105
|
+
|
|
106
|
+
if (propertyValue) {
|
|
107
|
+
try {
|
|
108
|
+
serviceInput.propertyValue = JSON.parse(propertyValue)
|
|
109
|
+
} catch (e) {
|
|
110
|
+
logger('List property value is not JSON', e)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const propertyNameSingular = pluralize(propertyName!, 1)
|
|
115
|
+
|
|
116
|
+
this._alias = propertyName
|
|
117
|
+
|
|
118
|
+
serviceInput.propertyName = `${propertyNameSingular}${propertyRecordSchema.ref}Ids`
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!this._alias && propertyNameWithoutId) {
|
|
122
|
+
this._alias = propertyNameWithoutId
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
serviceInput.isRelation = this._isRelation
|
|
128
|
+
|
|
129
|
+
this._subject = new BehaviorSubject(propertyValue)
|
|
130
|
+
this._service = createActor(propertyMachine, {
|
|
131
|
+
input: serviceInput,
|
|
132
|
+
})
|
|
133
|
+
this._subscription = this._service.subscribe((snapshot) => {
|
|
134
|
+
const { context } = snapshot
|
|
135
|
+
|
|
136
|
+
// if (this.uid && !cacheHasProperty(this.uid)) {
|
|
137
|
+
// addPropertyToCache(this)
|
|
138
|
+
// }
|
|
139
|
+
//
|
|
140
|
+
// if (!this.uid && this.localId && !cacheHasProperty(this.localId,)) {
|
|
141
|
+
// addPropertyToCache(this)
|
|
142
|
+
// }
|
|
143
|
+
|
|
144
|
+
if (context.seedLocalId) {
|
|
145
|
+
const cacheKey = ItemProperty.cacheKey(
|
|
146
|
+
context.seedLocalId,
|
|
147
|
+
context.propertyName,
|
|
148
|
+
)
|
|
149
|
+
if (!ItemProperty.instanceCache.has(cacheKey)) {
|
|
150
|
+
ItemProperty.instanceCache.set(cacheKey, {
|
|
151
|
+
instance: this,
|
|
152
|
+
refCount: 1,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
// this._updateResponseEvent = `property.${context.seedLocalId}.${this.propertyName}.save.response`
|
|
156
|
+
// eventEmitter.addListener(
|
|
157
|
+
// this._updateResponseEvent,
|
|
158
|
+
// this._updateResponseListener,
|
|
159
|
+
// )
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const renderValue = context.renderValue || context.propertyValue
|
|
163
|
+
|
|
164
|
+
let transformedPropertyName = propertyName
|
|
165
|
+
|
|
166
|
+
const skipTransform =
|
|
167
|
+
internalPropertyNames.includes(propertyName) || !!this._alias
|
|
168
|
+
|
|
169
|
+
if (!skipTransform && transformedPropertyName.endsWith('Id')) {
|
|
170
|
+
transformedPropertyName = transformedPropertyName.slice(0, -2)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!skipTransform && transformedPropertyName.endsWith('Ids')) {
|
|
174
|
+
transformedPropertyName = transformedPropertyName.slice(0, -3)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (skipTransform && this._alias) {
|
|
178
|
+
transformedPropertyName = this._alias
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (skipTransform && !this._alias) {
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this._subject.next(renderValue)
|
|
185
|
+
if (context.seedLocalId) {
|
|
186
|
+
eventEmitter.emit(`item.${itemModelName}.${context.seedLocalId}.update`)
|
|
187
|
+
}
|
|
188
|
+
if (context.seedUid) {
|
|
189
|
+
eventEmitter.emit(`item.${itemModelName}.${context.seedUid}.update`)
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
this._service.start()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private _updateResponseListener(event) {
|
|
197
|
+
logger(
|
|
198
|
+
`[ItemProperty] [_updateResponseListener] [${this.itemModelName}.${this.seedLocalId}] ${this.propertyName} event`,
|
|
199
|
+
event,
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static create(props: ItemPropertyProps): ItemProperty<any> | undefined {
|
|
204
|
+
const { propertyName, seedLocalId, seedUid } = props
|
|
205
|
+
if (!propertyName || (!seedLocalId && !seedUid)) {
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
const cacheKey = ItemProperty.cacheKey(
|
|
209
|
+
(seedUid || seedLocalId) as string,
|
|
210
|
+
propertyName,
|
|
211
|
+
)
|
|
212
|
+
if (seedLocalId && propertyName) {
|
|
213
|
+
if (ItemProperty.instanceCache.has(cacheKey)) {
|
|
214
|
+
const { instance, refCount } = ItemProperty.instanceCache.get(cacheKey)!
|
|
215
|
+
ItemProperty.instanceCache.set(cacheKey, {
|
|
216
|
+
instance,
|
|
217
|
+
refCount: refCount + 1,
|
|
218
|
+
})
|
|
219
|
+
return instance
|
|
220
|
+
}
|
|
221
|
+
if (!ItemProperty.instanceCache.has(cacheKey)) {
|
|
222
|
+
const newInstance = new ItemProperty(props)
|
|
223
|
+
ItemProperty.instanceCache.set(cacheKey, {
|
|
224
|
+
instance: newInstance,
|
|
225
|
+
refCount: 1,
|
|
226
|
+
})
|
|
227
|
+
return newInstance
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (seedUid && propertyName) {
|
|
231
|
+
if (this.instanceCache.has(cacheKey)) {
|
|
232
|
+
const { instance, refCount } = this.instanceCache.get(cacheKey)!
|
|
233
|
+
this.instanceCache.set(cacheKey, { instance, refCount: refCount + 1 })
|
|
234
|
+
return instance
|
|
235
|
+
}
|
|
236
|
+
if (!this.instanceCache.has(cacheKey)) {
|
|
237
|
+
const newInstance = new ItemProperty(props)
|
|
238
|
+
this.instanceCache.set(cacheKey, { instance: newInstance, refCount: 1 })
|
|
239
|
+
return newInstance
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return new ItemProperty(props)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static async find({
|
|
246
|
+
propertyName,
|
|
247
|
+
seedLocalId,
|
|
248
|
+
seedUid,
|
|
249
|
+
}: ItemPropertyFindProps): Promise<ItemProperty<any> | undefined> {
|
|
250
|
+
if ((!seedLocalId && !seedUid) || !propertyName) {
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
const cacheKeyId = seedUid || seedLocalId
|
|
254
|
+
const cacheKey = ItemProperty.cacheKey(cacheKeyId!, propertyName)
|
|
255
|
+
if (this.instanceCache.has(cacheKey)) {
|
|
256
|
+
const { instance, refCount } = this.instanceCache.get(cacheKey)!
|
|
257
|
+
this.instanceCache.set(cacheKey, {
|
|
258
|
+
instance,
|
|
259
|
+
refCount: refCount + 1,
|
|
260
|
+
})
|
|
261
|
+
if (instance.status === 'idle') {
|
|
262
|
+
instance.getService().send({ type: 'refresh' })
|
|
263
|
+
}
|
|
264
|
+
return instance
|
|
265
|
+
}
|
|
266
|
+
const propertyData = await getPropertyData(
|
|
267
|
+
propertyName,
|
|
268
|
+
seedLocalId,
|
|
269
|
+
seedUid,
|
|
270
|
+
)
|
|
271
|
+
if (!propertyData) {
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
return ItemProperty.create(propertyData)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
static cacheKey(seedLocalIdOrUid: string, propertyName: string): string {
|
|
278
|
+
const { uid, localId } = getCorrectId(seedLocalIdOrUid)
|
|
279
|
+
return `Item_${uid || localId}_${propertyName}`
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
getService() {
|
|
283
|
+
return this._service
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
get localId() {
|
|
287
|
+
return this._service.getSnapshot().context.localId
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
get uid() {
|
|
291
|
+
return this._service.getSnapshot().context.uid
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
get seedLocalId() {
|
|
295
|
+
return this._service.getSnapshot().context.seedLocalId
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
get seedUid() {
|
|
299
|
+
return this._service.getSnapshot().context.seedUid
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
get propertyName() {
|
|
303
|
+
if (this._alias) {
|
|
304
|
+
return this._alias
|
|
305
|
+
}
|
|
306
|
+
return this._service.getSnapshot().context.propertyName
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
get itemModelName() {
|
|
310
|
+
return this._service.getSnapshot().context.itemModelName
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
get propertyDef(): Static<typeof TProperty> | undefined {
|
|
314
|
+
return this._service.getSnapshot().context.propertyRecordSchema
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
get status() {
|
|
318
|
+
return this._service.getSnapshot().value
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
get alias() {
|
|
322
|
+
return this._alias
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
get value() {
|
|
326
|
+
// logger(
|
|
327
|
+
// `[XXXXXXXXXX] [value] [get] subjectValue: ${this._subject.value} serviceValue: ${this._service.getSnapshot().context.renderValue}`,
|
|
328
|
+
// )
|
|
329
|
+
return this._subject.value
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
set value(value: any) {
|
|
333
|
+
if (this._subject.value === value) {
|
|
334
|
+
return
|
|
335
|
+
}
|
|
336
|
+
const context = this._service.getSnapshot().context
|
|
337
|
+
if (!context.propertyRecordSchema) {
|
|
338
|
+
this._subject.next(value)
|
|
339
|
+
}
|
|
340
|
+
this._service.send({
|
|
341
|
+
type: 'save',
|
|
342
|
+
newValue: value,
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
get published(): boolean {
|
|
347
|
+
return !!this._service.getSnapshot().context.uid
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
subscribe(callback: Partial<Subscriber<any>>) {
|
|
351
|
+
return this._subject.subscribe(callback)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async save(): Promise<void> {
|
|
355
|
+
await waitFor(
|
|
356
|
+
this._service,
|
|
357
|
+
(snapshot) => !snapshot.context.isSaving && snapshot.value === 'idle',
|
|
358
|
+
{
|
|
359
|
+
timeout: 10_000,
|
|
360
|
+
},
|
|
361
|
+
)
|
|
362
|
+
// return new Promise((resolve) => {
|
|
363
|
+
// const saveSub = this._service.subscribe((snapshot) => {
|
|
364
|
+
// if (!snapshot.context.isSaving) {
|
|
365
|
+
// saveSub.unsubscribe()
|
|
366
|
+
// resolve()
|
|
367
|
+
// }
|
|
368
|
+
// })
|
|
369
|
+
// })
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
unload() {
|
|
373
|
+
this._service.stop()
|
|
374
|
+
logger(
|
|
375
|
+
`[XXXXXX] [ItemProperty] [${this.seedLocalId}] [unload] removing listener`,
|
|
376
|
+
this._updateResponseEvent,
|
|
377
|
+
)
|
|
378
|
+
eventEmitter.removeListener(
|
|
379
|
+
this._updateResponseEvent,
|
|
380
|
+
this._updateResponseListener,
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
|
|
3
|
+
export const metadata = sqliteTable('metadata', {
|
|
4
|
+
localId: text('local_id').unique(),
|
|
5
|
+
uid: text('uid'),
|
|
6
|
+
propertyName: text('property_name'),
|
|
7
|
+
propertyValue: text('property_value'),
|
|
8
|
+
schemaUid: text('schema_uid'),
|
|
9
|
+
modelType: text('model_type'),
|
|
10
|
+
seedLocalId: text('seed_local_id'),
|
|
11
|
+
seedUid: text('seed_uid'),
|
|
12
|
+
versionLocalId: text('version_local_id'),
|
|
13
|
+
versionUid: text('version_uid'),
|
|
14
|
+
easDataType: text('eas_data_type'),
|
|
15
|
+
refValueType: text('ref_value_type'),
|
|
16
|
+
refModelUid: text('ref_schema_uid'),
|
|
17
|
+
refSeedType: text('ref_seed_type'),
|
|
18
|
+
refResolvedValue: text('ref_resolved_value'),
|
|
19
|
+
refResolvedDisplayValue: text('ref_resolved_display_value'),
|
|
20
|
+
localStorageDir: text('local_storage_dir'),
|
|
21
|
+
attestationRaw: text('attestation_raw'),
|
|
22
|
+
attestationCreatedAt: int('attestation_created_at'),
|
|
23
|
+
contentHash: text('content_hash'),
|
|
24
|
+
createdAt: int('created_at'),
|
|
25
|
+
updatedAt: int('updated_at'),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export type MetadataType = metadata.$inferSelect
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { int, sqliteTable, text, unique } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { relations } from 'drizzle-orm'
|
|
3
|
+
|
|
4
|
+
export const models = sqliteTable('models', {
|
|
5
|
+
id: int('id').primaryKey({ autoIncrement: true }),
|
|
6
|
+
name: text('name').notNull(),
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
export const modelsRelations = relations(models, ({ many }) => ({
|
|
10
|
+
properties: many(properties),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
export type NewModelRecord = typeof models.$inferInsert
|
|
14
|
+
export type ModelRecordType = typeof models.$inferSelect
|
|
15
|
+
|
|
16
|
+
export const properties = sqliteTable(
|
|
17
|
+
'properties',
|
|
18
|
+
{
|
|
19
|
+
id: int('id').primaryKey({ autoIncrement: true }),
|
|
20
|
+
name: text('name').notNull(),
|
|
21
|
+
dataType: text('data_type').notNull(),
|
|
22
|
+
readEndpoint: text('read_endpoint'),
|
|
23
|
+
updateEndpoint: text('update_endpoint'),
|
|
24
|
+
modelId: int('model_id')
|
|
25
|
+
.notNull()
|
|
26
|
+
.references(() => models.id),
|
|
27
|
+
refModelId: int('ref_model_id').references(() => models.id),
|
|
28
|
+
refValueType: text('ref_value_type'),
|
|
29
|
+
},
|
|
30
|
+
(table) => {
|
|
31
|
+
return {
|
|
32
|
+
uniqueNameModelId: unique('unique_name_model_id').on(
|
|
33
|
+
table.name,
|
|
34
|
+
table.modelId,
|
|
35
|
+
),
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export const propertiesRelations = relations(properties, ({ one }) => ({
|
|
41
|
+
model: one(models),
|
|
42
|
+
refModel: one(models),
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
export type NewPropertyRecord = typeof properties.$inferInsert
|
|
46
|
+
export type PropertyType = typeof properties.$inferSelect
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { relations } from 'drizzle-orm'
|
|
3
|
+
import { models } from './ModelSchema'
|
|
4
|
+
|
|
5
|
+
export const modelUids = sqliteTable('model_uids', {
|
|
6
|
+
id: int('id').primaryKey({ autoIncrement: true }),
|
|
7
|
+
uid: text('uid').notNull(),
|
|
8
|
+
modelId: int('model_id')
|
|
9
|
+
.notNull()
|
|
10
|
+
.unique()
|
|
11
|
+
.references(() => models.id),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const modelRelations = relations(modelUids, ({ many, one }) => ({
|
|
15
|
+
model: one(models),
|
|
16
|
+
}))
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { int, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
import { relations } from 'drizzle-orm'
|
|
3
|
+
import { models, properties } from './ModelSchema'
|
|
4
|
+
|
|
5
|
+
export const propertyUids = sqliteTable('property_uids', {
|
|
6
|
+
id: int('id').primaryKey({ autoIncrement: true }),
|
|
7
|
+
uid: text('uid').notNull(),
|
|
8
|
+
propertyId: int('property_id')
|
|
9
|
+
.notNull()
|
|
10
|
+
.unique()
|
|
11
|
+
.references(() => models.id),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export const propertyUidRelations = relations(propertyUids, ({ one }) => ({
|
|
15
|
+
property: one(properties),
|
|
16
|
+
}))
|