@seedprotocol/sdk 0.7.4 → 0.7.5-next.850.g9ab585b

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 (99) hide show
  1. package/README.md +99 -0
  2. package/dist/{BasePathResolver-DrzGVH9L.js → BasePathResolver-CsZHPrk9.js} +141 -7
  3. package/dist/BasePathResolver-CsZHPrk9.js.map +1 -0
  4. package/dist/{ClientManager-Dfu4jcgm.js → ClientManager-DETTj0_z.js} +43 -33
  5. package/dist/ClientManager-DETTj0_z.js.map +1 -0
  6. package/dist/{Item-BUUFuywT.js → Item-TMrVEPeX.js} +63 -63
  7. package/dist/{Item-BUUFuywT.js.map → Item-TMrVEPeX.js.map} +1 -1
  8. package/dist/{ModelProperty-B6cnRvIz.js → ModelProperty-Bw6N8OMK.js} +36 -36
  9. package/dist/{ModelProperty-B6cnRvIz.js.map → ModelProperty-Bw6N8OMK.js.map} +1 -1
  10. package/dist/{Schema-Bf-jOLq0.js → Schema-VLenyJDy.js} +56 -36
  11. package/dist/Schema-VLenyJDy.js.map +1 -0
  12. package/dist/{SchemaValidationService-BNYMacsx.js → SchemaValidationService-CLGadxgf.js} +6 -6
  13. package/dist/{SchemaValidationService-BNYMacsx.js.map → SchemaValidationService-CLGadxgf.js.map} +1 -1
  14. package/dist/{backfillMetadataPropertyIds-C2-s_jUa.js → backfillMetadataPropertyIds-C8fSvzy2.js} +3 -3
  15. package/dist/{backfillMetadataPropertyIds-C2-s_jUa.js.map → backfillMetadataPropertyIds-C8fSvzy2.js.map} +1 -1
  16. package/dist/{configurePlatform-BzfirKuM.js → configurePlatform-C3E0BS3u.js} +2 -2
  17. package/dist/{configurePlatform-BzfirKuM.js.map → configurePlatform-C3E0BS3u.js.map} +1 -1
  18. package/dist/{detachRowsBeforeDelete-B0Daoz9Z.js → detachRowsBeforeDelete-D1gTseFW.js} +2 -2
  19. package/dist/{detachRowsBeforeDelete-B0Daoz9Z.js.map → detachRowsBeforeDelete-D1gTseFW.js.map} +1 -1
  20. package/dist/{eas-Dq5Kx_Nd.js → eas-A82zVNQ9.js} +25 -12
  21. package/dist/eas-A82zVNQ9.js.map +1 -0
  22. package/dist/{errors-DdWbxb_n.js → errors-CWKup8tw.js} +40 -37
  23. package/dist/errors-CWKup8tw.js.map +1 -0
  24. package/dist/{getItem-9bYSErSj.js → getItem-ChieGxJV.js} +4 -4
  25. package/dist/{getItem-9bYSErSj.js.map → getItem-ChieGxJV.js.map} +1 -1
  26. package/dist/{getPublishPayload-DPy-uMrR.js → getPublishPayload-CWfjl8PM.js} +25 -15
  27. package/dist/getPublishPayload-CWfjl8PM.js.map +1 -0
  28. package/dist/{getPublishUploads-J-143iSV.js → getPublishUploads-cLbSEXLk.js} +8 -8
  29. package/dist/{getPublishUploads-J-143iSV.js.map → getPublishUploads-cLbSEXLk.js.map} +1 -1
  30. package/dist/{index-7y2f_iQz.js → index-CURf9L4d.js} +2 -2
  31. package/dist/index-CURf9L4d.js.map +1 -0
  32. package/dist/{index-C61Rxy0F.js → index-CXkcz4hT.js} +8 -8
  33. package/dist/index-CXkcz4hT.js.map +1 -0
  34. package/dist/{index.browser-C1pisOEa.js → index.browser-47W0fJPw.js} +10 -10
  35. package/dist/{index.browser-C1pisOEa.js.map → index.browser-47W0fJPw.js.map} +1 -1
  36. package/dist/{index.node-BAlST8pD.js → index.node-BiQhZQvH.js} +6 -6
  37. package/dist/{index.node-BAlST8pD.js.map → index.node-BiQhZQvH.js.map} +1 -1
  38. package/dist/main.js +25 -23
  39. package/dist/main.js.map +1 -1
  40. package/dist/node.js +10 -10
  41. package/dist/platform.browser.js +5 -5
  42. package/dist/platform.node.js +4 -4
  43. package/dist/{property-zFPMtR3T.js → property-tgPI5hMu.js} +7 -7
  44. package/dist/{property-zFPMtR3T.js.map → property-tgPI5hMu.js.map} +1 -1
  45. package/dist/{propertyValidationRules-CeFVhdQg.js → propertyValidationRules-BLVxTejW.js} +10 -10
  46. package/dist/{propertyValidationRules-CeFVhdQg.js.map → propertyValidationRules-BLVxTejW.js.map} +1 -1
  47. package/dist/{publishDraftGraph-CuVq6iAR.js → publishDraftGraph-FAfecR_4.js} +6 -6
  48. package/dist/{publishDraftGraph-CuVq6iAR.js.map → publishDraftGraph-FAfecR_4.js.map} +1 -1
  49. package/dist/{resetAmbiguousLegacyItemData-DsFTnMBz.js → resetAmbiguousLegacyItemData-kz2PYdZi.js} +2 -2
  50. package/dist/{resetAmbiguousLegacyItemData-DsFTnMBz.js.map → resetAmbiguousLegacyItemData-kz2PYdZi.js.map} +1 -1
  51. package/dist/{resolveModelForSyncedSeed-RUsgAZXG.js → resolveModelForSyncedSeed-Dm1E4ebt.js} +2 -2
  52. package/dist/{resolveModelForSyncedSeed-RUsgAZXG.js.map → resolveModelForSyncedSeed-Dm1E4ebt.js.map} +1 -1
  53. package/dist/src/Item/Item.d.ts.map +1 -1
  54. package/dist/src/Model/Model.d.ts +2 -1
  55. package/dist/src/Model/Model.d.ts.map +1 -1
  56. package/dist/src/Schema/Schema.d.ts.map +1 -1
  57. package/dist/src/Schema/service/schemaMachine.d.ts +3 -0
  58. package/dist/src/Schema/service/schemaMachine.d.ts.map +1 -1
  59. package/dist/src/db/canonicalizeModelTypes.d.ts +2 -2
  60. package/dist/src/db/canonicalizeModelTypes.d.ts.map +1 -1
  61. package/dist/src/db/read/getModelSchemas.d.ts +3 -2
  62. package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
  63. package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
  64. package/dist/src/db/read/nameMatchLevels.d.ts +64 -0
  65. package/dist/src/db/read/nameMatchLevels.d.ts.map +1 -0
  66. package/dist/src/db/read/resolveModelRecord.d.ts.map +1 -1
  67. package/dist/src/db/read/summarizePublishWork.d.ts +2 -0
  68. package/dist/src/db/read/summarizePublishWork.d.ts.map +1 -1
  69. package/dist/src/eas.d.ts.map +1 -1
  70. package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
  71. package/dist/src/helpers/constants.d.ts.map +1 -1
  72. package/dist/src/helpers/db.d.ts.map +1 -1
  73. package/dist/src/helpers/easValueTypes.d.ts +16 -0
  74. package/dist/src/helpers/easValueTypes.d.ts.map +1 -0
  75. package/dist/src/imports/index.d.ts +1 -1
  76. package/dist/src/imports/index.d.ts.map +1 -1
  77. package/dist/src/imports/json.d.ts.map +1 -1
  78. package/dist/src/index.d.ts +1 -1
  79. package/dist/src/index.d.ts.map +1 -1
  80. package/dist/src/types/import.d.ts +20 -0
  81. package/dist/src/types/import.d.ts.map +1 -1
  82. package/dist/{syncDbWithEas-CRpnkq00.js → syncDbWithEas-CMCAihFh.js} +92 -22
  83. package/dist/syncDbWithEas-CMCAihFh.js.map +1 -0
  84. package/dist/{tabEvents-nBUq_1u1.js → tabEvents-BEAmMncP.js} +4 -4
  85. package/dist/{tabEvents-nBUq_1u1.js.map → tabEvents-BEAmMncP.js.map} +1 -1
  86. package/dist/{tolerantWebAccess-DIt3R8_u.js → tolerantWebAccess-CqiDGEyR.js} +6 -6
  87. package/dist/{tolerantWebAccess-DIt3R8_u.js.map → tolerantWebAccess-CqiDGEyR.js.map} +1 -1
  88. package/dist/{updateSeedRevokedAt-DtTPSzpM.js → updateSeedRevokedAt-Bw3uEStt.js} +3 -3
  89. package/dist/{updateSeedRevokedAt-DtTPSzpM.js.map → updateSeedRevokedAt-Bw3uEStt.js.map} +1 -1
  90. package/package.json +9 -5
  91. package/dist/BasePathResolver-DrzGVH9L.js.map +0 -1
  92. package/dist/ClientManager-Dfu4jcgm.js.map +0 -1
  93. package/dist/Schema-Bf-jOLq0.js.map +0 -1
  94. package/dist/eas-Dq5Kx_Nd.js.map +0 -1
  95. package/dist/errors-DdWbxb_n.js.map +0 -1
  96. package/dist/getPublishPayload-DPy-uMrR.js.map +0 -1
  97. package/dist/index-7y2f_iQz.js.map +0 -1
  98. package/dist/index-C61Rxy0F.js.map +0 -1
  99. package/dist/syncDbWithEas-CRpnkq00.js.map +0 -1
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # @seedprotocol/sdk
2
+
3
+ [![npm](https://img.shields.io/npm/v/@seedprotocol/sdk.svg)](https://www.npmjs.com/package/@seedprotocol/sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js](https://img.shields.io/node/v/@seedprotocol/sdk.svg)](https://nodejs.org)
6
+ [![Docs](https://img.shields.io/badge/docs-seedprotocol.io-0B6E4F)](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
- return [...localNamesInBestMatchTier(nameOrType, names)];
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,7 +4071,7 @@ 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-Dfu4jcgm.js');
4074
+ const _mod_0 = await import('./ClientManager-DETTj0_z.js');
3942
4075
  const _ns_0 = _mod_0.M;
3943
4076
  const clientManagerMod = _ns_0;
3944
4077
  const { getClient } = clientManagerMod;
@@ -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: 'uint8',
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 { generateId as $, seeds as A, uploadProcesses as B, versions as C, DEFAULT_TEXT_MAX_LENGTH as D, BaseDb as E, resolveStorageNameToSchemaName as F, AmbiguousModelError as G, eventEmitter as H, BasePathResolver as I, BaseFileManager as J, getPropertyIdForModelAndName as K, resolveItemModelFileId as L, ModelPropertyDataTypes as M, resolveSeedIdsFromRefString as N, normalizeRelationPropertyValue as O, Property as P, isPublishedSeedRef as Q, getStorageDirForDataType as R, getContentSha256 as S, THtmlEmbeddedDataUriPolicy as T, buildArweaveContentTags as U, getItemStorageSubdir as V, getItemStorageLocalFileName as W, normalizePublisher as X, getAllAddressesFromDb as Y, scheduleBulkFilesDownloadFromEasSync as Z, EAS_SEED_DATA_SYNCED_TO_DB_EVENT as _, TProperty as a, getPropertyIdForSchemaFileId as a$, normalizeHexAddress as a0, listRelationEasPropertyName as a1, easPropertyNameForPublish as a2, toMetadataPropertyName as a3, getItemStoragePropertiesForModel as a4, addModelsToDb as a5, INIT_SCRIPT_SUCCESS_MESSAGE as a6, SCHEMA_TS as a7, getCorrectId as a8, SEED_CONFIG_FILE as a9, ensureImageLocal as aA, getAddressesForItemsFilter as aB, getFeedItemStringField as aC, normalizeAddressConfig as aD, normalizeAddressList as aE, normalizeArweaveTxIdForEnsure as aF, normalizeFeedItemFields as aG, resolveMediaRef as aH, isInternalSchema as aI, writeModelToDb as aJ, writePropertyToDb as aK, addSchemaToDb as aL, renameModelInDb as aM, loadModelsFromDbForSchema as aN, downloadAllFilesRequestHandler as aO, downloadAllFilesBinaryRequestHandler as aP, INTERNAL_SCHEMA_IDS as aQ, linkModelToSchema as aR, getWatchedAddressesFromDb as aS, getOwnedAddressesFromDb as aT, CLIENT_NOT_INITIALIZED as aU, toSchemaPropertyName as aV, getStorageTransactionIdForSeedUid as aW, convertTxIdToImage as aX, getMetadataPropertyNamesForQuery as aY, downloadTransactionIdWithDedupe as aZ, resolveMetadataRecord as a_, SEED_CONFIG_FALLBACKS as aa, isNode as ab, ZERO_BYTES32 as ac, resolveModelRecord as ad, getItemModelScope as ae, VERSION_SCHEMA_UID as af, INTERNAL_PROPERTY_NAMES as ag, isStorageSeedRef as ah, defaultAttestationData as ai, INTERNAL_DATA_TYPES as aj, isBrowser as ak, getModelIdByFileId as al, getModelId as am, setCachedPropertyRefresher as an, getArweaveUrlForTransaction as ao, INTERNAL_STORAGE_MODEL_FILE_IDS as ap, CONTENT_SHA256_TAG as aq, CONTENT_TYPE_TAG as ar, ImageSize as as, SEED_PROTOCOL_SCHEMA_NAME as at, SeedModels as au, VERSION_SCHEMA_DEF as av, VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA as aw, classifyMediaRef as ax, closestImageSize as ay, contentSha256TagMatches as az, TPropertyConstructor as b, getDataTypeFromString as b0, getMimeType as b1, listRelationStoragePropertyName as b2, PROPERTY_NAMES_EXEMPT_FROM_ID_SUFFIX_STRIP as b3, getAlternatePropertyNameForInstanceLookup as b4, BaseDb$1 as b5, ModelSchema as b6, BaseFileManager$1 as b7, SchemaSchema as b8, ModelSchemaSchema as b9, resolveModelRecord$1 as ba, db as bb, download as bc, generateId$1 as bd, TPropertyDataType as c, TPropertyDefs as d, TStorageType as e, TValidationRules as f, normalizePropertyRecordSchema as g, appState as h, isDataType as i, arweaveL1FinalizeJobs as j, config as k, easSyncProcesses as l, metadata as m, normalizeDataType as n, htmlEmbeddedImageCoPublish as o, modelRelations as p, modelSchemas as q, modelUids as r, models as s, modelsRelations as t, properties as u, propertiesRelations as v, propertyUidRelations as w, propertyUids as x, publishProcesses as y, schemas as z };
4835
- //# sourceMappingURL=BasePathResolver-DrzGVH9L.js.map
4968
+ export { getCorrectId as $, seeds as A, uploadProcesses as B, versions as C, DEFAULT_TEXT_MAX_LENGTH as D, BaseDb as E, resolveStorageNameToSchemaName as F, AmbiguousModelError as G, eventEmitter as H, nameMatchLevels as I, BasePathResolver as J, BaseFileManager as K, getPropertyIdForModelAndName as L, ModelPropertyDataTypes as M, resolveItemModelFileId as N, resolveSeedIdsFromRefString as O, Property as P, normalizeRelationPropertyValue as Q, isPublishedSeedRef as R, getStorageDirForDataType as S, THtmlEmbeddedDataUriPolicy as T, getContentSha256 as U, buildArweaveContentTags as V, getItemStorageSubdir as W, getItemStorageLocalFileName as X, addModelsToDb as Y, INIT_SCRIPT_SUCCESS_MESSAGE as Z, SCHEMA_TS as _, TProperty as a, getStorageTransactionIdForSeedUid as a$, SEED_CONFIG_FILE as a0, SEED_CONFIG_FALLBACKS as a1, isNode as a2, ZERO_BYTES32 as a3, resolveModelRecord as a4, getItemModelScope as a5, VERSION_SCHEMA_UID as a6, INTERNAL_PROPERTY_NAMES as a7, isStorageSeedRef as a8, defaultAttestationData 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_, INTERNAL_DATA_TYPES as aa, listRelationEasPropertyName as ab, easPropertyNameForPublish as ac, isBrowser as ad, EAS_SEED_DATA_SYNCED_TO_DB_EVENT as ae, normalizePublisher as af, getAllAddressesFromDb as ag, loadNameMatchLevels as ah, scheduleBulkFilesDownloadFromEasSync as ai, generateId as aj, normalizeHexAddress as ak, toMetadataPropertyName as al, getItemStoragePropertiesForModel as am, getModelIdByFileId as an, getModelId as ao, setCachedPropertyRefresher as ap, getArweaveUrlForTransaction as aq, INTERNAL_STORAGE_MODEL_FILE_IDS 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, appState as h, isDataType as i, arweaveL1FinalizeJobs as j, config as k, easSyncProcesses as l, metadata as m, normalizeDataType as n, htmlEmbeddedImageCoPublish as o, modelRelations as p, modelSchemas as q, modelUids as r, models as s, modelsRelations as t, properties as u, propertiesRelations as v, propertyUidRelations as w, propertyUids as x, publishProcesses as y, schemas as z };
4969
+ //# sourceMappingURL=BasePathResolver-CsZHPrk9.js.map