@seedprotocol/sdk 0.6.5 → 0.6.7
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/{BasePathResolver-BGxb4Qod.js → BasePathResolver-qV0apdVY.js} +124 -2
- package/dist/BasePathResolver-qV0apdVY.js.map +1 -0
- package/dist/{index-BMeU7u_g.js → ClientManager-Y5EWQuJj.js} +1517 -5491
- package/dist/ClientManager-Y5EWQuJj.js.map +1 -0
- package/dist/{ModelProperty-BKvUJGud.js → ModelProperty-DuB5nk6A.js} +33 -30
- package/dist/ModelProperty-DuB5nk6A.js.map +1 -0
- package/dist/{Schema-BBh7ZhRk.js → Schema-BYM-GNdE.js} +40 -39
- package/dist/{Schema-BBh7ZhRk.js.map → Schema-BYM-GNdE.js.map} +1 -1
- package/dist/{SchemaValidationService-BnJ43zov.js → SchemaValidationService-Dr6nmwPm.js} +12 -9
- package/dist/{SchemaValidationService-BnJ43zov.js.map → SchemaValidationService-Dr6nmwPm.js.map} +1 -1
- package/dist/{backfillMetadataPropertyIds-BEryy6Mu.js → backfillMetadataPropertyIds-BzbAB-C5.js} +4 -3
- package/dist/{backfillMetadataPropertyIds-BEryy6Mu.js.map → backfillMetadataPropertyIds-BzbAB-C5.js.map} +1 -1
- package/dist/cjs/{ModelProperty-CGjXNHFW.js → ModelProperty-CDTOx5zi.js} +21 -20
- package/dist/cjs/{ModelProperty-CGjXNHFW.js.map → ModelProperty-CDTOx5zi.js.map} +1 -1
- package/dist/cjs/{Schema-CLMqGTHn.js → Schema-XXcwj3hV.js} +24 -23
- package/dist/cjs/{Schema-CLMqGTHn.js.map → Schema-XXcwj3hV.js.map} +1 -1
- package/dist/cjs/{SchemaValidationService-BnS8o5FK.js → SchemaValidationService-Z7OhtGn5.js} +6 -5
- package/dist/cjs/{SchemaValidationService-BnS8o5FK.js.map → SchemaValidationService-Z7OhtGn5.js.map} +1 -1
- package/dist/cjs/{backfillMetadataPropertyIds-B3xNIFjQ.js → backfillMetadataPropertyIds-Bt4fzfIV.js} +6 -5
- package/dist/cjs/{backfillMetadataPropertyIds-B3xNIFjQ.js.map → backfillMetadataPropertyIds-Bt4fzfIV.js.map} +1 -1
- package/dist/cjs/{eas-wqfFyiti.js → eas-DdI-4vwl.js} +31 -6
- package/dist/cjs/eas-DdI-4vwl.js.map +1 -0
- package/dist/cjs/{getItem-BbEWSf4-.js → getItem-B_2GeTQf.js} +5 -4
- package/dist/cjs/{getItem-BbEWSf4-.js.map → getItem-B_2GeTQf.js.map} +1 -1
- package/dist/cjs/{getPublishPayload-i3UrBhza.js → getPublishPayload-Jmgi1RUj.js} +13 -12
- package/dist/cjs/getPublishPayload-Jmgi1RUj.js.map +1 -0
- package/dist/cjs/{getPublishUploads-CHhrLQmE.js → getPublishUploads-DNULcrN5.js} +8 -7
- package/dist/cjs/{getPublishUploads-CHhrLQmE.js.map → getPublishUploads-DNULcrN5.js.map} +1 -1
- package/dist/cjs/{getSegmentedItemProperties-ZlOTqI0r.js → getSegmentedItemProperties-DK82kjri.js} +3 -3
- package/dist/cjs/{getSegmentedItemProperties-ZlOTqI0r.js.map → getSegmentedItemProperties-DK82kjri.js.map} +1 -1
- package/dist/cjs/{index-Bx8ReSFI.js → index-DM1WR83P.js} +5148 -4967
- package/dist/cjs/index-DM1WR83P.js.map +1 -0
- package/dist/cjs/{index-DBGNShZR.js → index-tpO1Nj4v.js} +7 -6
- package/dist/cjs/index-tpO1Nj4v.js.map +1 -0
- package/dist/cjs/{property-CWZoijFu.js → property-DmvgA8FD.js} +8 -7
- package/dist/cjs/{property-CWZoijFu.js.map → property-DmvgA8FD.js.map} +1 -1
- package/dist/cjs/{syncDbWithEas-DRbf_wzk.js → syncDbWithEas-3hOoPdu1.js} +9 -8
- package/dist/cjs/{syncDbWithEas-DRbf_wzk.js.map → syncDbWithEas-3hOoPdu1.js.map} +1 -1
- package/dist/{configurePlatform-bGvKBBQy.js → configurePlatform-CCYQruij.js} +6 -3
- package/dist/{configurePlatform-bGvKBBQy.js.map → configurePlatform-CCYQruij.js.map} +1 -1
- package/dist/constants-DSqHBPNe.js +1347 -0
- package/dist/constants-DSqHBPNe.js.map +1 -0
- package/dist/{db-CbeA8ykN.js → db-CceyWksv.js} +29 -35
- package/dist/{db-CbeA8ykN.js.map → db-CceyWksv.js.map} +1 -1
- package/dist/{eas-CDANhqoz.js → eas-CH8iFIST.js} +9 -6
- package/dist/eas-CH8iFIST.js.map +1 -0
- package/dist/generateId-BopUwD8F.js +9 -0
- package/dist/generateId-BopUwD8F.js.map +1 -0
- package/dist/{getItem-CUOCDTe8.js → getItem-C7Mtfz6O.js} +11 -9
- package/dist/{getItem-CUOCDTe8.js.map → getItem-C7Mtfz6O.js.map} +1 -1
- package/dist/{getPublishPayload-0ntIkzv8.js → getPublishPayload-2gnnDdMh.js} +23 -20
- package/dist/getPublishPayload-2gnnDdMh.js.map +1 -0
- package/dist/{getPublishUploads-DLeAkS2m.js → getPublishUploads-AKISt3JA.js} +14 -11
- package/dist/{getPublishUploads-DLeAkS2m.js.map → getPublishUploads-AKISt3JA.js.map} +1 -1
- package/dist/{getSegmentedItemProperties-C0rMewcl.js → getSegmentedItemProperties-eIjvhCP_.js} +5 -5
- package/dist/{getSegmentedItemProperties-C0rMewcl.js.map → getSegmentedItemProperties-eIjvhCP_.js.map} +1 -1
- package/dist/index-BFpbtEsg.js +3492 -0
- package/dist/index-BFpbtEsg.js.map +1 -0
- package/dist/{index-CQIlolE1.js → index-CHi212ST.js} +15 -12
- package/dist/index-CHi212ST.js.map +1 -0
- package/dist/{index-C_5xwOPQ.js → index-CsmiM0RI.js} +2 -2
- package/dist/index-CsmiM0RI.js.map +1 -0
- package/dist/{index.node-DkpiPLbZ.js → index.node-CbWB4MDz.js} +4 -5
- package/dist/{index.node-DkpiPLbZ.js.map → index.node-CbWB4MDz.js.map} +1 -1
- package/dist/main.cjs +5 -4
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +33 -31
- package/dist/main.js.map +1 -1
- package/dist/model-DGMe-TTm.js +25 -0
- package/dist/model-DGMe-TTm.js.map +1 -0
- package/dist/node.js +19 -16
- package/dist/node.js.map +1 -1
- package/dist/platform.browser.js +177 -43
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.node.js +4 -5
- package/dist/platform.node.js.map +1 -1
- package/dist/{property-B-9szEcZ.js → property-CWKcZ5YZ.js} +18 -16
- package/dist/property-CWKcZ5YZ.js.map +1 -0
- package/dist/src/Item/Item.d.ts.map +1 -1
- package/dist/src/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/loadOrCreateProperty.d.ts.map +1 -1
- package/dist/src/Model/service/actors/loadOrCreateModel.d.ts.map +1 -1
- package/dist/src/browser/db/Db.d.ts +1 -1
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/db/createSqlocalDrizzle.d.ts +21 -0
- package/dist/src/browser/db/createSqlocalDrizzle.d.ts.map +1 -0
- package/dist/src/browser/db/embeddedMigrations.d.ts +17 -0
- package/dist/src/browser/db/embeddedMigrations.d.ts.map +1 -0
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/eas.d.ts +2 -2
- package/dist/src/eas.d.ts.map +1 -1
- package/dist/src/helpers/ArweaveClient/selectReadGateway.d.ts +1 -1
- package/dist/src/helpers/ArweaveClient/selectReadGateway.d.ts.map +1 -1
- package/dist/src/helpers/constants.d.ts +1 -2
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/crypto.d.ts +3 -2
- package/dist/src/helpers/crypto.d.ts.map +1 -1
- package/dist/src/helpers/ensureImageLocal.d.ts +24 -0
- package/dist/src/helpers/ensureImageLocal.d.ts.map +1 -0
- package/dist/src/helpers/ethereumUtils.d.ts.map +1 -1
- package/dist/src/helpers/index.d.ts +10 -2
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/imports/json.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/{syncDbWithEas-CNBuYKo_.js → syncDbWithEas-5kZneTEL.js} +19 -17
- package/dist/syncDbWithEas-5kZneTEL.js.map +1 -0
- package/dist/{updateSeedRevokedAt-D5ZbBehZ.js → updateSeedRevokedAt-CgfOBtqJ.js} +2 -2
- package/dist/{updateSeedRevokedAt-D5ZbBehZ.js.map → updateSeedRevokedAt-CgfOBtqJ.js.map} +1 -1
- package/package.json +6 -6
- package/dist/BasePathResolver-BGxb4Qod.js.map +0 -1
- package/dist/ModelProperty-BKvUJGud.js.map +0 -1
- package/dist/cjs/eas-wqfFyiti.js.map +0 -1
- package/dist/cjs/getPublishPayload-i3UrBhza.js.map +0 -1
- package/dist/cjs/index-Bx8ReSFI.js.map +0 -1
- package/dist/cjs/index-DBGNShZR.js.map +0 -1
- package/dist/constants-Bre6dTJR.js +0 -122
- package/dist/constants-Bre6dTJR.js.map +0 -1
- package/dist/constants-CTs2RUrM.js +0 -657
- package/dist/constants-CTs2RUrM.js.map +0 -1
- package/dist/eas-CDANhqoz.js.map +0 -1
- package/dist/getPublishPayload-0ntIkzv8.js.map +0 -1
- package/dist/index-BMeU7u_g.js.map +0 -1
- package/dist/index-CQIlolE1.js.map +0 -1
- package/dist/index-C_5xwOPQ.js.map +0 -1
- package/dist/property-B-9szEcZ.js.map +0 -1
- package/dist/syncDbWithEas-CNBuYKo_.js.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert Model.properties array to object format (for backward compatibility)
|
|
3
|
+
* This replaces the old model.schema getter
|
|
4
|
+
*/
|
|
5
|
+
function modelPropertiesToObject(properties) {
|
|
6
|
+
const schemaObj = {};
|
|
7
|
+
for (const property of properties) {
|
|
8
|
+
const propContext = property._getSnapshotContext();
|
|
9
|
+
if (propContext.name) {
|
|
10
|
+
schemaObj[propContext.name] = {
|
|
11
|
+
dataType: propContext.dataType,
|
|
12
|
+
ref: propContext.refModelName || propContext.ref,
|
|
13
|
+
refValueType: propContext.refValueType,
|
|
14
|
+
storageType: propContext.storageType,
|
|
15
|
+
localStorageDir: propContext.localStorageDir,
|
|
16
|
+
filenameSuffix: propContext.filenameSuffix,
|
|
17
|
+
required: propContext.required,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return schemaObj;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { modelPropertiesToObject };
|
|
25
|
+
//# sourceMappingURL=model-DGMe-TTm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-DGMe-TTm.js","sources":["../../src/helpers/model.ts"],"sourcesContent":["import { ModelProperty } from '@/ModelProperty/ModelProperty'\n\n/**\n * Convert Model.properties array to object format (for backward compatibility)\n * This replaces the old model.schema getter\n */\nexport function modelPropertiesToObject(properties: ModelProperty[]): { [propertyName: string]: any } {\n const schemaObj: { [propertyName: string]: any } = {}\n \n for (const property of properties) {\n const propContext = property._getSnapshotContext()\n if (propContext.name) {\n schemaObj[propContext.name] = {\n dataType: propContext.dataType,\n ref: propContext.refModelName || propContext.ref,\n refValueType: propContext.refValueType,\n storageType: propContext.storageType,\n localStorageDir: propContext.localStorageDir,\n filenameSuffix: propContext.filenameSuffix,\n required: propContext.required,\n }\n }\n }\n \n return schemaObj\n}\n\n"],"names":[],"mappings":"AAEA;;;AAGG;AACG,SAAU,uBAAuB,CAAC,UAA2B,EAAA;IACjE,MAAM,SAAS,GAAoC,EAAE;AAErD,IAAA,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;AACjC,QAAA,MAAM,WAAW,GAAG,QAAQ,CAAC,mBAAmB,EAAE;AAClD,QAAA,IAAI,WAAW,CAAC,IAAI,EAAE;AACpB,YAAA,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG;gBAC5B,QAAQ,EAAE,WAAW,CAAC,QAAQ;AAC9B,gBAAA,GAAG,EAAE,WAAW,CAAC,YAAY,IAAI,WAAW,CAAC,GAAG;gBAChD,YAAY,EAAE,WAAW,CAAC,YAAY;gBACtC,WAAW,EAAE,WAAW,CAAC,WAAW;gBACpC,eAAe,EAAE,WAAW,CAAC,eAAe;gBAC5C,cAAc,EAAE,WAAW,CAAC,cAAc;gBAC1C,QAAQ,EAAE,WAAW,CAAC,QAAQ;aAC/B;QACH;IACF;AAEA,IAAA,OAAO,SAAS;AAClB;;"}
|
package/dist/node.js
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import { enableMapSet } from 'immer';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
|
-
export {
|
|
4
|
-
import { M as ModelPropertyDataTypes, P as Property } from './constants-
|
|
5
|
-
export { B as Boolean, a as Date, I as Image, J as Json, L as List, N as Number, R as Relation, j as Text, l as getCorrectId } from './constants-
|
|
3
|
+
export { M as Model } from './index-BFpbtEsg.js';
|
|
4
|
+
import { M as ModelPropertyDataTypes, P as Property } from './constants-DSqHBPNe.js';
|
|
5
|
+
export { B as Boolean, a as Date, I as Image, J as Json, L as List, N as Number, R as Relation, j as Text, m as eventEmitter, l as getCorrectId } from './constants-DSqHBPNe.js';
|
|
6
6
|
import 'pluralize';
|
|
7
|
-
import { a as BaseDb } from './BasePathResolver-
|
|
8
|
-
export { t as BasePathResolver, c as appState, e as config, b as metadata, j as modelUids, m as models, r as seeds, v as versions } from './BasePathResolver-
|
|
7
|
+
import { a as BaseDb } from './BasePathResolver-qV0apdVY.js';
|
|
8
|
+
export { t as BasePathResolver, y as INIT_SCRIPT_SUCCESS_MESSAGE, S as SCHEMA_TS, c as appState, e as config, b as metadata, j as modelUids, m as models, r as seeds, v as versions } from './BasePathResolver-qV0apdVY.js';
|
|
9
9
|
import 'drizzle-orm';
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export { I as Item, f as ItemProperty, C as client, h as getRefValueType, i as importJsonSchema, l as loadSchemaFromFile, j as readJsonImportFile, s as syncSchemaFromSource, t as transformImportToSchemaFile } from './ClientManager-Y5EWQuJj.js';
|
|
11
|
+
import { c as createPlatformServices } from './index.node-CbWB4MDz.js';
|
|
12
|
+
export { D as Db, F as FileManager, P as PathResolver, r as resolveSdkDrizzleMigrationsDir } from './index.node-CbWB4MDz.js';
|
|
12
13
|
import yaml from 'js-yaml';
|
|
13
14
|
import fs__default, { readFileSync } from 'fs';
|
|
14
|
-
import { c as addModelsToDb } from './db-
|
|
15
|
+
import { c as addModelsToDb } from './db-CceyWksv.js';
|
|
15
16
|
import { execSync } from 'child_process';
|
|
16
17
|
import path from 'path';
|
|
17
|
-
|
|
18
|
-
import { configurePlatform } from './configurePlatform-bGvKBBQy.js';
|
|
18
|
+
import { configurePlatform } from './configurePlatform-CCYQruij.js';
|
|
19
19
|
import 'xstate';
|
|
20
20
|
import 'debug';
|
|
21
|
+
import './generateId-BopUwD8F.js';
|
|
21
22
|
import 'nanoid';
|
|
22
23
|
import 'nanoid-dictionary';
|
|
23
|
-
import '
|
|
24
|
-
import 'rxjs';
|
|
25
|
-
import 'lodash-es';
|
|
24
|
+
import './model-DGMe-TTm.js';
|
|
26
25
|
import 'drizzle-orm/casing';
|
|
26
|
+
import '@sinclair/typebox';
|
|
27
27
|
import '@seedprotocol/arweave';
|
|
28
|
-
import '
|
|
28
|
+
import '@seedprotocol/eas';
|
|
29
29
|
import '@seedprotocol/query';
|
|
30
|
-
import '
|
|
30
|
+
import 'lodash-es';
|
|
31
31
|
import 'drizzle-orm/sqlite-core';
|
|
32
|
+
import '@noble/hashes/sha3';
|
|
33
|
+
import '@noble/hashes/utils';
|
|
34
|
+
import 'rxjs';
|
|
32
35
|
import 'fs/promises';
|
|
33
36
|
import 'node:url';
|
|
34
|
-
import './index-
|
|
37
|
+
import './index-CsmiM0RI.js';
|
|
35
38
|
import '@libsql/client';
|
|
36
39
|
import 'drizzle-orm/libsql';
|
|
37
40
|
import 'drizzle-orm/libsql/migrator';
|
package/dist/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sources":["../../src/imports/markdown.ts","../../src/node/webpack/index.ts","../../src/node/helpers/scripts.ts","../../src/node/index.ts"],"sourcesContent":["import yaml from 'js-yaml'\nimport { readFileSync } from 'fs'\nimport { Property, ModelPropertyDataTypes } from '@/Schema'\nimport { ModelDefinitions } from '@/types'\nimport { addModelsToDb } from '../helpers/db'\nimport type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3'\nimport { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy'\nimport type { Model } from '@/Model/Model'\n\n/**\n * Configuration structure expected in markdown frontmatter\n */\ntype SeedConfig = {\n seed: {\n model: string\n properties: {\n [propertyName: string]: {\n type: string\n target?: string\n /** For List: element type when primitive (e.g. 'Text', 'Number'). Use target for list of relations. */\n itemsType?: string\n }\n }\n }\n}\n\n/**\n * Parses markdown frontmatter from a file\n * @param filePath Path to the markdown file\n * @returns The parsed frontmatter as an object, or null if no frontmatter found\n */\nexport const parseMarkdownFrontmatter = (\n filePath: string,\n): Record<string, any> | null => {\n const content = readFileSync(filePath, 'utf-8')\n \n // Check for frontmatter delimiters (more flexible regex)\n // Matches --- at start, optional whitespace, content, ---, optional whitespace\n const frontmatterRegex = /^---\\s*\\n([\\s\\S]*?)\\n---(\\s*\\n|$)/\n const match = content.match(frontmatterRegex)\n \n if (!match) {\n return null\n }\n \n const frontmatterYaml = match[1]\n \n try {\n const frontmatter = yaml.load(frontmatterYaml) as Record<string, any>\n return frontmatter\n } catch (error) {\n throw new Error(\n `Failed to parse YAML frontmatter in ${filePath}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\n/**\n * Converts a seed config from frontmatter to ModelDefinitions format\n * @param config The seed configuration from frontmatter\n * @returns ModelDefinitions object ready to be saved to database\n */\nexport const processSeedConfig = (config: SeedConfig): ModelDefinitions => {\n if (!config.seed) {\n throw new Error('No seed configuration found in frontmatter')\n }\n \n const { model: modelName, properties: propertiesConfig } = config.seed\n \n if (!modelName) {\n throw new Error('Model name is required in seed configuration')\n }\n \n if (!propertiesConfig || Object.keys(propertiesConfig).length === 0) {\n throw new Error('Properties are required in seed configuration')\n }\n \n // Convert property configs to Property definitions\n const schema: Record<string, any> = {}\n \n for (const [propertyName, propertyConfig] of Object.entries(propertiesConfig)) {\n const { type, target, itemsType } = propertyConfig\n \n if (!type) {\n throw new Error(`Property type is required for ${propertyName}`)\n }\n \n // Map the type to Property constructor\n switch (type) {\n case ModelPropertyDataTypes.Text:\n schema[propertyName] = Property.Text()\n break\n case ModelPropertyDataTypes.Number:\n schema[propertyName] = Property.Number()\n break\n case ModelPropertyDataTypes.Boolean:\n schema[propertyName] = Property.Boolean()\n break\n case ModelPropertyDataTypes.Date:\n schema[propertyName] = Property.Date()\n break\n case ModelPropertyDataTypes.Image:\n schema[propertyName] = Property.Image()\n break\n case ModelPropertyDataTypes.Json:\n schema[propertyName] = Property.Json()\n break\n case ModelPropertyDataTypes.File:\n schema[propertyName] = Property.File()\n break\n case ModelPropertyDataTypes.Relation:\n if (!target) {\n throw new Error(\n `Target model is required for Relation property ${propertyName}`,\n )\n }\n schema[propertyName] = Property.Relation(target)\n break\n case ModelPropertyDataTypes.List:\n if (itemsType) {\n // List of primitives: itemsType = 'Text', 'Number', etc.\n if (itemsType === ModelPropertyDataTypes.Relation && target) {\n schema[propertyName] = Property.List('Relation', target)\n } else if (itemsType !== ModelPropertyDataTypes.Relation) {\n schema[propertyName] = Property.List(itemsType as any)\n } else {\n throw new Error(\n `List of relations requires target model for property ${propertyName}`,\n )\n }\n } else if (target) {\n // Backward compat: target = model name for list of relations\n schema[propertyName] = Property.List('Relation', target)\n } else {\n throw new Error(\n `List property ${propertyName} requires either itemsType (e.g. 'Text') or target (model name for list of relations)`,\n )\n }\n break\n default:\n throw new Error(\n `Unknown property type: ${type} for property ${propertyName}`,\n )\n }\n }\n \n // Create a mock ModelClass structure that matches ModelDefinitions\n // This is a simplified version that works with addModelsToInternalDb\n const modelClass = {\n schema,\n create: async () => {\n throw new Error('Model.create() should not be called directly')\n },\n originalConstructor: class {},\n }\n \n return {\n [modelName]: modelClass as any as Model,\n }\n}\n\n/**\n * Reads a markdown file, parses frontmatter, and saves models/properties to database\n * @param filePath Path to the markdown file\n * @param db Database instance (BetterSQLite3Database or SqliteRemoteDatabase)\n * @returns The created ModelDefinitions\n */\nexport const saveModelsFromMarkdown = async (\n filePath: string,\n db: BetterSQLite3Database<any> | SqliteRemoteDatabase<any>,\n): Promise<ModelDefinitions> => {\n // Parse frontmatter\n const frontmatter = parseMarkdownFrontmatter(filePath)\n \n if (!frontmatter) {\n throw new Error(`No frontmatter found in ${filePath}`)\n }\n \n // Validate and process seed config\n const seedConfig = frontmatter as SeedConfig\n const modelDefinitions = processSeedConfig(seedConfig)\n \n // Save to database\n await addModelsToDb(modelDefinitions, undefined, undefined, undefined)\n \n return modelDefinitions\n}\n","/**\n * Webpack / Next.js config helper for Seed Protocol apps.\n */\nexport const withSeed = (config: any, webpack: any, isServer: boolean) => {\n config.plugins.push(\n new webpack.NormalModuleReplacementPlugin(/node:/, (resource: { request: string }) => {\n resource.request = resource.request.replace(/^node:/, '')\n }),\n )\n\n if (!isServer) {\n config.resolve.alias['fs'] = '@zenfs/core'\n config.resolve.alias['node:fs'] = '@zenfs/core'\n config.resolve.alias['node:path'] = 'path-browserify'\n config.resolve.alias['path'] = 'path-browserify'\n }\n\n if (isServer) {\n config.externals.push('@sqlite.org/sqlite-wasm')\n config.externals.push('chokidar')\n config.externals.push('arweave')\n }\n\n return config\n}\n","import { execSync } from 'child_process'\nimport path from 'path'\nimport fs from 'fs'\nimport { BaseDb } from '@/db/Db/BaseDb'\n\nexport const commandExists = (command: string): boolean => {\n try {\n execSync(`which ${command}`, { stdio: 'ignore' })\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Finds the seed binary path, trying multiple locations\n * @returns The path to the seed binary, or null if not found\n */\nexport const findSeedBinary = (): string | null => {\n const cwd = process.cwd()\n\n const possiblePaths = [\n path.join(cwd, 'node_modules', '.bin', 'seed'),\n path.join(cwd, 'node_modules', '@seedprotocol', 'cli', 'dist', 'bin.js'),\n path.join(cwd, '..', 'node_modules', '.bin', 'seed'),\n path.join(cwd, '..', 'node_modules', '@seedprotocol', 'cli', 'dist', 'bin.js'),\n path.join(cwd, '..', '..', 'node_modules', '.bin', 'seed'),\n path.join(cwd, '..', '..', 'node_modules', '@seedprotocol', 'cli', 'dist', 'bin.js'),\n ]\n\n for (const binPath of possiblePaths) {\n if (fs.existsSync(binPath)) {\n return binPath\n }\n }\n\n return null\n}\n\n/**\n * Ensures the Node app DB exists and SDK migrations are applied.\n * (Formerly `runSeedInit`; CLI spawn / npx fallbacks archived under docs/archive/commented/.)\n */\nexport const ensureNodeDbSchema = async (\n _schemaFileDir?: string,\n appFilesDirPath?: string\n): Promise<void> => {\n if (!appFilesDirPath) {\n throw new Error('ensureNodeDbSchema requires appFilesDirPath')\n }\n\n await BaseDb.prepareDb(appFilesDirPath)\n}\n\n/** @deprecated Use ensureNodeDbSchema */\nexport const runSeedInit = ensureNodeDbSchema\n","import { enableMapSet } from 'immer'\n\n// Core schema exports\nexport {\n Model,\n Property,\n Image,\n List,\n Text,\n Json,\n Relation,\n Boolean,\n Number,\n Date,\n} from '../Schema'\n\n// Core classes\nexport { Item } from '../Item/Item'\nexport { ItemProperty } from '../ItemProperty/ItemProperty'\n\n// Node.js specific exports\nexport { FileManager } from './helpers/FileManager'\nexport { Db, resolveSdkDrizzleMigrationsDir } from './db/Db'\n\n// Schema exports\nexport { models, versions, seeds, metadata, appState, config, modelUids } from '../seedSchema'\n\n// Model access - use Model static methods instead\n// Models are accessible via Model.all(), Model.getById(), Model.getByName(), etc.\n\n// Helper exports\nexport { getCorrectId } from '../helpers'\n\n// Import exports\nexport * from '../imports'\n\n// Event bus\nexport { eventEmitter } from '../eventBus'\n\n// Webpack helper\nexport { withSeed } from './webpack'\n\n// Types\n// Note: PublishUpload type is available from '../db/read/getPublishUploads'\n// Type-only exports cause issues with Rollup's parser. Import directly if needed:\n// import type { PublishUpload } from '@seedprotocol/sdk/db/read/getPublishUploads'\n\n// Client\nexport { client } from '../client'\n\n// All types\nexport * from '../types'\n\n// CLI exports\nexport { PathResolver } from './helpers/PathResolver'\nexport { BasePathResolver } from '../helpers/PathResolver/BasePathResolver'\nexport {\n commandExists,\n ensureNodeDbSchema,\n runSeedInit,\n findSeedBinary,\n} from './helpers/scripts'\nexport { INIT_SCRIPT_SUCCESS_MESSAGE, SCHEMA_TS } from '../helpers/constants'\n\n// Side effect imports for CLI — register platform services\nimport { createPlatformServices } from '../platform/index.node'\nimport { configurePlatform } from '../platform/configurePlatform'\nconfigurePlatform(createPlatformServices())\n\nenableMapSet() "],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;AAIG;AACI,MAAM,wBAAwB,GAAG,CACtC,QAAgB,KACc;IAC9B,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC;;;IAI/C,MAAM,gBAAgB,GAAG,mCAAmC;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC;IAE7C,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC;AAEhC,IAAA,IAAI;QACF,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,CAAwB;AACrE,QAAA,OAAO,WAAW;IACpB;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CACb,CAAA,oCAAA,EAAuC,QAAQ,KAAK,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA,CAAE,CAC7G;IACH;AACF;AAEA;;;;AAIG;AACI,MAAM,iBAAiB,GAAG,CAAC,MAAkB,KAAsB;AACxE,IAAA,IAAI,CAAC,MAAM,C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,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC;KACrF;AAED,IAAA,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE;AACnC,QAAA,IAAIA,WAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;AAC1B,YAAA,OAAO,OAAO;QAChB;IACF;AAEA,IAAA,OAAO,IAAI;AACb;AAEA;;;AAGG;AACI,MAAM,kBAAkB,GAAG,OAChC,cAAuB,EACvB,eAAwB,KACP;IACjB,IAAI,CAAC,eAAe,EAAE;AACpB,QAAA,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC;IAChE;AAEA,IAAA,MAAM,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC;AACzC;AAEA;AACO,MAAM,WAAW,GAAG;;ACY3B,iBAAiB,CAAC,sBAAsB,EAAE,CAAC;AAE3C,YAAY,EAAE;;"}
|
|
1
|
+
{"version":3,"file":"node.js","sources":["../../src/imports/markdown.ts","../../src/node/webpack/index.ts","../../src/node/helpers/scripts.ts","../../src/node/index.ts"],"sourcesContent":["import yaml from 'js-yaml'\nimport { readFileSync } from 'fs'\nimport { Property, ModelPropertyDataTypes } from '@/Schema'\nimport { ModelDefinitions } from '@/types'\nimport { addModelsToDb } from '../helpers/db'\nimport type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3'\nimport { SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy'\nimport type { Model } from '@/Model/Model'\n\n/**\n * Configuration structure expected in markdown frontmatter\n */\ntype SeedConfig = {\n seed: {\n model: string\n properties: {\n [propertyName: string]: {\n type: string\n target?: string\n /** For List: element type when primitive (e.g. 'Text', 'Number'). Use target for list of relations. */\n itemsType?: string\n }\n }\n }\n}\n\n/**\n * Parses markdown frontmatter from a file\n * @param filePath Path to the markdown file\n * @returns The parsed frontmatter as an object, or null if no frontmatter found\n */\nexport const parseMarkdownFrontmatter = (\n filePath: string,\n): Record<string, any> | null => {\n const content = readFileSync(filePath, 'utf-8')\n \n // Check for frontmatter delimiters (more flexible regex)\n // Matches --- at start, optional whitespace, content, ---, optional whitespace\n const frontmatterRegex = /^---\\s*\\n([\\s\\S]*?)\\n---(\\s*\\n|$)/\n const match = content.match(frontmatterRegex)\n \n if (!match) {\n return null\n }\n \n const frontmatterYaml = match[1]\n \n try {\n const frontmatter = yaml.load(frontmatterYaml) as Record<string, any>\n return frontmatter\n } catch (error) {\n throw new Error(\n `Failed to parse YAML frontmatter in ${filePath}: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\n/**\n * Converts a seed config from frontmatter to ModelDefinitions format\n * @param config The seed configuration from frontmatter\n * @returns ModelDefinitions object ready to be saved to database\n */\nexport const processSeedConfig = (config: SeedConfig): ModelDefinitions => {\n if (!config.seed) {\n throw new Error('No seed configuration found in frontmatter')\n }\n \n const { model: modelName, properties: propertiesConfig } = config.seed\n \n if (!modelName) {\n throw new Error('Model name is required in seed configuration')\n }\n \n if (!propertiesConfig || Object.keys(propertiesConfig).length === 0) {\n throw new Error('Properties are required in seed configuration')\n }\n \n // Convert property configs to Property definitions\n const schema: Record<string, any> = {}\n \n for (const [propertyName, propertyConfig] of Object.entries(propertiesConfig)) {\n const { type, target, itemsType } = propertyConfig\n \n if (!type) {\n throw new Error(`Property type is required for ${propertyName}`)\n }\n \n // Map the type to Property constructor\n switch (type) {\n case ModelPropertyDataTypes.Text:\n schema[propertyName] = Property.Text()\n break\n case ModelPropertyDataTypes.Number:\n schema[propertyName] = Property.Number()\n break\n case ModelPropertyDataTypes.Boolean:\n schema[propertyName] = Property.Boolean()\n break\n case ModelPropertyDataTypes.Date:\n schema[propertyName] = Property.Date()\n break\n case ModelPropertyDataTypes.Image:\n schema[propertyName] = Property.Image()\n break\n case ModelPropertyDataTypes.Json:\n schema[propertyName] = Property.Json()\n break\n case ModelPropertyDataTypes.File:\n schema[propertyName] = Property.File()\n break\n case ModelPropertyDataTypes.Relation:\n if (!target) {\n throw new Error(\n `Target model is required for Relation property ${propertyName}`,\n )\n }\n schema[propertyName] = Property.Relation(target)\n break\n case ModelPropertyDataTypes.List:\n if (itemsType) {\n // List of primitives: itemsType = 'Text', 'Number', etc.\n if (itemsType === ModelPropertyDataTypes.Relation && target) {\n schema[propertyName] = Property.List('Relation', target)\n } else if (itemsType !== ModelPropertyDataTypes.Relation) {\n schema[propertyName] = Property.List(itemsType as any)\n } else {\n throw new Error(\n `List of relations requires target model for property ${propertyName}`,\n )\n }\n } else if (target) {\n // Backward compat: target = model name for list of relations\n schema[propertyName] = Property.List('Relation', target)\n } else {\n throw new Error(\n `List property ${propertyName} requires either itemsType (e.g. 'Text') or target (model name for list of relations)`,\n )\n }\n break\n default:\n throw new Error(\n `Unknown property type: ${type} for property ${propertyName}`,\n )\n }\n }\n \n // Create a mock ModelClass structure that matches ModelDefinitions\n // This is a simplified version that works with addModelsToInternalDb\n const modelClass = {\n schema,\n create: async () => {\n throw new Error('Model.create() should not be called directly')\n },\n originalConstructor: class {},\n }\n \n return {\n [modelName]: modelClass as any as Model,\n }\n}\n\n/**\n * Reads a markdown file, parses frontmatter, and saves models/properties to database\n * @param filePath Path to the markdown file\n * @param db Database instance (BetterSQLite3Database or SqliteRemoteDatabase)\n * @returns The created ModelDefinitions\n */\nexport const saveModelsFromMarkdown = async (\n filePath: string,\n db: BetterSQLite3Database<any> | SqliteRemoteDatabase<any>,\n): Promise<ModelDefinitions> => {\n // Parse frontmatter\n const frontmatter = parseMarkdownFrontmatter(filePath)\n \n if (!frontmatter) {\n throw new Error(`No frontmatter found in ${filePath}`)\n }\n \n // Validate and process seed config\n const seedConfig = frontmatter as SeedConfig\n const modelDefinitions = processSeedConfig(seedConfig)\n \n // Save to database\n await addModelsToDb(modelDefinitions, undefined, undefined, undefined)\n \n return modelDefinitions\n}\n","/**\n * Webpack / Next.js config helper for Seed Protocol apps.\n */\nexport const withSeed = (config: any, webpack: any, isServer: boolean) => {\n config.plugins.push(\n new webpack.NormalModuleReplacementPlugin(/node:/, (resource: { request: string }) => {\n resource.request = resource.request.replace(/^node:/, '')\n }),\n )\n\n if (!isServer) {\n config.resolve.alias['fs'] = '@zenfs/core'\n config.resolve.alias['node:fs'] = '@zenfs/core'\n config.resolve.alias['node:path'] = 'path-browserify'\n config.resolve.alias['path'] = 'path-browserify'\n }\n\n if (isServer) {\n config.externals.push('@sqlite.org/sqlite-wasm')\n config.externals.push('chokidar')\n config.externals.push('arweave')\n }\n\n return config\n}\n","import { execSync } from 'child_process'\nimport path from 'path'\nimport fs from 'fs'\nimport { BaseDb } from '@/db/Db/BaseDb'\n\nexport const commandExists = (command: string): boolean => {\n try {\n execSync(`which ${command}`, { stdio: 'ignore' })\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Finds the seed binary path, trying multiple locations\n * @returns The path to the seed binary, or null if not found\n */\nexport const findSeedBinary = (): string | null => {\n const cwd = process.cwd()\n\n const possiblePaths = [\n path.join(cwd, 'node_modules', '.bin', 'seed'),\n path.join(cwd, 'node_modules', '@seedprotocol', 'cli', 'dist', 'bin.js'),\n path.join(cwd, '..', 'node_modules', '.bin', 'seed'),\n path.join(cwd, '..', 'node_modules', '@seedprotocol', 'cli', 'dist', 'bin.js'),\n path.join(cwd, '..', '..', 'node_modules', '.bin', 'seed'),\n path.join(cwd, '..', '..', 'node_modules', '@seedprotocol', 'cli', 'dist', 'bin.js'),\n ]\n\n for (const binPath of possiblePaths) {\n if (fs.existsSync(binPath)) {\n return binPath\n }\n }\n\n return null\n}\n\n/**\n * Ensures the Node app DB exists and SDK migrations are applied.\n * (Formerly `runSeedInit`; CLI spawn / npx fallbacks archived under docs/archive/commented/.)\n */\nexport const ensureNodeDbSchema = async (\n _schemaFileDir?: string,\n appFilesDirPath?: string\n): Promise<void> => {\n if (!appFilesDirPath) {\n throw new Error('ensureNodeDbSchema requires appFilesDirPath')\n }\n\n await BaseDb.prepareDb(appFilesDirPath)\n}\n\n/** @deprecated Use ensureNodeDbSchema */\nexport const runSeedInit = ensureNodeDbSchema\n","import { enableMapSet } from 'immer'\n\n// Core schema exports\nexport {\n Model,\n Property,\n Image,\n List,\n Text,\n Json,\n Relation,\n Boolean,\n Number,\n Date,\n} from '../Schema'\n\n// Core classes\nexport { Item } from '../Item/Item'\nexport { ItemProperty } from '../ItemProperty/ItemProperty'\n\n// Node.js specific exports\nexport { FileManager } from './helpers/FileManager'\nexport { Db, resolveSdkDrizzleMigrationsDir } from './db/Db'\n\n// Schema exports\nexport { models, versions, seeds, metadata, appState, config, modelUids } from '../seedSchema'\n\n// Model access - use Model static methods instead\n// Models are accessible via Model.all(), Model.getById(), Model.getByName(), etc.\n\n// Helper exports\nexport { getCorrectId } from '../helpers'\n\n// Import exports\nexport * from '../imports'\n\n// Event bus\nexport { eventEmitter } from '../eventBus'\n\n// Webpack helper\nexport { withSeed } from './webpack'\n\n// Types\n// Note: PublishUpload type is available from '../db/read/getPublishUploads'\n// Type-only exports cause issues with Rollup's parser. Import directly if needed:\n// import type { PublishUpload } from '@seedprotocol/sdk/db/read/getPublishUploads'\n\n// Client\nexport { client } from '../client'\n\n// All types\nexport * from '../types'\n\n// CLI exports\nexport { PathResolver } from './helpers/PathResolver'\nexport { BasePathResolver } from '../helpers/PathResolver/BasePathResolver'\nexport {\n commandExists,\n ensureNodeDbSchema,\n runSeedInit,\n findSeedBinary,\n} from './helpers/scripts'\nexport { INIT_SCRIPT_SUCCESS_MESSAGE, SCHEMA_TS } from '../helpers/constants'\n\n// Side effect imports for CLI — register platform services\nimport { createPlatformServices } from '../platform/index.node'\nimport { configurePlatform } from '../platform/configurePlatform'\nconfigurePlatform(createPlatformServices())\n\nenableMapSet() "],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;;;AAIG;AACI,MAAM,wBAAwB,GAAG,CACtC,QAAgB,KACc;IAC9B,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE,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|
package/dist/platform.browser.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as BaseDb, c as appState, t as BasePathResolver, B as BaseFileManager } from './BasePathResolver-
|
|
1
|
+
import { a as BaseDb, c as appState, t as BasePathResolver, B as BaseFileManager } from './BasePathResolver-qV0apdVY.js';
|
|
2
2
|
import debug from 'debug';
|
|
3
|
-
import { sql } from 'drizzle-orm';
|
|
4
|
-
import { readMigrationFiles } from 'drizzle-orm/migrator';
|
|
5
3
|
import { drizzle } from 'drizzle-orm/sqlite-proxy';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
5
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
|
|
6
|
+
import { sql } from 'drizzle-orm';
|
|
7
|
+
import { E as EAS_ENDPOINT } from './constants-DSqHBPNe.js';
|
|
8
|
+
import { s as schema } from './index-CsmiM0RI.js';
|
|
9
9
|
import { SQLocalDrizzle } from 'sqlocal/drizzle';
|
|
10
10
|
import { Observable, distinctUntilChanged } from 'rxjs';
|
|
11
11
|
import { BaseArweaveClient, GET_TRANSACTION_TAGS } from '@seedprotocol/arweave';
|
|
@@ -17,6 +17,9 @@ import 'drizzle-orm/sqlite-core';
|
|
|
17
17
|
import 'xstate';
|
|
18
18
|
import 'pluralize';
|
|
19
19
|
import '@sinclair/typebox';
|
|
20
|
+
import './db-CceyWksv.js';
|
|
21
|
+
import 'drizzle-orm/casing';
|
|
22
|
+
import 'lodash-es';
|
|
20
23
|
import 'nanoid';
|
|
21
24
|
import 'nanoid-dictionary';
|
|
22
25
|
import '@seedprotocol/query';
|
|
@@ -347,7 +350,7 @@ var filesDownload = `(
|
|
|
347
350
|
}.toString()}
|
|
348
351
|
)()`;
|
|
349
352
|
|
|
350
|
-
const logger$
|
|
353
|
+
const logger$5 = debug('seedSdk:browser:workers:FileDownloader');
|
|
351
354
|
class FileDownloader {
|
|
352
355
|
constructor() {
|
|
353
356
|
this.workersArchive = [];
|
|
@@ -364,7 +367,7 @@ class FileDownloader {
|
|
|
364
367
|
const localExcludedTransactions = new Set(excludedTransactions);
|
|
365
368
|
return new Promise((resolve, reject) => {
|
|
366
369
|
worker.onmessage = (e) => {
|
|
367
|
-
logger$
|
|
370
|
+
logger$5('filesDownload main thread onmessage', e.data);
|
|
368
371
|
if (e.data.message === 'excludeTransaction') {
|
|
369
372
|
localExcludedTransactions.add(e.data.transactionId);
|
|
370
373
|
}
|
|
@@ -384,7 +387,7 @@ class FileDownloader {
|
|
|
384
387
|
worker.postMessage({
|
|
385
388
|
transactionIds,
|
|
386
389
|
arweaveHost,
|
|
387
|
-
debug: logger$
|
|
390
|
+
debug: logger$5.enabled,
|
|
388
391
|
filesRoot: BaseFileManager.getWorkingDir(),
|
|
389
392
|
});
|
|
390
393
|
});
|
|
@@ -788,7 +791,7 @@ var imageResize = `(
|
|
|
788
791
|
}.toString()}
|
|
789
792
|
)()`;
|
|
790
793
|
|
|
791
|
-
const logger$
|
|
794
|
+
const logger$4 = debug('seedSdk:browser:workers:ImageResizer');
|
|
792
795
|
class ImageResizer {
|
|
793
796
|
constructor() {
|
|
794
797
|
this.workersArchive = new Map();
|
|
@@ -799,18 +802,18 @@ class ImageResizer {
|
|
|
799
802
|
if (this.workersArchive.has(filePath)) {
|
|
800
803
|
const savedWorker = this.workersArchive.get(filePath);
|
|
801
804
|
savedWorker?.terminate();
|
|
802
|
-
logger$
|
|
805
|
+
logger$4('[ImageResizer.resize] Terminated worker for filePath due to incoming request', filePath);
|
|
803
806
|
this.workersArchive.delete(filePath);
|
|
804
807
|
}
|
|
805
808
|
const worker = new Worker(this.workerBlobUrl);
|
|
806
809
|
this.workersArchive.set(filePath, worker);
|
|
807
810
|
return new Promise((resolve, reject) => {
|
|
808
811
|
worker.onmessage = (e) => {
|
|
809
|
-
logger$
|
|
812
|
+
logger$4('[ImageResizer.resize] main thread onmessage', e.data);
|
|
810
813
|
if (e.data.done) {
|
|
811
814
|
const savedWorker = this.workersArchive.get(filePath);
|
|
812
815
|
savedWorker?.terminate();
|
|
813
|
-
logger$
|
|
816
|
+
logger$4('[ImageResizer.resize] Terminated worker for filePath due to done', filePath);
|
|
814
817
|
this.workersArchive.delete(filePath);
|
|
815
818
|
resolve(e.data);
|
|
816
819
|
}
|
|
@@ -825,7 +828,7 @@ class ImageResizer {
|
|
|
825
828
|
filePath,
|
|
826
829
|
width,
|
|
827
830
|
height,
|
|
828
|
-
debug: logger$
|
|
831
|
+
debug: logger$4.enabled,
|
|
829
832
|
});
|
|
830
833
|
});
|
|
831
834
|
}
|
|
@@ -848,7 +851,7 @@ class ImageResizer {
|
|
|
848
851
|
}
|
|
849
852
|
}
|
|
850
853
|
|
|
851
|
-
const logger$
|
|
854
|
+
const logger$3 = debug('seedSdk:browser:helpers:FileManager');
|
|
852
855
|
/**
|
|
853
856
|
* Browser-safe path helpers for SDK virtual file paths.
|
|
854
857
|
* We intentionally avoid Node/CJS path polyfills here to keep browser bundles ESM-safe.
|
|
@@ -1072,7 +1075,7 @@ class BrowserFileManager {
|
|
|
1072
1075
|
}
|
|
1073
1076
|
catch (error) {
|
|
1074
1077
|
// This is a no-op. We tried to create a directory that already exists.
|
|
1075
|
-
logger$
|
|
1078
|
+
logger$3('Attempted to create a directory that already exists');
|
|
1076
1079
|
}
|
|
1077
1080
|
}
|
|
1078
1081
|
}
|
|
@@ -1094,7 +1097,7 @@ class BrowserFileManager {
|
|
|
1094
1097
|
const startTime = Date.now();
|
|
1095
1098
|
let isBusy = false;
|
|
1096
1099
|
const cancelableInterval = new CancelableInterval(async (stop) => {
|
|
1097
|
-
logger$
|
|
1100
|
+
logger$3('waitForFile', filePath);
|
|
1098
1101
|
if (isBusy) {
|
|
1099
1102
|
return;
|
|
1100
1103
|
}
|
|
@@ -1178,7 +1181,7 @@ class BrowserFileManager {
|
|
|
1178
1181
|
const startTime = Date.now();
|
|
1179
1182
|
let isBusy = false;
|
|
1180
1183
|
const cancelableInterval = new CancelableInterval(async (stop) => {
|
|
1181
|
-
logger$
|
|
1184
|
+
logger$3('waitForFileWithContent', filePath);
|
|
1182
1185
|
if (isBusy) {
|
|
1183
1186
|
return;
|
|
1184
1187
|
}
|
|
@@ -1389,7 +1392,7 @@ class CancelableInterval {
|
|
|
1389
1392
|
}
|
|
1390
1393
|
catch (error) {
|
|
1391
1394
|
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
1392
|
-
logger$
|
|
1395
|
+
logger$3('Previous task was canceled.');
|
|
1393
1396
|
}
|
|
1394
1397
|
else {
|
|
1395
1398
|
console.error('Task error:', error);
|
|
@@ -3040,6 +3043,144 @@ var drizzleFiles = /*#__PURE__*/Object.freeze({
|
|
|
3040
3043
|
snapshotJson: snapshotJson
|
|
3041
3044
|
});
|
|
3042
3045
|
|
|
3046
|
+
/**
|
|
3047
|
+
* Build drizzle migration metadata from embedded SQL strings.
|
|
3048
|
+
* Avoids `drizzle-orm/migrator` (Node fs / path / crypto) on the browser graph.
|
|
3049
|
+
*/
|
|
3050
|
+
function getEmbeddedMigrations() {
|
|
3051
|
+
const journal = JSON.parse(journalJson);
|
|
3052
|
+
const entries = journal.entries ?? [];
|
|
3053
|
+
return entries.map((entry) => {
|
|
3054
|
+
const varName = `migrationSql_${entry.tag}`;
|
|
3055
|
+
const query = drizzleFiles[varName];
|
|
3056
|
+
if (typeof query !== 'string') {
|
|
3057
|
+
throw new Error(`No embedded migration content for ${entry.tag}`);
|
|
3058
|
+
}
|
|
3059
|
+
const trimmed = query.trim();
|
|
3060
|
+
return {
|
|
3061
|
+
sql: trimmed.split('--> statement-breakpoint'),
|
|
3062
|
+
bps: Boolean(entry.breakpoints),
|
|
3063
|
+
folderMillis: entry.when,
|
|
3064
|
+
hash: bytesToHex(sha256(utf8ToBytes(trimmed))),
|
|
3065
|
+
};
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
3068
|
+
/**
|
|
3069
|
+
* Same apply loop as drizzle-orm/sqlite-proxy/migrator, with in-memory migrations.
|
|
3070
|
+
*/
|
|
3071
|
+
async function applyEmbeddedMigrations(db, migrations, migrationsTable = '__drizzle_migrations') {
|
|
3072
|
+
await db.run(sql `
|
|
3073
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(migrationsTable)} (
|
|
3074
|
+
id SERIAL PRIMARY KEY,
|
|
3075
|
+
hash text NOT NULL,
|
|
3076
|
+
created_at numeric
|
|
3077
|
+
)
|
|
3078
|
+
`);
|
|
3079
|
+
const dbMigrations = await db.values(sql `SELECT id, hash, created_at FROM ${sql.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1`);
|
|
3080
|
+
const lastDbMigration = dbMigrations[0] ?? undefined;
|
|
3081
|
+
const queriesToRun = [];
|
|
3082
|
+
for (const migration of migrations) {
|
|
3083
|
+
if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) {
|
|
3084
|
+
queriesToRun.push(...migration.sql, `INSERT INTO \`${migrationsTable}\` ("hash", "created_at") VALUES('${migration.hash}', '${migration.folderMillis}')`);
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
for (const query of queriesToRun) {
|
|
3088
|
+
await db.run(sql.raw(query));
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
const logger$2 = debug('seedSdk:browser:db:createSqlocalDrizzle');
|
|
3093
|
+
/** First sqlocal work can include sqlite-wasm fetch; keep this long to avoid false positives. */
|
|
3094
|
+
const SQLOCAL_FIRST_QUERY_TIMEOUT_MS = 90000;
|
|
3095
|
+
const HTTP_MODULE_WORKER_URL = /^https?:/i;
|
|
3096
|
+
function shouldBlobWrapModuleWorker(scriptURL, options) {
|
|
3097
|
+
const type = options?.type ?? 'classic';
|
|
3098
|
+
if (type !== 'module')
|
|
3099
|
+
return false;
|
|
3100
|
+
return HTTP_MODULE_WORKER_URL.test(String(scriptURL));
|
|
3101
|
+
}
|
|
3102
|
+
function createBlobModuleWorkerSource(scriptURL) {
|
|
3103
|
+
return `import ${JSON.stringify(String(scriptURL))};`;
|
|
3104
|
+
}
|
|
3105
|
+
/**
|
|
3106
|
+
* Construct SQLocal while starting its HTTPS module worker from a blob that
|
|
3107
|
+
* only imports the bundled worker URL. Some Chrome profiles kill
|
|
3108
|
+
* `new Worker(https://…/worker-HASH.js, { type: 'module' })` as an entry
|
|
3109
|
+
* script; importing the same URL from a blob worker reaches connect.
|
|
3110
|
+
*
|
|
3111
|
+
* The `Worker` patch is scoped to `factory()` so Vite still sees sqlocal's
|
|
3112
|
+
* own `new Worker(new URL('./worker', import.meta.url))` and emits a real
|
|
3113
|
+
* worker chunk.
|
|
3114
|
+
*/
|
|
3115
|
+
function createSqlocalDrizzle(factory) {
|
|
3116
|
+
let rejectFailed;
|
|
3117
|
+
const workerFailed = new Promise((_, reject) => {
|
|
3118
|
+
rejectFailed = reject;
|
|
3119
|
+
});
|
|
3120
|
+
// Avoid an unhandled rejection if the caller throws before racing this promise.
|
|
3121
|
+
workerFailed.catch(() => { });
|
|
3122
|
+
const restore = installModuleWorkerBlobWrap((error) => {
|
|
3123
|
+
rejectFailed?.(error);
|
|
3124
|
+
});
|
|
3125
|
+
try {
|
|
3126
|
+
return { instance: factory(), workerFailed };
|
|
3127
|
+
}
|
|
3128
|
+
finally {
|
|
3129
|
+
restore();
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
async function raceSqlocalStartup(work, workerFailed, timeoutMs = SQLOCAL_FIRST_QUERY_TIMEOUT_MS) {
|
|
3133
|
+
let timeoutId;
|
|
3134
|
+
const timedOut = new Promise((_, reject) => {
|
|
3135
|
+
timeoutId = setTimeout(() => {
|
|
3136
|
+
reject(new Error(`sqlocal database failed to become ready within ${timeoutMs}ms`));
|
|
3137
|
+
}, timeoutMs);
|
|
3138
|
+
});
|
|
3139
|
+
try {
|
|
3140
|
+
return await Promise.race([work, workerFailed, timedOut]);
|
|
3141
|
+
}
|
|
3142
|
+
finally {
|
|
3143
|
+
if (timeoutId !== undefined) {
|
|
3144
|
+
clearTimeout(timeoutId);
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
function installModuleWorkerBlobWrap(onWorkerFailed) {
|
|
3149
|
+
const OriginalWorker = globalThis.Worker;
|
|
3150
|
+
if (typeof OriginalWorker === 'undefined') {
|
|
3151
|
+
return () => { };
|
|
3152
|
+
}
|
|
3153
|
+
function WrappedWorker(scriptURL, options) {
|
|
3154
|
+
const worker = shouldBlobWrapModuleWorker(scriptURL, options)
|
|
3155
|
+
? new OriginalWorker(URL.createObjectURL(new Blob([createBlobModuleWorkerSource(scriptURL)], {
|
|
3156
|
+
type: 'text/javascript',
|
|
3157
|
+
})), { ...options, type: 'module' })
|
|
3158
|
+
: new OriginalWorker(scriptURL, options);
|
|
3159
|
+
const fail = (event) => {
|
|
3160
|
+
const filename = 'filename' in event && typeof event.filename === 'string'
|
|
3161
|
+
? event.filename
|
|
3162
|
+
: '';
|
|
3163
|
+
const message = 'message' in event && typeof event.message === 'string'
|
|
3164
|
+
? event.message
|
|
3165
|
+
: event.type;
|
|
3166
|
+
const error = new Error(filename
|
|
3167
|
+
? `sqlocal worker failed to start (${event.type}): ${message} [${filename}]`
|
|
3168
|
+
: `sqlocal worker failed to start (${event.type}): ${message}`);
|
|
3169
|
+
logger$2('[createSqlocalDrizzle] worker failed', error.message);
|
|
3170
|
+
onWorkerFailed(error);
|
|
3171
|
+
};
|
|
3172
|
+
worker.addEventListener('error', fail);
|
|
3173
|
+
worker.addEventListener('messageerror', fail);
|
|
3174
|
+
return worker;
|
|
3175
|
+
}
|
|
3176
|
+
WrappedWorker.prototype = OriginalWorker.prototype;
|
|
3177
|
+
Object.setPrototypeOf(WrappedWorker, OriginalWorker);
|
|
3178
|
+
globalThis.Worker = WrappedWorker;
|
|
3179
|
+
return () => {
|
|
3180
|
+
globalThis.Worker = OriginalWorker;
|
|
3181
|
+
};
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3043
3184
|
const logger$1 = debug('seedSdk:browser:db:Db');
|
|
3044
3185
|
class BrowserDb {
|
|
3045
3186
|
getAppDb() {
|
|
@@ -3072,11 +3213,14 @@ class BrowserDb {
|
|
|
3072
3213
|
logger$1('[Db.prepareDb] waiting for journal file to be fully written...');
|
|
3073
3214
|
await BaseFileManager.waitForFileWithContent(journalFilePath, 100, 5000);
|
|
3074
3215
|
logger$1('[Db.prepareDb] journal file is ready');
|
|
3075
|
-
// Initialize SQLocalDrizzle with reactive: true to enable reactive queries
|
|
3076
|
-
|
|
3216
|
+
// Initialize SQLocalDrizzle with reactive: true to enable reactive queries.
|
|
3217
|
+
// Blob-wrap sqlocal's HTTPS module worker so Chrome profiles that kill
|
|
3218
|
+
// `new Worker(https://…/worker-HASH.js, { type: 'module' })` as an entry
|
|
3219
|
+
// still reach connect via `import` of the same URL.
|
|
3220
|
+
const { instance: sqlocalDrizzle, workerFailed } = createSqlocalDrizzle(() => new SQLocalDrizzle({
|
|
3077
3221
|
databasePath: `${this.filesDir}/db/seed.db`,
|
|
3078
|
-
reactive: true
|
|
3079
|
-
});
|
|
3222
|
+
reactive: true,
|
|
3223
|
+
}));
|
|
3080
3224
|
const { driver, batchDriver } = sqlocalDrizzle;
|
|
3081
3225
|
// Store SQLocalDrizzle instance for reactive queries
|
|
3082
3226
|
this.sqlocalInstance = sqlocalDrizzle;
|
|
@@ -3087,10 +3231,12 @@ class BrowserDb {
|
|
|
3087
3231
|
schema,
|
|
3088
3232
|
});
|
|
3089
3233
|
logger$1('[Db.prepareDb] database prepared');
|
|
3090
|
-
await
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3234
|
+
await raceSqlocalStartup((async () => {
|
|
3235
|
+
await this.runMigrations(db);
|
|
3236
|
+
this.appDb = db;
|
|
3237
|
+
const { backfillMetadataPropertyIds } = await import('./backfillMetadataPropertyIds-BzbAB-C5.js');
|
|
3238
|
+
await backfillMetadataPropertyIds();
|
|
3239
|
+
})(), workerFailed);
|
|
3094
3240
|
return this.appDb;
|
|
3095
3241
|
}
|
|
3096
3242
|
catch (error) {
|
|
@@ -3211,23 +3357,11 @@ class BrowserDb {
|
|
|
3211
3357
|
}
|
|
3212
3358
|
}
|
|
3213
3359
|
/** Internal migration runner. Used by prepareDb before appDb is set. */
|
|
3214
|
-
async runMigrations(db,
|
|
3215
|
-
const migrationsFolder = pathToDbDir ?? `${this.filesDir}/db`;
|
|
3360
|
+
async runMigrations(db, _pathToDbDir) {
|
|
3216
3361
|
try {
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
});
|
|
3221
|
-
logger$1('[Db.runMigrations] migrations', migrations);
|
|
3222
|
-
await migrate(db, async (queriesToRun) => {
|
|
3223
|
-
logger$1('queriesToRun', queriesToRun);
|
|
3224
|
-
for (const query of queriesToRun) {
|
|
3225
|
-
logger$1('query', query);
|
|
3226
|
-
await db.run(sql.raw(query));
|
|
3227
|
-
}
|
|
3228
|
-
}, {
|
|
3229
|
-
migrationsFolder,
|
|
3230
|
-
});
|
|
3362
|
+
const migrations = getEmbeddedMigrations();
|
|
3363
|
+
logger$1('[Db.runMigrations] embedded migrations', migrations.length);
|
|
3364
|
+
await applyEmbeddedMigrations(db, migrations);
|
|
3231
3365
|
logger$1('[Db.runMigrations] migrations completed');
|
|
3232
3366
|
}
|
|
3233
3367
|
catch (error) {
|