@happyvertical/smrt-core 0.55.7 → 0.55.9
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/AGENTS.md +2 -1
- package/agents/browser-entry.md +44 -0
- package/agents/build-knowledge.md +7 -0
- package/agents/recipes.md +217 -0
- package/agents/revision-guard.md +72 -1
- package/dist/audit-context.d.ts.map +1 -1
- package/dist/audit-context.js +2 -2
- package/dist/audit-context.js.map +1 -1
- package/dist/browser.d.ts +2 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +7 -7
- package/dist/cascade.d.ts +1 -1
- package/dist/cascade.d.ts.map +1 -1
- package/dist/cascade.js +1 -1
- package/dist/cascade.js.map +1 -1
- package/dist/change-feed.d.ts.map +1 -1
- package/dist/change-feed.js +1 -2
- package/dist/change-feed.js.map +1 -1
- package/dist/class.d.ts +1 -1
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +7 -3
- package/dist/class.js.map +1 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +1 -1
- package/dist/collection.js.map +1 -1
- package/dist/consumer-plugin/index.js +2 -2
- package/dist/data-query.d.ts.map +1 -1
- package/dist/data-query.js +2 -13
- package/dist/data-query.js.map +1 -1
- package/dist/database.js +1 -1
- package/dist/database.js.map +1 -1
- package/dist/dispatch/bus.js +1 -1
- package/dist/dispatch/bus.js.map +1 -1
- package/dist/embedded-write-queue.d.ts +1 -1
- package/dist/embedded-write-queue.d.ts.map +1 -1
- package/dist/embedded-write-queue.js +7 -5
- package/dist/embedded-write-queue.js.map +1 -1
- package/dist/embeddings/hash.js +2 -2
- package/dist/embeddings/hash.js.map +1 -1
- package/dist/embeddings/storage.d.ts.map +1 -1
- package/dist/embeddings/storage.js +1 -2
- package/dist/embeddings/storage.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/generation-snapshot.js +1 -1
- package/dist/generators/index.js +1 -1
- package/dist/generators/mcp.js +3 -3
- package/dist/generators/preflight-route.js +1 -1
- package/dist/generators/rest.js +1 -1
- package/dist/generators.js +1 -1
- package/dist/host.browser.d.ts +12 -0
- package/dist/host.browser.d.ts.map +1 -0
- package/dist/host.browser.js +30 -0
- package/dist/host.browser.js.map +1 -0
- package/dist/host.d.ts +18 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +15 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/knowledge.d.ts.map +1 -1
- package/dist/knowledge.js +5 -4
- package/dist/knowledge.js.map +1 -1
- package/dist/manifest/browser-capability.generated.d.ts +14 -0
- package/dist/manifest/browser-capability.generated.d.ts.map +1 -0
- package/dist/manifest/browser-capability.generated.js +499 -0
- package/dist/manifest/browser-capability.generated.js.map +1 -0
- package/dist/manifest/discover-base-classes.js +1 -1
- package/dist/manifest/discover-smrt-packages.js +1 -1
- package/dist/manifest/generator.js +3 -3
- package/dist/manifest/index.js +2 -2
- package/dist/manifest/local-manifest-reader.d.ts +48 -0
- package/dist/manifest/local-manifest-reader.d.ts.map +1 -0
- package/dist/manifest/local-manifest-reader.js +81 -0
- package/dist/manifest/local-manifest-reader.js.map +1 -0
- package/dist/manifest/manager.d.ts +5 -28
- package/dist/manifest/manager.d.ts.map +1 -1
- package/dist/manifest/manager.js +10 -56
- package/dist/manifest/manager.js.map +1 -1
- package/dist/manifest/manifest-loader.d.ts +1 -1
- package/dist/manifest/manifest-loader.d.ts.map +1 -1
- package/dist/manifest/manifest-loader.js +43 -12
- package/dist/manifest/manifest-loader.js.map +1 -1
- package/dist/manifest/node-host.d.ts +38 -0
- package/dist/manifest/node-host.d.ts.map +1 -0
- package/dist/manifest/node-host.js +52 -0
- package/dist/manifest/node-host.js.map +1 -0
- package/dist/manifest/package-manifest-exports.js +1 -1
- package/dist/manifest/static-manifest.d.ts.map +1 -1
- package/dist/manifest/static-manifest.js +7 -2
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.d.ts +2 -1
- package/dist/manifest/store.d.ts.map +1 -1
- package/dist/manifest/store.js +7 -4
- package/dist/manifest/store.js.map +1 -1
- package/dist/manifest.js +1 -1
- package/dist/manifest.json +9 -2
- package/dist/native-duckdb.d.ts +28 -0
- package/dist/native-duckdb.d.ts.map +1 -0
- package/dist/native-duckdb.js +51 -0
- package/dist/native-duckdb.js.map +1 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/_md.js +169 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/_md.js.map +1 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/_u64.js +13 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/_u64.js.map +1 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/sha2.js +198 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/sha2.js.map +1 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/utils.js +243 -0
- package/dist/node_modules/.pnpm/@noble_hashes@2.4.0/node_modules/@noble/hashes/utils.js.map +1 -0
- package/dist/object.d.ts +56 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +139 -16
- package/dist/object.js.map +1 -1
- package/dist/postgres-permissions.d.ts.map +1 -1
- package/dist/postgres-permissions.js +3 -3
- package/dist/postgres-permissions.js.map +1 -1
- package/dist/prebuild/index.js +1 -1
- package/dist/recipe-demo.d.ts +70 -0
- package/dist/recipe-demo.d.ts.map +1 -0
- package/dist/recipe-demo.js +130 -0
- package/dist/recipe-demo.js.map +1 -0
- package/dist/recipe.d.ts +64 -1
- package/dist/recipe.d.ts.map +1 -1
- package/dist/recipe.js +30 -0
- package/dist/recipe.js.map +1 -1
- package/dist/registry/class-registration.js +2 -2
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/db-cache-key.js +4 -5
- package/dist/registry/db-cache-key.js.map +1 -1
- package/dist/registry/inheritance-resolver.js +1 -1
- package/dist/registry/name-resolver.js +1 -1
- package/dist/registry/qualified-name-aliases.js +1 -1
- package/dist/registry/schema-builder.d.ts.map +1 -1
- package/dist/registry/schema-builder.js +3 -3
- package/dist/registry/schema-builder.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +5 -8
- package/dist/registry.js.map +1 -1
- package/dist/revision-guard.js +1 -1
- package/dist/revision-guard.js.map +1 -1
- package/dist/scanner/manifest-generator.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.js +19 -10
- package/dist/scanner/manifest-generator.js.map +1 -1
- package/dist/scanner/recipe-demo-pass.d.ts +14 -0
- package/dist/scanner/recipe-demo-pass.d.ts.map +1 -0
- package/dist/scanner/recipe-demo-pass.js +33 -0
- package/dist/scanner/recipe-demo-pass.js.map +1 -0
- package/dist/scanner/types.d.ts +7 -1
- package/dist/scanner/types.d.ts.map +1 -1
- package/dist/scanner/types.js.map +1 -1
- package/dist/schema/ddl/duckdb-strategy.d.ts.map +1 -1
- package/dist/schema/ddl/duckdb-strategy.js +1 -1
- package/dist/schema/ddl/duckdb-strategy.js.map +1 -1
- package/dist/schema/foreign-key-planner.d.ts.map +1 -1
- package/dist/schema/foreign-key-planner.js +1 -1
- package/dist/schema/foreign-key-planner.js.map +1 -1
- package/dist/schema/generator.d.ts.map +1 -1
- package/dist/schema/generator.js +10 -14
- package/dist/schema/generator.js.map +1 -1
- package/dist/schema/schema-aggregator.js +1 -1
- package/dist/scripts/browser-entry-evaluation.mjs +157 -0
- package/dist/smrt-knowledge.json +27 -12
- package/dist/system/browser.d.ts +16 -0
- package/dist/system/browser.d.ts.map +1 -0
- package/dist/system/browser.js +6 -0
- package/dist/system/index.d.ts +1 -6
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js +2 -1
- package/dist/testing/database.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/unchanged-indexed.d.ts +85 -0
- package/dist/unchanged-indexed.d.ts.map +1 -0
- package/dist/unchanged-indexed.js +219 -0
- package/dist/unchanged-indexed.js.map +1 -0
- package/dist/utils/async-context.d.ts +22 -0
- package/dist/utils/async-context.d.ts.map +1 -0
- package/dist/utils/async-context.js +27 -0
- package/dist/utils/async-context.js.map +1 -0
- package/dist/utils/import-project-vite.js +1 -1
- package/dist/utils/import-workspace-module.js +1 -1
- package/dist/utils/json.browser.d.ts +18 -0
- package/dist/utils/json.browser.d.ts.map +1 -0
- package/dist/utils/json.browser.js +47 -0
- package/dist/utils/json.browser.js.map +1 -0
- package/dist/utils/sha256.d.ts +15 -0
- package/dist/utils/sha256.d.ts.map +1 -0
- package/dist/utils/sha256.js +29 -0
- package/dist/utils/sha256.js.map +1 -0
- package/dist/vite-plugin/changes-route.js +1 -1
- package/dist/vite-plugin/dev-plane-route.js +1 -1
- package/dist/vite-plugin/events-route.js +1 -1
- package/dist/vite-plugin/import-build-aware.js +1 -1
- package/dist/vite-plugin/index.js +2 -2
- package/dist/vite-plugin/resources-route.js +1 -1
- package/dist/vite-plugin/sveltekit-generator.js +2 -2
- package/dist/vite-plugin/sveltekit-path.js +1 -1
- package/dist/vite-plugin/sveltekit-register-injection.js +1 -1
- package/dist/vite-plugin/sveltekit-route-coordinator.js +1 -1
- package/dist/vite-plugin/sync-apply-route.js +1 -1
- package/dist/vite-plugin/web-collections.js +2 -2
- package/package.json +21 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","names":[],"sources":["../../src/manifest/store.ts"],"sourcesContent":["/**\n * Leaf manifest storage + pure fs/URL helpers.\n *\n * This module has **no dependency on ObjectRegistry, registry.ts, or\n * class-registration.ts**. It owns the globalThis manifest caches and the\n * filesystem helpers that resolve and read manifest.json files from the\n * workspace, installed node_modules, and smrt-core's own bundle.\n *\n * Breaking the cycle: Before this module existed, `registry.ts` and\n * `manifest-loader.ts` both maintained their own copies of these helpers\n * (`registry.ts` had its own because `registerPackageManifest` needed them\n * and could not import `manifest-loader.ts` due to a module cycle —\n * `registry.ts → class-registration.ts → manifest-loader.ts → registry.ts`).\n * Centralizing them here lets both files import from a leaf, so the cycle\n * goes away and Release B's `ManifestSource` abstraction can live above\n * this leaf without re-creating it.\n *\n * @see https://github.com/happyvertical/smrt/issues/1133\n */\n\nimport { createLogger } from '@happyvertical/logger';\nimport { recordRegistryDiagnostic } from '../registry/diagnostics.js';\nimport {\n bumpRegistryGeneration,\n createGenerationTrackedMap,\n isGenerationTrackedMap,\n} from '../registry/generation.js';\nimport type {\n SmartObjectDefinition,\n SmartObjectManifest,\n} from '../scanner/types.js';\nimport { MANIFEST_TIMESTAMP } from '../scanner/types.js';\nimport type { ColumnDefinition } from '../schema/types.js';\nimport {\n createQualifiedName,\n isQualifiedName,\n parseQualifiedName,\n} from '../utils/qualified-names.js';\n\nconst logger = createLogger({ level: 'info' });\n\nexport type ManifestLoadOptions = {\n warn?: boolean;\n};\n\n// ── Runtime environment detection ────────────────────────────────────────\n\n/**\n * Detect whether we're running inside a test runner. Test manifests must\n * never load in production to avoid test classes colliding with real ones.\n */\nexport function isTestEnvironment(): boolean {\n return (\n process.env.NODE_ENV === 'test' ||\n process.env.VITEST === 'true' ||\n process.env.JEST_WORKER_ID !== undefined\n );\n}\n\n/**\n * Best-effort detection of the current package under test.\n *\n * In workspace consumers, `process.cwd()` points at the consuming app/package,\n * while in smrt-core's own tests it points at `packages/core`. We use that\n * distinction to keep smrt-core's internal test manifest scoped to its own\n * test suite instead of leaking those fixtures into every consumer test run.\n */\nexport function getCurrentPackageName(): string | null {\n const explicitPackageName = process.env.npm_package_name;\n if (explicitPackageName) {\n return explicitPackageName;\n }\n\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n let currentDir = process.cwd();\n\n while (true) {\n const packageJsonPath = builtins.path.join(currentDir, 'package.json');\n if (builtins.fs.existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(\n builtins.fs.readFileSync(packageJsonPath, 'utf-8'),\n ) as { name?: string };\n return packageJson.name ?? null;\n } catch {\n return null;\n }\n }\n\n const parentDir = builtins.path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n\n currentDir = parentDir;\n }\n}\n\n/**\n * smrt-core's committed test manifest is for smrt-core's own tests only.\n * Consumer packages should expose only their local test manifest plus real\n * published manifests from dependencies.\n */\nexport function shouldLoadCoreTestManifest(): boolean {\n if (!isTestEnvironment()) {\n return false;\n }\n\n const currentPackageName = getCurrentPackageName();\n if (currentPackageName) {\n return currentPackageName === '@happyvertical/smrt-core';\n }\n\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return false;\n }\n\n const moduleDir = builtins.path.dirname(\n builtins.url.fileURLToPath(import.meta.url),\n );\n const workspaceRoot = findWorkspaceRootSync(moduleDir);\n if (!workspaceRoot) {\n return false;\n }\n\n const corePackageDir = builtins.path.join(workspaceRoot, 'packages', 'core');\n const relative = builtins.path.relative(corePackageDir, process.cwd());\n return (\n relative === '' ||\n (!relative.startsWith('..') && !builtins.path.isAbsolute(relative))\n );\n}\n\n// ── Node builtins access ─────────────────────────────────────────────────\n\n/**\n * Resolve Node's built-in `fs`/`path`/`url` modules without a static import.\n *\n * `process.getBuiltinModule()` is a Node 22+ API that returns the live\n * built-in without going through the module loader. This avoids Vite's\n * static-import analysis flagging these builtins and simulated\n * \"externalized for browser\" warnings in bundled browser builds.\n */\nexport function getNodeBuiltins() {\n const getBuiltinModule = (\n process as typeof process & {\n getBuiltinModule?: (id: string) => unknown;\n }\n ).getBuiltinModule;\n if (typeof getBuiltinModule !== 'function') {\n return null;\n }\n\n const fs = getBuiltinModule('node:fs') as\n | typeof import('node:fs')\n | undefined;\n const path = getBuiltinModule('node:path') as\n | typeof import('node:path')\n | undefined;\n const url = getBuiltinModule('node:url') as\n | typeof import('node:url')\n | undefined;\n\n if (!fs || !path || !url) {\n return null;\n }\n\n return { fs, path, url };\n}\n\n// ── globalThis cache accessors ───────────────────────────────────────────\n\ntype ManifestGlobals = typeof globalThis & {\n __smrtManifestStatic?: SmartObjectManifest | null;\n __smrtManifestStaticLoadAttempted?: boolean;\n __smrtManifestTest?: SmartObjectManifest | null;\n __smrtManifestLocalTest?: SmartObjectManifest | null;\n __smrtManifestCache?: Map<string, SmartObjectManifest>;\n};\n\nfunction getManifestGlobals(): ManifestGlobals {\n return globalThis as ManifestGlobals;\n}\n\n/**\n * Return the mutable external-manifest cache, creating it if absent.\n *\n * Writers: `registerPackageManifest()` (Release A, each package's shim),\n * `loadExternalManifestSyncWithNode()`, `loadManifestFromPathSyncWithNode()`.\n * Readers: all discovery paths.\n */\n/**\n * Whether the package's stored manifest declares that its library build\n * stamps each decorated class with its package (`stampsConstructors`,\n * #3490). Read from the manifest record itself, so every path that stores a\n * manifest carries the capability and every path that clears or replaces it\n * drops it.\n */\nexport function packageStampsConstructors(packageName: string): boolean {\n return getManifestCache().get(packageName)?.stampsConstructors === true;\n}\n\nexport function getManifestCache(): Map<string, SmartObjectManifest> {\n const globals = getManifestGlobals();\n const current = globals.__smrtManifestCache;\n if (current && isGenerationTrackedMap(current)) {\n return current;\n }\n // A newly cached manifest can change what manifest discovery returns, so\n // it invalidates the generation-keyed registry memos (#3047).\n const tracked = createGenerationTrackedMap<string, SmartObjectManifest>(\n current,\n );\n globals.__smrtManifestCache = tracked;\n return tracked;\n}\n\n/** Read-only snapshot of the static manifest, if cached. */\nexport function getStaticManifestCache(): SmartObjectManifest | null {\n return getManifestGlobals().__smrtManifestStatic ?? null;\n}\n\n/** Read-only snapshot of the core test manifest, if cached. */\nexport function getTestManifestCache(): SmartObjectManifest | null {\n return getManifestGlobals().__smrtManifestTest ?? null;\n}\n\n/**\n * Read-only snapshot of the local (domain package) test manifest.\n *\n * Preserves the three-state semantics that `discoverManifestEntry()` relies\n * on: `undefined` means \"never attempted to load\" and triggers the lazy\n * loader; `null` means \"attempted but no local test manifest in this\n * package\"; a manifest object means \"loaded\". Do not collapse `undefined`\n * to `null` here — the async-discovery lazy-load path keys off the\n * distinction (see manifest-loader.ts:`if (getLocalTestManifestCache() === undefined) loadLocalTestManifestSync()`).\n */\nexport function getLocalTestManifestCache():\n | SmartObjectManifest\n | null\n | undefined {\n return getManifestGlobals().__smrtManifestLocalTest;\n}\n\n// ── Manifest shape helpers ───────────────────────────────────────────────\n\nexport function createEmptyStaticManifest(): SmartObjectManifest {\n return {\n version: '1.0.0',\n timestamp: MANIFEST_TIMESTAMP,\n objects: {},\n packageName: '@happyvertical/smrt-core',\n };\n}\n\n/**\n * Deep-clone a manifest's schema column map so downstream mutators don't\n * corrupt the cached manifest. Foreign-key descriptors get their own copy\n * because manifest-loader.ts and registerFromManifest() both splice them\n * into live schema entries.\n */\nexport function cloneManifestSchemaColumns(\n columns: Record<string, unknown> | undefined,\n): Record<string, ColumnDefinition> {\n return Object.fromEntries(\n Object.entries(columns || {}).map(([columnName, column]) => {\n const clonedColumn = {\n ...(column as ColumnDefinition & Record<string, unknown>),\n } as ColumnDefinition;\n const manifestDefault = (\n clonedColumn as ColumnDefinition & {\n default?: unknown;\n }\n ).default;\n\n if (\n clonedColumn.defaultValue === undefined &&\n manifestDefault !== undefined\n ) {\n clonedColumn.defaultValue = manifestDefault;\n }\n\n if (clonedColumn.foreignKey) {\n clonedColumn.foreignKey = { ...clonedColumn.foreignKey };\n }\n\n return [columnName, clonedColumn];\n }),\n ) as Record<string, ColumnDefinition>;\n}\n\n/**\n * Look up a class definition inside a single manifest.\n *\n * Tries qualified-key, simple-name, and lowercase-name lookups, then falls\n * back to iterating every entry in the manifest comparing lowered names.\n * This is the low-level primitive used by every sync discovery path.\n */\nexport function lookupCachedManifestEntry(\n manifest: SmartObjectManifest | null | undefined,\n className: string,\n): SmartObjectDefinition | undefined {\n if (!manifest?.objects) {\n return undefined;\n }\n\n const requestedQualifiedName = isQualifiedName(className)\n ? className\n : undefined;\n const requestedClassName = requestedQualifiedName\n ? parseQualifiedName(requestedQualifiedName).className\n : className;\n const lowerClassName = requestedClassName.toLowerCase();\n const packageName = manifest.packageName;\n const qualifiedKey =\n requestedQualifiedName ||\n (packageName\n ? createQualifiedName(packageName, requestedClassName)\n : undefined);\n\n // A qualified request names one package's class. Another package's\n // manifest can only answer it by an exact qualified key (aggregated\n // manifests); a simple-name hit there is a different class (#3098).\n const requestedPackage = requestedQualifiedName\n ? parseQualifiedName(requestedQualifiedName).packageName\n : undefined;\n if (\n requestedQualifiedName &&\n packageName !== undefined &&\n packageName !== requestedPackage\n ) {\n const direct = manifest.objects[requestedQualifiedName];\n return direct &&\n (direct.packageName === undefined ||\n direct.packageName === requestedPackage)\n ? direct\n : undefined;\n }\n\n return (\n (qualifiedKey ? manifest.objects[qualifiedKey] : undefined) ||\n manifest.objects[requestedClassName] ||\n manifest.objects[lowerClassName] ||\n Object.values(manifest.objects).find((entry) => {\n if (!entry) {\n return false;\n }\n\n if (entry.className?.toLowerCase() === lowerClassName) {\n return true;\n }\n\n return (\n requestedQualifiedName !== undefined &&\n packageName !== undefined &&\n createQualifiedName(packageName, entry.className || '') ===\n requestedQualifiedName\n );\n })\n );\n}\n\n// ── Filesystem helpers ───────────────────────────────────────────────────\n\nexport function findWorkspaceRootSync(startDir: string): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n let currentDir = startDir;\n\n while (true) {\n if (\n builtins.fs.existsSync(\n builtins.path.join(currentDir, 'pnpm-workspace.yaml'),\n )\n ) {\n return currentDir;\n }\n\n const parentDir = builtins.path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n\n currentDir = parentDir;\n }\n}\n\nexport function resolveInstalledPackageJsonPathSync(\n packageName: string,\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n let currentDir = process.cwd();\n\n while (true) {\n const packageJsonPath = builtins.path.join(\n currentDir,\n 'node_modules',\n packageName,\n 'package.json',\n );\n\n if (builtins.fs.existsSync(packageJsonPath)) {\n return packageJsonPath;\n }\n\n const parentDir = builtins.path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n\n currentDir = parentDir;\n }\n}\n\nexport function resolveWorkspacePackageJsonPathSync(\n packageName: string,\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const workspaceRoot = findWorkspaceRootSync(process.cwd());\n if (!workspaceRoot) {\n return null;\n }\n\n const workspacePackagesDir = builtins.path.join(workspaceRoot, 'packages');\n if (!builtins.fs.existsSync(workspacePackagesDir)) {\n return null;\n }\n\n for (const packageDirName of builtins.fs.readdirSync(workspacePackagesDir)) {\n const packageJsonPath = builtins.path.join(\n workspacePackagesDir,\n packageDirName,\n 'package.json',\n );\n if (!builtins.fs.existsSync(packageJsonPath)) {\n continue;\n }\n\n try {\n const packageJson = JSON.parse(\n builtins.fs.readFileSync(packageJsonPath, 'utf-8'),\n ) as { name?: string };\n if (packageJson.name === packageName) {\n return packageJsonPath;\n }\n } catch {\n // Ignore unreadable workspace package metadata and continue scanning.\n }\n }\n\n return null;\n}\n\nexport function resolveWorkspaceSourceManifestPathSync(\n packageDir: string,\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const candidates = [\n builtins.path.join(packageDir, 'src', 'manifest', 'manifest.json'),\n builtins.path.join(packageDir, '.smrt', 'manifest.json'),\n ];\n\n for (const candidate of candidates) {\n if (builtins.fs.existsSync(candidate)) {\n return candidate;\n }\n }\n\n return null;\n}\n\nexport function resolveManifestExportPathSync(\n packageName: string,\n options: ManifestLoadOptions = {},\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const shouldWarn = options.warn ?? true;\n const packageJsonPath =\n resolveInstalledPackageJsonPathSync(packageName) ||\n resolveWorkspacePackageJsonPathSync(packageName);\n\n if (!packageJsonPath) {\n return null;\n }\n\n const packageDir = builtins.path.dirname(packageJsonPath);\n const packageJson = JSON.parse(\n builtins.fs.readFileSync(packageJsonPath, 'utf-8'),\n ) as {\n exports?: Record<\n string,\n string | { default?: string; import?: string; require?: string }\n >;\n };\n const manifestExports = ['./manifest.json', './manifest'];\n\n for (const exportKey of manifestExports) {\n const manifestExport = packageJson.exports?.[exportKey];\n if (!manifestExport) {\n continue;\n }\n\n const manifestRelativePath =\n typeof manifestExport === 'string'\n ? manifestExport\n : manifestExport.import ||\n manifestExport.default ||\n manifestExport.require;\n\n if (!manifestRelativePath) {\n recordRegistryDiagnostic(\n 'error',\n 'MANIFEST_EXPORT_INVALID',\n `Package ${packageName} has invalid manifest export configuration for ${exportKey}`,\n { packageName, exportKey },\n );\n if (shouldWarn) {\n logger.warn(\n `Package ${packageName} has invalid manifest export configuration for ${exportKey}`,\n );\n }\n return null;\n }\n\n if (!manifestRelativePath.endsWith('.json')) {\n recordRegistryDiagnostic(\n 'error',\n 'MANIFEST_EXPORT_NOT_JSON',\n `Package ${packageName} must export a JSON manifest for ${exportKey}, received ${manifestRelativePath}`,\n { packageName, exportKey, manifestRelativePath },\n );\n if (shouldWarn) {\n logger.warn(\n `Package ${packageName} must export a JSON manifest for ${exportKey}, received ${manifestRelativePath}`,\n );\n }\n return null;\n }\n\n const manifestPath = builtins.path.join(packageDir, manifestRelativePath);\n if (builtins.fs.existsSync(manifestPath)) {\n return manifestPath;\n }\n\n const workspaceSourceManifest =\n resolveWorkspaceSourceManifestPathSync(packageDir);\n if (workspaceSourceManifest) {\n return workspaceSourceManifest;\n }\n\n recordRegistryDiagnostic(\n 'error',\n 'MANIFEST_EXPORT_NOT_FOUND',\n `Package ${packageName} declares manifest export ${manifestRelativePath}, but no manifest file was found.`,\n { packageName, exportKey, manifestRelativePath },\n );\n if (shouldWarn) {\n logger.warn(\n `Package ${packageName} declares manifest export ${manifestRelativePath}, but no manifest file was found.`,\n );\n }\n return null;\n }\n\n return null;\n}\n\n// ── Manifest reading (seeds caches) ──────────────────────────────────────\n\n/**\n * Load smrt-core's own bundled manifest from disk, caching in\n * `__smrtManifestStatic`. Resolves against this module's own `import.meta.url`\n * so paths work whether the code is running from `dist/` or `src/`.\n */\nexport function loadStaticManifestSyncWithNode(): SmartObjectManifest | null {\n const globals = getManifestGlobals();\n\n if (globals.__smrtManifestStatic !== undefined) {\n return globals.__smrtManifestStatic ?? null;\n }\n\n const builtins = getNodeBuiltins();\n globals.__smrtManifestStaticLoadAttempted = true;\n if (!builtins) {\n const fallbackManifest = createEmptyStaticManifest();\n globals.__smrtManifestStatic = fallbackManifest;\n bumpRegistryGeneration();\n return fallbackManifest;\n }\n\n // store.ts lives at src/manifest/store.ts (source) → dist/manifest/store.js\n // (compiled). In src, the static manifest is a sibling JSON; in dist, it is\n // the package's dist/manifest.json one level up.\n const candidates = import.meta.url.endsWith('.ts')\n ? [\n new URL('./static-manifest.json', import.meta.url),\n new URL('../../dist/manifest.json', import.meta.url),\n ]\n : [new URL('../manifest.json', import.meta.url)];\n\n for (const candidate of candidates) {\n try {\n if (!builtins.fs.existsSync(candidate)) {\n continue;\n }\n\n const manifest = JSON.parse(\n builtins.fs.readFileSync(candidate, 'utf-8'),\n ) as SmartObjectManifest;\n\n if (!manifest.objects || typeof manifest.objects !== 'object') {\n continue;\n }\n\n const cachedManifest = manifest.packageName\n ? manifest\n : { ...manifest, packageName: '@happyvertical/smrt-core' };\n globals.__smrtManifestStatic = cachedManifest;\n bumpRegistryGeneration();\n return cachedManifest;\n } catch {\n // Try the next candidate and fall back to the empty manifest if needed.\n }\n }\n\n const fallbackManifest = createEmptyStaticManifest();\n globals.__smrtManifestStatic = fallbackManifest;\n bumpRegistryGeneration();\n return fallbackManifest;\n}\n\n/**\n * Load a package's published manifest by package name, caching in\n * `__smrtManifestCache` under the package key. Returns null on miss or\n * invalid shape; records a diagnostic instead of throwing.\n */\nexport function loadExternalManifestSyncWithNode(\n packageName: string,\n options: ManifestLoadOptions = {},\n): SmartObjectManifest | null {\n const cache = getManifestCache();\n\n if (cache.has(packageName)) {\n return cache.get(packageName) || null;\n }\n\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const manifestPath = resolveManifestExportPathSync(packageName, options);\n if (!manifestPath) {\n return null;\n }\n\n try {\n const manifest = JSON.parse(\n builtins.fs.readFileSync(manifestPath, 'utf-8'),\n ) as SmartObjectManifest;\n\n if (!manifest.objects || typeof manifest.objects !== 'object') {\n if (options.warn ?? true) {\n logger.warn(`Invalid manifest structure for package ${packageName}`);\n }\n return null;\n }\n\n const cachedManifest = manifest.packageName\n ? manifest\n : { ...manifest, packageName };\n\n cache.set(packageName, cachedManifest);\n\n return cachedManifest;\n } catch (error) {\n if (options.warn ?? true) {\n logger.warn(\n `Failed to load manifest for package ${packageName}: ${error instanceof Error ? error.message : error}`,\n );\n }\n return null;\n }\n}\n\n/**\n * Load a manifest from an explicit filesystem path, caching in\n * `__smrtManifestCache` under the manifest's packageName (or the path as a\n * fallback key). Used by `loadAllManifests({ manifestPaths })` in registry.ts\n * and by the Release B `ExplicitPathsManifestSource`.\n */\nexport function loadManifestFromPathSyncWithNode(\n manifestPath: string,\n): SmartObjectManifest | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n try {\n const manifest = JSON.parse(\n builtins.fs.readFileSync(manifestPath, 'utf-8'),\n ) as SmartObjectManifest;\n\n if (!manifest.objects || typeof manifest.objects !== 'object') {\n logger.warn(`Invalid manifest structure at ${manifestPath}`);\n return null;\n }\n\n getManifestCache().set(manifest.packageName || manifestPath, manifest);\n\n return manifest;\n } catch (error) {\n logger.warn(\n `Failed to load manifest from path ${manifestPath}: ${error instanceof Error ? error.message : error}`,\n );\n return null;\n }\n}\n\n/**\n * Synchronous lookup across every cached manifest source, in priority order.\n *\n * Matches the historical order from manifest-loader.ts and registry.ts:\n * local test → core test → static (smrt-core bundled) → external cache.\n * The Release B `CompositeManifestSource` wraps the same priority behind a\n * higher-level abstraction.\n */\nexport function discoverCachedManifestSync(\n className: string,\n): SmartObjectDefinition | undefined {\n const manifests: Array<SmartObjectManifest | null | undefined> = [\n getLocalTestManifestCache(),\n getTestManifestCache(),\n loadStaticManifestSyncWithNode(),\n ...getManifestCache().values(),\n ];\n\n for (const manifest of manifests) {\n const entry = lookupCachedManifestEntry(manifest, className);\n if (entry) {\n return entry;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAM,SAAS,aAAa,EAAE,OAAO,OAAO,CAAC;;;;;AAY7C,SAAgB,oBAA6B;CAC3C,OAAA,QAAA,IAAA,aAC2B,UACzB,QAAQ,IAAI,WAAW,UACvB,QAAQ,IAAI,mBAAmB,KAAA;AAEnC;;;;;;;;;AAUA,SAAgB,wBAAuC;CACrD,MAAM,sBAAsB,QAAQ,IAAI;CACxC,IAAI,qBACF,OAAO;CAGT,MAAM,WAAW,gBAAgB;CACjC,IAAI,CAAC,UACH,OAAO;CAGT,IAAI,aAAa,QAAQ,IAAI;CAE7B,OAAO,MAAM;EACX,MAAM,kBAAkB,SAAS,KAAK,KAAK,YAAY,cAAc;EACrE,IAAI,SAAS,GAAG,WAAW,eAAe,GACxC,IAAI;GAIF,OAHoB,KAAK,MACvB,SAAS,GAAG,aAAa,iBAAiB,OAAO,CAE5C,CAAA,CAAY,QAAQ;EAC7B,QAAQ;GACN,OAAO;EACT;EAGF,MAAM,YAAY,SAAS,KAAK,QAAQ,UAAU;EAClD,IAAI,cAAc,YAChB,OAAO;EAGT,aAAa;CACf;AACF;;;;;;AAOA,SAAgB,6BAAsC;CACpD,IAAI,CAAC,kBAAkB,GACrB,OAAO;CAGT,MAAM,qBAAqB,sBAAsB;CACjD,IAAI,oBACF,OAAO,uBAAuB;CAGhC,MAAM,WAAW,gBAAgB;CACjC,IAAI,CAAC,UACH,OAAO;CAMT,MAAM,gBAAgB,sBAHJ,SAAS,KAAK,QAC9B,SAAS,IAAI,cAAc,OAAO,KAAK,GAAG,CAEA,CAAS;CACrD,IAAI,CAAC,eACH,OAAO;CAGT,MAAM,iBAAiB,SAAS,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U,SAAS;EAC3D,IAAI,OACF,OAAO;CAEX;AAGF"}
|
|
1
|
+
{"version":3,"file":"store.js","names":[],"sources":["../../src/manifest/store.ts"],"sourcesContent":["/**\n * Leaf manifest storage + pure fs/URL helpers.\n *\n * This module has **no dependency on ObjectRegistry, registry.ts, or\n * class-registration.ts**. It owns the globalThis manifest caches and the\n * filesystem helpers that resolve and read manifest.json files from the\n * workspace, installed node_modules, and smrt-core's own bundle.\n *\n * Breaking the cycle: Before this module existed, `registry.ts` and\n * `manifest-loader.ts` both maintained their own copies of these helpers\n * (`registry.ts` had its own because `registerPackageManifest` needed them\n * and could not import `manifest-loader.ts` due to a module cycle —\n * `registry.ts → class-registration.ts → manifest-loader.ts → registry.ts`).\n * Centralizing them here lets both files import from a leaf, so the cycle\n * goes away and Release B's `ManifestSource` abstraction can live above\n * this leaf without re-creating it.\n *\n * @see https://github.com/happyvertical/smrt/issues/1133\n */\n\nimport { createLogger } from '@happyvertical/logger';\nimport { recordRegistryDiagnostic } from '../registry/diagnostics.js';\nimport {\n bumpRegistryGeneration,\n createGenerationTrackedMap,\n isGenerationTrackedMap,\n} from '../registry/generation.js';\nimport type {\n SmartObjectDefinition,\n SmartObjectManifest,\n} from '../scanner/types.js';\nimport { MANIFEST_TIMESTAMP } from '../scanner/types.js';\nimport type { ColumnDefinition } from '../schema/types.js';\nimport {\n createQualifiedName,\n isQualifiedName,\n parseQualifiedName,\n} from '../utils/qualified-names.js';\n\nconst logger = createLogger({ level: 'info' });\n\nexport type ManifestLoadOptions = {\n warn?: boolean;\n};\n\n// ── Runtime environment detection ────────────────────────────────────────\n\n/**\n * Detect whether we're running inside a test runner. Test manifests must\n * never load in production to avoid test classes colliding with real ones.\n */\nexport function isTestEnvironment(): boolean {\n return (\n process.env.NODE_ENV === 'test' ||\n process.env.VITEST === 'true' ||\n process.env.JEST_WORKER_ID !== undefined\n );\n}\n\n/**\n * Best-effort detection of the current package under test.\n *\n * In workspace consumers, `process.cwd()` points at the consuming app/package,\n * while in smrt-core's own tests it points at `packages/core`. We use that\n * distinction to keep smrt-core's internal test manifest scoped to its own\n * test suite instead of leaking those fixtures into every consumer test run.\n */\nexport function getCurrentPackageName(): string | null {\n const explicitPackageName = process.env.npm_package_name;\n if (explicitPackageName) {\n return explicitPackageName;\n }\n\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n let currentDir = process.cwd();\n\n while (true) {\n const packageJsonPath = builtins.path.join(currentDir, 'package.json');\n if (builtins.fs.existsSync(packageJsonPath)) {\n try {\n const packageJson = JSON.parse(\n builtins.fs.readFileSync(packageJsonPath, 'utf-8'),\n ) as { name?: string };\n return packageJson.name ?? null;\n } catch {\n return null;\n }\n }\n\n const parentDir = builtins.path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n\n currentDir = parentDir;\n }\n}\n\n/**\n * smrt-core's committed test manifest is for smrt-core's own tests only.\n * Consumer packages should expose only their local test manifest plus real\n * published manifests from dependencies.\n */\nexport function shouldLoadCoreTestManifest(): boolean {\n if (!isTestEnvironment()) {\n return false;\n }\n\n const currentPackageName = getCurrentPackageName();\n if (currentPackageName) {\n return currentPackageName === '@happyvertical/smrt-core';\n }\n\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return false;\n }\n\n const moduleDir = builtins.path.dirname(\n builtins.url.fileURLToPath(import.meta.url),\n );\n const workspaceRoot = findWorkspaceRootSync(moduleDir);\n if (!workspaceRoot) {\n return false;\n }\n\n const corePackageDir = builtins.path.join(workspaceRoot, 'packages', 'core');\n const relative = builtins.path.relative(corePackageDir, process.cwd());\n return (\n relative === '' ||\n (!relative.startsWith('..') && !builtins.path.isAbsolute(relative))\n );\n}\n\n// ── Node builtins access ─────────────────────────────────────────────────\n\n/**\n * Resolve Node's built-in `fs`/`path`/`url`/`module` modules without a static import.\n *\n * `process.getBuiltinModule()` is a Node 22+ API that returns the live\n * built-in without going through the module loader. This avoids Vite's\n * static-import analysis flagging these builtins and simulated\n * \"externalized for browser\" warnings in bundled browser builds.\n */\nexport function getNodeBuiltins() {\n // A browser bundle has no `process` global at all; reading a property of it\n // would throw rather than report \"no Node host\" (#2838).\n if (typeof process === 'undefined') {\n return null;\n }\n const getBuiltinModule = (\n process as typeof process & {\n getBuiltinModule?: (id: string) => unknown;\n }\n ).getBuiltinModule;\n if (typeof getBuiltinModule !== 'function') {\n return null;\n }\n\n const fs = getBuiltinModule('node:fs') as\n | typeof import('node:fs')\n | undefined;\n const path = getBuiltinModule('node:path') as\n | typeof import('node:path')\n | undefined;\n const url = getBuiltinModule('node:url') as\n | typeof import('node:url')\n | undefined;\n const module = getBuiltinModule('node:module') as\n | typeof import('node:module')\n | undefined;\n\n if (!fs || !path || !url || !module) {\n return null;\n }\n\n return { fs, path, url, module };\n}\n\n// ── globalThis cache accessors ───────────────────────────────────────────\n\ntype ManifestGlobals = typeof globalThis & {\n __smrtManifestStatic?: SmartObjectManifest | null;\n __smrtManifestStaticLoadAttempted?: boolean;\n __smrtManifestTest?: SmartObjectManifest | null;\n __smrtManifestLocalTest?: SmartObjectManifest | null;\n __smrtManifestCache?: Map<string, SmartObjectManifest>;\n};\n\nfunction getManifestGlobals(): ManifestGlobals {\n return globalThis as ManifestGlobals;\n}\n\n/**\n * Return the mutable external-manifest cache, creating it if absent.\n *\n * Writers: `registerPackageManifest()` (Release A, each package's shim),\n * `loadExternalManifestSyncWithNode()`, `loadManifestFromPathSyncWithNode()`.\n * Readers: all discovery paths.\n */\n/**\n * Whether the package's stored manifest declares that its library build\n * stamps each decorated class with its package (`stampsConstructors`,\n * #3490). Read from the manifest record itself, so every path that stores a\n * manifest carries the capability and every path that clears or replaces it\n * drops it.\n */\nexport function packageStampsConstructors(packageName: string): boolean {\n return getManifestCache().get(packageName)?.stampsConstructors === true;\n}\n\nexport function getManifestCache(): Map<string, SmartObjectManifest> {\n const globals = getManifestGlobals();\n const current = globals.__smrtManifestCache;\n if (current && isGenerationTrackedMap(current)) {\n return current;\n }\n // A newly cached manifest can change what manifest discovery returns, so\n // it invalidates the generation-keyed registry memos (#3047).\n const tracked = createGenerationTrackedMap<string, SmartObjectManifest>(\n current,\n );\n globals.__smrtManifestCache = tracked;\n return tracked;\n}\n\n/** Read-only snapshot of the static manifest, if cached. */\nexport function getStaticManifestCache(): SmartObjectManifest | null {\n return getManifestGlobals().__smrtManifestStatic ?? null;\n}\n\n/** Read-only snapshot of the core test manifest, if cached. */\nexport function getTestManifestCache(): SmartObjectManifest | null {\n return getManifestGlobals().__smrtManifestTest ?? null;\n}\n\n/**\n * Read-only snapshot of the local (domain package) test manifest.\n *\n * Preserves the three-state semantics that `discoverManifestEntry()` relies\n * on: `undefined` means \"never attempted to load\" and triggers the lazy\n * loader; `null` means \"attempted but no local test manifest in this\n * package\"; a manifest object means \"loaded\". Do not collapse `undefined`\n * to `null` here — the async-discovery lazy-load path keys off the\n * distinction (see manifest-loader.ts:`if (getLocalTestManifestCache() === undefined) loadLocalTestManifestSync()`).\n */\nexport function getLocalTestManifestCache():\n | SmartObjectManifest\n | null\n | undefined {\n return getManifestGlobals().__smrtManifestLocalTest;\n}\n\n// ── Manifest shape helpers ───────────────────────────────────────────────\n\nexport function createEmptyStaticManifest(): SmartObjectManifest {\n return {\n version: '1.0.0',\n timestamp: MANIFEST_TIMESTAMP,\n objects: {},\n packageName: '@happyvertical/smrt-core',\n };\n}\n\n/**\n * Deep-clone a manifest's schema column map so downstream mutators don't\n * corrupt the cached manifest. Foreign-key descriptors get their own copy\n * because manifest-loader.ts and registerFromManifest() both splice them\n * into live schema entries.\n */\nexport function cloneManifestSchemaColumns(\n columns: Record<string, unknown> | undefined,\n): Record<string, ColumnDefinition> {\n return Object.fromEntries(\n Object.entries(columns || {}).map(([columnName, column]) => {\n const clonedColumn = {\n ...(column as ColumnDefinition & Record<string, unknown>),\n } as ColumnDefinition;\n const manifestDefault = (\n clonedColumn as ColumnDefinition & {\n default?: unknown;\n }\n ).default;\n\n if (\n clonedColumn.defaultValue === undefined &&\n manifestDefault !== undefined\n ) {\n clonedColumn.defaultValue = manifestDefault;\n }\n\n if (clonedColumn.foreignKey) {\n clonedColumn.foreignKey = { ...clonedColumn.foreignKey };\n }\n\n return [columnName, clonedColumn];\n }),\n ) as Record<string, ColumnDefinition>;\n}\n\n/**\n * Look up a class definition inside a single manifest.\n *\n * Tries qualified-key, simple-name, and lowercase-name lookups, then falls\n * back to iterating every entry in the manifest comparing lowered names.\n * This is the low-level primitive used by every sync discovery path.\n */\nexport function lookupCachedManifestEntry(\n manifest: SmartObjectManifest | null | undefined,\n className: string,\n): SmartObjectDefinition | undefined {\n if (!manifest?.objects) {\n return undefined;\n }\n\n const requestedQualifiedName = isQualifiedName(className)\n ? className\n : undefined;\n const requestedClassName = requestedQualifiedName\n ? parseQualifiedName(requestedQualifiedName).className\n : className;\n const lowerClassName = requestedClassName.toLowerCase();\n const packageName = manifest.packageName;\n const qualifiedKey =\n requestedQualifiedName ||\n (packageName\n ? createQualifiedName(packageName, requestedClassName)\n : undefined);\n\n // A qualified request names one package's class. Another package's\n // manifest can only answer it by an exact qualified key (aggregated\n // manifests); a simple-name hit there is a different class (#3098).\n const requestedPackage = requestedQualifiedName\n ? parseQualifiedName(requestedQualifiedName).packageName\n : undefined;\n if (\n requestedQualifiedName &&\n packageName !== undefined &&\n packageName !== requestedPackage\n ) {\n const direct = manifest.objects[requestedQualifiedName];\n return direct &&\n (direct.packageName === undefined ||\n direct.packageName === requestedPackage)\n ? direct\n : undefined;\n }\n\n return (\n (qualifiedKey ? manifest.objects[qualifiedKey] : undefined) ||\n manifest.objects[requestedClassName] ||\n manifest.objects[lowerClassName] ||\n Object.values(manifest.objects).find((entry) => {\n if (!entry) {\n return false;\n }\n\n if (entry.className?.toLowerCase() === lowerClassName) {\n return true;\n }\n\n return (\n requestedQualifiedName !== undefined &&\n packageName !== undefined &&\n createQualifiedName(packageName, entry.className || '') ===\n requestedQualifiedName\n );\n })\n );\n}\n\n// ── Filesystem helpers ───────────────────────────────────────────────────\n\nexport function findWorkspaceRootSync(startDir: string): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n let currentDir = startDir;\n\n while (true) {\n if (\n builtins.fs.existsSync(\n builtins.path.join(currentDir, 'pnpm-workspace.yaml'),\n )\n ) {\n return currentDir;\n }\n\n const parentDir = builtins.path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n\n currentDir = parentDir;\n }\n}\n\nexport function resolveInstalledPackageJsonPathSync(\n packageName: string,\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n let currentDir = process.cwd();\n\n while (true) {\n const packageJsonPath = builtins.path.join(\n currentDir,\n 'node_modules',\n packageName,\n 'package.json',\n );\n\n if (builtins.fs.existsSync(packageJsonPath)) {\n return packageJsonPath;\n }\n\n const parentDir = builtins.path.dirname(currentDir);\n if (parentDir === currentDir) {\n return null;\n }\n\n currentDir = parentDir;\n }\n}\n\nexport function resolveWorkspacePackageJsonPathSync(\n packageName: string,\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const workspaceRoot = findWorkspaceRootSync(process.cwd());\n if (!workspaceRoot) {\n return null;\n }\n\n const workspacePackagesDir = builtins.path.join(workspaceRoot, 'packages');\n if (!builtins.fs.existsSync(workspacePackagesDir)) {\n return null;\n }\n\n for (const packageDirName of builtins.fs.readdirSync(workspacePackagesDir)) {\n const packageJsonPath = builtins.path.join(\n workspacePackagesDir,\n packageDirName,\n 'package.json',\n );\n if (!builtins.fs.existsSync(packageJsonPath)) {\n continue;\n }\n\n try {\n const packageJson = JSON.parse(\n builtins.fs.readFileSync(packageJsonPath, 'utf-8'),\n ) as { name?: string };\n if (packageJson.name === packageName) {\n return packageJsonPath;\n }\n } catch {\n // Ignore unreadable workspace package metadata and continue scanning.\n }\n }\n\n return null;\n}\n\nexport function resolveWorkspaceSourceManifestPathSync(\n packageDir: string,\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const candidates = [\n builtins.path.join(packageDir, 'src', 'manifest', 'manifest.json'),\n builtins.path.join(packageDir, '.smrt', 'manifest.json'),\n ];\n\n for (const candidate of candidates) {\n if (builtins.fs.existsSync(candidate)) {\n return candidate;\n }\n }\n\n return null;\n}\n\nexport function resolveManifestExportPathSync(\n packageName: string,\n options: ManifestLoadOptions = {},\n): string | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const shouldWarn = options.warn ?? true;\n const packageJsonPath =\n resolveInstalledPackageJsonPathSync(packageName) ||\n resolveWorkspacePackageJsonPathSync(packageName);\n\n if (!packageJsonPath) {\n return null;\n }\n\n const packageDir = builtins.path.dirname(packageJsonPath);\n const packageJson = JSON.parse(\n builtins.fs.readFileSync(packageJsonPath, 'utf-8'),\n ) as {\n exports?: Record<\n string,\n string | { default?: string; import?: string; require?: string }\n >;\n };\n const manifestExports = ['./manifest.json', './manifest'];\n\n for (const exportKey of manifestExports) {\n const manifestExport = packageJson.exports?.[exportKey];\n if (!manifestExport) {\n continue;\n }\n\n const manifestRelativePath =\n typeof manifestExport === 'string'\n ? manifestExport\n : manifestExport.import ||\n manifestExport.default ||\n manifestExport.require;\n\n if (!manifestRelativePath) {\n recordRegistryDiagnostic(\n 'error',\n 'MANIFEST_EXPORT_INVALID',\n `Package ${packageName} has invalid manifest export configuration for ${exportKey}`,\n { packageName, exportKey },\n );\n if (shouldWarn) {\n logger.warn(\n `Package ${packageName} has invalid manifest export configuration for ${exportKey}`,\n );\n }\n return null;\n }\n\n if (!manifestRelativePath.endsWith('.json')) {\n recordRegistryDiagnostic(\n 'error',\n 'MANIFEST_EXPORT_NOT_JSON',\n `Package ${packageName} must export a JSON manifest for ${exportKey}, received ${manifestRelativePath}`,\n { packageName, exportKey, manifestRelativePath },\n );\n if (shouldWarn) {\n logger.warn(\n `Package ${packageName} must export a JSON manifest for ${exportKey}, received ${manifestRelativePath}`,\n );\n }\n return null;\n }\n\n const manifestPath = builtins.path.join(packageDir, manifestRelativePath);\n if (builtins.fs.existsSync(manifestPath)) {\n return manifestPath;\n }\n\n const workspaceSourceManifest =\n resolveWorkspaceSourceManifestPathSync(packageDir);\n if (workspaceSourceManifest) {\n return workspaceSourceManifest;\n }\n\n recordRegistryDiagnostic(\n 'error',\n 'MANIFEST_EXPORT_NOT_FOUND',\n `Package ${packageName} declares manifest export ${manifestRelativePath}, but no manifest file was found.`,\n { packageName, exportKey, manifestRelativePath },\n );\n if (shouldWarn) {\n logger.warn(\n `Package ${packageName} declares manifest export ${manifestRelativePath}, but no manifest file was found.`,\n );\n }\n return null;\n }\n\n return null;\n}\n\n// ── Manifest reading (seeds caches) ──────────────────────────────────────\n\n/**\n * Load smrt-core's own bundled manifest from disk, caching in\n * `__smrtManifestStatic`. Resolves against this module's own `import.meta.url`\n * so paths work whether the code is running from `dist/` or `src/`.\n */\nexport function loadStaticManifestSyncWithNode(): SmartObjectManifest | null {\n const globals = getManifestGlobals();\n\n if (globals.__smrtManifestStatic !== undefined) {\n return globals.__smrtManifestStatic ?? null;\n }\n\n const builtins = getNodeBuiltins();\n globals.__smrtManifestStaticLoadAttempted = true;\n if (!builtins) {\n const fallbackManifest = createEmptyStaticManifest();\n globals.__smrtManifestStatic = fallbackManifest;\n bumpRegistryGeneration();\n return fallbackManifest;\n }\n\n // store.ts lives at src/manifest/store.ts (source) → dist/manifest/store.js\n // (compiled). In src, the static manifest is a sibling JSON; in dist, it is\n // the package's dist/manifest.json one level up.\n const candidates = import.meta.url.endsWith('.ts')\n ? [\n new URL('./static-manifest.json', import.meta.url),\n new URL('../../dist/manifest.json', import.meta.url),\n ]\n : [new URL('../manifest.json', import.meta.url)];\n\n for (const candidate of candidates) {\n try {\n if (!builtins.fs.existsSync(candidate)) {\n continue;\n }\n\n const manifest = JSON.parse(\n builtins.fs.readFileSync(candidate, 'utf-8'),\n ) as SmartObjectManifest;\n\n if (!manifest.objects || typeof manifest.objects !== 'object') {\n continue;\n }\n\n const cachedManifest = manifest.packageName\n ? manifest\n : { ...manifest, packageName: '@happyvertical/smrt-core' };\n globals.__smrtManifestStatic = cachedManifest;\n bumpRegistryGeneration();\n return cachedManifest;\n } catch {\n // Try the next candidate and fall back to the empty manifest if needed.\n }\n }\n\n const fallbackManifest = createEmptyStaticManifest();\n globals.__smrtManifestStatic = fallbackManifest;\n bumpRegistryGeneration();\n return fallbackManifest;\n}\n\n/**\n * Load a package's published manifest by package name, caching in\n * `__smrtManifestCache` under the package key. Returns null on miss or\n * invalid shape; records a diagnostic instead of throwing.\n */\nexport function loadExternalManifestSyncWithNode(\n packageName: string,\n options: ManifestLoadOptions = {},\n): SmartObjectManifest | null {\n const cache = getManifestCache();\n\n if (cache.has(packageName)) {\n return cache.get(packageName) || null;\n }\n\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n const manifestPath = resolveManifestExportPathSync(packageName, options);\n if (!manifestPath) {\n return null;\n }\n\n try {\n const manifest = JSON.parse(\n builtins.fs.readFileSync(manifestPath, 'utf-8'),\n ) as SmartObjectManifest;\n\n if (!manifest.objects || typeof manifest.objects !== 'object') {\n if (options.warn ?? true) {\n logger.warn(`Invalid manifest structure for package ${packageName}`);\n }\n return null;\n }\n\n const cachedManifest = manifest.packageName\n ? manifest\n : { ...manifest, packageName };\n\n cache.set(packageName, cachedManifest);\n\n return cachedManifest;\n } catch (error) {\n if (options.warn ?? true) {\n logger.warn(\n `Failed to load manifest for package ${packageName}: ${error instanceof Error ? error.message : error}`,\n );\n }\n return null;\n }\n}\n\n/**\n * Load a manifest from an explicit filesystem path, caching in\n * `__smrtManifestCache` under the manifest's packageName (or the path as a\n * fallback key). Used by `loadAllManifests({ manifestPaths })` in registry.ts\n * and by the Release B `ExplicitPathsManifestSource`.\n */\nexport function loadManifestFromPathSyncWithNode(\n manifestPath: string,\n): SmartObjectManifest | null {\n const builtins = getNodeBuiltins();\n if (!builtins) {\n return null;\n }\n\n try {\n const manifest = JSON.parse(\n builtins.fs.readFileSync(manifestPath, 'utf-8'),\n ) as SmartObjectManifest;\n\n if (!manifest.objects || typeof manifest.objects !== 'object') {\n logger.warn(`Invalid manifest structure at ${manifestPath}`);\n return null;\n }\n\n getManifestCache().set(manifest.packageName || manifestPath, manifest);\n\n return manifest;\n } catch (error) {\n logger.warn(\n `Failed to load manifest from path ${manifestPath}: ${error instanceof Error ? error.message : error}`,\n );\n return null;\n }\n}\n\n/**\n * Synchronous lookup across every cached manifest source, in priority order.\n *\n * Matches the historical order from manifest-loader.ts and registry.ts:\n * local test → core test → static (smrt-core bundled) → external cache.\n * The Release B `CompositeManifestSource` wraps the same priority behind a\n * higher-level abstraction.\n */\nexport function discoverCachedManifestSync(\n className: string,\n): SmartObjectDefinition | undefined {\n const manifests: Array<SmartObjectManifest | null | undefined> = [\n getLocalTestManifestCache(),\n getTestManifestCache(),\n loadStaticManifestSyncWithNode(),\n ...getManifestCache().values(),\n ];\n\n for (const manifest of manifests) {\n const entry = lookupCachedManifestEntry(manifest, className);\n if (entry) {\n return entry;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAM,SAAS,aAAa,EAAE,OAAO,OAAO,CAAC;;;;;AAY7C,SAAgB,oBAA6B;CAC3C,OAAA,QAAA,IAAA,aAC2B,UACzB,QAAQ,IAAI,WAAW,UACvB,QAAQ,IAAI,mBAAmB,KAAA;AAEnC;;;;;;;;;AAUA,SAAgB,wBAAuC;CACrD,MAAM,sBAAsB,QAAQ,IAAI;CACxC,IAAI,qBACF,OAAO;CAGT,MAAM,WAAW,gBAAgB;CACjC,IAAI,CAAC,UACH,OAAO;CAGT,IAAI,aAAa,QAAQ,IAAI;CAE7B,OAAO,MAAM;EACX,MAAM,kBAAkB,SAAS,KAAK,KAAK,YAAY,cAAc;EACrE,IAAI,SAAS,GAAG,WAAW,eAAe,GACxC,IAAI;GAIF,OAHoB,KAAK,MACvB,SAAS,GAAG,aAAa,iBAAiB,OAAO,CAE5C,CAAA,CAAY,QAAQ;EAC7B,QAAQ;GACN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ACpB,SAAS,GAAG,aAAa,cAAc,OAAO,CAChD;EAEA,IAAI,CAAC,SAAS,WAAW,OAAO,SAAS,YAAY,UAAU;GAC7D,OAAO,KAAK,iCAAiC,cAAc;GAC3D,OAAO;EACT;EAEA,iBAAiB,CAAC,CAAC,IAAI,SAAS,eAAe,cAAc,QAAQ;EAErE,OAAO;CACT,SAAS,OAAO;EACd,OAAO,KACL,qCAAqC,aAAa,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OACjG;EACA,OAAO;CACT;AACF;;;;;;;;;AAUA,SAAgB,2BACd,WACmC;CACnC,MAAM,YAA2D;EAC/D,0BAA0B;EAC1B,qBAAqB;EACrB,+BAA+B;EAC/B,GAAG,iBAAiB,CAAC,CAAC,OAAO;CAC/B;CAEA,KAAK,MAAM,YAAY,WAAW;EAChC,MAAM,QAAQ,0BAA0B,UAAU,SAAS;EAC3D,IAAI,OACF,OAAO;CAEX;AAGF"}
|
package/dist/manifest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { discoverManifestEntry, findManifestEntryByQualifiedName, loadExternalManifest, loadExternalManifestSync, loadLocalTestManifestSync, loadManifestFromPathSync } from "./manifest/manifest-loader.js";
|
|
1
2
|
import { ManifestGenerator } from "./scanner/manifest-generator.js";
|
|
2
3
|
import { ManifestManager } from "./manifest/manager.js";
|
|
3
|
-
import { discoverManifestEntry, findManifestEntryByQualifiedName, loadExternalManifest, loadExternalManifestSync, loadLocalTestManifestSync, loadManifestFromPathSync } from "./manifest/manifest-loader.js";
|
|
4
4
|
import { ManifestBuilder } from "./manifest/generator.js";
|
|
5
5
|
import manifest, { getManifest, staticManifest } from "./manifest/index.js";
|
|
6
6
|
export { ManifestBuilder, ManifestGenerator, ManifestManager, discoverManifestEntry, findManifestEntryByQualifiedName, getManifest, loadExternalManifest, loadExternalManifestSync, loadLocalTestManifestSync, loadManifestFromPathSync, manifest, staticManifest };
|
package/dist/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": "1.0.0",
|
|
3
3
|
"timestamp": 0,
|
|
4
4
|
"packageName": "@happyvertical/smrt-core",
|
|
5
|
-
"packageVersion": "0.55.
|
|
5
|
+
"packageVersion": "0.55.9",
|
|
6
6
|
"objects": {
|
|
7
7
|
"@happyvertical/smrt-core:SmrtClass": {
|
|
8
8
|
"name": "smrtclass",
|
|
@@ -1848,5 +1848,12 @@
|
|
|
1848
1848
|
"importPath": "@happyvertical/smrt-core"
|
|
1849
1849
|
}
|
|
1850
1850
|
},
|
|
1851
|
-
"moduleType": "smrt"
|
|
1851
|
+
"moduleType": "smrt",
|
|
1852
|
+
"browser": {
|
|
1853
|
+
"status": "server-only",
|
|
1854
|
+
"issues": [
|
|
1855
|
+
"#3635"
|
|
1856
|
+
],
|
|
1857
|
+
"reason": "model roots import server-only helpers (manifest loader, route helpers, startRestServer) the browser entry deliberately omits; core's own graph reaches no Node-only module (#2838, held by the browser-boundary core-entry test)"
|
|
1858
|
+
}
|
|
1852
1859
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positive identification of the NATIVE DuckDB adapter (#3737).
|
|
3
|
+
*
|
|
4
|
+
* The JSON adapter wraps the same `DuckDBConnection` class and the same SQL
|
|
5
|
+
* dialect, but persists a table to `<table>.json` only from its own
|
|
6
|
+
* insert/update/upsert/delete, so a raw write there is lost on the next
|
|
7
|
+
* process. Only a root native handle can be told apart structurally: it
|
|
8
|
+
* exposes `getTableSchema`, which the JSON adapter does not. A transaction
|
|
9
|
+
* handle exposes neither marker (it carries the root's `client` and nothing
|
|
10
|
+
* more), so it is recognized through its client once the root was noted.
|
|
11
|
+
*
|
|
12
|
+
* Roots are noted wherever core sees one before binding to a transaction:
|
|
13
|
+
* `SmrtClass.initialize()`, `withDatabase()` (the handle being swapped out)
|
|
14
|
+
* and `withEmbeddedWriteTransaction()`. A transaction handle whose root core
|
|
15
|
+
* never saw stays unidentified, and its writers keep the adapter `upsert`
|
|
16
|
+
* path; it is never treated as native by guesswork.
|
|
17
|
+
*/
|
|
18
|
+
/** Whether `db` carries a capability only the JSON adapter has. */
|
|
19
|
+
export declare function isJsonAdapterHandle(db: unknown): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Remember `db`'s client when `db` is positively a native DuckDB root: a
|
|
22
|
+
* DuckDB client, no JSON-only capability, and the native structural marker or
|
|
23
|
+
* an explicit `duckdb` engine hint. A `json` hint never registers.
|
|
24
|
+
*/
|
|
25
|
+
export declare function noteNativeDuckDbHandle(db: unknown, engineHint?: string): void;
|
|
26
|
+
/** Whether `db` (a root or any of its transaction handles) is native DuckDB. */
|
|
27
|
+
export declare function isKnownNativeDuckDbHandle(db: unknown, engineHint?: string): boolean;
|
|
28
|
+
//# sourceMappingURL=native-duckdb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-duckdb.d.ts","sourceRoot":"","sources":["../src/native-duckdb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAoBH,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAMxD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAU7E;AAED,gFAAgF;AAChF,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,OAAO,EACX,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAKT"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/native-duckdb.ts
|
|
2
|
+
/**
|
|
3
|
+
* Positive identification of the NATIVE DuckDB adapter (#3737).
|
|
4
|
+
*
|
|
5
|
+
* The JSON adapter wraps the same `DuckDBConnection` class and the same SQL
|
|
6
|
+
* dialect, but persists a table to `<table>.json` only from its own
|
|
7
|
+
* insert/update/upsert/delete, so a raw write there is lost on the next
|
|
8
|
+
* process. Only a root native handle can be told apart structurally: it
|
|
9
|
+
* exposes `getTableSchema`, which the JSON adapter does not. A transaction
|
|
10
|
+
* handle exposes neither marker (it carries the root's `client` and nothing
|
|
11
|
+
* more), so it is recognized through its client once the root was noted.
|
|
12
|
+
*
|
|
13
|
+
* Roots are noted wherever core sees one before binding to a transaction:
|
|
14
|
+
* `SmrtClass.initialize()`, `withDatabase()` (the handle being swapped out)
|
|
15
|
+
* and `withEmbeddedWriteTransaction()`. A transaction handle whose root core
|
|
16
|
+
* never saw stays unidentified, and its writers keep the adapter `upsert`
|
|
17
|
+
* path; it is never treated as native by guesswork.
|
|
18
|
+
*/
|
|
19
|
+
var nativeClients = /* @__PURE__ */ new WeakSet();
|
|
20
|
+
function duckDbClientOf(db) {
|
|
21
|
+
const client = db?.client;
|
|
22
|
+
if (client === null || typeof client !== "object") return void 0;
|
|
23
|
+
return (client.constructor?.name?.toLowerCase())?.includes("duckdb") ? client : void 0;
|
|
24
|
+
}
|
|
25
|
+
/** Whether `db` carries a capability only the JSON adapter has. */
|
|
26
|
+
function isJsonAdapterHandle(db) {
|
|
27
|
+
const handle = db;
|
|
28
|
+
return typeof handle?.inferSchemaFromJSON === "function" || typeof handle?.getTableLoadErrors === "function";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Remember `db`'s client when `db` is positively a native DuckDB root: a
|
|
32
|
+
* DuckDB client, no JSON-only capability, and the native structural marker or
|
|
33
|
+
* an explicit `duckdb` engine hint. A `json` hint never registers.
|
|
34
|
+
*/
|
|
35
|
+
function noteNativeDuckDbHandle(db, engineHint) {
|
|
36
|
+
if (engineHint === "json" || isJsonAdapterHandle(db)) return;
|
|
37
|
+
const client = duckDbClientOf(db);
|
|
38
|
+
if (!client) return;
|
|
39
|
+
if (typeof db.getTableSchema === "function" || engineHint === "duckdb") nativeClients.add(client);
|
|
40
|
+
}
|
|
41
|
+
/** Whether `db` (a root or any of its transaction handles) is native DuckDB. */
|
|
42
|
+
function isKnownNativeDuckDbHandle(db, engineHint) {
|
|
43
|
+
if (engineHint === "json" || isJsonAdapterHandle(db)) return false;
|
|
44
|
+
noteNativeDuckDbHandle(db, engineHint);
|
|
45
|
+
const client = duckDbClientOf(db);
|
|
46
|
+
return client !== void 0 && nativeClients.has(client);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { isJsonAdapterHandle, isKnownNativeDuckDbHandle, noteNativeDuckDbHandle };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=native-duckdb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-duckdb.js","names":[],"sources":["../src/native-duckdb.ts"],"sourcesContent":["/**\n * Positive identification of the NATIVE DuckDB adapter (#3737).\n *\n * The JSON adapter wraps the same `DuckDBConnection` class and the same SQL\n * dialect, but persists a table to `<table>.json` only from its own\n * insert/update/upsert/delete, so a raw write there is lost on the next\n * process. Only a root native handle can be told apart structurally: it\n * exposes `getTableSchema`, which the JSON adapter does not. A transaction\n * handle exposes neither marker (it carries the root's `client` and nothing\n * more), so it is recognized through its client once the root was noted.\n *\n * Roots are noted wherever core sees one before binding to a transaction:\n * `SmrtClass.initialize()`, `withDatabase()` (the handle being swapped out)\n * and `withEmbeddedWriteTransaction()`. A transaction handle whose root core\n * never saw stays unidentified, and its writers keep the adapter `upsert`\n * path; it is never treated as native by guesswork.\n */\n\nconst nativeClients = new WeakSet<object>();\n\ninterface AdapterHandle {\n client?: unknown;\n getTableSchema?: unknown;\n inferSchemaFromJSON?: unknown;\n getTableLoadErrors?: unknown;\n}\n\nfunction duckDbClientOf(db: unknown): object | undefined {\n const client = (db as AdapterHandle | null | undefined)?.client;\n if (client === null || typeof client !== 'object') return undefined;\n const name = (\n client as { constructor?: { name?: string } }\n ).constructor?.name?.toLowerCase();\n return name?.includes('duckdb') ? client : undefined;\n}\n\n/** Whether `db` carries a capability only the JSON adapter has. */\nexport function isJsonAdapterHandle(db: unknown): boolean {\n const handle = db as AdapterHandle | null | undefined;\n return (\n typeof handle?.inferSchemaFromJSON === 'function' ||\n typeof handle?.getTableLoadErrors === 'function'\n );\n}\n\n/**\n * Remember `db`'s client when `db` is positively a native DuckDB root: a\n * DuckDB client, no JSON-only capability, and the native structural marker or\n * an explicit `duckdb` engine hint. A `json` hint never registers.\n */\nexport function noteNativeDuckDbHandle(db: unknown, engineHint?: string): void {\n if (engineHint === 'json' || isJsonAdapterHandle(db)) return;\n const client = duckDbClientOf(db);\n if (!client) return;\n if (\n typeof (db as AdapterHandle).getTableSchema === 'function' ||\n engineHint === 'duckdb'\n ) {\n nativeClients.add(client);\n }\n}\n\n/** Whether `db` (a root or any of its transaction handles) is native DuckDB. */\nexport function isKnownNativeDuckDbHandle(\n db: unknown,\n engineHint?: string,\n): boolean {\n if (engineHint === 'json' || isJsonAdapterHandle(db)) return false;\n noteNativeDuckDbHandle(db, engineHint);\n const client = duckDbClientOf(db);\n return client !== undefined && nativeClients.has(client);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,IAAM,gCAAgB,IAAI,QAAgB;AAS1C,SAAS,eAAe,IAAiC;CACvD,MAAM,SAAU,IAAyC;CACzD,IAAI,WAAW,QAAQ,OAAO,WAAW,UAAU,OAAO,KAAA;CAI1D,QAFE,OACA,aAAa,MAAM,YAAY,EAAA,EACpB,SAAS,QAAQ,IAAI,SAAS,KAAA;AAC7C;;AAGA,SAAgB,oBAAoB,IAAsB;CACxD,MAAM,SAAS;CACf,OACE,OAAO,QAAQ,wBAAwB,cACvC,OAAO,QAAQ,uBAAuB;AAE1C;;;;;;AAOA,SAAgB,uBAAuB,IAAa,YAA2B;CAC7E,IAAI,eAAe,UAAU,oBAAoB,EAAE,GAAG;CACtD,MAAM,SAAS,eAAe,EAAE;CAChC,IAAI,CAAC,QAAQ;CACb,IACE,OAAQ,GAAqB,mBAAmB,cAChD,eAAe,UAEf,cAAc,IAAI,MAAM;AAE5B;;AAGA,SAAgB,0BACd,IACA,YACS;CACT,IAAI,eAAe,UAAU,oBAAoB,EAAE,GAAG,OAAO;CAC7D,uBAAuB,IAAI,UAAU;CACrC,MAAM,SAAS,eAAe,EAAE;CAChC,OAAO,WAAW,KAAA,KAAa,cAAc,IAAI,MAAM;AACzD"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { setU64FromNum } from "./_u64.js";
|
|
2
|
+
import { abytes, aexists, aoutput, createView } from "./utils.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
|
|
4
|
+
/**
|
|
5
|
+
* Internal Merkle-Damgard hash utils.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.
|
|
10
|
+
* Returns bits from `b` when `a` is set, otherwise from `c`.
|
|
11
|
+
* The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never
|
|
12
|
+
* set the same bit.
|
|
13
|
+
* @param a - selector word
|
|
14
|
+
* @param b - word chosen when selector bit is set
|
|
15
|
+
* @param c - word chosen when selector bit is clear
|
|
16
|
+
* @returns Mixed 32-bit word.
|
|
17
|
+
* @example
|
|
18
|
+
* Combine three words with the shared 32-bit choice primitive.
|
|
19
|
+
* ```ts
|
|
20
|
+
* Chi(0xffffffff, 0x12345678, 0x87654321);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function Chi(a, b, c) {
|
|
24
|
+
return a & b ^ ~a & c;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Shared 32-bit majority primitive reused by SHA-256 and SHA-1.
|
|
28
|
+
* Returns bits shared by at least two inputs.
|
|
29
|
+
* @param a - first input word
|
|
30
|
+
* @param b - second input word
|
|
31
|
+
* @param c - third input word
|
|
32
|
+
* @returns Mixed 32-bit word.
|
|
33
|
+
* @example
|
|
34
|
+
* Combine three words with the shared 32-bit majority primitive.
|
|
35
|
+
* ```ts
|
|
36
|
+
* Maj(0xffffffff, 0x12345678, 0x87654321);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function Maj(a, b, c) {
|
|
40
|
+
return a & b ^ a & c ^ b & c;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Merkle-Damgard hash construction base class.
|
|
44
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
45
|
+
* Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit
|
|
46
|
+
* strings with partial-byte tails.
|
|
47
|
+
* @param blockLen - internal block size in bytes
|
|
48
|
+
* @param outputLen - digest size in bytes
|
|
49
|
+
* @param padOffset - trailing length field size in bytes
|
|
50
|
+
* @param isLE - whether length and state words are encoded in little-endian
|
|
51
|
+
* @example
|
|
52
|
+
* Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { _SHA1 } from '@noble/hashes/legacy.js';
|
|
55
|
+
* const hash = new _SHA1();
|
|
56
|
+
* hash.update(new Uint8Array([97, 98, 99]));
|
|
57
|
+
* hash.digest();
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
var HashMD = class {
|
|
61
|
+
blockLen;
|
|
62
|
+
outputLen;
|
|
63
|
+
canXOF = false;
|
|
64
|
+
padOffset;
|
|
65
|
+
isLE;
|
|
66
|
+
buffer;
|
|
67
|
+
view;
|
|
68
|
+
finished = false;
|
|
69
|
+
length = 0;
|
|
70
|
+
pos = 0;
|
|
71
|
+
destroyed = false;
|
|
72
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
73
|
+
this.blockLen = blockLen;
|
|
74
|
+
this.outputLen = outputLen;
|
|
75
|
+
this.padOffset = padOffset;
|
|
76
|
+
this.isLE = isLE;
|
|
77
|
+
this.buffer = new Uint8Array(blockLen);
|
|
78
|
+
this.view = createView(this.buffer);
|
|
79
|
+
}
|
|
80
|
+
update(data) {
|
|
81
|
+
aexists(this);
|
|
82
|
+
abytes(data);
|
|
83
|
+
const { view, buffer, blockLen } = this;
|
|
84
|
+
const len = data.length;
|
|
85
|
+
let processed = false;
|
|
86
|
+
for (let pos = 0; pos < len;) {
|
|
87
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
88
|
+
if (take === blockLen) {
|
|
89
|
+
const dataView = createView(data);
|
|
90
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(dataView, pos);
|
|
91
|
+
processed = true;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
95
|
+
this.pos += take;
|
|
96
|
+
pos += take;
|
|
97
|
+
if (this.pos === blockLen) {
|
|
98
|
+
this.process(view, 0);
|
|
99
|
+
this.pos = 0;
|
|
100
|
+
processed = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.length += data.length;
|
|
104
|
+
if (processed) this.roundClean();
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
digestInto(out) {
|
|
108
|
+
aexists(this);
|
|
109
|
+
aoutput(out, this);
|
|
110
|
+
this.finished = true;
|
|
111
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
112
|
+
let { pos } = this;
|
|
113
|
+
buffer[pos++] = 128;
|
|
114
|
+
buffer.fill(0, pos);
|
|
115
|
+
if (this.padOffset > blockLen - pos) {
|
|
116
|
+
this.process(view, 0);
|
|
117
|
+
buffer.fill(0);
|
|
118
|
+
}
|
|
119
|
+
setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
|
|
120
|
+
this.process(view, 0);
|
|
121
|
+
this.roundClean();
|
|
122
|
+
const oview = out === buffer ? view : createView(out);
|
|
123
|
+
const len = this.outputLen;
|
|
124
|
+
const outLen = len / 4;
|
|
125
|
+
const state = this.get();
|
|
126
|
+
if (len % 4 || outLen > state.length) throw new Error("invalid outputLen");
|
|
127
|
+
for (let i = 0; i < outLen; i++) oview.setUint32(4 * i, state[i], isLE);
|
|
128
|
+
}
|
|
129
|
+
digest() {
|
|
130
|
+
const { buffer, outputLen } = this;
|
|
131
|
+
this.digestInto(buffer);
|
|
132
|
+
const res = buffer.slice(0, outputLen);
|
|
133
|
+
this.destroy();
|
|
134
|
+
return res;
|
|
135
|
+
}
|
|
136
|
+
_cloneIntoMeta(to) {
|
|
137
|
+
const { buffer, length, finished, destroyed, pos } = this;
|
|
138
|
+
to.destroyed = destroyed;
|
|
139
|
+
to.finished = finished;
|
|
140
|
+
to.length = length;
|
|
141
|
+
to.pos = pos;
|
|
142
|
+
if (pos) to.buffer.set(buffer);
|
|
143
|
+
return to;
|
|
144
|
+
}
|
|
145
|
+
clone() {
|
|
146
|
+
return this._cloneInto();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.
|
|
151
|
+
* Check out `test/misc/sha2-gen-iv.js` for recomputation guide.
|
|
152
|
+
*/
|
|
153
|
+
/** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the
|
|
154
|
+
* square roots of the first eight prime numbers. Exported as a shared table; callers must treat
|
|
155
|
+
* it as read-only because constructors copy words from it by index. */
|
|
156
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
157
|
+
1779033703,
|
|
158
|
+
3144134277,
|
|
159
|
+
1013904242,
|
|
160
|
+
2773480762,
|
|
161
|
+
1359893119,
|
|
162
|
+
2600822924,
|
|
163
|
+
528734635,
|
|
164
|
+
1541459225
|
|
165
|
+
]);
|
|
166
|
+
//#endregion
|
|
167
|
+
export { Chi, HashMD, Maj, SHA256_IV };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=_md.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_md.js","names":[],"sources":["../../../../../../../../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js"],"sourcesContent":["/**\n * Internal Merkle-Damgard hash utils.\n * @module\n */\nimport { setU64FromNum } from \"./_u64.js\";\nimport { abytes, aexists, aoutput, createView } from \"./utils.js\";\n/**\n * Shared 32-bit conditional boolean primitive reused by SHA-256, SHA-1, and MD5 `F`.\n * Returns bits from `b` when `a` is set, otherwise from `c`.\n * The XOR form is equivalent to MD5's `F(X,Y,Z) = XY v not(X)Z` because the masked terms never\n * set the same bit.\n * @param a - selector word\n * @param b - word chosen when selector bit is set\n * @param c - word chosen when selector bit is clear\n * @returns Mixed 32-bit word.\n * @example\n * Combine three words with the shared 32-bit choice primitive.\n * ```ts\n * Chi(0xffffffff, 0x12345678, 0x87654321);\n * ```\n */\nexport function Chi(a, b, c) {\n return (a & b) ^ (~a & c);\n}\n/**\n * Shared 32-bit majority primitive reused by SHA-256 and SHA-1.\n * Returns bits shared by at least two inputs.\n * @param a - first input word\n * @param b - second input word\n * @param c - third input word\n * @returns Mixed 32-bit word.\n * @example\n * Combine three words with the shared 32-bit majority primitive.\n * ```ts\n * Maj(0xffffffff, 0x12345678, 0x87654321);\n * ```\n */\nexport function Maj(a, b, c) {\n return (a & b) ^ (a & c) ^ (b & c);\n}\n/**\n * Merkle-Damgard hash construction base class.\n * Could be used to create MD5, RIPEMD, SHA1, SHA2.\n * Accepts only byte-aligned `Uint8Array` input, even when the underlying spec describes bit\n * strings with partial-byte tails.\n * @param blockLen - internal block size in bytes\n * @param outputLen - digest size in bytes\n * @param padOffset - trailing length field size in bytes\n * @param isLE - whether length and state words are encoded in little-endian\n * @example\n * Use a concrete subclass to get the shared Merkle-Damgard update/digest flow.\n * ```ts\n * import { _SHA1 } from '@noble/hashes/legacy.js';\n * const hash = new _SHA1();\n * hash.update(new Uint8Array([97, 98, 99]));\n * hash.digest();\n * ```\n */\nexport class HashMD {\n blockLen;\n outputLen;\n canXOF = false;\n padOffset;\n isLE;\n // For partial updates less than block size\n buffer;\n view;\n finished = false;\n length = 0;\n pos = 0;\n destroyed = false;\n constructor(blockLen, outputLen, padOffset, isLE) {\n this.blockLen = blockLen;\n this.outputLen = outputLen;\n this.padOffset = padOffset;\n this.isLE = isLE;\n this.buffer = new Uint8Array(blockLen);\n this.view = createView(this.buffer);\n }\n update(data) {\n aexists(this);\n abytes(data);\n const { view, buffer, blockLen } = this;\n const len = data.length;\n let processed = false;\n for (let pos = 0; pos < len;) {\n const take = Math.min(blockLen - this.pos, len - pos);\n // Fast path only when there is no buffered partial block: `take === blockLen` implies\n // `this.pos === 0`, so we can process full blocks directly from the input view.\n if (take === blockLen) {\n const dataView = createView(data);\n for (; blockLen <= len - pos; pos += blockLen)\n this.process(dataView, pos);\n processed = true;\n continue;\n }\n // When the whole input is buffered in one go (common for short messages), passing `data`\n // directly avoids allocating a subarray view.\n buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);\n this.pos += take;\n pos += take;\n if (this.pos === blockLen) {\n this.process(view, 0);\n this.pos = 0;\n processed = true;\n }\n }\n this.length += data.length;\n // Shared schedule buffers only pick up input-derived words inside process(); if everything\n // was buffered without processing, there is nothing to zero.\n if (processed)\n this.roundClean();\n return this;\n }\n digestInto(out) {\n aexists(this);\n aoutput(out, this);\n this.finished = true;\n // Padding\n // We can avoid allocation of buffer for padding completely if it\n // was previously not allocated here. But it won't change performance.\n const { buffer, view, blockLen, isLE } = this;\n let { pos } = this;\n // append the bit '1' to the message, then zero-pad the rest of the block\n buffer[pos++] = 0b10000000;\n buffer.fill(0, pos);\n // we have less than padOffset left in buffer, so we cannot put length in\n // current block, need process it and pad again\n if (this.padOffset > blockLen - pos) {\n this.process(view, 0);\n buffer.fill(0);\n }\n // `padOffset` reserves the whole length field. For SHA-384/512 the high 64 bits stay zero from\n // the padding fill above, and JS will overflow before user input can make that half non-zero.\n // So we only need to write the low 64 bits here (`length * 8` only scales the exponent of an\n // integer below 2**53, so the split inside the helper stays exact).\n setU64FromNum(view, blockLen - 8, this.length * 8, isLE);\n this.process(view, 0);\n // The final block above is processed outside update(), so the shared message-schedule\n // buffers (e.g. SHA256_W) would otherwise retain input-derived words after digest().\n this.roundClean();\n // digest() passes our own `buffer` as `out`; reuse its cached view instead of allocating one.\n const oview = out === buffer ? view : createView(out);\n const len = this.outputLen;\n // NOTE: we do division by 4 later, which must be fused in single op with modulo by JIT\n const outLen = len / 4;\n const state = this.get();\n // Subclass-misconfiguration invariant: outputLen must be 32-bit aligned and fit the state.\n if (len % 4 || outLen > state.length)\n throw new Error('invalid outputLen');\n for (let i = 0; i < outLen; i++)\n oview.setUint32(4 * i, state[i], isLE);\n }\n digest() {\n const { buffer, outputLen } = this;\n this.digestInto(buffer);\n // Copy before destroy(): subclasses wipe `buffer` during cleanup, but `digest()` must return\n // fresh bytes to the caller.\n const res = buffer.slice(0, outputLen);\n this.destroy();\n return res;\n }\n _cloneIntoMeta(to) {\n const { buffer, length, finished, destroyed, pos } = this;\n to.destroyed = destroyed;\n to.finished = finished;\n to.length = length;\n to.pos = pos;\n // Only partial-block bytes need copying: when `length % blockLen === 0`, `pos === 0` and\n // later `update()` / `digestInto()` overwrite `to.buffer` from the start before reading it.\n if (pos)\n to.buffer.set(buffer); // Avoid a hot modulo guard.\n return to;\n }\n clone() {\n return this._cloneInto();\n }\n}\n/**\n * Initial SHA-2 state: fractional parts of square roots of first 16 primes 2..53.\n * Check out `test/misc/sha2-gen-iv.js` for recomputation guide.\n */\n/** Initial SHA256 state from RFC 6234 §6.1: the first 32 bits of the fractional parts of the\n * square roots of the first eight prime numbers. Exported as a shared table; callers must treat\n * it as read-only because constructors copy words from it by index. */\nexport const SHA256_IV = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\n]);\n/** Initial SHA224 state `H(0)` from RFC 6234 §6.1. Exported as a shared table; callers must\n * treat it as read-only because constructors copy words from it by index. */\nexport const SHA224_IV = /* @__PURE__ */ Uint32Array.from([\n 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,\n]);\n/** Initial SHA384 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen\n * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the ninth\n * through sixteenth prime numbers. Exported as a shared table; callers must treat it as read-only\n * because constructors copy halves from it by index. */\nexport const SHA384_IV = /* @__PURE__ */ Uint32Array.from([\n 0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939,\n 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4,\n]);\n/** Initial SHA512 state from RFC 6234 §6.3: eight RFC 64-bit `H(0)` words stored as sixteen\n * big-endian 32-bit halves. Derived from the fractional parts of the square roots of the first\n * eight prime numbers. Exported as a shared table; callers must treat it as read-only because\n * constructors copy halves from it by index. */\nexport const SHA512_IV = /* @__PURE__ */ Uint32Array.from([\n 0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1,\n 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,\n]);\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,IAAI,GAAG,GAAG,GAAG;CACzB,OAAQ,IAAI,IAAM,CAAC,IAAI;AAC3B;;;;;;;;;;;;;;AAcA,SAAgB,IAAI,GAAG,GAAG,GAAG;CACzB,OAAQ,IAAI,IAAM,IAAI,IAAM,IAAI;AACpC;;;;;;;;;;;;;;;;;;;AAmBA,IAAa,SAAb,MAAoB;CAChB;CACA;CACA,SAAS;CACT;CACA;CAEA;CACA;CACA,WAAW;CACX,SAAS;CACT,MAAM;CACN,YAAY;CACZ,YAAY,UAAU,WAAW,WAA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KAAK,WAAW;EAEhB,MAAM,QAAQ,QAAQ,SAAS,OAAO,WAAW,GAAG;EACpD,MAAM,MAAM,KAAK;EAEjB,MAAM,SAAS,MAAM;EACrB,MAAM,QAAQ,KAAK,IAAI;EAEvB,IAAI,MAAM,KAAK,SAAS,MAAM,QAC1B,MAAM,IAAI,MAAM,mBAAmB;EACvC,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KACxB,MAAM,UAAU,IAAI,GAAG,MAAM,IAAI,IAAI;CAC7C;CACA,SAAS;EACL,MAAM,EAAE,QAAQ,cAAc;EAC9B,KAAK,WAAW,MAAM;EAGtB,MAAM,MAAM,OAAO,MAAM,GAAG,SAAS;EACrC,KAAK,QAAQ;EACb,OAAO;CACX;CACA,eAAe,IAAI;EACf,MAAM,EAAE,QAAQ,QAAQ,UAAU,WAAW,QAAQ;EACrD,GAAG,YAAY;EACf,GAAG,WAAW;EACd,GAAG,SAAS;EACZ,GAAG,MAAM;EAGT,IAAI,KACA,GAAG,OAAO,IAAI,MAAM;EACxB,OAAO;CACX;CACA,QAAQ;EACJ,OAAO,KAAK,WAAW;CAC3B;AACJ;;;;;;;;AAQA,IAAa,YAA4B,4BAAY,KAAK;CACtD;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;CAAY;AACxF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js
|
|
2
|
+
var fromNumH = (n) => n / 2 ** 32 | 0;
|
|
3
|
+
var fromNumL = (n) => n >>> 0;
|
|
4
|
+
function setU64FromNum(view, byteOffset, n, isLE) {
|
|
5
|
+
const h = fromNumH(n);
|
|
6
|
+
const l = fromNumL(n);
|
|
7
|
+
view.setUint32(byteOffset, isLE ? l : h, isLE);
|
|
8
|
+
view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { fromNumH, fromNumL, setU64FromNum };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=_u64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_u64.js","names":[],"sources":["../../../../../../../../../node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js"],"sourcesContent":["const U32_MASK64 = /* @__PURE__ */ (() => BigInt(2 ** 32 - 1))();\nconst _32n = /* @__PURE__ */ BigInt(32);\n// Split bigint into two 32-bit halves. With `le=true`, returned fields become `{ h: low, l: high\n// }` to match little-endian word order rather than the property names.\nfunction fromBig(n, le = false) {\n if (le)\n return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };\n return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };\n}\n// Split bigint list into `[highWords, lowWords]` when `le=false`; with `le=true`, the first array\n// holds the low halves because `fromBig(...)` swaps the semantic meaning of `h` and `l`.\nfunction split(lst, le = false) {\n const len = lst.length;\n let Ah = new Uint32Array(len);\n let Al = new Uint32Array(len);\n for (let i = 0; i < len; i++) {\n const { h, l } = fromBig(lst[i], le);\n [Ah[i], Al[i]] = [h, l];\n }\n return [Ah, Al];\n}\n// Combine explicit `(high, low)` 32-bit halves into a bigint; `>>> 0` normalizes signed JS\n// bitwise results back to uint32 first, and little-endian callers must swap.\nconst toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);\n// Split a JS number into u32 halves without a BigInt allocation. Exact only for integers\n// `0 <= n < 2**53`; callers use it on byte / bit counters, which JS length math caps far below\n// that (an ArrayBuffer cannot exceed 2**53 - 1 bytes).\nconst fromNumH = (n) => (n / 2 ** 32) | 0;\nconst fromNumL = (n) => n >>> 0;\n// Drop-in replacement for `view.setBigUint64(byteOffset, BigInt(n), isLE)` without the per-call\n// BigInt allocation. Same `n < 2**53` precondition as `fromNumH`/`fromNumL`.\nfunction setU64FromNum(view, byteOffset, n, isLE) {\n const h = fromNumH(n);\n const l = fromNumL(n);\n view.setUint32(byteOffset, isLE ? l : h, isLE);\n view.setUint32(byteOffset + 4, isLE ? h : l, isLE);\n}\n// High 32-bit half of a 64-bit logical right shift for `s` in `0..31`.\nconst shrSH = (h, _l, s) => h >>> s;\n// Low 32-bit half of a 64-bit logical right shift, valid for `s` in `1..31`.\nconst shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);\n// High 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.\nconst rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));\n// Low 32-bit half of a 64-bit right rotate, valid for `s` in `1..31`.\nconst rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);\n// High 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.\nconst rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));\n// Low 32-bit half of a 64-bit right rotate, valid for `s` in `33..63`; `32` uses `rotr32*`.\nconst rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));\n// High 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped low half.\nconst rotr32H = (_h, l) => l;\n// Low 32-bit half of a 64-bit right rotate for `s === 32`; this is just the swapped high half.\nconst rotr32L = (h, _l) => h;\n// 64-bit left rotates (rotl*) are not defined here: sha3.ts, their only consumer, keeps\n// local copies so V8 inlines them into keccakP.\n// Add two split 64-bit words and return the split `{ h, l }` sum.\n// JS uses 32-bit signed integers for bitwise operations, so we cannot simply shift the carry out\n// of the low sum and instead use division.\nfunction add(Ah, Al, Bh, Bl) {\n const l = (Al >>> 0) + (Bl >>> 0);\n return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };\n}\n// Addition with more than 2 elements\n// Unmasked low-word accumulator for 3-way addition; pass the raw result into `add3H(...)`.\nconst add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);\n// High-word finalize step for 3-way addition; `low` must be the untruncated output of `add3L(...)`.\nconst add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;\n// Unmasked low-word accumulator for 4-way addition; pass the raw result into `add4H(...)`.\nconst add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);\n// High-word finalize step for 4-way addition; `low` must be the untruncated output of `add4L(...)`.\nconst add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;\n// Unmasked low-word accumulator for 5-way addition; pass the raw result into `add5H(...)`.\nconst add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);\n// High-word finalize step for 5-way addition; `low` must be the untruncated output of `add5L(...)`.\nconst add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;\n// prettier-ignore\nexport { add, add3H, add3L, add4H, add4L, add5H, add5L, fromBig, fromNumH, fromNumL, rotr32H, rotr32L, rotrBH, rotrBL, rotrSH, rotrSL, setU64FromNum, shrSH, shrSL, split, toBig };\n"],"x_google_ignoreList":[0],"mappings":";AA2BA,IAAM,YAAY,MAAO,IAAI,KAAK,KAAM;AACxC,IAAM,YAAY,MAAM,MAAM;AAG9B,SAAS,cAAc,MAAM,YAAY,GAAG,MAAM;CAC9C,MAAM,IAAI,SAAS,CAAC;CACpB,MAAM,IAAI,SAAS,CAAC;CACpB,KAAK,UAAU,YAAY,OAAO,IAAI,GAAG,IAAI;CAC7C,KAAK,UAAU,aAAa,GAAG,OAAO,IAAI,GAAG,IAAI;AACrD"}
|