@seedprotocol/sdk 0.7.4 → 0.7.5-next.871.g8788c94
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/README.md +99 -0
- package/dist/{BasePathResolver-DrzGVH9L.js → BasePathResolver-B-fK7_N_.js} +142 -8
- package/dist/BasePathResolver-B-fK7_N_.js.map +1 -0
- package/dist/{ClientManager-Dfu4jcgm.js → ClientManager-C7VkO5Hg.js} +342 -206
- package/dist/ClientManager-C7VkO5Hg.js.map +1 -0
- package/dist/{Item-BUUFuywT.js → Item-BDmsdNTQ.js} +234 -163
- package/dist/Item-BDmsdNTQ.js.map +1 -0
- package/dist/{ModelProperty-B6cnRvIz.js → ModelProperty-Cqw6yn7y.js} +37 -37
- package/dist/{ModelProperty-B6cnRvIz.js.map → ModelProperty-Cqw6yn7y.js.map} +1 -1
- package/dist/{Schema-Bf-jOLq0.js → Schema-BJLYOUgp.js} +57 -37
- package/dist/Schema-BJLYOUgp.js.map +1 -0
- package/dist/{SchemaValidationService-BNYMacsx.js → SchemaValidationService-CzybXLiS.js} +6 -6
- package/dist/{SchemaValidationService-BNYMacsx.js.map → SchemaValidationService-CzybXLiS.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-C2-s_jUa.js → backfillMetadataPropertyIds-DAsETfD_.js} +3 -3
- package/dist/{backfillMetadataPropertyIds-C2-s_jUa.js.map → backfillMetadataPropertyIds-DAsETfD_.js.map} +1 -1
- package/dist/{configurePlatform-BzfirKuM.js → configurePlatform-CFQF_i1T.js} +2 -2
- package/dist/{configurePlatform-BzfirKuM.js.map → configurePlatform-CFQF_i1T.js.map} +1 -1
- package/dist/{detachRowsBeforeDelete-B0Daoz9Z.js → detachRowsBeforeDelete-D4gxxk46.js} +2 -2
- package/dist/{detachRowsBeforeDelete-B0Daoz9Z.js.map → detachRowsBeforeDelete-D4gxxk46.js.map} +1 -1
- package/dist/discardNewDraft-g8w3uHFM.js +78 -0
- package/dist/discardNewDraft-g8w3uHFM.js.map +1 -0
- package/dist/{eas-Dq5Kx_Nd.js → eas-BcXZ2hIn.js} +25 -12
- package/dist/eas-BcXZ2hIn.js.map +1 -0
- package/dist/{errors-DdWbxb_n.js → errors-CCMxedOB.js} +43 -38
- package/dist/errors-CCMxedOB.js.map +1 -0
- package/dist/{getItem-9bYSErSj.js → getItem-BUs1Xa48.js} +4 -4
- package/dist/{getItem-9bYSErSj.js.map → getItem-BUs1Xa48.js.map} +1 -1
- package/dist/{getPublishPayload-DPy-uMrR.js → getPublishPayload-CwNOhnir.js} +25 -15
- package/dist/getPublishPayload-CwNOhnir.js.map +1 -0
- package/dist/{getPublishUploads-J-143iSV.js → getPublishUploads-pEOrXJbF.js} +506 -45
- package/dist/getPublishUploads-pEOrXJbF.js.map +1 -0
- package/dist/{index-7y2f_iQz.js → index-BQSK-r_A.js} +2 -2
- package/dist/index-BQSK-r_A.js.map +1 -0
- package/dist/{index-C61Rxy0F.js → index-zAs84LDi.js} +8 -8
- package/dist/index-zAs84LDi.js.map +1 -0
- package/dist/{index.browser-C1pisOEa.js → index.browser-irwaBIj0.js} +11 -11
- package/dist/{index.browser-C1pisOEa.js.map → index.browser-irwaBIj0.js.map} +1 -1
- package/dist/{index.node-BAlST8pD.js → index.node-BYkndQN7.js} +6 -6
- package/dist/{index.node-BAlST8pD.js.map → index.node-BYkndQN7.js.map} +1 -1
- package/dist/main.js +91 -504
- package/dist/main.js.map +1 -1
- package/dist/{mimeTypes-DHAHC4eZ.js → mimeTypes-C9r76DCH.js} +7 -2
- package/dist/{mimeTypes-DHAHC4eZ.js.map → mimeTypes-C9r76DCH.js.map} +1 -1
- package/dist/node.js +10 -10
- package/dist/platform.browser.js +6 -6
- package/dist/platform.node.js +4 -4
- package/dist/{property-zFPMtR3T.js → property-5AD2naVS.js} +7 -7
- package/dist/{property-zFPMtR3T.js.map → property-5AD2naVS.js.map} +1 -1
- package/dist/{propertyValidationRules-CeFVhdQg.js → propertyValidationRules-Bdgz0Nrr.js} +10 -10
- package/dist/{propertyValidationRules-CeFVhdQg.js.map → propertyValidationRules-Bdgz0Nrr.js.map} +1 -1
- package/dist/{publishDraftGraph-CuVq6iAR.js → publishDraftGraph-DGhC9ifI.js} +6 -6
- package/dist/{publishDraftGraph-CuVq6iAR.js.map → publishDraftGraph-DGhC9ifI.js.map} +1 -1
- package/dist/{resetAmbiguousLegacyItemData-DsFTnMBz.js → resetAmbiguousLegacyItemData-HSB77N9c.js} +2 -2
- package/dist/{resetAmbiguousLegacyItemData-DsFTnMBz.js.map → resetAmbiguousLegacyItemData-HSB77N9c.js.map} +1 -1
- package/dist/{resolveModelForSyncedSeed-RUsgAZXG.js → resolveModelForSyncedSeed-CAKAJgr6.js} +2 -2
- package/dist/{resolveModelForSyncedSeed-RUsgAZXG.js.map → resolveModelForSyncedSeed-CAKAJgr6.js.map} +1 -1
- package/dist/src/Item/Item.d.ts +4 -1
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/Item/errors.d.ts +3 -1
- package/dist/src/Item/errors.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/saveValueToDb/saveItemStorage.d.ts.map +1 -1
- package/dist/src/Model/Model.d.ts +2 -1
- package/dist/src/Model/Model.d.ts.map +1 -1
- package/dist/src/Schema/Schema.d.ts.map +1 -1
- package/dist/src/Schema/service/schemaMachine.d.ts +3 -0
- package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/db/alignRowPublishers.d.ts +25 -0
- package/dist/src/db/alignRowPublishers.d.ts.map +1 -0
- package/dist/src/db/canonicalizeModelTypes.d.ts +2 -2
- package/dist/src/db/canonicalizeModelTypes.d.ts.map +1 -1
- package/dist/src/db/read/getModelSchemas.d.ts +3 -2
- package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getSchemaUidForModel.d.ts.map +1 -1
- package/dist/src/db/read/getSeedPublisher.d.ts +7 -0
- package/dist/src/db/read/getSeedPublisher.d.ts.map +1 -0
- package/dist/src/db/read/nameMatchLevels.d.ts +64 -0
- package/dist/src/db/read/nameMatchLevels.d.ts.map +1 -0
- package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -1
- package/dist/src/db/read/summarizePublishWork.d.ts +2 -0
- package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
- package/dist/src/db/write/applyArweaveL1TransactionIdLocal.d.ts +5 -3
- package/dist/src/db/write/applyArweaveL1TransactionIdLocal.d.ts.map +1 -1
- package/dist/src/db/write/claimUnpublishedDrafts.d.ts +4 -2
- package/dist/src/db/write/claimUnpublishedDrafts.d.ts.map +1 -1
- package/dist/src/db/write/createMetadata.d.ts.map +1 -1
- package/dist/src/db/write/createNewItem.d.ts.map +1 -1
- package/dist/src/db/write/createSeed.d.ts.map +1 -1
- package/dist/src/db/write/createVersion.d.ts.map +1 -1
- package/dist/src/db/write/discardNewDraft.d.ts +8 -0
- package/dist/src/db/write/discardNewDraft.d.ts.map +1 -0
- package/dist/src/db/write/restoreDataItemIdsOverwrittenByL1.d.ts +18 -0
- package/dist/src/db/write/restoreDataItemIdsOverwrittenByL1.d.ts.map +1 -0
- package/dist/src/db/write/updateItemPropertyValue.d.ts.map +1 -1
- package/dist/src/eas.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/db.d.ts.map +1 -1
- package/dist/src/helpers/easValueTypes.d.ts +16 -0
- package/dist/src/helpers/easValueTypes.d.ts.map +1 -0
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts +13 -2
- package/dist/src/helpers/htmlEmbeddedDataUriPublish.d.ts.map +1 -1
- package/dist/src/helpers/ownership.d.ts +9 -12
- package/dist/src/helpers/ownership.d.ts.map +1 -1
- package/dist/src/helpers/publishConfig.d.ts +9 -4
- package/dist/src/helpers/publishConfig.d.ts.map +1 -1
- package/dist/src/imports/index.d.ts +1 -1
- package/dist/src/imports/index.d.ts.map +1 -1
- package/dist/src/imports/json.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/types/import.d.ts +20 -0
- package/dist/src/types/import.d.ts.map +1 -1
- package/dist/{syncDbWithEas-CRpnkq00.js → syncDbWithEas-BmJXqfgN.js} +92 -22
- package/dist/syncDbWithEas-BmJXqfgN.js.map +1 -0
- package/dist/{tabEvents-nBUq_1u1.js → tabEvents-DXun7vdK.js} +4 -4
- package/dist/{tabEvents-nBUq_1u1.js.map → tabEvents-DXun7vdK.js.map} +1 -1
- package/dist/{tolerantWebAccess-DIt3R8_u.js → tolerantWebAccess-DXxgX2x7.js} +7 -7
- package/dist/{tolerantWebAccess-DIt3R8_u.js.map → tolerantWebAccess-DXxgX2x7.js.map} +1 -1
- package/dist/{updateSeedRevokedAt-DtTPSzpM.js → updateSeedRevokedAt-DkLSDwUX.js} +3 -3
- package/dist/{updateSeedRevokedAt-DtTPSzpM.js.map → updateSeedRevokedAt-DkLSDwUX.js.map} +1 -1
- package/package.json +9 -5
- package/dist/BasePathResolver-DrzGVH9L.js.map +0 -1
- package/dist/ClientManager-Dfu4jcgm.js.map +0 -1
- package/dist/Item-BUUFuywT.js.map +0 -1
- package/dist/Schema-Bf-jOLq0.js.map +0 -1
- package/dist/eas-Dq5Kx_Nd.js.map +0 -1
- package/dist/errors-DdWbxb_n.js.map +0 -1
- package/dist/getPublishPayload-DPy-uMrR.js.map +0 -1
- package/dist/getPublishUploads-J-143iSV.js.map +0 -1
- package/dist/index-7y2f_iQz.js.map +0 -1
- package/dist/index-C61Rxy0F.js.map +0 -1
- package/dist/syncDbWithEas-CRpnkq00.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @seedprotocol/sdk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@seedprotocol/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org)
|
|
6
|
+
[](https://seedprotocol.io)
|
|
7
|
+
|
|
8
|
+
The official TypeScript SDK for [Seed Protocol](https://seedprotocol.io): a local-first, decentralized data layer.
|
|
9
|
+
|
|
10
|
+
**[→ Full documentation at seedprotocol.io](https://seedprotocol.io)**
|
|
11
|
+
|
|
12
|
+
## What it does
|
|
13
|
+
|
|
14
|
+
- **Local-first ORM.** Define schemas, models and properties; the SDK stores items in SQLite and files in OPFS in the user's browser (or on disk in Node).
|
|
15
|
+
- **Decentralized sync.** Data is read from and published to the [Ethereum Attestation Service (EAS)](https://attest.sh) and [Arweave](https://www.arweave.org). There is no backend for you to run.
|
|
16
|
+
- **No custody.** User data lives on public infrastructure and in the user's browser, not on your servers.
|
|
17
|
+
|
|
18
|
+
Built and used by [PermaPress](https://permapress.xyz), the first client for Seed Protocol (by [JournoLabs](https://journolabs.xyz)).
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- **Node.js** `>= 20` and `<= 24`
|
|
23
|
+
- **Browser:** a modern browser with OPFS (e.g. Chromium-based, recent Firefox)
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @seedprotocol/sdk
|
|
29
|
+
# or
|
|
30
|
+
bun add @seedprotocol/sdk
|
|
31
|
+
# or
|
|
32
|
+
pnpm add @seedprotocol/sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Browser apps built with Vite should also add [`@seedprotocol/vite`](https://www.npmjs.com/package/@seedprotocol/vite). For React hooks, add [`@seedprotocol/react`](https://www.npmjs.com/package/@seedprotocol/react).
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
Initialize the client once, then create schemas, models and items:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { client, Schema, Model } from '@seedprotocol/sdk'
|
|
43
|
+
|
|
44
|
+
await client.init({
|
|
45
|
+
config: {
|
|
46
|
+
filesDir: '.seed',
|
|
47
|
+
endpoints: { filePaths: '/files', files: '.seed' }, // optional on Node when filesDir is set
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const schema = await Schema.create('Blog')
|
|
52
|
+
|
|
53
|
+
const Post = await Model.create('Post', schema, {
|
|
54
|
+
properties: {
|
|
55
|
+
title: { dataType: 'Text' },
|
|
56
|
+
content: { dataType: 'Html' },
|
|
57
|
+
publishedAt: { dataType: 'Date' },
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const post = await Post.create({ title: 'Hello', content: '<p>First post</p>' })
|
|
62
|
+
|
|
63
|
+
// Update by assignment; the SDK persists the change.
|
|
64
|
+
post.title = 'Hello, world'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
You can also declare your schema in a config file at the project root: `seed.config.ts` (recommended), `seed.schema.ts`, or `schema.ts`.
|
|
68
|
+
|
|
69
|
+
To publish items to EAS and Arweave, use [`@seedprotocol/publish`](https://www.npmjs.com/package/@seedprotocol/publish).
|
|
70
|
+
|
|
71
|
+
See the [Getting Started guide](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/GETTING_STARTED.md) for configuration, address sessions, property types, files and images.
|
|
72
|
+
|
|
73
|
+
## Entry points
|
|
74
|
+
|
|
75
|
+
| Import | Use |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `@seedprotocol/sdk` | Main API: `client`, `Schema`, `Model`, `Item`, `ItemProperty`, query helpers |
|
|
78
|
+
| `@seedprotocol/sdk/node` | Node entry: `client`, `Item`, `FileManager`, `Db`, and `withSeed` for webpack configs |
|
|
79
|
+
| `@seedprotocol/sdk/platform` | Platform services: `configurePlatform`, `createPlatformServices` |
|
|
80
|
+
| `@seedprotocol/sdk/vite` | Re-export of `seedVitePlugin` from `@seedprotocol/vite` |
|
|
81
|
+
|
|
82
|
+
ESM is recommended. CommonJS also works: `const { Schema, Model, Item } = require('@seedprotocol/sdk')`.
|
|
83
|
+
|
|
84
|
+
## Related packages
|
|
85
|
+
|
|
86
|
+
| Package | Description |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| [`@seedprotocol/react`](https://www.npmjs.com/package/@seedprotocol/react) | React hooks and components |
|
|
89
|
+
| [`@seedprotocol/publish`](https://www.npmjs.com/package/@seedprotocol/publish) | Publish flow (EAS attestations + Arweave uploads) |
|
|
90
|
+
| [`@seedprotocol/vite`](https://www.npmjs.com/package/@seedprotocol/vite) | Vite plugin for browser apps |
|
|
91
|
+
| [`@seedprotocol/query`](https://www.npmjs.com/package/@seedprotocol/query) | Canonical Seed JSON queries over EAS or local SQLite |
|
|
92
|
+
| [`@seedprotocol/feed`](https://www.npmjs.com/package/@seedprotocol/feed) | RSS, Atom and JSON Feed generation |
|
|
93
|
+
| [`@seedprotocol/mapping`](https://www.npmjs.com/package/@seedprotocol/mapping) | Field mapping from external sources to models |
|
|
94
|
+
| [`@seedprotocol/eas`](https://www.npmjs.com/package/@seedprotocol/eas) | EAS GraphQL read client |
|
|
95
|
+
| [`@seedprotocol/arweave`](https://www.npmjs.com/package/@seedprotocol/arweave) | Arweave gateway client |
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import debug from 'debug';
|
|
2
2
|
import { isEasAttestationExplorerUrl, BaseArweaveClient, ensureReadGatewaySelected, getArweaveReadBaseUrls, getTransactionTagsByIds } from '@seedprotocol/arweave';
|
|
3
|
-
import { easName, localNamesInBestMatchTier, BaseQueryClient, BaseEasClient, GET_FILES_METADATA } from '@seedprotocol/eas';
|
|
3
|
+
import { easName, DEFAULT_NAME_MATCH_LEVEL, compareNameMatchTiers, isNameMatchLevel, localNamesInBestMatchTier, BaseQueryClient, BaseEasClient, GET_FILES_METADATA } from '@seedprotocol/eas';
|
|
4
4
|
import { waitFor } from 'xstate';
|
|
5
5
|
import pluralize from 'pluralize';
|
|
6
6
|
import { Type } from '@sinclair/typebox';
|
|
@@ -1307,6 +1307,133 @@ function stackWithoutFrames(stack) {
|
|
|
1307
1307
|
.join('\n');
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
|
+
const level = (value) => (isNameMatchLevel(value) ? value : undefined);
|
|
1311
|
+
const tighter = (a, b) => a === undefined || compareNameMatchTiers(b, a) < 0 ? b : a;
|
|
1312
|
+
/** The levels in one schema file for one of its models, or undefined when the file lacks the model. */
|
|
1313
|
+
const modelLevelsFromFile = (file, modelName) => {
|
|
1314
|
+
const modelDef = file.models?.[modelName];
|
|
1315
|
+
if (!modelDef)
|
|
1316
|
+
return undefined;
|
|
1317
|
+
const model = level(modelDef.nameMatch) ?? level(file.nameMatch) ?? DEFAULT_NAME_MATCH_LEVEL;
|
|
1318
|
+
const properties = new Map();
|
|
1319
|
+
for (const [propertyName, def] of Object.entries(modelDef.properties ?? {})) {
|
|
1320
|
+
properties.set(propertyName, level(def?.nameMatch) ?? model);
|
|
1321
|
+
}
|
|
1322
|
+
return { model, properties };
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* Builds NameMatchLevels from the schema files that own each model row. Exported for tests;
|
|
1326
|
+
* use {@link nameMatchLevels}.
|
|
1327
|
+
*/
|
|
1328
|
+
const nameMatchLevelsFromRows = (rows) => {
|
|
1329
|
+
const byFileId = new Map();
|
|
1330
|
+
const byName = new Map();
|
|
1331
|
+
const parsed = new Map();
|
|
1332
|
+
for (const row of rows) {
|
|
1333
|
+
if (!row.schemaData)
|
|
1334
|
+
continue;
|
|
1335
|
+
if (!parsed.has(row.schemaData)) {
|
|
1336
|
+
try {
|
|
1337
|
+
parsed.set(row.schemaData, JSON.parse(row.schemaData));
|
|
1338
|
+
}
|
|
1339
|
+
catch {
|
|
1340
|
+
parsed.set(row.schemaData, undefined);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const file = parsed.get(row.schemaData);
|
|
1344
|
+
const levels = file && modelLevelsFromFile(file, row.modelName);
|
|
1345
|
+
if (!levels)
|
|
1346
|
+
continue;
|
|
1347
|
+
if (row.modelFileId)
|
|
1348
|
+
byFileId.set(row.modelFileId, levels);
|
|
1349
|
+
const seen = byName.get(row.modelName);
|
|
1350
|
+
if (!seen) {
|
|
1351
|
+
byName.set(row.modelName, { model: levels.model, properties: new Map(levels.properties) });
|
|
1352
|
+
continue;
|
|
1353
|
+
}
|
|
1354
|
+
seen.model = tighter(seen.model, levels.model);
|
|
1355
|
+
for (const [name, value] of levels.properties)
|
|
1356
|
+
seen.properties.set(name, tighter(seen.properties.get(name), value));
|
|
1357
|
+
}
|
|
1358
|
+
return {
|
|
1359
|
+
model: (modelName) => byName.get(modelName)?.model ?? DEFAULT_NAME_MATCH_LEVEL,
|
|
1360
|
+
property: (modelName, propertyName, modelFileId) => {
|
|
1361
|
+
const levels = (modelFileId ? byFileId.get(modelFileId) : undefined) ?? byName.get(modelName);
|
|
1362
|
+
return levels?.properties.get(propertyName) ?? levels?.model ?? DEFAULT_NAME_MATCH_LEVEL;
|
|
1363
|
+
},
|
|
1364
|
+
};
|
|
1365
|
+
};
|
|
1366
|
+
const DEFAULT_LEVELS = {
|
|
1367
|
+
model: () => DEFAULT_NAME_MATCH_LEVEL,
|
|
1368
|
+
property: () => DEFAULT_NAME_MATCH_LEVEL,
|
|
1369
|
+
};
|
|
1370
|
+
let current;
|
|
1371
|
+
let loading;
|
|
1372
|
+
/** Reads the levels from the schema files stored with each model's schema row (schemas.schema_data). */
|
|
1373
|
+
const loadNameMatchLevels = async (db = BaseDb.getAppDb()) => {
|
|
1374
|
+
if (!db)
|
|
1375
|
+
return DEFAULT_LEVELS;
|
|
1376
|
+
const load = (async () => {
|
|
1377
|
+
const rows = (await db
|
|
1378
|
+
.select({ modelName: models.name, modelFileId: models.schemaFileId, schemaData: schemas.schemaData })
|
|
1379
|
+
.from(models)
|
|
1380
|
+
.innerJoin(modelSchemas, eq(models.id, modelSchemas.modelId))
|
|
1381
|
+
.innerJoin(schemas, eq(modelSchemas.schemaId, schemas.id)));
|
|
1382
|
+
return nameMatchLevelsFromRows(rows);
|
|
1383
|
+
})();
|
|
1384
|
+
loading = load;
|
|
1385
|
+
try {
|
|
1386
|
+
const levels = await load;
|
|
1387
|
+
if (loading === load)
|
|
1388
|
+
current = levels;
|
|
1389
|
+
return levels;
|
|
1390
|
+
}
|
|
1391
|
+
finally {
|
|
1392
|
+
if (loading === load)
|
|
1393
|
+
loading = undefined;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
/** The levels, loaded once and reused until a schema write clears them. */
|
|
1397
|
+
const nameMatchLevels = async (db = BaseDb.getAppDb()) => current ?? loading ?? loadNameMatchLevels(db);
|
|
1398
|
+
/**
|
|
1399
|
+
* The last loaded levels, for synchronous callers (Model.findByModelType). Sync and the post-init
|
|
1400
|
+
* model type pass load them; before that every name is at DEFAULT_NAME_MATCH_LEVEL.
|
|
1401
|
+
*/
|
|
1402
|
+
const currentNameMatchLevels = () => current ?? DEFAULT_LEVELS;
|
|
1403
|
+
/** Called when a schema row or its models are written, so the next read reloads. */
|
|
1404
|
+
const clearNameMatchLevels = () => {
|
|
1405
|
+
current = undefined;
|
|
1406
|
+
loading = undefined;
|
|
1407
|
+
};
|
|
1408
|
+
/**
|
|
1409
|
+
* `nameMatch` values in a schema file that aren't a level. They are ignored (the next level up
|
|
1410
|
+
* applies); schema loads warn about them.
|
|
1411
|
+
*/
|
|
1412
|
+
const invalidNameMatchValues = (file) => {
|
|
1413
|
+
const problems = [];
|
|
1414
|
+
const check = (where, value) => {
|
|
1415
|
+
if (value !== undefined && !isNameMatchLevel(value)) {
|
|
1416
|
+
problems.push(`${where} nameMatch ${JSON.stringify(value)} is not 'exact', 'normalized' or 'fuzzy'`);
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
check('schema', file.nameMatch);
|
|
1420
|
+
for (const [modelName, modelDef] of Object.entries(file.models ?? {})) {
|
|
1421
|
+
check(modelName, modelDef?.nameMatch);
|
|
1422
|
+
for (const [propertyName, def] of Object.entries(modelDef?.properties ?? {})) {
|
|
1423
|
+
check(`${modelName}.${propertyName}`, def?.nameMatch);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
return problems;
|
|
1427
|
+
};
|
|
1428
|
+
/** Warns about {@link invalidNameMatchValues}. */
|
|
1429
|
+
const warnOnInvalidNameMatch = (file) => {
|
|
1430
|
+
const problems = invalidNameMatchValues(file);
|
|
1431
|
+
for (const problem of problems) {
|
|
1432
|
+
console.warn(`[seed] schema ${file.metadata?.name ?? ''}: ${problem}; it is ignored.`);
|
|
1433
|
+
}
|
|
1434
|
+
return problems;
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1310
1437
|
/**
|
|
1311
1438
|
* Thrown when a model name exists in more than one schema and nothing says which one is meant.
|
|
1312
1439
|
* Model names are only unique within a schema; pass `schemaName` (or `modelFileId`) to choose.
|
|
@@ -1390,14 +1517,16 @@ const resolveModelRecordByNameOnly = async (modelName, db, label = Array.isArray
|
|
|
1390
1517
|
/**
|
|
1391
1518
|
* The model names a model name or EAS model type can refer to: the name itself, else the names
|
|
1392
1519
|
* that match it in the tightest tier (ADR 0008, as Model.findByModelType matches): `new_model` →
|
|
1393
|
-
* "New model", `sync_storage_post` → "SyncStoragePost", `htmlpage` → "HTMLPage".
|
|
1520
|
+
* "New model", `sync_storage_post` → "SyncStoragePost", `htmlpage` → "HTMLPage". Each name at its
|
|
1521
|
+
* nameMatch level (ADR 0009).
|
|
1394
1522
|
*/
|
|
1395
1523
|
const modelNamesForNameOrType = async (nameOrType, db) => {
|
|
1396
1524
|
const rows = (await db.selectDistinct({ name: models.name }).from(models));
|
|
1397
1525
|
const names = rows.map((r) => r.name);
|
|
1398
1526
|
if (names.includes(nameOrType))
|
|
1399
1527
|
return [nameOrType];
|
|
1400
|
-
|
|
1528
|
+
const levels = await nameMatchLevels(db);
|
|
1529
|
+
return [...localNamesInBestMatchTier(nameOrType, names, { level: (name) => levels.model(name) })];
|
|
1401
1530
|
};
|
|
1402
1531
|
/**
|
|
1403
1532
|
* resolveModelRecord for a model name **or** an EAS model type (snake_case model name, what sync
|
|
@@ -2085,6 +2214,8 @@ const addSchemaToDb = async (schema, schemaFileId, schemaData, isDraft, isEdited
|
|
|
2085
2214
|
if (!db) {
|
|
2086
2215
|
throw new Error('Database not found');
|
|
2087
2216
|
}
|
|
2217
|
+
// The stored schema file may change its nameMatch levels (ADR 0009).
|
|
2218
|
+
clearNameMatchLevels();
|
|
2088
2219
|
// First, try to find existing schema by schemaFileId (preferred for change tracking)
|
|
2089
2220
|
if (schemaFileId) {
|
|
2090
2221
|
const existingByFileId = await db
|
|
@@ -2553,6 +2684,8 @@ const addModelsToDb = async (models$1, schema, modelRenames, schemaFileData) =>
|
|
|
2553
2684
|
if (!db) {
|
|
2554
2685
|
throw new Error('Database not found');
|
|
2555
2686
|
}
|
|
2687
|
+
// Model rows and their schema links decide which schema file's nameMatch applies (ADR 0009).
|
|
2688
|
+
clearNameMatchLevels();
|
|
2556
2689
|
// If schema is provided, add it to the database
|
|
2557
2690
|
// Note: schema might already be a database record (with id) if passed from importJsonSchema
|
|
2558
2691
|
let schemaRecord;
|
|
@@ -3938,8 +4071,8 @@ const syncDbFiles = async (endpoints) => {
|
|
|
3938
4071
|
const getAppDbReady = async () => {
|
|
3939
4072
|
if (!BaseDb.isAppDbReady()) {
|
|
3940
4073
|
// Wait for ClientManager to be ready (DB_INIT state or later)
|
|
3941
|
-
const _mod_0 = await import('./ClientManager-
|
|
3942
|
-
const _ns_0 = _mod_0.
|
|
4074
|
+
const _mod_0 = await import('./ClientManager-C7VkO5Hg.js');
|
|
4075
|
+
const _ns_0 = _mod_0.N;
|
|
3943
4076
|
const clientManagerMod = _ns_0;
|
|
3944
4077
|
const { getClient } = clientManagerMod;
|
|
3945
4078
|
const clientManager = getClient();
|
|
@@ -4334,8 +4467,9 @@ const INTERNAL_DATA_TYPES = {
|
|
|
4334
4467
|
Text: {
|
|
4335
4468
|
eas: 'string',
|
|
4336
4469
|
},
|
|
4470
|
+
// ADR 0010: decimal strings, so negatives, fractions and values above 255 publish.
|
|
4337
4471
|
Number: {
|
|
4338
|
-
eas: '
|
|
4472
|
+
eas: 'string',
|
|
4339
4473
|
},
|
|
4340
4474
|
Image: {
|
|
4341
4475
|
eas: 'bytes32',
|
|
@@ -4831,5 +4965,5 @@ class BasePathResolver {
|
|
|
4831
4965
|
}
|
|
4832
4966
|
BasePathResolver._impl = null;
|
|
4833
4967
|
|
|
4834
|
-
export {
|
|
4835
|
-
//# sourceMappingURL=BasePathResolver-
|
|
4968
|
+
export { getStorageDirForDataType as $, schemas as A, BaseDb as B, seeds as C, DEFAULT_TEXT_MAX_LENGTH as D, uploadProcesses as E, versions as F, resolveStorageNameToSchemaName as G, AmbiguousModelError as H, eventEmitter as I, nameMatchLevels as J, BasePathResolver as K, getPropertyIdForModelAndName as L, ModelPropertyDataTypes as M, resolveItemModelFileId as N, addModelsToDb as O, Property as P, INIT_SCRIPT_SUCCESS_MESSAGE as Q, getCorrectId as R, SCHEMA_TS as S, THtmlEmbeddedDataUriPolicy as T, isPublishedSeedRef as U, normalizeRelationPropertyValue as V, resolveSeedIdsFromRefString as W, SEED_CONFIG_FILE as X, SEED_CONFIG_FALLBACKS as Y, getArweaveUrlForTransaction as Z, INTERNAL_STORAGE_MODEL_FILE_IDS as _, TProperty as a, getStorageTransactionIdForSeedUid as a$, getContentSha256 as a0, buildArweaveContentTags as a1, getItemStorageSubdir as a2, getItemStorageLocalFileName as a3, isNode as a4, ZERO_BYTES32 as a5, resolveModelRecord as a6, getItemModelScope as a7, VERSION_SCHEMA_UID as a8, INTERNAL_PROPERTY_NAMES as a9, closestImageSize as aA, contentSha256TagMatches as aB, ensureImageLocal as aC, getAddressesForItemsFilter as aD, getFeedItemStringField as aE, normalizeAddressConfig as aF, normalizeAddressList as aG, normalizeArweaveTxIdForEnsure as aH, normalizeFeedItemFields as aI, resolveMediaRef as aJ, isInternalSchema as aK, writeModelToDb as aL, writePropertyToDb as aM, addSchemaToDb as aN, renameModelInDb as aO, currentNameMatchLevels as aP, loadModelsFromDbForSchema as aQ, clearNameMatchLevels as aR, downloadAllFilesRequestHandler as aS, downloadAllFilesBinaryRequestHandler as aT, warnOnInvalidNameMatch as aU, INTERNAL_SCHEMA_IDS as aV, linkModelToSchema as aW, getWatchedAddressesFromDb as aX, getOwnedAddressesFromDb as aY, CLIENT_NOT_INITIALIZED as aZ, toSchemaPropertyName as a_, isStorageSeedRef as aa, defaultAttestationData as ab, INTERNAL_DATA_TYPES as ac, listRelationEasPropertyName as ad, easPropertyNameForPublish as ae, isBrowser as af, EAS_SEED_DATA_SYNCED_TO_DB_EVENT as ag, normalizePublisher as ah, getAllAddressesFromDb as ai, loadNameMatchLevels as aj, scheduleBulkFilesDownloadFromEasSync as ak, generateId as al, normalizeHexAddress as am, toMetadataPropertyName as an, getItemStoragePropertiesForModel as ao, getModelIdByFileId as ap, getModelId as aq, setCachedPropertyRefresher as ar, CONTENT_SHA256_TAG as as, CONTENT_TYPE_TAG as at, ImageSize as au, SEED_PROTOCOL_SCHEMA_NAME as av, SeedModels as aw, VERSION_SCHEMA_DEF as ax, VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA as ay, classifyMediaRef as az, TPropertyConstructor as b, convertTxIdToImage as b0, getMetadataPropertyNamesForQuery as b1, downloadTransactionIdWithDedupe as b2, resolveMetadataRecord as b3, getPropertyIdForSchemaFileId as b4, getDataTypeFromString as b5, getMimeType as b6, listRelationStoragePropertyName as b7, PROPERTY_NAMES_EXEMPT_FROM_ID_SUFFIX_STRIP as b8, getAlternatePropertyNameForInstanceLookup as b9, BaseDb$1 as ba, ModelSchema as bb, BaseFileManager$1 as bc, SchemaSchema as bd, ModelSchemaSchema as be, resolveModelRecord$1 as bf, db as bg, download as bh, generateId$1 as bi, TPropertyDataType as c, TPropertyDefs as d, TStorageType as e, TValidationRules as f, normalizePropertyRecordSchema as g, BaseFileManager as h, isDataType as i, appState as j, arweaveL1FinalizeJobs as k, config as l, metadata as m, normalizeDataType as n, easSyncProcesses as o, htmlEmbeddedImageCoPublish as p, modelRelations as q, modelSchemas as r, modelUids as s, models as t, modelsRelations as u, properties as v, propertiesRelations as w, propertyUidRelations as x, propertyUids as y, publishProcesses as z };
|
|
4969
|
+
//# sourceMappingURL=BasePathResolver-B-fK7_N_.js.map
|