dreamteamer 0.49.1 → 0.50.0
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/bin/dreamteamer.js +163 -87
- package/collections/modules.collection.yaml +4 -0
- package/dist/api.d.ts +89 -0
- package/dist/api.js +139 -0
- package/dist/changes/commitPending.d.ts +28 -0
- package/dist/changes/commitPending.js +658 -0
- package/dist/changes/composeSubject.d.ts +9 -0
- package/dist/changes/composeSubject.js +19 -0
- package/dist/changes/consts.d.ts +11 -0
- package/dist/changes/consts.js +19 -0
- package/dist/changes/deriveEvents.d.ts +19 -0
- package/dist/changes/deriveEvents.js +118 -0
- package/dist/changes/foldChanges.d.ts +13 -0
- package/dist/changes/foldChanges.js +47 -0
- package/dist/changes/groupChanges.d.ts +6 -0
- package/dist/changes/groupChanges.js +23 -0
- package/dist/changes/layerOf.d.ts +6 -0
- package/dist/changes/layerOf.js +12 -0
- package/dist/changes/lib/reportLine.d.ts +7 -0
- package/dist/changes/lib/reportLine.js +14 -0
- package/dist/changes/printChanges.d.ts +11 -0
- package/dist/changes/printChanges.js +20 -0
- package/dist/changes/recordChanges.d.ts +21 -0
- package/dist/changes/recordChanges.js +32 -0
- package/dist/changes/rowChanges.d.ts +7 -0
- package/dist/changes/rowChanges.js +27 -0
- package/dist/changes/types.d.ts +28 -0
- package/dist/changes/types.js +1 -0
- package/dist/check/check.d.ts +11 -0
- package/dist/check/check.js +555 -0
- package/dist/check/checkAlone.d.ts +9 -0
- package/dist/check/checkAlone.js +200 -0
- package/dist/check/consts.d.ts +1 -0
- package/dist/check/consts.js +3 -0
- package/dist/check/engineRun.d.ts +3 -0
- package/dist/check/engineRun.js +20 -0
- package/dist/check/freshWorkspace.d.ts +5 -0
- package/dist/check/freshWorkspace.js +24 -0
- package/dist/check/isStale.d.ts +3 -0
- package/dist/check/isStale.js +2 -0
- package/dist/check/symlinkedChildRoots.d.ts +3 -0
- package/dist/check/symlinkedChildRoots.js +13 -0
- package/dist/check/unreadData.d.ts +7 -0
- package/dist/check/unreadData.js +113 -0
- package/dist/cli.d.ts +21 -0
- package/dist/cli.js +151 -0
- package/dist/collections/addField.d.ts +23 -0
- package/dist/collections/addField.js +28 -0
- package/dist/collections/collectionsCommand.d.ts +7 -0
- package/dist/collections/collectionsCommand.js +357 -0
- package/dist/collections/createCollection.d.ts +21 -0
- package/dist/collections/createCollection.js +134 -0
- package/dist/collections/lib/applyRewrites.d.ts +4 -0
- package/dist/collections/lib/applyRewrites.js +26 -0
- package/dist/collections/lib/consts.d.ts +18 -0
- package/dist/collections/lib/consts.js +56 -0
- package/dist/collections/lib/declaringSource.d.ts +18 -0
- package/dist/collections/lib/declaringSource.js +44 -0
- package/dist/collections/lib/descriptorSources.d.ts +4 -0
- package/dist/collections/lib/descriptorSources.js +16 -0
- package/dist/collections/lib/fieldRenameWalk.d.ts +10 -0
- package/dist/collections/lib/fieldRenameWalk.js +50 -0
- package/dist/collections/lib/mixinDeclaring.d.ts +7 -0
- package/dist/collections/lib/mixinDeclaring.js +13 -0
- package/dist/collections/lib/mixinSources.d.ts +6 -0
- package/dist/collections/lib/mixinSources.js +18 -0
- package/dist/collections/lib/mixinsListedBy.d.ts +3 -0
- package/dist/collections/lib/mixinsListedBy.js +14 -0
- package/dist/collections/lib/placeField.d.ts +7 -0
- package/dist/collections/lib/placeField.js +19 -0
- package/dist/collections/lib/positionLines.d.ts +10 -0
- package/dist/collections/lib/positionLines.js +7 -0
- package/dist/collections/lib/qualify.d.ts +2 -0
- package/dist/collections/lib/qualify.js +5 -0
- package/dist/collections/lib/recordRewrites.d.ts +5 -0
- package/dist/collections/lib/recordRewrites.js +27 -0
- package/dist/collections/lib/removeFieldPlan.d.ts +26 -0
- package/dist/collections/lib/removeFieldPlan.js +57 -0
- package/dist/collections/lib/renameFieldPlan.d.ts +12 -0
- package/dist/collections/lib/renameFieldPlan.js +18 -0
- package/dist/collections/lib/renameInConstraint.d.ts +2 -0
- package/dist/collections/lib/renameInConstraint.js +45 -0
- package/dist/collections/lib/renameInDisplay.d.ts +2 -0
- package/dist/collections/lib/renameInDisplay.js +52 -0
- package/dist/collections/lib/renameInTemplate.d.ts +3 -0
- package/dist/collections/lib/renameInTemplate.js +12 -0
- package/dist/collections/lib/renameKeys.d.ts +13 -0
- package/dist/collections/lib/renameKeys.js +31 -0
- package/dist/collections/lib/renameMirrorOf.d.ts +3 -0
- package/dist/collections/lib/renameMirrorOf.js +10 -0
- package/dist/collections/lib/renameOwnField.d.ts +3 -0
- package/dist/collections/lib/renameOwnField.js +30 -0
- package/dist/collections/lib/renameValueInCondition.d.ts +4 -0
- package/dist/collections/lib/renameValueInCondition.js +42 -0
- package/dist/collections/lib/renameValueInConstraint.d.ts +3 -0
- package/dist/collections/lib/renameValueInConstraint.js +19 -0
- package/dist/collections/lib/renameValueInSubschema.d.ts +3 -0
- package/dist/collections/lib/renameValueInSubschema.js +24 -0
- package/dist/collections/lib/renameValuePlan.d.ts +13 -0
- package/dist/collections/lib/renameValuePlan.js +33 -0
- package/dist/collections/lib/reportMirror.d.ts +8 -0
- package/dist/collections/lib/reportMirror.js +19 -0
- package/dist/collections/lib/types.d.ts +36 -0
- package/dist/collections/lib/types.js +1 -0
- package/dist/collections/lib/upsertField.d.ts +22 -0
- package/dist/collections/lib/upsertField.js +39 -0
- package/dist/collections/lib/valueRenameWalk.d.ts +4 -0
- package/dist/collections/lib/valueRenameWalk.js +60 -0
- package/dist/collections/lib/viewSources.d.ts +6 -0
- package/dist/collections/lib/viewSources.js +20 -0
- package/dist/collections/lib/walkFilter.d.ts +3 -0
- package/dist/collections/lib/walkFilter.js +25 -0
- package/dist/collections/lib/walkSources.d.ts +17 -0
- package/dist/collections/lib/walkSources.js +80 -0
- package/dist/collections/moveCollection.d.ts +42 -0
- package/dist/collections/moveCollection.js +176 -0
- package/dist/collections/removeCollection.d.ts +8 -0
- package/dist/collections/removeCollection.js +40 -0
- package/dist/collections/removeField.d.ts +30 -0
- package/dist/collections/removeField.js +150 -0
- package/dist/collections/renameCollection.d.ts +55 -0
- package/dist/collections/renameCollection.js +492 -0
- package/dist/collections/renameField.d.ts +32 -0
- package/dist/collections/renameField.js +49 -0
- package/dist/collections/renameValue.d.ts +29 -0
- package/dist/collections/renameValue.js +35 -0
- package/dist/collections/setCollectionScalars.d.ts +32 -0
- package/dist/collections/setCollectionScalars.js +248 -0
- package/dist/collections/updateField.d.ts +27 -0
- package/dist/collections/updateField.js +20 -0
- package/dist/commands/addCommand.d.ts +1 -0
- package/dist/commands/addCommand.js +2 -0
- package/dist/commands/addFieldCommand.d.ts +1 -0
- package/dist/commands/addFieldCommand.js +2 -0
- package/dist/commands/changesCommand.d.ts +10 -0
- package/dist/commands/changesCommand.js +37 -0
- package/dist/commands/checkCommand.d.ts +1 -0
- package/dist/commands/checkCommand.js +22 -0
- package/dist/commands/commitCommand.d.ts +6 -0
- package/dist/commands/commitCommand.js +89 -0
- package/dist/commands/compileCommand.d.ts +2 -0
- package/dist/commands/compileCommand.js +35 -0
- package/dist/commands/diffCommand.d.ts +1 -0
- package/dist/commands/diffCommand.js +2 -0
- package/dist/commands/doctorCommand.d.ts +1 -0
- package/dist/commands/doctorCommand.js +14 -0
- package/dist/commands/exportsCommand.d.ts +1 -0
- package/dist/commands/exportsCommand.js +10 -0
- package/dist/commands/fmtCommand.d.ts +1 -0
- package/dist/commands/fmtCommand.js +27 -0
- package/dist/commands/getCommand.d.ts +1 -0
- package/dist/commands/getCommand.js +2 -0
- package/dist/commands/helpCommand.d.ts +5 -0
- package/dist/commands/helpCommand.js +27 -0
- package/dist/commands/historyCommand.d.ts +1 -0
- package/dist/commands/historyCommand.js +2 -0
- package/dist/commands/initCommand.d.ts +2 -0
- package/dist/commands/initCommand.js +17 -0
- package/dist/commands/installCommand.d.ts +1 -0
- package/dist/commands/installCommand.js +12 -0
- package/dist/commands/lib/fieldVerb.d.ts +12 -0
- package/dist/commands/lib/fieldVerb.js +26 -0
- package/dist/commands/lib/recordVerb.d.ts +2 -0
- package/dist/commands/lib/recordVerb.js +53 -0
- package/dist/commands/lib/unknownVerb.d.ts +14 -0
- package/dist/commands/lib/unknownVerb.js +74 -0
- package/dist/commands/lib/verify.d.ts +3 -0
- package/dist/commands/lib/verify.js +4 -0
- package/dist/commands/listCommand.d.ts +1 -0
- package/dist/commands/listCommand.js +2 -0
- package/dist/commands/nextCommand.d.ts +1 -0
- package/dist/commands/nextCommand.js +2 -0
- package/dist/commands/relationsCommand.d.ts +11 -0
- package/dist/commands/relationsCommand.js +186 -0
- package/dist/commands/relocateCommand.d.ts +1 -0
- package/dist/commands/relocateCommand.js +39 -0
- package/dist/commands/renameCommand.d.ts +1 -0
- package/dist/commands/renameCommand.js +2 -0
- package/dist/commands/renameFieldCommand.d.ts +1 -0
- package/dist/commands/renameFieldCommand.js +2 -0
- package/dist/commands/renameValueCommand.d.ts +1 -0
- package/dist/commands/renameValueCommand.js +2 -0
- package/dist/commands/reorderCommand.d.ts +1 -0
- package/dist/commands/reorderCommand.js +2 -0
- package/dist/commands/resolveCommand.d.ts +15 -0
- package/dist/commands/resolveCommand.js +69 -0
- package/dist/commands/revertCommand.d.ts +1 -0
- package/dist/commands/revertCommand.js +2 -0
- package/dist/commands/rmCommand.d.ts +1 -0
- package/dist/commands/rmCommand.js +2 -0
- package/dist/commands/rmFieldCommand.d.ts +1 -0
- package/dist/commands/rmFieldCommand.js +2 -0
- package/dist/commands/runCommand.d.ts +5 -0
- package/dist/commands/runCommand.js +9 -0
- package/dist/commands/setCommand.d.ts +1 -0
- package/dist/commands/setCommand.js +2 -0
- package/dist/commands/setFieldCommand.d.ts +1 -0
- package/dist/commands/setFieldCommand.js +2 -0
- package/dist/commands/setupCommand.d.ts +5 -0
- package/dist/commands/setupCommand.js +196 -0
- package/dist/commands/statusCommand.d.ts +1 -0
- package/dist/commands/statusCommand.js +16 -0
- package/dist/commands/updateCommand.d.ts +1 -0
- package/dist/commands/updateCommand.js +18 -0
- package/dist/commands/valuesCommand.d.ts +1 -0
- package/dist/commands/valuesCommand.js +2 -0
- package/dist/commands/versionCommand.d.ts +2 -0
- package/dist/commands/versionCommand.js +7 -0
- package/dist/compile/compile.d.ts +24 -0
- package/dist/compile/compile.js +1553 -0
- package/dist/compile/consts.d.ts +52 -0
- package/dist/compile/consts.js +120 -0
- package/dist/compile/ensureEditorRecommendation.d.ts +1 -0
- package/dist/compile/ensureEditorRecommendation.js +31 -0
- package/dist/compile/isV2.d.ts +2 -0
- package/dist/compile/isV2.js +1 -0
- package/dist/compile/kindDir.d.ts +11 -0
- package/dist/compile/kindDir.js +19 -0
- package/dist/compile/lib/bindingErrors.d.ts +11 -0
- package/dist/compile/lib/bindingErrors.js +47 -0
- package/dist/compile/lib/buildCollectionsIndex.d.ts +8 -0
- package/dist/compile/lib/buildCollectionsIndex.js +49 -0
- package/dist/compile/lib/buildModulesIndex.d.ts +9 -0
- package/dist/compile/lib/buildModulesIndex.js +54 -0
- package/dist/compile/lib/compileCollections.d.ts +74 -0
- package/dist/compile/lib/compileCollections.js +614 -0
- package/dist/compile/lib/consts.d.ts +5 -0
- package/dist/compile/lib/consts.js +10 -0
- package/dist/compile/lib/ensureEnvExample.d.ts +28 -0
- package/dist/compile/lib/ensureEnvExample.js +79 -0
- package/dist/compile/lib/ensureGitignored.d.ts +6 -0
- package/dist/compile/lib/ensureGitignored.js +16 -0
- package/dist/compile/lib/filterFields.d.ts +5 -0
- package/dist/compile/lib/filterFields.js +17 -0
- package/dist/compile/lib/harnessMarkers.d.ts +2 -0
- package/dist/compile/lib/harnessMarkers.js +4 -0
- package/dist/compile/lib/mergeMixins.d.ts +14 -0
- package/dist/compile/lib/mergeMixins.js +55 -0
- package/dist/compile/lib/mergeOverlays.d.ts +6 -0
- package/dist/compile/lib/mergeOverlays.js +37 -0
- package/dist/compile/lib/nameErrors.d.ts +6 -0
- package/dist/compile/lib/nameErrors.js +57 -0
- package/dist/compile/lib/namespaceProblems.d.ts +8 -0
- package/dist/compile/lib/namespaceProblems.js +34 -0
- package/dist/compile/lib/overlayView.d.ts +2 -0
- package/dist/compile/lib/overlayView.js +17 -0
- package/dist/compile/lib/renderContributions.d.ts +14 -0
- package/dist/compile/lib/renderContributions.js +50 -0
- package/dist/compile/lib/resolveFields.d.ts +21 -0
- package/dist/compile/lib/resolveFields.js +232 -0
- package/dist/compile/lib/runHarnessAdapters.d.ts +19 -0
- package/dist/compile/lib/runHarnessAdapters.js +590 -0
- package/dist/compile/lib/shapeErrors.d.ts +3 -0
- package/dist/compile/lib/shapeErrors.js +64 -0
- package/dist/compile/lib/storageOverlaps.d.ts +17 -0
- package/dist/compile/lib/storageOverlaps.js +26 -0
- package/dist/compile/lib/subpathProblem.d.ts +6 -0
- package/dist/compile/lib/subpathProblem.js +14 -0
- package/dist/compile/lib/toJsonSchema.d.ts +9 -0
- package/dist/compile/lib/toJsonSchema.js +100 -0
- package/dist/compile/lib/types.d.ts +46 -0
- package/dist/compile/lib/types.js +1 -0
- package/dist/compile/lib/unqualifiedProblems.d.ts +6 -0
- package/dist/compile/lib/unqualifiedProblems.js +18 -0
- package/dist/compile/lib/viewDisplay.d.ts +6 -0
- package/dist/compile/lib/viewDisplay.js +21 -0
- package/dist/compile/lib/viewErrors.d.ts +20 -0
- package/dist/compile/lib/viewErrors.js +143 -0
- package/dist/compile/lib/writeLine.d.ts +12 -0
- package/dist/compile/lib/writeLine.js +31 -0
- package/dist/compile/sha256.d.ts +1 -0
- package/dist/compile/sha256.js +2 -0
- package/dist/compile/stagedKindDir.d.ts +18 -0
- package/dist/compile/stagedKindDir.js +32 -0
- package/dist/compile/staleness.d.ts +11 -0
- package/dist/compile/staleness.js +118 -0
- package/dist/compile/toPosix.d.ts +2 -0
- package/dist/compile/toPosix.js +3 -0
- package/dist/compile/types.d.ts +39 -0
- package/dist/compile/types.js +1 -0
- package/dist/compile/v1ManifestRefusal.d.ts +8 -0
- package/dist/compile/v1ManifestRefusal.js +16 -0
- package/dist/compile/v1Refusal.d.ts +2 -0
- package/dist/compile/v1Refusal.js +5 -0
- package/dist/compile/views.d.ts +2 -0
- package/dist/compile/views.js +3 -0
- package/dist/compile/warnIfStale.d.ts +3 -0
- package/dist/compile/warnIfStale.js +10 -0
- package/dist/coreVerbs.d.ts +6 -0
- package/dist/coreVerbs.js +50 -0
- package/dist/doctor/consts.d.ts +10 -0
- package/dist/doctor/consts.js +10 -0
- package/dist/doctor/doctorBoard.d.ts +7 -0
- package/dist/doctor/doctorBoard.js +97 -0
- package/dist/doctor/renderBoard.d.ts +2 -0
- package/dist/doctor/renderBoard.js +9 -0
- package/dist/doctor/types.d.ts +7 -0
- package/dist/doctor/types.js +1 -0
- package/dist/entities/createSkill.d.ts +12 -0
- package/dist/entities/createSkill.js +56 -0
- package/dist/entities/entitiesCommand.d.ts +7 -0
- package/dist/entities/entitiesCommand.js +97 -0
- package/dist/entities/lib/consts.d.ts +2 -0
- package/dist/entities/lib/consts.js +2 -0
- package/dist/entities/lib/entitySource.d.ts +10 -0
- package/dist/entities/lib/entitySource.js +17 -0
- package/dist/entities/lib/refuseBuiltSkill.d.ts +9 -0
- package/dist/entities/lib/refuseBuiltSkill.js +23 -0
- package/dist/entities/lib/refuseHandAuthored.d.ts +7 -0
- package/dist/entities/lib/refuseHandAuthored.js +15 -0
- package/dist/entities/lib/setFrontmatterKey.d.ts +8 -0
- package/dist/entities/lib/setFrontmatterKey.js +21 -0
- package/dist/entities/removeEntity.d.ts +7 -0
- package/dist/entities/removeEntity.js +35 -0
- package/dist/entities/renameEntity.d.ts +11 -0
- package/dist/entities/renameEntity.js +51 -0
- package/dist/entities/setEntityFrontmatter.d.ts +9 -0
- package/dist/entities/setEntityFrontmatter.js +58 -0
- package/dist/exports/planExports.d.ts +10 -0
- package/dist/exports/planExports.js +72 -0
- package/dist/exports/runExports.d.ts +7 -0
- package/dist/exports/runExports.js +95 -0
- package/dist/exports/serializeExports.d.ts +6 -0
- package/dist/exports/serializeExports.js +17 -0
- package/dist/extensions/consts.d.ts +1 -0
- package/dist/extensions/consts.js +1 -0
- package/dist/extensions/declaredExtensions.d.ts +17 -0
- package/dist/extensions/declaredExtensions.js +85 -0
- package/dist/extensions/extensions.d.ts +21 -0
- package/dist/extensions/extensions.js +24 -0
- package/dist/extensions/lib/consts.d.ts +2 -0
- package/dist/extensions/lib/consts.js +2 -0
- package/dist/extensions/lib/validateSetup.d.ts +15 -0
- package/dist/extensions/lib/validateSetup.js +128 -0
- package/dist/extensions/loadExtensions.d.ts +14 -0
- package/dist/extensions/loadExtensions.js +146 -0
- package/dist/extensions/manifestViolations.d.ts +11 -0
- package/dist/extensions/manifestViolations.js +17 -0
- package/dist/fmt/formatDescriptors.d.ts +20 -0
- package/dist/fmt/formatDescriptors.js +67 -0
- package/dist/fmt/formatSource.d.ts +7 -0
- package/dist/fmt/formatSource.js +50 -0
- package/dist/init/consts.d.ts +1 -0
- package/dist/init/consts.js +1 -0
- package/dist/init/escapes.d.ts +2 -0
- package/dist/init/escapes.js +64 -0
- package/dist/init/init.d.ts +7 -0
- package/dist/init/init.js +152 -0
- package/dist/init/initCommand.d.ts +30 -0
- package/dist/init/initCommand.js +407 -0
- package/dist/init/initFootprint.d.ts +6 -0
- package/dist/init/initFootprint.js +19 -0
- package/dist/init/seedBlock.d.ts +7 -0
- package/dist/init/seedBlock.js +37 -0
- package/dist/install/applyInstall.d.ts +15 -0
- package/dist/install/applyInstall.js +190 -0
- package/dist/install/buildClone.d.ts +5 -0
- package/dist/install/buildClone.js +22 -0
- package/dist/install/commitOf.d.ts +1 -0
- package/dist/install/commitOf.js +2 -0
- package/dist/install/declaredDeps.d.ts +3 -0
- package/dist/install/declaredDeps.js +2 -0
- package/dist/install/indexFolder.d.ts +6 -0
- package/dist/install/indexFolder.js +32 -0
- package/dist/install/install.d.ts +8 -0
- package/dist/install/install.js +177 -0
- package/dist/install/installCheckout.d.ts +15 -0
- package/dist/install/installCheckout.js +142 -0
- package/dist/install/installClone.d.ts +6 -0
- package/dist/install/installClone.js +32 -0
- package/dist/install/installCommand.d.ts +15 -0
- package/dist/install/installCommand.js +61 -0
- package/dist/install/installModules.d.ts +17 -0
- package/dist/install/installModules.js +208 -0
- package/dist/install/installedModules.d.ts +12 -0
- package/dist/install/installedModules.js +27 -0
- package/dist/install/isLink.d.ts +1 -0
- package/dist/install/isLink.js +9 -0
- package/dist/install/lib/readTarballManifest.d.ts +6 -0
- package/dist/install/lib/readTarballManifest.js +27 -0
- package/dist/install/npmAndCompile.d.ts +35 -0
- package/dist/install/npmAndCompile.js +151 -0
- package/dist/install/observeState.d.ts +29 -0
- package/dist/install/observeState.js +98 -0
- package/dist/install/offRef.d.ts +7 -0
- package/dist/install/offRef.js +19 -0
- package/dist/install/planInstall.d.ts +9 -0
- package/dist/install/planInstall.js +73 -0
- package/dist/install/presetMembers.d.ts +17 -0
- package/dist/install/presetMembers.js +25 -0
- package/dist/install/readHookInput.d.ts +17 -0
- package/dist/install/readHookInput.js +29 -0
- package/dist/install/readSpecManifest.d.ts +12 -0
- package/dist/install/readSpecManifest.js +55 -0
- package/dist/install/readStdin.d.ts +12 -0
- package/dist/install/readStdin.js +25 -0
- package/dist/install/resolveClosure.d.ts +21 -0
- package/dist/install/resolveClosure.js +69 -0
- package/dist/install/resolves.d.ts +8 -0
- package/dist/install/resolves.js +9 -0
- package/dist/install/types.d.ts +26 -0
- package/dist/install/types.js +1 -0
- package/dist/install/versions.d.ts +12 -0
- package/dist/install/versions.js +25 -0
- package/dist/lib/alreadyThat.d.ts +5 -0
- package/dist/lib/alreadyThat.js +8 -0
- package/dist/lib/appendMissing.d.ts +1 -0
- package/dist/lib/appendMissing.js +7 -0
- package/dist/lib/atomicWrite.d.ts +1 -0
- package/dist/lib/atomicWrite.js +9 -0
- package/dist/lib/baseDescriptorSource.d.ts +18 -0
- package/dist/lib/baseDescriptorSource.js +52 -0
- package/dist/lib/childEnv.d.ts +12 -0
- package/dist/lib/childEnv.js +16 -0
- package/dist/lib/collectionSourceFile.d.ts +26 -0
- package/dist/lib/collectionSourceFile.js +56 -0
- package/dist/lib/consts.d.ts +93 -0
- package/dist/lib/consts.js +180 -0
- package/dist/lib/dryRunPlan.d.ts +21 -0
- package/dist/lib/dryRunPlan.js +23 -0
- package/dist/lib/editWorkspacePkg.d.ts +8 -0
- package/dist/lib/editWorkspacePkg.js +19 -0
- package/dist/lib/emit.d.ts +32 -0
- package/dist/lib/emit.js +46 -0
- package/dist/lib/emitDocument.d.ts +6 -0
- package/dist/lib/emitDocument.js +61 -0
- package/dist/lib/endOf.d.ts +11 -0
- package/dist/lib/endOf.js +25 -0
- package/dist/lib/escapeRe.d.ts +2 -0
- package/dist/lib/escapeRe.js +2 -0
- package/dist/lib/fieldFromFlags.d.ts +13 -0
- package/dist/lib/fieldFromFlags.js +195 -0
- package/dist/lib/gatedTreeOp.d.ts +30 -0
- package/dist/lib/gatedTreeOp.js +59 -0
- package/dist/lib/git/commitArg.d.ts +1 -0
- package/dist/lib/git/commitArg.js +13 -0
- package/dist/lib/git/defaultGit.d.ts +1 -0
- package/dist/lib/git/defaultGit.js +20 -0
- package/dist/lib/git/describeCheckout.d.ts +9 -0
- package/dist/lib/git/describeCheckout.js +45 -0
- package/dist/lib/git/gitOk.d.ts +2 -0
- package/dist/lib/git/gitOk.js +11 -0
- package/dist/lib/git/inProgress.d.ts +5 -0
- package/dist/lib/git/inProgress.js +28 -0
- package/dist/lib/git/repoRootOf.d.ts +6 -0
- package/dist/lib/git/repoRootOf.js +20 -0
- package/dist/lib/git/tryGit.d.ts +1 -0
- package/dist/lib/git/tryGit.js +10 -0
- package/dist/lib/isEntityKind.d.ts +2 -0
- package/dist/lib/isEntityKind.js +3 -0
- package/dist/lib/nearest.d.ts +5 -0
- package/dist/lib/nearest.js +21 -0
- package/dist/lib/need.d.ts +1 -0
- package/dist/lib/need.js +5 -0
- package/dist/lib/npm/exact.d.ts +5 -0
- package/dist/lib/npm/exact.js +5 -0
- package/dist/lib/npm/npmFloor.d.ts +2 -0
- package/dist/lib/npm/npmFloor.js +18 -0
- package/dist/lib/npm/resolveNpm.d.ts +10 -0
- package/dist/lib/npm/resolveNpm.js +35 -0
- package/dist/lib/npm/satisfies.d.ts +11 -0
- package/dist/lib/npm/satisfies.js +66 -0
- package/dist/lib/oneValue.d.ts +7 -0
- package/dist/lib/oneValue.js +12 -0
- package/dist/lib/pairs.d.ts +5 -0
- package/dist/lib/pairs.js +15 -0
- package/dist/lib/parseArgs.d.ts +17 -0
- package/dist/lib/parseArgs.js +36 -0
- package/dist/lib/refuseUnknownFlags.d.ts +3 -0
- package/dist/lib/refuseUnknownFlags.js +53 -0
- package/dist/lib/rel.d.ts +1 -0
- package/dist/lib/rel.js +3 -0
- package/dist/lib/schema-ops.d.ts +105 -0
- package/dist/lib/schema-ops.js +177 -0
- package/dist/lib/singular.d.ts +1 -0
- package/dist/lib/singular.js +23 -0
- package/dist/lib/stripMeta.d.ts +2 -0
- package/dist/lib/stripMeta.js +2 -0
- package/dist/lib/symlinkBelow.d.ts +13 -0
- package/dist/lib/symlinkBelow.js +33 -0
- package/dist/lib/types.d.ts +22 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/walk.d.ts +5 -0
- package/dist/lib/walk.js +21 -0
- package/dist/lib/writeSource.d.ts +7 -0
- package/dist/lib/writeSource.js +77 -0
- package/dist/lib/yaml.d.ts +18 -0
- package/dist/lib/yaml.js +26 -0
- package/dist/modules/createModule.d.ts +16 -0
- package/dist/modules/createModule.js +136 -0
- package/dist/modules/lib/consts.d.ts +10 -0
- package/dist/modules/lib/consts.js +17 -0
- package/dist/modules/lib/extensionText.d.ts +3 -0
- package/dist/modules/lib/extensionText.js +36 -0
- package/dist/modules/lib/readmeText.d.ts +6 -0
- package/dist/modules/lib/readmeText.js +25 -0
- package/dist/modules/lib/scaffoldKey.d.ts +2 -0
- package/dist/modules/lib/scaffoldKey.js +2 -0
- package/dist/modules/lib/testText.d.ts +7 -0
- package/dist/modules/lib/testText.js +19 -0
- package/dist/modules/modulesCommand.d.ts +4 -0
- package/dist/modules/modulesCommand.js +121 -0
- package/dist/modules/removeModule.d.ts +25 -0
- package/dist/modules/removeModule.js +94 -0
- package/dist/modules/renameModule.d.ts +15 -0
- package/dist/modules/renameModule.js +109 -0
- package/dist/modules/runModuleScript.d.ts +17 -0
- package/dist/modules/runModuleScript.js +100 -0
- package/dist/modules/setModule.d.ts +9 -0
- package/dist/modules/setModule.js +88 -0
- package/dist/openWorkspace.d.ts +12 -0
- package/dist/openWorkspace.js +22 -0
- package/dist/record/bodyField.d.ts +2 -0
- package/dist/record/bodyField.js +4 -0
- package/dist/record/collectRefFields.d.ts +3 -0
- package/dist/record/collectRefFields.js +16 -0
- package/dist/record/consts.d.ts +43 -0
- package/dist/record/consts.js +85 -0
- package/dist/record/descriptor.d.ts +44 -0
- package/dist/record/descriptor.js +56 -0
- package/dist/record/displayOf.d.ts +3 -0
- package/dist/record/displayOf.js +13 -0
- package/dist/record/expectedMirrors.d.ts +10 -0
- package/dist/record/expectedMirrors.js +27 -0
- package/dist/record/exportsContext.d.ts +17 -0
- package/dist/record/exportsContext.js +62 -0
- package/dist/record/fields.d.ts +9 -0
- package/dist/record/fields.js +30 -0
- package/dist/record/idFromRecordPath.d.ts +16 -0
- package/dist/record/idFromRecordPath.js +28 -0
- package/dist/record/lib/applyFilter.d.ts +5 -0
- package/dist/record/lib/applyFilter.js +32 -0
- package/dist/record/lib/consts.d.ts +7 -0
- package/dist/record/lib/consts.js +7 -0
- package/dist/record/lib/enumChoices.d.ts +2 -0
- package/dist/record/lib/enumChoices.js +16 -0
- package/dist/record/lib/fmtDate.d.ts +1 -0
- package/dist/record/lib/fmtDate.js +18 -0
- package/dist/record/lib/placedChildAt.d.ts +10 -0
- package/dist/record/lib/placedChildAt.js +25 -0
- package/dist/record/lib/rootRecords.d.ts +8 -0
- package/dist/record/lib/rootRecords.js +37 -0
- package/dist/record/lib/types.d.ts +6 -0
- package/dist/record/lib/types.js +1 -0
- package/dist/record/namespace.d.ts +22 -0
- package/dist/record/namespace.js +36 -0
- package/dist/record/nav.d.ts +41 -0
- package/dist/record/nav.js +237 -0
- package/dist/record/normalizeNamespaces.d.ts +8 -0
- package/dist/record/normalizeNamespaces.js +20 -0
- package/dist/record/outsideRefs.d.ts +19 -0
- package/dist/record/outsideRefs.js +34 -0
- package/dist/record/ownerIdOf.d.ts +11 -0
- package/dist/record/ownerIdOf.js +12 -0
- package/dist/record/ownersReadIn.d.ts +9 -0
- package/dist/record/ownersReadIn.js +11 -0
- package/dist/record/parentFolders.d.ts +6 -0
- package/dist/record/parentFolders.js +18 -0
- package/dist/record/parseRecordText.d.ts +2 -0
- package/dist/record/parseRecordText.js +19 -0
- package/dist/record/parseRef.d.ts +11 -0
- package/dist/record/parseRef.js +27 -0
- package/dist/record/parseTemplate.d.ts +3 -0
- package/dist/record/parseTemplate.js +24 -0
- package/dist/record/pathToRecord.d.ts +9 -0
- package/dist/record/pathToRecord.js +39 -0
- package/dist/record/placedRecords.d.ts +8 -0
- package/dist/record/placedRecords.js +22 -0
- package/dist/record/placement.d.ts +15 -0
- package/dist/record/placement.js +19 -0
- package/dist/record/presentation.d.ts +3 -0
- package/dist/record/presentation.js +236 -0
- package/dist/record/readExports.d.ts +2 -0
- package/dist/record/readExports.js +14 -0
- package/dist/record/records.d.ts +15 -0
- package/dist/record/records.js +53 -0
- package/dist/record/ref.d.ts +12 -0
- package/dist/record/ref.js +26 -0
- package/dist/record/regenerate.d.ts +18 -0
- package/dist/record/regenerate.js +56 -0
- package/dist/record/relationsOf.d.ts +3 -0
- package/dist/record/relationsOf.js +33 -0
- package/dist/record/renderDisplay.d.ts +13 -0
- package/dist/record/renderDisplay.js +33 -0
- package/dist/record/sees.d.ts +6 -0
- package/dist/record/sees.js +7 -0
- package/dist/record/serialize.d.ts +2 -0
- package/dist/record/serialize.js +35 -0
- package/dist/record/splitRef.d.ts +10 -0
- package/dist/record/splitRef.js +23 -0
- package/dist/record/storageOf.d.ts +3 -0
- package/dist/record/storageOf.js +40 -0
- package/dist/record/template.d.ts +12 -0
- package/dist/record/template.js +28 -0
- package/dist/record/temporal.d.ts +2 -0
- package/dist/record/temporal.js +8 -0
- package/dist/record/types.d.ts +76 -0
- package/dist/record/types.js +1 -0
- package/dist/record/unknownOperators.d.ts +5 -0
- package/dist/record/unknownOperators.js +25 -0
- package/dist/record/unknownTokens.d.ts +5 -0
- package/dist/record/unknownTokens.js +17 -0
- package/dist/record/validateTemplate.d.ts +14 -0
- package/dist/record/validateTemplate.js +36 -0
- package/dist/record/valuesAt.d.ts +2 -0
- package/dist/record/valuesAt.js +11 -0
- package/dist/records/commandsFor.d.ts +18 -0
- package/dist/records/commandsFor.js +65 -0
- package/dist/records/distinctValues.d.ts +16 -0
- package/dist/records/distinctValues.js +63 -0
- package/dist/records/history.d.ts +19 -0
- package/dist/records/history.js +35 -0
- package/dist/records/historyDiff.d.ts +7 -0
- package/dist/records/historyDiff.js +14 -0
- package/dist/records/lib/coerceArrays.d.ts +3 -0
- package/dist/records/lib/coerceArrays.js +26 -0
- package/dist/records/lib/compareValues.d.ts +8 -0
- package/dist/records/lib/compareValues.js +21 -0
- package/dist/records/lib/consts.d.ts +3 -0
- package/dist/records/lib/consts.js +3 -0
- package/dist/records/lib/contributedNotes.d.ts +14 -0
- package/dist/records/lib/contributedNotes.js +28 -0
- package/dist/records/lib/fmtCell.d.ts +1 -0
- package/dist/records/lib/fmtCell.js +1 -0
- package/dist/records/lib/keyBetween.d.ts +2 -0
- package/dist/records/lib/keyBetween.js +4 -0
- package/dist/records/lib/landedIn.d.ts +9 -0
- package/dist/records/lib/landedIn.js +13 -0
- package/dist/records/lib/listColumns.d.ts +3 -0
- package/dist/records/lib/listColumns.js +6 -0
- package/dist/records/lib/looseEq.d.ts +6 -0
- package/dist/records/lib/looseEq.js +6 -0
- package/dist/records/lib/matchesFilter.d.ts +2 -0
- package/dist/records/lib/matchesFilter.js +151 -0
- package/dist/records/lib/narrowRows.d.ts +16 -0
- package/dist/records/lib/narrowRows.js +79 -0
- package/dist/records/lib/parseTemporal.d.ts +9 -0
- package/dist/records/lib/parseTemporal.js +27 -0
- package/dist/records/lib/placementKey.d.ts +12 -0
- package/dist/records/lib/placementKey.js +31 -0
- package/dist/records/lib/recordResolver.d.ts +8 -0
- package/dist/records/lib/recordResolver.js +35 -0
- package/dist/records/lib/sortRows.d.ts +6 -0
- package/dist/records/lib/sortRows.js +20 -0
- package/dist/records/lib/sourceHintFor.d.ts +3 -0
- package/dist/records/lib/sourceHintFor.js +12 -0
- package/dist/records/lib/tokenValue.d.ts +3 -0
- package/dist/records/lib/tokenValue.js +17 -0
- package/dist/records/lib/trackedPaths.d.ts +14 -0
- package/dist/records/lib/trackedPaths.js +29 -0
- package/dist/records/lib/whereKeys.d.ts +8 -0
- package/dist/records/lib/whereKeys.js +2 -0
- package/dist/records/nextCommand.d.ts +4 -0
- package/dist/records/nextCommand.js +53 -0
- package/dist/records/recordsCommand.d.ts +7 -0
- package/dist/records/recordsCommand.js +291 -0
- package/dist/records-api.d.ts +42 -0
- package/dist/records-api.js +41 -0
- package/dist/repos/lib/relPath.d.ts +1 -0
- package/dist/repos/lib/relPath.js +6 -0
- package/dist/repos/lib/repoPath.d.ts +3 -0
- package/dist/repos/lib/repoPath.js +11 -0
- package/dist/repos/listRepos.d.ts +12 -0
- package/dist/repos/listRepos.js +28 -0
- package/dist/repos/materializeRepo.d.ts +9 -0
- package/dist/repos/materializeRepo.js +26 -0
- package/dist/repos/repos.d.ts +14 -0
- package/dist/repos/repos.js +17 -0
- package/dist/repos/reposCommand.d.ts +4 -0
- package/dist/repos/reposCommand.js +28 -0
- package/dist/repos/types.d.ts +29 -0
- package/dist/repos/types.js +1 -0
- package/dist/runtime/consts.d.ts +12 -0
- package/dist/runtime/consts.js +12 -0
- package/dist/runtime/exportsFacts.d.ts +17 -0
- package/dist/runtime/exportsFacts.js +10 -0
- package/dist/runtime/loadDescriptors.d.ts +8 -0
- package/dist/runtime/loadDescriptors.js +46 -0
- package/dist/runtime/runtime.d.ts +35 -0
- package/dist/runtime/runtime.js +66 -0
- package/dist/runtime/sourceRoots.d.ts +10 -0
- package/dist/runtime/sourceRoots.js +22 -0
- package/dist/scripts/migrate-descriptors-v2.js +1248 -0
- package/dist/scripts/migrate-stubs.js +170 -0
- package/dist/setup/consts.d.ts +2 -0
- package/dist/setup/consts.js +2 -0
- package/dist/setup/fillInputs.d.ts +28 -0
- package/dist/setup/fillInputs.js +142 -0
- package/dist/setup/fold.d.ts +6 -0
- package/dist/setup/fold.js +30 -0
- package/dist/setup/lib/consent.d.ts +9 -0
- package/dist/setup/lib/consent.js +14 -0
- package/dist/setup/lib/env-write.d.ts +6 -0
- package/dist/setup/lib/env-write.js +10 -0
- package/dist/setup/lib/envSpans.d.ts +17 -0
- package/dist/setup/lib/envSpans.js +27 -0
- package/dist/setup/lib/fingerprint.d.ts +2 -0
- package/dist/setup/lib/fingerprint.js +21 -0
- package/dist/setup/lib/gitExposure.d.ts +8 -0
- package/dist/setup/lib/gitExposure.js +50 -0
- package/dist/setup/lib/judgeEnvAction.d.ts +25 -0
- package/dist/setup/lib/judgeEnvAction.js +60 -0
- package/dist/setup/lib/leftoverTemps.d.ts +2 -0
- package/dist/setup/lib/leftoverTemps.js +15 -0
- package/dist/setup/lib/redact.d.ts +7 -0
- package/dist/setup/lib/redact.js +28 -0
- package/dist/setup/lib/secretPathProblem.d.ts +2 -0
- package/dist/setup/lib/secretPathProblem.js +16 -0
- package/dist/setup/lib/setEnvValues.d.ts +12 -0
- package/dist/setup/lib/setEnvValues.js +57 -0
- package/dist/setup/lib/setup-contract.d.ts +5 -0
- package/dist/setup/lib/setup-contract.js +2 -0
- package/dist/setup/lib/validateEnvAction.d.ts +16 -0
- package/dist/setup/lib/validateEnvAction.js +25 -0
- package/dist/setup/lib/writeEnvAtomic.d.ts +7 -0
- package/dist/setup/lib/writeEnvAtomic.js +60 -0
- package/dist/setup/parseAllow.d.ts +8 -0
- package/dist/setup/parseAllow.js +20 -0
- package/dist/setup/parseInputFlags.d.ts +3 -0
- package/dist/setup/parseInputFlags.js +17 -0
- package/dist/setup/printUnitResults.d.ts +3 -0
- package/dist/setup/printUnitResults.js +23 -0
- package/dist/setup/renderStatusLines.d.ts +2 -0
- package/dist/setup/renderStatusLines.js +14 -0
- package/dist/setup/runUnit.d.ts +21 -0
- package/dist/setup/runUnit.js +204 -0
- package/dist/setup/safeInspect.d.ts +7 -0
- package/dist/setup/safeInspect.js +28 -0
- package/dist/setup/setup.d.ts +14 -0
- package/dist/setup/setup.js +28 -0
- package/dist/setup/setupAndCommit.d.ts +28 -0
- package/dist/setup/setupAndCommit.js +103 -0
- package/dist/setup/statusLines.d.ts +6 -0
- package/dist/setup/statusLines.js +90 -0
- package/dist/setup/ttyIO.d.ts +5 -0
- package/dist/setup/ttyIO.js +25 -0
- package/dist/setup/types.d.ts +65 -0
- package/dist/setup/types.js +1 -0
- package/dist/setup/unitEnvFor.d.ts +11 -0
- package/dist/setup/unitEnvFor.js +29 -0
- package/dist/setup/units.d.ts +4 -0
- package/dist/setup/units.js +7 -0
- package/dist/statusCommand.d.ts +2 -0
- package/dist/statusCommand.js +249 -0
- package/dist/store/Store.d.ts +561 -0
- package/dist/store/Store.js +744 -0
- package/dist/store/add.d.ts +14 -0
- package/dist/store/add.js +92 -0
- package/dist/store/addFile.d.ts +7 -0
- package/dist/store/addFile.js +43 -0
- package/dist/store/addedDates.d.ts +2 -0
- package/dist/store/addedDates.js +44 -0
- package/dist/store/createdOf.d.ts +3 -0
- package/dist/store/createdOf.js +20 -0
- package/dist/store/external.d.ts +8 -0
- package/dist/store/external.js +18 -0
- package/dist/store/findInboundRefs.d.ts +2 -0
- package/dist/store/findInboundRefs.js +13 -0
- package/dist/store/gitHead.d.ts +2 -0
- package/dist/store/gitHead.js +13 -0
- package/dist/store/ids.d.ts +2 -0
- package/dist/store/ids.js +19 -0
- package/dist/store/lib/applyMirrorEdits.d.ts +7 -0
- package/dist/store/lib/applyMirrorEdits.js +125 -0
- package/dist/store/lib/assertUnambiguous.d.ts +2 -0
- package/dist/store/lib/assertUnambiguous.js +11 -0
- package/dist/store/lib/checkRefs.d.ts +7 -0
- package/dist/store/lib/checkRefs.js +65 -0
- package/dist/store/lib/commit.d.ts +3 -0
- package/dist/store/lib/commit.js +40 -0
- package/dist/store/lib/commitIn.d.ts +3 -0
- package/dist/store/lib/commitIn.js +37 -0
- package/dist/store/lib/dirTreeStamps.d.ts +7 -0
- package/dist/store/lib/dirTreeStamps.js +33 -0
- package/dist/store/lib/filePath.d.ts +3 -0
- package/dist/store/lib/filePath.js +32 -0
- package/dist/store/lib/generateId.d.ts +4 -0
- package/dist/store/lib/generateId.js +72 -0
- package/dist/store/lib/gitDateToStamp.d.ts +6 -0
- package/dist/store/lib/gitDateToStamp.js +8 -0
- package/dist/store/lib/idsKey.d.ts +3 -0
- package/dist/store/lib/idsKey.js +23 -0
- package/dist/store/lib/indexAdd.d.ts +5 -0
- package/dist/store/lib/indexAdd.js +41 -0
- package/dist/store/lib/mirrorRemedy.d.ts +19 -0
- package/dist/store/lib/mirrorRemedy.js +24 -0
- package/dist/store/lib/moveRecord.d.ts +4 -0
- package/dist/store/lib/moveRecord.js +29 -0
- package/dist/store/lib/normalizeRecord.d.ts +2 -0
- package/dist/store/lib/normalizeRecord.js +28 -0
- package/dist/store/lib/normalizeTemporal.d.ts +10 -0
- package/dist/store/lib/normalizeTemporal.js +38 -0
- package/dist/store/lib/pathAt.d.ts +3 -0
- package/dist/store/lib/pathAt.js +29 -0
- package/dist/store/lib/placedChildrenIn.d.ts +8 -0
- package/dist/store/lib/placedChildrenIn.js +18 -0
- package/dist/store/lib/placementOfFile.d.ts +11 -0
- package/dist/store/lib/placementOfFile.js +20 -0
- package/dist/store/lib/pruneEmptyDirs.d.ts +8 -0
- package/dist/store/lib/pruneEmptyDirs.js +20 -0
- package/dist/store/lib/qualifyBareRefs.d.ts +3 -0
- package/dist/store/lib/qualifyBareRefs.js +16 -0
- package/dist/store/lib/recordFileName.d.ts +3 -0
- package/dist/store/lib/recordFileName.js +6 -0
- package/dist/store/lib/refuseDuplicateValues.d.ts +3 -0
- package/dist/store/lib/refuseDuplicateValues.js +16 -0
- package/dist/store/lib/refuseEngineWrites.d.ts +3 -0
- package/dist/store/lib/refuseEngineWrites.js +12 -0
- package/dist/store/lib/refuseMirrorWrites.d.ts +2 -0
- package/dist/store/lib/refuseMirrorWrites.js +8 -0
- package/dist/store/lib/snapshot.d.ts +17 -0
- package/dist/store/lib/snapshot.js +60 -0
- package/dist/store/lib/validate.d.ts +6 -0
- package/dist/store/lib/validate.js +33 -0
- package/dist/store/lib/walkIds.d.ts +3 -0
- package/dist/store/lib/walkIds.js +54 -0
- package/dist/store/lib/walkRoot.d.ts +3 -0
- package/dist/store/lib/walkRoot.js +24 -0
- package/dist/store/lib/writableDescriptor.d.ts +3 -0
- package/dist/store/lib/writableDescriptor.js +15 -0
- package/dist/store/recordFiles.d.ts +2 -0
- package/dist/store/recordFiles.js +27 -0
- package/dist/store/recordRoot.d.ts +3 -0
- package/dist/store/recordRoot.js +26 -0
- package/dist/store/relocate.d.ts +9 -0
- package/dist/store/relocate.js +52 -0
- package/dist/store/relocatePlan.d.ts +5 -0
- package/dist/store/relocatePlan.js +79 -0
- package/dist/store/rename.d.ts +8 -0
- package/dist/store/rename.js +95 -0
- package/dist/store/revert.d.ts +7 -0
- package/dist/store/revert.js +86 -0
- package/dist/store/rewriteRefsBatch.d.ts +3 -0
- package/dist/store/rewriteRefsBatch.js +142 -0
- package/dist/store/rm.d.ts +7 -0
- package/dist/store/rm.js +187 -0
- package/dist/store/set.d.ts +6 -0
- package/dist/store/set.js +80 -0
- package/dist/store/types.d.ts +40 -0
- package/dist/store/types.js +1 -0
- package/dist/store/vouched.d.ts +13 -0
- package/dist/store/vouched.js +31 -0
- package/dist/store/withWriteLock.d.ts +2 -0
- package/dist/store/withWriteLock.js +40 -0
- package/dist/store/writeLockPath.d.ts +2 -0
- package/dist/store/writeLockPath.js +20 -0
- package/dist/targetCommand.d.ts +2 -0
- package/dist/targetCommand.js +45 -0
- package/dist/testing.d.ts +23 -0
- package/dist/testing.js +85 -0
- package/dist/types.d.ts +699 -0
- package/dist/types.js +1 -0
- package/dist/ui-views/lib/assignPath.d.ts +17 -0
- package/dist/ui-views/lib/assignPath.js +34 -0
- package/dist/ui-views/lib/assignViewValue.d.ts +5 -0
- package/dist/ui-views/lib/assignViewValue.js +9 -0
- package/dist/ui-views/lib/consts.d.ts +21 -0
- package/dist/ui-views/lib/consts.js +27 -0
- package/dist/ui-views/lib/parseViewValue.d.ts +6 -0
- package/dist/ui-views/lib/parseViewValue.js +50 -0
- package/dist/ui-views/lib/viewOverlayOf.d.ts +2 -0
- package/dist/ui-views/lib/viewOverlayOf.js +19 -0
- package/dist/ui-views/moveUiView.d.ts +31 -0
- package/dist/ui-views/moveUiView.js +56 -0
- package/dist/ui-views/removeUiView.d.ts +6 -0
- package/dist/ui-views/removeUiView.js +17 -0
- package/dist/ui-views/saveUiView.d.ts +25 -0
- package/dist/ui-views/saveUiView.js +80 -0
- package/dist/ui-views/uiViewsCommand.d.ts +4 -0
- package/dist/ui-views/uiViewsCommand.js +118 -0
- package/dist/update/parseUpdateArgs.d.ts +9 -0
- package/dist/update/parseUpdateArgs.js +32 -0
- package/dist/update/update.d.ts +7 -0
- package/dist/update/update.js +57 -0
- package/dist/update/updateModules.d.ts +19 -0
- package/dist/update/updateModules.js +221 -0
- package/dist/update-setup.d.ts +1 -0
- package/dist/update-setup.js +14 -0
- package/dist/usage.d.ts +1 -0
- package/dist/usage.js +281 -0
- package/dist/workspace/commitByRepo.d.ts +4 -0
- package/dist/workspace/commitByRepo.js +51 -0
- package/dist/workspace/declaredGitModules.d.ts +51 -0
- package/dist/workspace/declaredGitModules.js +89 -0
- package/dist/workspace/discoverModules.d.ts +23 -0
- package/dist/workspace/discoverModules.js +123 -0
- package/dist/workspace/envContext.d.ts +3 -0
- package/dist/workspace/envContext.js +11 -0
- package/dist/workspace/findWorkspace.d.ts +2 -0
- package/dist/workspace/findWorkspace.js +49 -0
- package/dist/workspace/layerEntries.d.ts +16 -0
- package/dist/workspace/layerEntries.js +36 -0
- package/dist/workspace/lib/aheadCount.d.ts +6 -0
- package/dist/workspace/lib/aheadCount.js +29 -0
- package/dist/workspace/lib/assertCommentsKept.d.ts +16 -0
- package/dist/workspace/lib/assertCommentsKept.js +27 -0
- package/dist/workspace/lib/isTracked.d.ts +2 -0
- package/dist/workspace/lib/isTracked.js +14 -0
- package/dist/workspace/lib/shortHead.d.ts +1 -0
- package/dist/workspace/lib/shortHead.js +10 -0
- package/dist/workspace/moduleRows.d.ts +7 -0
- package/dist/workspace/moduleRows.js +9 -0
- package/dist/workspace/navFragments.d.ts +54 -0
- package/dist/workspace/navFragments.js +223 -0
- package/dist/workspace/parseEnvValues.d.ts +1 -0
- package/dist/workspace/parseEnvValues.js +13 -0
- package/dist/workspace/renderTemplate.d.ts +2 -0
- package/dist/workspace/renderTemplate.js +26 -0
- package/dist/workspace/reportCommits.d.ts +10 -0
- package/dist/workspace/reportCommits.js +18 -0
- package/dist/workspace/types.d.ts +90 -0
- package/dist/workspace/types.js +1 -0
- package/dist/workspace/writeGated.d.ts +9 -0
- package/dist/workspace/writeGated.js +128 -0
- package/package.json +45 -22
- package/skills/using-dreamteamer/SKILL.md +1 -1
- package/skills/using-dreamteamer/references/collections.md +1 -1
- package/skills/using-dreamteamer/references/skills.md +7 -0
- package/skills/using-dreamteamer/references/writing-a-module.md +14 -0
- package/scripts/migrate-descriptors-v2.mjs +0 -795
- package/scripts/migrate-stubs.mjs +0 -98
- package/src/api.d.ts +0 -154
- package/src/api.js +0 -109
- package/src/check-alone.js +0 -171
- package/src/check.js +0 -427
- package/src/checkout.js +0 -705
- package/src/cli.js +0 -1000
- package/src/collections-cli.js +0 -1352
- package/src/commit.js +0 -611
- package/src/compile-collections.js +0 -481
- package/src/compile.js +0 -1511
- package/src/descriptor-v2.js +0 -167
- package/src/descriptor.js +0 -99
- package/src/doctor.js +0 -69
- package/src/env-vars.js +0 -59
- package/src/env-write.js +0 -162
- package/src/events.js +0 -204
- package/src/exports-cli.js +0 -91
- package/src/exports.js +0 -162
- package/src/extensions.js +0 -228
- package/src/field-values.js +0 -70
- package/src/fields.js +0 -255
- package/src/filter.js +0 -154
- package/src/fractional-index.js +0 -44
- package/src/harnesses.js +0 -649
- package/src/history.js +0 -90
- package/src/init.js +0 -473
- package/src/install-modules.js +0 -450
- package/src/namespace.js +0 -215
- package/src/nav-fragments.js +0 -190
- package/src/nav.js +0 -185
- package/src/placement.js +0 -219
- package/src/presentation.js +0 -182
- package/src/record-commands.js +0 -94
- package/src/records-api.d.ts +0 -210
- package/src/records-api.js +0 -41
- package/src/records.js +0 -109
- package/src/ref.js +0 -39
- package/src/relations.js +0 -62
- package/src/runtime.js +0 -160
- package/src/scaffold-templates.js +0 -85
- package/src/schema-ops.js +0 -2959
- package/src/semver.js +0 -36
- package/src/setup-contract.js +0 -101
- package/src/setup.js +0 -518
- package/src/store.js +0 -1964
- package/src/template.js +0 -201
- package/src/temporal.js +0 -157
- package/src/testing.d.ts +0 -29
- package/src/testing.js +0 -86
- package/src/unread-data.js +0 -74
- package/src/update-setup.js +0 -22
- package/src/update.js +0 -139
- package/src/views.js +0 -206
- package/src/workspace.js +0 -253
- package/src/yaml.js +0 -251
package/src/store.js
DELETED
|
@@ -1,1964 +0,0 @@
|
|
|
1
|
-
// the validating store — every tooling write goes through here:
|
|
2
|
-
// parse → coerce → defaults → validate (HARD: rejected before disk) →
|
|
3
|
-
// atomic write → one git commit. direct file edits stay first-class and are
|
|
4
|
-
// covered by `check` after the fact.
|
|
5
|
-
import { execFileSync } from 'node:child_process';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import Ajv from 'ajv';
|
|
9
|
-
import addFormats from 'ajv-formats';
|
|
10
|
-
import { dump, writeSource } from './yaml.js';
|
|
11
|
-
import { generateId } from './template.js';
|
|
12
|
-
import { parseRecord, parseRecordText, patternRe, fmtAjvError, unknownFields, walk, EXT, assertSafeId, idFromRecordPath, MAX_RECORD_BYTES } from './records.js';
|
|
13
|
-
import { normalizeRecord, normalizeTemporal } from './temporal.js';
|
|
14
|
-
import { NO_RUNTIME, sourceHint, loadDescriptors, runtimeDir, namespaces as compiledNamespaces, sourceRoots as compiledSourceRoots, exportsFacts } from './runtime.js';
|
|
15
|
-
import { EXPORTS_FILE, readExports, exportsContext, sees } from './exports.js';
|
|
16
|
-
import { parseRef } from './namespace.js';
|
|
17
|
-
import { relationsOf, expectedMirrors } from './relations.js';
|
|
18
|
-
import { placementOf, placedRecords, rootRecords, placedRoot, placementOfFile, ownerIdOf, symlinkBelow, dirTreeStamps, isNested, parentOfNestedId, localOfNestedId } from './placement.js';
|
|
19
|
-
import { pathToRecord } from './events.js';
|
|
20
|
-
import { commitArg } from './history.js';
|
|
21
|
-
|
|
22
|
-
import { storageOf, fieldsOf, targetsOf, isSoft, jsonSchemaOf, unresolvedPeersOf, bodyFieldOf, idsOf } from './descriptor.js';
|
|
23
|
-
// git calls whose failure we CATCH must not print git's own error: execFileSync forwards the
|
|
24
|
-
// child's stderr to ours unless told otherwise, so a handled "not a git repository" still
|
|
25
|
-
// reached the user's terminal. stdout stays piped because we read it.
|
|
26
|
-
const QUIET = ['ignore', 'pipe', 'ignore'];
|
|
27
|
-
|
|
28
|
-
export class Store {
|
|
29
|
-
constructor({ root, pkg }) {
|
|
30
|
-
this.root = root;
|
|
31
|
-
this.runtime = runtimeDir(root);
|
|
32
|
-
// Committing is POLICY, not durability — a write is on disk either way. Default OFF:
|
|
33
|
-
// `dt commit` is what publishes. `"auto-commit": true` restores the old behaviour of one
|
|
34
|
-
// commit per mutation.
|
|
35
|
-
this.autoCommit = (pkg ?? readPkg(root)).dreamteamer?.auto_commit === true;
|
|
36
|
-
this.ajv = new Ajv({ allErrors: true, strict: false, useDefaults: true, coerceTypes: 'array' });
|
|
37
|
-
addFormats(this.ajv);
|
|
38
|
-
this.ajv.addFormat('markdown', true);
|
|
39
|
-
this._idsCache = new Map(); // collection -> { key, ids } (see ids())
|
|
40
|
-
this._duplicates = new Map(); // placed collection -> id -> [files], refreshed by every walk (see assertUnambiguous)
|
|
41
|
-
this._head = undefined; // memoized `git rev-parse HEAD` (see gitHead())
|
|
42
|
-
const descriptors = loadDescriptors(root);
|
|
43
|
-
if (!descriptors) throw new Error(NO_RUNTIME);
|
|
44
|
-
this.descriptors = descriptors;
|
|
45
|
-
// The closed set every reference is split against (see src/namespace.js). Read once per Store:
|
|
46
|
-
// it is compile output, and a Store is already rebuilt whenever the runtime changes.
|
|
47
|
-
this.namespaces = compiledNamespaces(root);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
descriptor(collection) {
|
|
51
|
-
const d = this.descriptors.get(collection);
|
|
52
|
-
if (!d) throw new Error(`unknown collection "${collection}" (known: ${[...this.descriptors.keys()].join(', ')})`);
|
|
53
|
-
return d;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// data/state collections are writable through the store; runtime-based (knowhow/meta)
|
|
57
|
-
// entities are edited as SOURCES + compile — refuse politely.
|
|
58
|
-
writableDescriptor(collection) {
|
|
59
|
-
const d = this.descriptor(collection);
|
|
60
|
-
if (storageOf(d).runtime) {
|
|
61
|
-
// Two different runtime shapes, and pointing at the wrong one is worse than saying
|
|
62
|
-
// nothing: a STAGED kind (skills, commands, ui-views…) really does have a source file
|
|
63
|
-
// under `modules/<module>/<kind>/`, while a PROJECTED one (modules) has no such folder
|
|
64
|
-
// and never should — its source is the module's package.json. `x-source` says which,
|
|
65
|
-
// stated as data on the descriptor so the store never has to know what a module is.
|
|
66
|
-
const from = sourceHint(d);
|
|
67
|
-
throw new Error(`"${collection}" records are compiled sources — edit ${from} and run \`dreamteamer compile\``);
|
|
68
|
-
}
|
|
69
|
-
return d;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Can the store rewrite this collection's records AT ALL? The two shapes it cannot are the same
|
|
73
|
-
// pair `applyMirrorEdits` bails on: a runtime-based record is a build artifact under
|
|
74
|
-
// `.dreamteamer/` whose source lives elsewhere, and a `format: binary` record's bytes ARE the record
|
|
75
|
-
// — `serialize` has no branch for it, so a write would replace an SVG with frontmatter. A
|
|
76
|
-
// predicate rather than a throw, because the callers that need this are CHOOSING a path (rm's
|
|
77
|
-
// set-null falls back to restrict) rather than refusing a request.
|
|
78
|
-
canRewrite(collection) {
|
|
79
|
-
const d = this.descriptors.get(collection);
|
|
80
|
-
return !!d && !storageOf(d).runtime && storageOf(d).format !== 'binary';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Relations, decoded ONCE per Store — the same reasoning as `namespaces` in the constructor: this
|
|
84
|
-
// is compile output, and a Store is already rebuilt whenever the runtime changes.
|
|
85
|
-
relations() { return (this._relations ??= relationsOf(this.descriptors)); }
|
|
86
|
-
|
|
87
|
-
// A generated mirror sits on the TARGET's schema, so it looks like any other field to whoever
|
|
88
|
-
// holds the descriptor — and `readOnly` is documentation, not a gate: ajv does not enforce it.
|
|
89
|
-
// Left alone, a hand-set mirror is a value the engine recomputes from the owning side, and the
|
|
90
|
-
// two disagree silently. Refuse instead, and name the write that WOULD have worked: "this field
|
|
91
|
-
// is generated" without the owning side is a dead end.
|
|
92
|
-
refuseMirrorWrites(collection, id, changed) {
|
|
93
|
-
const relations = this.relations();
|
|
94
|
-
for (const key of changed) {
|
|
95
|
-
const r = relations.find((rel) => rel.target === collection && rel.mirror === key);
|
|
96
|
-
if (r) throw new Error(`${key} is generated from ${r.owner}.${r.field} — set that instead: dreamteamer set ${r.owner}/<id> ${r.field}=${collection}/${id ?? '<id>'} — nothing was written.`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ---- descriptor v2: the fields the engine writes, and values that must be unique ----------
|
|
101
|
-
// Read from `compiled.fields`, the resolved v2 field list — the first reader of it in the store.
|
|
102
|
-
// A collection compiled from a v1 source has no `compiled` block, and none of this applies to it.
|
|
103
|
-
|
|
104
|
-
/** `derived` (stored, engine-written: `created`) and `virtual` (computed on read: `id`,
|
|
105
|
-
* `last_modified`) fields are refused from every writer, naming which they are. */
|
|
106
|
-
refuseEngineWrites(d, changed) {
|
|
107
|
-
const fields = d.compiled?.fields;
|
|
108
|
-
if (!fields) return;
|
|
109
|
-
for (const key of changed) {
|
|
110
|
-
const f = fields[key];
|
|
111
|
-
if (f?.derived) throw new Error(`${key} is written by the engine${key === 'created' ? ' (stamped when the record is added)' : ''} — nothing was written.`);
|
|
112
|
-
if (f?.virtual) throw new Error(`${key} is not stored — it is computed when the record is read — nothing was written.`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** `unique: true` on a scalar field: no two records of the collection may hold one value. Null and
|
|
117
|
-
* absent never claim. Only the keys being written are asked, so an unrelated edit to a record
|
|
118
|
-
* that already shares a value is not where that conflict is reported — `check` is. */
|
|
119
|
-
refuseDuplicateValues(d, collection, id, fields, keys) {
|
|
120
|
-
const unique = Object.entries(d.compiled?.fields ?? {}).filter(([k, f]) => f.unique && !f.many && keys.includes(k));
|
|
121
|
-
if (!unique.length) return;
|
|
122
|
-
for (const { id: other, fields: of } of this.readAll(collection)) {
|
|
123
|
-
if (other === id) continue;
|
|
124
|
-
for (const [k] of unique) {
|
|
125
|
-
const v = fields[k];
|
|
126
|
-
if (v === undefined || v === null || v === '') continue;
|
|
127
|
-
if (of[k] === v) throw new Error(`${k}: "${v}" is already taken by ${collection}/${other} (unique) — nothing was written.`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/** Mirror maintenance for ONE owner-record write: rewrites every TARGET whose mirror has to change
|
|
133
|
-
* so it says what `after` implies, and hands back those files plus the undo that puts them back.
|
|
134
|
-
* The values written are exactly what `expectedMirrors` computes, which is what `check` compares
|
|
135
|
-
* against — the two read the same relation rows, so they cannot disagree about what a mirror holds.
|
|
136
|
-
*
|
|
137
|
-
* Runs INSIDE withWriteLock, after the owner file is on disk. Nothing is validated here: an attach
|
|
138
|
-
* was proved by `checkRefs` before the lock — to exist, or to be external (vouched for by an exports
|
|
139
|
-
* manifest, no record here to mirror onto) — and a detach is removal, which cannot dangle.
|
|
140
|
-
*
|
|
141
|
-
* ⚠ ALL-OR-NOTHING, by its own hand. The one refusal it can raise (a unique owner) is discoverable only
|
|
142
|
-
* ON a target, i.e. partway through a loop that may already have rewritten other targets — so a
|
|
143
|
-
* throw undoes its own work before it propagates, and the caller is left with exactly one thing to
|
|
144
|
-
* roll back: the owner write.
|
|
145
|
-
*
|
|
146
|
-
* @returns {{files: string[], undo: () => void}} */
|
|
147
|
-
applyMirrorEdits(d, id, before, after, ownerFile = null) {
|
|
148
|
-
const self = `${d.name}/${id}`;
|
|
149
|
-
// ⚠ `before` comes straight off DISK while `after` has been through validate(), which qualifies
|
|
150
|
-
// bare refs — so diffing them as written strings read `meeting: standup` (hand-edited, or
|
|
151
|
-
// written before namespaces) as a detach of "standup", which parses as nothing and is skipped,
|
|
152
|
-
// plus an attach of "meetings/standup". The old target kept its link forever and a GREEN
|
|
153
|
-
// `dt set` was what created the staleness. Qualify a COPY: qualifyBareRefs mutates, and
|
|
154
|
-
// `before` is the caller's live record.
|
|
155
|
-
const prior = before ? { ...before } : null;
|
|
156
|
-
if (prior) this.qualifyBareRefs(d, prior);
|
|
157
|
-
const files = [];
|
|
158
|
-
const undos = [];
|
|
159
|
-
// a COPY before reversing: `undo` is handed to `commit`, and an in-place reverse would make a
|
|
160
|
-
// second call replay the writes forwards rather than unwind them.
|
|
161
|
-
const rollback = () => { for (const u of [...undos].reverse()) u(); };
|
|
162
|
-
const toArr = (v) => (v == null ? [] : Array.isArray(v) ? v : [v]);
|
|
163
|
-
// A mirror is kept between records of ONE repo. An owner in this workspace naming a target a
|
|
164
|
-
// layer holds would write into the layer's clone a link that does not exist when that clone is
|
|
165
|
-
// opened as its own workspace — its `check` would strip it, ours would put it back. So the edit
|
|
166
|
-
// below skips a target in another repo, and `check` expects mirrors per repo for the same reason.
|
|
167
|
-
// `ownerFile` comes from the caller, which just wrote or read it — asking the index here would
|
|
168
|
-
// re-walk the collection on every write, the quadratic shape `_indexAdd` exists to prevent.
|
|
169
|
-
const ownerRepo = this.repoOfFile(d, ownerFile ?? this.ids(d.name).get(id) ?? this.dir(d));
|
|
170
|
-
try {
|
|
171
|
-
// EVERY row whose owner is this collection, never the first match: a union FK
|
|
172
|
-
// (`type: [a, b]`) decodes to one relation row PER TARGET, all sharing one owner
|
|
173
|
-
// field, and each row maintains only the refs naming its own target — which is what the
|
|
174
|
-
// `parsed.collection` guard in `touch` enforces. Finding one row would maintain one member
|
|
175
|
-
// of the union and silently leave the others stale.
|
|
176
|
-
for (const rel of this.relations()) {
|
|
177
|
-
if (rel.owner !== d.name) continue;
|
|
178
|
-
const was = new Set(toArr(prior?.[rel.field]));
|
|
179
|
-
const now = new Set(toArr(after?.[rel.field]));
|
|
180
|
-
const touch = (ref, fn) => {
|
|
181
|
-
const parsed = parseRef(ref, this.namespaces);
|
|
182
|
-
if (!parsed || parsed.collection !== rel.target) return; // malformed, or another union member — not this row's business
|
|
183
|
-
// TWO TARGETS THAT CANNOT HOLD A MIRROR, and compile refuses both (see stampMirror).
|
|
184
|
-
// This is the belt to that brace, because getting it wrong DESTROYS bytes rather than
|
|
185
|
-
// merely mis-linking. `writableDescriptor` first: a runtime-based target's records are
|
|
186
|
-
// compiled from sources, and writing one means editing a build artifact under
|
|
187
|
-
// `.dreamteamer/` that is gitignored and gone at the next compile — refuse, loudly.
|
|
188
|
-
const td = this.writableDescriptor(rel.target);
|
|
189
|
-
// A `format: binary` record's bytes ARE the record: `read` derives its fields and
|
|
190
|
-
// `serialize` has no branch for it, so this line would replace an SVG with frontmatter.
|
|
191
|
-
// BAIL rather than throw — an unwritten mirror is a `check` violation someone can act
|
|
192
|
-
// on; overwritten bytes are simply gone.
|
|
193
|
-
if (storageOf(td).format === 'binary') return;
|
|
194
|
-
// A DETACH can name a target that is already gone: the owner outlived it (a `--force`
|
|
195
|
-
// rm), and its FK is the dangling reference `check` reports. There is no mirror left
|
|
196
|
-
// to edit and `read` would throw, turning someone else's stale data into a refusal of
|
|
197
|
-
// this write. An attach lands here missing only when checkRefs accepted it as external
|
|
198
|
-
// (an exports manifest vouches for it): nothing here holds it, so there is no mirror to write.
|
|
199
|
-
// A target whose env-pointed root cannot render here is unread: no mirror either.
|
|
200
|
-
if (storageOf(td).unavailable || !this.ids(rel.target).has(parsed.id)) return;
|
|
201
|
-
// another repo answers: no mirror there (see above) — mirrors stay per repo
|
|
202
|
-
const file = this.mirrorFileFor(rel.target, parsed.id, ownerRepo);
|
|
203
|
-
if (!file) return;
|
|
204
|
-
const fields = parseRecord(file, td, bodyField(td));
|
|
205
|
-
const previous = fs.readFileSync(file, 'utf8');
|
|
206
|
-
fn(fields, parsed.id);
|
|
207
|
-
atomicWrite(file, serialize(td, fields));
|
|
208
|
-
this._idsCache.delete(rel.target); // every mutation drops the memo, exactly as the verbs do for their own collection
|
|
209
|
-
files.push(file);
|
|
210
|
-
undos.push(() => atomicWrite(file, previous));
|
|
211
|
-
};
|
|
212
|
-
for (const ref of [...was].filter((x) => !now.has(x))) touch(ref, (f) => {
|
|
213
|
-
// scoped to SELF: a unique mirror naming someone else belongs to that someone else,
|
|
214
|
-
// and a list mirror holds every other owner's claim alongside this one.
|
|
215
|
-
if (rel.unique) { if (f[rel.mirror] === self) delete f[rel.mirror]; }
|
|
216
|
-
else f[rel.mirror] = toArr(f[rel.mirror]).filter((x) => x !== self);
|
|
217
|
-
// the last element takes the KEY with it. `[]` and absent read the same to `check`,
|
|
218
|
-
// but only absent is what the record looks like before anything ever attached to it,
|
|
219
|
-
// and a file accumulating empty keys is derived state leaking into the source.
|
|
220
|
-
if (Array.isArray(f[rel.mirror]) && f[rel.mirror].length === 0) delete f[rel.mirror];
|
|
221
|
-
});
|
|
222
|
-
for (const ref of [...now].filter((x) => !was.has(x))) touch(ref, (f, tid) => {
|
|
223
|
-
if (rel.unique) {
|
|
224
|
-
// The FK is one-to-one, so the mirror is a SCALAR and physically cannot hold a
|
|
225
|
-
// second claimant. Refusing here rather than overwriting is what keeps the owning
|
|
226
|
-
// side the truth: the alternative silently unlinks whoever got there first.
|
|
227
|
-
if (f[rel.mirror] && f[rel.mirror] !== self) {
|
|
228
|
-
throw new Error(`${rel.field}: ${rel.target}/${tid} already has a ${rel.mirror} (${f[rel.mirror]}) — the reference is unique — nothing was written.\n if that claim is STALE, dreamteamer relations rebuild ${rel.target} recomputes it from the owning side.`);
|
|
229
|
-
}
|
|
230
|
-
f[rel.mirror] = self;
|
|
231
|
-
} else {
|
|
232
|
-
// Sorted, because `expectedMirrors` sorts and `check` compares against it. Deduped,
|
|
233
|
-
// because `was`/`now` are compared as written STRINGS: a hand-edited bare FK is
|
|
234
|
-
// qualified on its way through validate(), so an untouched link reads as a detach of
|
|
235
|
-
// `standup` plus an attach of `meetings/standup` and the mirror would grow a second
|
|
236
|
-
// copy of self.
|
|
237
|
-
f[rel.mirror] = [...new Set([...toArr(f[rel.mirror]), self])].sort();
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
} catch (e) {
|
|
242
|
-
rollback();
|
|
243
|
-
throw e;
|
|
244
|
-
}
|
|
245
|
-
return { files, undo: rollback };
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/** The collection's OWN folder. For a collection stored under another (`storage.under`) this is
|
|
249
|
-
* the FALLBACK root — where a record with no owner lives — and not an enumeration of where its
|
|
250
|
-
* records are: that is `ids()`, and the directories git has to be asked about are `recordDirs`. */
|
|
251
|
-
dir(d) {
|
|
252
|
-
return path.resolve(storageOf(d).runtime ? this.runtime : this.root, this.rootPath(d));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** The write root's path as compile resolved it — absolute for an env-pointed root outside the
|
|
256
|
-
* workspace, which is why every root is `path.resolve`d and never `path.join`ed. ⚠ An env-pointed
|
|
257
|
-
* root that could NOT render on this machine refuses HERE, at the first verb that would touch it:
|
|
258
|
-
* the alternative was reading and writing a literal `${env:NAME}/` folder with every verb saying ✔. */
|
|
259
|
-
rootPath(d) {
|
|
260
|
-
const s = storageOf(d);
|
|
261
|
-
if (s.unavailable) throw new Error(`collection "${d.name}" keeps its records at ${s.path}, which cannot render on this machine — ${s.unavailable}. Set it in .env and run dreamteamer compile; nothing was read or written.`);
|
|
262
|
-
return s.path;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/** The parent collection's folder, for a collection stored under one. */
|
|
266
|
-
parentDir(d) {
|
|
267
|
-
return this.dir(this.descriptor(placementOf(d).collection));
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/** Every directory a record of `d` can sit in: its own root, plus the parent collection's root when
|
|
271
|
-
* it is stored under one. What `commit` scopes `git status` to and what a surface asks git about. */
|
|
272
|
-
recordDirs(d) {
|
|
273
|
-
const own = placementOf(d) ? [this.dir(d), this.parentDir(d)] : [this.dir(d)];
|
|
274
|
-
return [...own, ...this.rootsOf(d).slice(1).map((r) => r.abs)];
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/** Every root a record of `d` can be READ from, write root first, then each record layer — another
|
|
278
|
-
* workspace cloned under git_modules/ whose manifest entry lists this collection. */
|
|
279
|
-
rootsOf(d) {
|
|
280
|
-
this.rootPath(d); // the refusal, before any root is resolved
|
|
281
|
-
return storageOf(d).roots.map((r) => ({ ...r, abs: path.resolve(storageOf(d).runtime ? this.runtime : this.root, r.path) }));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/** Does a record layer contribute to `d`? Such a collection is indexed across every root. */
|
|
285
|
-
layered(d) { return storageOf(d).layers.length > 0; }
|
|
286
|
-
|
|
287
|
-
/** The file an owner in `ownerRepo` keeps the mirror of `collection/id` in: the record that answers
|
|
288
|
-
* the id when it sits in that repo, else null (the id is another repo's, and mirrors stay per repo). The one place the choice is made — the mirror
|
|
289
|
-
* pass writes it and rm's guard credits it, so the two cannot disagree. */
|
|
290
|
-
mirrorFileFor(collection, id, ownerRepo) {
|
|
291
|
-
const d = this.descriptor(collection);
|
|
292
|
-
const answering = this.ids(collection).get(id);
|
|
293
|
-
if (!answering) return null;
|
|
294
|
-
if (this.repoOfFile(d, answering) === ownerRepo) return answering;
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/** The layer an existing file of `d` was read from — `{ layer, path, repo, abs }` — or null for a
|
|
299
|
-
* file in the write root. What decides which repo an edit of it commits to. */
|
|
300
|
-
layerOfFile(d, file) {
|
|
301
|
-
const abs = path.resolve(file);
|
|
302
|
-
return this.rootsOf(d).slice(1).find((r) => abs.startsWith(path.resolve(r.abs) + path.sep)) ?? null;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/** The git repo that owns a file of `d`, workspace-relative: a layer's when a layer holds it. */
|
|
306
|
-
repoOfFile(d, file) { return this.layerOfFile(d, file)?.repo ?? storageOf(d).repo; }
|
|
307
|
-
|
|
308
|
-
/** WHERE a record is read from, and which repo commits it — what `dt get --json` and `dt list
|
|
309
|
-
* --json` say as `$file` and `$repo`. `file` is workspace-relative, `repo` the workspace-relative
|
|
310
|
-
* repo root (`.`, `git_modules/<clone>`); a collection kept outside every repo here (an
|
|
311
|
-
* env-pointed root) answers its absolute file and `repo: null` — it is never committed. */
|
|
312
|
-
locate(collection, id) {
|
|
313
|
-
const file = this.ids(collection).get(id);
|
|
314
|
-
if (!file) throw new Error(`${collection}/${id}: no such record`);
|
|
315
|
-
return this.locationOf(this.descriptor(collection), file);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/** `locate` for a file already in hand — one row of a listing, without a second index lookup. */
|
|
319
|
-
locationOf(d, file) {
|
|
320
|
-
if (storageOf(d).external) return { file: path.resolve(file), repo: null };
|
|
321
|
-
return { file: path.relative(this.root, file).split(path.sep).join('/'), repo: this.repoOfFile(d, file) };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/** The file a record of `d` with these `fields` belongs at. For a placed collection the owner
|
|
325
|
-
* field decides the root — the parent's folder, or the fallback root when it is empty — so a
|
|
326
|
-
* caller that has no fields (a bare id) must go through the index instead (recordRoot). */
|
|
327
|
-
filePath(d, id, ext, fields) {
|
|
328
|
-
assertSafeId(id); // never fs-join an id that can climb out of the collection
|
|
329
|
-
if (storageOf(d).shape === 'folder') {
|
|
330
|
-
if (!storageOf(d).entry) throw new Error(`collection "${d.name}" is folder-shape but declares no storage.entry`);
|
|
331
|
-
return path.join(this.dir(d), id, storageOf(d).entry);
|
|
332
|
-
}
|
|
333
|
-
if (storageOf(d).format === 'binary') {
|
|
334
|
-
// An opaque record's extension is not derivable from its id. A caller that WRITES says what
|
|
335
|
-
// it is; a caller that reads goes through the id index instead (recordRoot, below).
|
|
336
|
-
if (!ext) throw new Error(`collection "${d.name}" is \`format: binary\` — its path needs the file's extension`);
|
|
337
|
-
return path.join(this.dir(d), `${id}.${storageOf(d).suffix}.${ext}`);
|
|
338
|
-
}
|
|
339
|
-
const under = placementOf(d);
|
|
340
|
-
if (isNested(under) && fields) {
|
|
341
|
-
const parentId = ownerIdOf(fields, under, (v) => parseRef(v, this.namespaces));
|
|
342
|
-
if (parentId) {
|
|
343
|
-
if (parentOfNestedId(id) !== parentId || !id.includes('/')) throw new Error(`${d.name}/${id}: the id must begin with its ${under.parent}'s id ("${parentId}/…") — ids of ${d.name} are nested under their parent. nothing was written.`);
|
|
344
|
-
return path.join(this.rootFor(d, fields), recordFileName(d, localOfNestedId(id)));
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return path.join(this.rootFor(d, fields), recordFileName(d, id));
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/** The root a record with these fields belongs under: the owner's child folder, or the fallback. */
|
|
351
|
-
rootFor(d, fields) {
|
|
352
|
-
const under = placementOf(d);
|
|
353
|
-
if (!under || !fields) return this.dir(d);
|
|
354
|
-
const parentId = ownerIdOf(fields, under, (v) => parseRef(v, this.namespaces));
|
|
355
|
-
if (parentId) assertSafeId(parentId); // a parsed ref, but it is about to be fs-joined
|
|
356
|
-
return placedRoot(under, this.dir(d), this.parentDir(d), parentId);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
/** The root an EXISTING file of `d` sits under — the inverse of rootFor, for pruning and for the
|
|
360
|
-
* observed-vs-declared comparison. Falls back to the collection's own root for a file found
|
|
361
|
-
* under neither, which cannot happen for a file the index produced. */
|
|
362
|
-
rootOfFile(d, file) {
|
|
363
|
-
const under = placementOf(d);
|
|
364
|
-
if (!under) return this.dir(d);
|
|
365
|
-
return placementOfFile(under, file, this.dir(d), this.parentDir(d))?.root ?? this.dir(d);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// the on-disk unit of a record: its folder for folder shapes, its file otherwise
|
|
369
|
-
recordRoot(d, id) {
|
|
370
|
-
assertSafeId(id);
|
|
371
|
-
if (this.layered(d)) {
|
|
372
|
-
// a record a layer holds is wherever the index found it — its folder for a folder shape
|
|
373
|
-
const file = this.ids(d.name).get(id);
|
|
374
|
-
if (!file) throw new Error(`${d.name}/${id}: no such record`);
|
|
375
|
-
return storageOf(d).shape === 'folder' ? path.dirname(file) : file;
|
|
376
|
-
}
|
|
377
|
-
if (storageOf(d).shape === 'folder') return path.join(this.dir(d), id);
|
|
378
|
-
// Only the index knows an opaque record's extension, so the on-disk unit is looked up rather
|
|
379
|
-
// than derived. An unknown id is the caller's error either way — `read` says so first. The same
|
|
380
|
-
// goes for a placed record: which parent folder it sits in is a fact about the file, not the id.
|
|
381
|
-
if (storageOf(d).format === 'binary' || placementOf(d)) {
|
|
382
|
-
const file = this.ids(d.name).get(id);
|
|
383
|
-
if (!file) throw new Error(`${d.name}/${id}: no such record`);
|
|
384
|
-
return file;
|
|
385
|
-
}
|
|
386
|
-
return this.filePath(d, id);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Current HEAD, MEMOIZED PER STORE — one rev-parse per process rather than one per `ids()` call.
|
|
391
|
-
*
|
|
392
|
-
* ⚠ THE SUBPROCESS WAS THE COST OF THE CACHE, not of the walk it avoids. `ids()` asks this on
|
|
393
|
-
* EVERY call, hit or miss, and a `git rev-parse` is ~10ms of process spawn. Profiled on a
|
|
394
|
-
* 4,186-record workspace, a one-hop relational filter — which resolves one referenced record per
|
|
395
|
-
* row, and `read()` goes through the id index — spent 1,525ms of a 1,677ms command in this one
|
|
396
|
-
* method. Reproduced by `npm run perf` at 1/14 the scale: 300 rows, 301 spawns.
|
|
397
|
-
*
|
|
398
|
-
* ⚠ INVALIDATED BY WHATEVER RUNS `git commit` — `headMoved()`, below. It used to be dropped on
|
|
399
|
-
* the way OUT of every write lock instead, on the reasoning that everything able to move HEAD
|
|
400
|
-
* takes that lock. Two things were wrong with it. It was not TRUE — `commitPending` (`dt commit`,
|
|
401
|
-
* the verb that exists to move HEAD) takes no lock at all — and it was far too WIDE: with
|
|
402
|
-
* `auto-commit` off, which is the default, a record write moves nothing, and dropping the memo
|
|
403
|
-
* anyway cost the next `ids()` call a ~10ms subprocess to re-read a sha that had not changed. A
|
|
404
|
-
* run of 400 adds paid 400 of them: 9.9ms of the 10.7ms an add cost, measured on a generated
|
|
405
|
-
* collection. Naming the four commit sites is both narrower and more honest than naming the lock.
|
|
406
|
-
*
|
|
407
|
-
* What the memo does give up, stated rather than discovered: ANOTHER process committing during
|
|
408
|
-
* this one's lifetime no longer invalidates the id map. It costs nothing real — a commit does not
|
|
409
|
-
* change which record files exist, and one that does (a checkout, a revert) moves the collection
|
|
410
|
-
* directory's mtime, which is the other half of the key. A CLI process runs one verb, and the
|
|
411
|
-
* server already rebuilds its Store when the manifest moves.
|
|
412
|
-
*/
|
|
413
|
-
gitHead() {
|
|
414
|
-
if (this._head === undefined) {
|
|
415
|
-
try { this._head = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: this.root, stdio: QUIET }).toString().trim(); }
|
|
416
|
-
catch { this._head = 'no-git'; }
|
|
417
|
-
}
|
|
418
|
-
return this._head;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/** "This process just committed" — said by the four places that run `git commit` while a Store is
|
|
422
|
-
* alive: `commit()` below, `commitPending`, and schema-ops' two source commits. See gitHead. */
|
|
423
|
-
headMoved() { this._head = undefined; }
|
|
424
|
-
|
|
425
|
-
ids(collection) {
|
|
426
|
-
const d = this.descriptor(collection);
|
|
427
|
-
const dir = this.dir(d);
|
|
428
|
-
if (!this.recordDirs(d).some((p) => fs.existsSync(p))) return new Map();
|
|
429
|
-
// memoized per collection, keyed by (HEAD sha, collection dir mtime): every tool
|
|
430
|
-
// write commits (HEAD moves) and every store mutation clears its entry below;
|
|
431
|
-
// direct top-level edits move the dir mtime. honest gap: a DEEP direct edit that
|
|
432
|
-
// adds/removes a record without touching HEAD or the top dir mtime can serve one
|
|
433
|
-
// stale read — acceptable, tool writes always commit and `check` covers hand edits.
|
|
434
|
-
const key = this._idsKey(d);
|
|
435
|
-
const hit = this._idsCache.get(collection);
|
|
436
|
-
if (hit?.key === key) return hit.ids;
|
|
437
|
-
const ids = this._walkIds(d, dir);
|
|
438
|
-
this._idsCache.set(collection, { key, ids });
|
|
439
|
-
return ids;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/** The validity key `ids()` compares against, as its own method because `add` restates it AFTER
|
|
443
|
-
* its write — the only way an index it just extended can still be accepted by the next call.
|
|
444
|
-
* For a placed collection the PARENT root's mtime is in it too: a new parent folder is a new
|
|
445
|
-
* place records can be, and nothing under the fallback root moves when one appears. */
|
|
446
|
-
_idsKey(d) {
|
|
447
|
-
const stamp = (p) => { try { return String(fs.statSync(p).mtimeMs); } catch { return '-'; } };
|
|
448
|
-
if (!placementOf(d) && !this.layered(d)) return `${this.gitHead()}:${stamp(this.dir(d))}`;
|
|
449
|
-
// A placed collection's records sit three levels down in folders this process did not create,
|
|
450
|
-
// and another writer (an agent, the editor, a hand) adds or removes one without touching a
|
|
451
|
-
// root's own mtime — so a root-mtime key served a long-lived Store a stale index (R4). Every
|
|
452
|
-
// DIRECTORY in every root is stamped instead: O(directories), which is small, and a new or
|
|
453
|
-
// vanished folder changes the string as surely as a changed one. A LAYER is the same shape:
|
|
454
|
-
// `dt update` pulls files into it without moving this workspace's HEAD or any root's mtime.
|
|
455
|
-
const dirs = this.recordDirs(d);
|
|
456
|
-
return `${this.gitHead()}:${dirs.map(dirTreeStamps).join('|')}`;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
/** Refuse a placed write whose path crosses a symlink inside the parent collection's root — a link
|
|
460
|
-
* there points anywhere, and "inside the parent's folder" is the whole promise (R2). */
|
|
461
|
-
_assertContained(d, file) {
|
|
462
|
-
const under = placementOf(d);
|
|
463
|
-
if (!under) return;
|
|
464
|
-
const link = symlinkBelow(this.parentDir(d), file);
|
|
465
|
-
if (link) throw new Error(`${path.relative(this.root, link)} is a symlink — a placed record is written only inside its parent's real folder, never through a link. nothing was written.`);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* The id index this add invalidated, handed back with ONE MORE ENTRY rather than thrown away.
|
|
470
|
-
*
|
|
471
|
-
* ⚠ A RUN OF ADDS WAS QUADRATIC, and the walk was the smaller half of it. `add` needs the ids
|
|
472
|
-
* that already exist in order to generate one that is unique, so every add called `ids()` — which
|
|
473
|
-
* asked `git rev-parse HEAD` for its key and then re-walked the collection from disk, because the
|
|
474
|
-
* previous add had deleted the very memo it was rebuilding. Measured on a generated 400-record
|
|
475
|
-
* collection: 10.7 ms/rec, of which 9.9 ms was the subprocess (see gitHead) and 0.68 ms the
|
|
476
|
-
* walk — and the walk is the term that GROWS. An add with an explicit id, which calls neither,
|
|
477
|
-
* costs 0.18 ms. After both: 0.57 ms, one subprocess for the whole run.
|
|
478
|
-
*
|
|
479
|
-
* The entry is INSERTED IN WALK ORDER, never appended. `ids()` iteration order is what `dt list`
|
|
480
|
-
* prints when nobody passes `--sort`, so an index that ordered records differently from a cold
|
|
481
|
-
* rebuild would make that order depend on how many writes the process had done first.
|
|
482
|
-
*
|
|
483
|
-
* The honest gap it adds, beside the two `ids()` already states: the key is stated from a stat
|
|
484
|
-
* taken just AFTER this write, so a record another process dropped into the same directory in
|
|
485
|
-
* that window goes unnoticed until something else moves the mtime. Same shape and same size as
|
|
486
|
-
* the cross-process gap the memo already accepts.
|
|
487
|
-
*/
|
|
488
|
-
_indexAdd(collection, memo, id, file) {
|
|
489
|
-
// nothing was memoized before this write, or the mirror pass has already rebuilt it cold from
|
|
490
|
-
// disk — either way a walk is the current answer and this has nothing to add to it.
|
|
491
|
-
if (!memo || this._idsCache.has(collection)) return;
|
|
492
|
-
const d = this.descriptor(collection);
|
|
493
|
-
if (this.layered(d)) return; // ordered by root, then by walk — the next ids() rebuilds it across every root
|
|
494
|
-
const dir = this.dir(d);
|
|
495
|
-
// a placed collection's order is by ID (see _walkIds), so the insertion point is too
|
|
496
|
-
const byId = !!placementOf(d);
|
|
497
|
-
const isBefore = (k, v) => (byId ? id < k : beforeInWalk(path.relative(dir, file), path.relative(dir, v)));
|
|
498
|
-
const ids = new Map();
|
|
499
|
-
let placed = false;
|
|
500
|
-
for (const [k, v] of memo.ids) {
|
|
501
|
-
if (!placed && isBefore(k, v)) { ids.set(id, file); placed = true; }
|
|
502
|
-
ids.set(k, v);
|
|
503
|
-
}
|
|
504
|
-
if (!placed) ids.set(id, file);
|
|
505
|
-
this._idsCache.set(collection, { key: this._idsKey(d), ids });
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
_walkIds(d, dir) {
|
|
509
|
-
const ids = new Map();
|
|
510
|
-
if (this.layered(d)) {
|
|
511
|
-
// Across every root, write root first. FIRST claimant wins and the rest are left for `check`
|
|
512
|
-
// to report — the same rule placement follows, for the same reason: a `get` that answered
|
|
513
|
-
// from whichever layer sorted later would make the answer depend on the clone order.
|
|
514
|
-
const claims = new Map();
|
|
515
|
-
for (const root of this.rootsOf(d)) {
|
|
516
|
-
for (const [id, f] of this._walkRoot(d, root.abs)) {
|
|
517
|
-
const c = claims.get(id);
|
|
518
|
-
if (c) c.push(f); else claims.set(id, [f]);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
const dupes = new Map();
|
|
522
|
-
for (const [id, files] of claims) {
|
|
523
|
-
ids.set(id, files[0]);
|
|
524
|
-
if (files.length > 1) dupes.set(id, files);
|
|
525
|
-
}
|
|
526
|
-
this._duplicates.set(d.name, dupes);
|
|
527
|
-
return ids;
|
|
528
|
-
}
|
|
529
|
-
if (storageOf(d).shape === 'folder') {
|
|
530
|
-
for (const [id, f] of this._walkRoot(d, dir)) ids.set(id, f);
|
|
531
|
-
return ids;
|
|
532
|
-
}
|
|
533
|
-
if (placementOf(d)) {
|
|
534
|
-
// Across every root. FIRST claimant wins and the rest are left for `check` to report as
|
|
535
|
-
// duplicates — never last-one-wins, which would make `get` answer with whichever folder
|
|
536
|
-
// happened to sort later. Ordered by ID, not by where the file sits: a listing whose order
|
|
537
|
-
// changed because a record moved between two companies would be reporting placement, which
|
|
538
|
-
// is not what the reader asked.
|
|
539
|
-
const dupes = new Map();
|
|
540
|
-
for (const r of placedRecords(d, dir, this.parentDir(d))) {
|
|
541
|
-
if (!ids.has(r.id)) { ids.set(r.id, r.file); continue; }
|
|
542
|
-
dupes.set(r.id, [...(dupes.get(r.id) ?? [ids.get(r.id)]), r.file]);
|
|
543
|
-
}
|
|
544
|
-
this._duplicates.set(d.name, dupes);
|
|
545
|
-
return new Map([...ids].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
546
|
-
}
|
|
547
|
-
for (const [id, f] of this._walkRoot(d, dir)) ids.set(id, f);
|
|
548
|
-
return ids;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
/** The records of `d` under ONE root — `[id, file]` pairs, in walk order. A folder-shape record is
|
|
552
|
-
* its entry file; anything else is a file whose name parses as a record of `d`. */
|
|
553
|
-
*_walkRoot(d, root) {
|
|
554
|
-
if (!fs.existsSync(root)) return;
|
|
555
|
-
if (storageOf(d).shape === 'folder') {
|
|
556
|
-
for (const e of fs.readdirSync(root).sort()) {
|
|
557
|
-
if (e.startsWith('.')) continue;
|
|
558
|
-
const main = path.join(root, e, storageOf(d).entry ?? 'SKILL.md');
|
|
559
|
-
if (fs.existsSync(main)) yield [e, main];
|
|
560
|
-
}
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
for (const f of walk(root)) {
|
|
564
|
-
const id = idFromRecordPath(d, path.relative(root, f));
|
|
565
|
-
if (id !== null) yield [id, f];
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/** The parent record folders of a folder-shape collection that hold records of a collection
|
|
570
|
-
* stored under it — the reason `rm` and `rename` on a parent have to look inside the folder. */
|
|
571
|
-
placedChildrenIn(d, unit) {
|
|
572
|
-
const out = [];
|
|
573
|
-
if (storageOf(d).shape !== 'folder') return out;
|
|
574
|
-
for (const c of this.descriptors.values()) {
|
|
575
|
-
const under = placementOf(c);
|
|
576
|
-
if (under?.collection !== d.name) continue;
|
|
577
|
-
const n = [...rootRecords(c, path.join(unit, under.subfolder))].length;
|
|
578
|
-
if (n) out.push({ collection: c.name, under, count: n });
|
|
579
|
-
}
|
|
580
|
-
return out;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/** Drop the id memo of every collection stored under `collection` — a parent folder that moved or
|
|
584
|
-
* went carries their files with it. */
|
|
585
|
-
_dropPlacedUnder(collection) {
|
|
586
|
-
for (const c of this.descriptors.values()) if (placementOf(c)?.collection === collection) this._idsCache.delete(c.name);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Move one record file to the root its fields now say it belongs in — the ONE place a placed
|
|
591
|
-
* record changes folders. Creates the destination's parents, prunes the emptied ones up to the
|
|
592
|
-
* root it left (so a company's `meetings/` folder disappears with its last meeting), and hands
|
|
593
|
-
* back the undo. The caller has already refused an occupied destination.
|
|
594
|
-
*/
|
|
595
|
-
_moveRecord(d, from, to) {
|
|
596
|
-
try {
|
|
597
|
-
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
598
|
-
fs.renameSync(from, to);
|
|
599
|
-
} catch (e) {
|
|
600
|
-
this._pruneAround(d, to); // the folders a failed move created, and nothing more
|
|
601
|
-
throw e;
|
|
602
|
-
}
|
|
603
|
-
// The undo exists from the moment the rename has happened, and anything that fails AFTER it
|
|
604
|
-
// runs the undo before it propagates (R1b): a cleanup that threw used to leave the caller with
|
|
605
|
-
// no undo and both copies on disk. Pruning itself no longer throws (pruneEmptyDirs), so this
|
|
606
|
-
// is the belt to that brace.
|
|
607
|
-
const undo = () => {
|
|
608
|
-
fs.mkdirSync(path.dirname(from), { recursive: true });
|
|
609
|
-
fs.renameSync(to, from);
|
|
610
|
-
this._pruneAround(d, to);
|
|
611
|
-
};
|
|
612
|
-
try { this._pruneAround(d, from); } catch (e) { undo(); throw e; }
|
|
613
|
-
return undo;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/** Empty directories a placed record left behind: its date folders up to the root it sat in, and —
|
|
617
|
-
* inside a parent folder — that root itself (`northwind/meetings/`), never the parent folder and
|
|
618
|
-
* never the collection's own fallback root. */
|
|
619
|
-
_pruneAround(d, file) {
|
|
620
|
-
const under = placementOf(d);
|
|
621
|
-
const where = under ? placementOfFile(under, file, this.dir(d), this.parentDir(d)) : null;
|
|
622
|
-
const root = where?.root ?? this.dir(d);
|
|
623
|
-
pruneEmptyDirs(path.dirname(file), root);
|
|
624
|
-
if (where?.parentId) pruneEmptyDirs(root, path.join(this.parentDir(d), where.parentId));
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
/** An id no root here holds that an exports manifest vouches for (cr-dt-004): `{ label, from?, manifest }`,
|
|
628
|
-
* or null. The manifest is the referring record's repo's — `referrer` (`<collection>/<id>`), else this
|
|
629
|
-
* workspace's — and it answers only where its holder is not read here: exactly where `check` says
|
|
630
|
-
* external. A referrer this workspace does not read is refused, naming it. */
|
|
631
|
-
external(collection, id, { referrer } = {}) {
|
|
632
|
-
if (this.ids(collection).has(id)) return null;
|
|
633
|
-
let repo = null;
|
|
634
|
-
if (referrer) {
|
|
635
|
-
const r = parseRef(referrer, this.namespaces);
|
|
636
|
-
const rd = r && this.descriptors.get(r.collection);
|
|
637
|
-
const f = rd && this.ids(r.collection).get(r.id);
|
|
638
|
-
if (!f) throw new Error(`${referrer}: no such record here — a referrer is a record this workspace reads`);
|
|
639
|
-
repo = this.layerOfFile(rd, f)?.layer ?? null;
|
|
640
|
-
}
|
|
641
|
-
const v = this.vouched(collection, id, repo);
|
|
642
|
-
if (!v || v.seen) return null;
|
|
643
|
-
return { label: v.label, ...(v.from ? { from: v.from } : {}), manifest: v.manifest };
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
/** The entry the exports manifest of `repo` (a layer name; null: the write root) holds for an id —
|
|
647
|
-
* `{ label, from?, manifest, seen }`, `seen` when its holder is read here (so the entry vouches for
|
|
648
|
-
* nothing: the holder answers, and lacks it) — or null. The one reading `external` and `checkRefs`
|
|
649
|
-
* share, so a write and `check` (src/check.js checkRef) reach one verdict on identical bytes. */
|
|
650
|
-
vouched(collection, id, repo = null) {
|
|
651
|
-
const facts = exportsFacts(this.root);
|
|
652
|
-
const ctx = exportsContext({ root: this.root, descriptors: this.descriptors, own: facts.own, layers: facts.layers, dataPath: facts.data });
|
|
653
|
-
const e = readExports(ctx.rootOf(repo))?.[collection]?.[id];
|
|
654
|
-
if (!e) return null;
|
|
655
|
-
return { label: e.label, ...(e.from ? { from: e.from } : {}), manifest: path.relative(this.root, path.join(ctx.rootOf(repo), EXPORTS_FILE)), seen: sees(e, collection, ctx) };
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
read(collection, id) {
|
|
659
|
-
const d = this.descriptor(collection);
|
|
660
|
-
const file = this.ids(collection).get(id);
|
|
661
|
-
if (!file) throw new Error(`${collection}/${id}: no such record`);
|
|
662
|
-
return { fields: parseRecord(file, d, bodyField(d)), file, descriptor: d };
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
* A record's `created`, READ — never written — when the record predates the stamp.
|
|
667
|
-
* The stamp wins. Without one: the id's own date when the collection's ids are made from
|
|
668
|
-
* `created` (that date is what the stamp would have said), else the first commit holding the file,
|
|
669
|
-
* following renames, which also covers a binary record with no frontmatter. Undefined for a
|
|
670
|
-
* collection without a `created` field (a runtime kind), and for a record no commit holds yet.
|
|
671
|
-
*/
|
|
672
|
-
createdOf(collection, id, fields, file) {
|
|
673
|
-
const d = this.descriptor(collection);
|
|
674
|
-
if (!fieldsOf(d).created) return undefined;
|
|
675
|
-
if (fields?.created) return fields.created;
|
|
676
|
-
if (storageOf(d).external) return undefined; // outside every repo here: no commit ever held it
|
|
677
|
-
const from = [idsOf(d).from ?? []].flat();
|
|
678
|
-
if (/^\{\{\s*created\b/.test(String(from[0] ?? ''))) {
|
|
679
|
-
const day = /(\d{4}-\d{2}-\d{2})/.exec(id)?.[1];
|
|
680
|
-
if (day) return normalizeTemporal(day, 'date-time');
|
|
681
|
-
}
|
|
682
|
-
return this.addedDates(collection).get(path.relative(this.root, file).split(path.sep).join('/'));
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* When each file of a collection first entered history, following renames — ONE `git log` for the
|
|
687
|
-
* whole collection, cached for this Store, so a list can answer `created` for every row.
|
|
688
|
-
* @returns {Map<string, string>} root-relative path -> ISO date of the commit that added it
|
|
689
|
-
*/
|
|
690
|
-
addedDates(collection) {
|
|
691
|
-
this._addedDates ??= new Map();
|
|
692
|
-
if (this._addedDates.has(collection)) return this._addedDates.get(collection);
|
|
693
|
-
const dates = new Map();
|
|
694
|
-
const s = storageOf(this.descriptor(collection));
|
|
695
|
-
// one `git log` per REPO a root sits in — the write root's, and each record layer's clone
|
|
696
|
-
for (const root of s.roots) {
|
|
697
|
-
const repo = path.resolve(this.root, root.repo ?? '.');
|
|
698
|
-
const inRepo = (p) => path.relative(repo, path.resolve(this.root, p)).split(path.sep).join('/');
|
|
699
|
-
// every place a record of this collection can sit: its own folder, and — when it is stored under a
|
|
700
|
-
// parent — each parent record's subfolder, so a move between the two is seen as the rename it is
|
|
701
|
-
const where = [inRepo(root.path)];
|
|
702
|
-
if (!root.layer && s.under?.collection && s.under.subfolder) where.push(`:(glob)${inRepo(storageOf(this.descriptor(s.under.collection)).path)}/**/${s.under.subfolder}/**`);
|
|
703
|
-
try {
|
|
704
|
-
const out = execFileSync('git', ['log', '--reverse', '-M', '--diff-filter=AR', '--name-status', '--format=%x01%aI', '--', ...where],
|
|
705
|
-
{ cwd: repo, stdio: ['ignore', 'pipe', 'ignore'], timeout: 60_000, maxBuffer: 256 * 1024 * 1024 }).toString();
|
|
706
|
-
const key = (p) => path.relative(this.root, path.join(repo, p)).split(path.sep).join('/');
|
|
707
|
-
let at;
|
|
708
|
-
for (const line of out.split('\n')) {
|
|
709
|
-
if (line.startsWith('\x01')) { at = gitDateToStamp(line.slice(1)); continue; }
|
|
710
|
-
const [status, a, b] = line.split('\t');
|
|
711
|
-
if (status === 'A' && !dates.has(key(a))) dates.set(key(a), at);
|
|
712
|
-
else if (status?.startsWith('R') && b) { dates.set(key(b), dates.get(key(a)) ?? at); dates.delete(key(a)); }
|
|
713
|
-
}
|
|
714
|
-
} catch { /* no git, or no history yet: every date stays unknown */ }
|
|
715
|
-
}
|
|
716
|
-
this._addedDates.set(collection, dates);
|
|
717
|
-
return dates;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
// list-path reader: ONE directory walk for the whole collection (review finding 2:
|
|
721
|
-
// per-id read() re-walked the dir — O(N²) lists, 46s at 3k records).
|
|
722
|
-
*readAll(collection) {
|
|
723
|
-
const d = this.descriptor(collection);
|
|
724
|
-
const bf = bodyField(d);
|
|
725
|
-
for (const [id, file] of this.ids(collection)) {
|
|
726
|
-
yield { id, file, fields: parseRecord(file, d, bf) };
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// restore a record to its content at `hash` — validated like any other write, one commit.
|
|
731
|
-
revert(collection, id, hash) {
|
|
732
|
-
commitArg(hash);
|
|
733
|
-
const d = this.writableDescriptor(collection);
|
|
734
|
-
this.assertUnambiguous(collection, id);
|
|
735
|
-
const { fields: currentFields, file } = this.read(collection, id);
|
|
736
|
-
if (storageOf(d).external) throw new Error(`${collection}/${id} is kept under ${storageOf(d).path}, outside every git repo here — there is no revision to revert to. nothing was reverted.`);
|
|
737
|
-
// A placed record may have sat in ANOTHER parent's folder at `hash` — the move is what is being
|
|
738
|
-
// reverted — so the historical path is looked up in that commit's tree, not assumed to be today's.
|
|
739
|
-
// `<rev>:<path>` takes `/` on every OS — Windows' path.relative spells it with `\`
|
|
740
|
-
// in the repo that holds the FILE — a layer record's history is in the layer's clone
|
|
741
|
-
const fileRepo = path.resolve(this.root, this.repoOfFile(d, file));
|
|
742
|
-
const relPath = this.pathAt(d, id, hash) ?? path.relative(fileRepo, file).split(path.sep).join('/');
|
|
743
|
-
let previousContent;
|
|
744
|
-
try {
|
|
745
|
-
previousContent = execFileSync('git', ['show', '--end-of-options', `${hash}:${relPath}`], { cwd: fileRepo, stdio: QUIET }).toString();
|
|
746
|
-
} catch {
|
|
747
|
-
throw new Error(`${collection}/${id}: no content at ${hash} for ${relPath} — nothing was reverted.`);
|
|
748
|
-
}
|
|
749
|
-
const current = fs.readFileSync(file, 'utf8');
|
|
750
|
-
if (current === previousContent) return { id, reverted: false };
|
|
751
|
-
// parse + validate the historical content before it touches disk
|
|
752
|
-
const tmpFields = parseRecordText(previousContent, d, bodyField(d));
|
|
753
|
-
// Snapshot BEFORE validate(), which qualifies bare refs in place. The mirror pass has to see
|
|
754
|
-
// the record as the restored BYTES spell it — revert writes historical content verbatim, which
|
|
755
|
-
// is the whole point of a revert — because `check` re-reads that file and expects a mirror only
|
|
756
|
-
// for a ref it can parse. Qualifying `after` here would attach a mirror check then calls stale.
|
|
757
|
-
const restored = { ...tmpFields };
|
|
758
|
-
this.validate(d, tmpFields, { repo: this.layerOfFile(d, file)?.layer ?? null });
|
|
759
|
-
// Restoring an owner field restores its PLACEMENT too — the historical record lived where its
|
|
760
|
-
// historical owner put it, and writing it into whatever folder the record sits in today would
|
|
761
|
-
// leave a file `check` reports the moment it lands. Same rule as `set`: only the owner moves it.
|
|
762
|
-
this._assertContained(d, file);
|
|
763
|
-
const target = this.ownerChanged(d, currentFields, tmpFields) ? this.filePath(d, id, undefined, tmpFields) : file;
|
|
764
|
-
if (target !== file) this._assertContained(d, target);
|
|
765
|
-
if (target !== file && fs.existsSync(target)) throw new Error(`${collection}/${id}: ${path.relative(this.root, target)} already exists — nothing was reverted.`);
|
|
766
|
-
return this.withWriteLock(() => {
|
|
767
|
-
this._idsCache.delete(collection); // every mutation drops the memo — cleared even if the commit rolls back
|
|
768
|
-
let unmove = null;
|
|
769
|
-
const undo = () => { unmove?.(); atomicWrite(file, current); };
|
|
770
|
-
try {
|
|
771
|
-
atomicWrite(file, previousContent);
|
|
772
|
-
if (target !== file) unmove = this._moveRecord(d, file, target);
|
|
773
|
-
} catch (e) {
|
|
774
|
-
undo();
|
|
775
|
-
throw e;
|
|
776
|
-
}
|
|
777
|
-
// revert is SET-shaped — it changes the owner's foreign key — so the mirrors move with it.
|
|
778
|
-
// Skipping this left BOTH targets stale: the restored one never got its link back, and the
|
|
779
|
-
// abandoned one kept a link the owner no longer claims. Same ordering as `add`, see there.
|
|
780
|
-
let mirrors;
|
|
781
|
-
try {
|
|
782
|
-
mirrors = this.applyMirrorEdits(d, id, currentFields, restored, file);
|
|
783
|
-
} catch (e) {
|
|
784
|
-
undo();
|
|
785
|
-
throw e;
|
|
786
|
-
}
|
|
787
|
-
this.commit([target, ...(unmove ? [file] : []), ...mirrors.files], `dreamteamer: ${collection} revert ${id} to ${String(hash).slice(0, 7)}`, () => {
|
|
788
|
-
mirrors.undo();
|
|
789
|
-
undo();
|
|
790
|
-
}, this.repoOfFile(d, file));
|
|
791
|
-
return { id, reverted: true, hash, file: target };
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* What `relocate` would do: every record of `collection` whose file is not where the compiled
|
|
797
|
-
* descriptor says it belongs, as `{ id, from, to, why }` — plus the problems that make the plan
|
|
798
|
-
* unsafe to apply. Read-only. Two kinds of drift are recognised:
|
|
799
|
-
*
|
|
800
|
-
* - `placement`: a placed record whose folder disagrees with its owner field — hand-moved, written
|
|
801
|
-
* by an engine from before `storage.under` existed, or sitting in the fallback root after the
|
|
802
|
-
* annotation was switched on. The field is the truth; the file moves.
|
|
803
|
-
* - `shape`: a FILE record (`<id>.<suffix>.md`) at the root of a collection that is now
|
|
804
|
-
* `shape: folder` — the state a collection is in the moment its descriptor gains a folder shape so
|
|
805
|
-
* something can live inside its records. The bytes move to `<id>/<entry>`; the id is unchanged.
|
|
806
|
-
*
|
|
807
|
-
* A destination that already exists is a PROBLEM, never a silent overwrite: two files claiming one
|
|
808
|
-
* id is exactly the ambiguity `check` reports, and resolving it is a decision, not a move.
|
|
809
|
-
*/
|
|
810
|
-
relocatePlan(collection, only = null, { toRoot = false } = {}) {
|
|
811
|
-
const d = this.writableDescriptor(collection);
|
|
812
|
-
const moves = [];
|
|
813
|
-
const problems = [];
|
|
814
|
-
const rel = (p) => path.relative(this.root, p);
|
|
815
|
-
const wanted = only ? new Set(only) : null;
|
|
816
|
-
const plan = (id, from, to, why) => {
|
|
817
|
-
const link = placementOf(d) ? symlinkBelow(this.parentDir(d), to) : null;
|
|
818
|
-
if (link) problems.push(`${collection}/${id}: ${rel(to)} is behind the symlink ${rel(link)} — a placed record is never written through a link`);
|
|
819
|
-
else if (fs.existsSync(to)) problems.push(`${collection}/${id}: ${rel(from)} belongs at ${rel(to)}, which already exists — two files claim one id; remove one before relocating`);
|
|
820
|
-
else moves.push({ id, from, to, why });
|
|
821
|
-
};
|
|
822
|
-
const under = placementOf(d);
|
|
823
|
-
if (under && toRoot) {
|
|
824
|
-
// the REVERSE: every record out of its parent's folder and into the collection's own root, ids
|
|
825
|
-
// unchanged — what makes dropping or changing `storage.under` a safe two-step (see compile)
|
|
826
|
-
for (const [id, file] of this.ids(collection)) {
|
|
827
|
-
if (wanted && !wanted.has(id)) continue;
|
|
828
|
-
const to = path.join(this.dir(d), recordFileName(d, id));
|
|
829
|
-
if (to !== file) plan(id, file, to, 'to-root');
|
|
830
|
-
}
|
|
831
|
-
} else if (under) {
|
|
832
|
-
const bf = bodyField(d);
|
|
833
|
-
const parse = (v) => parseRef(v, this.namespaces);
|
|
834
|
-
for (const [id, file] of this.ids(collection)) {
|
|
835
|
-
if (wanted && !wanted.has(id)) continue;
|
|
836
|
-
const fields = parseRecord(file, d, bf);
|
|
837
|
-
this.qualifyBareRefs(d, fields);
|
|
838
|
-
// The OWNER is validated before any destination is computed (R5): a folder is never made
|
|
839
|
-
// for a parent that does not exist, and a value that is not a reference to the parent
|
|
840
|
-
// collection is a field to fix, not a place to move to. Either stops the whole plan.
|
|
841
|
-
const raw = fields[under.parent];
|
|
842
|
-
const parentId = ownerIdOf(fields, under, parse);
|
|
843
|
-
if (raw != null && raw !== '' && !parentId) { problems.push(`${collection}/${id}: ${under.parent} is "${raw}", not a reference to ${under.collection} — fix the field first`); continue; }
|
|
844
|
-
if (parentId && !this.ids(under.collection).has(parentId)) { problems.push(`${collection}/${id}: ${under.parent} is ${raw} — no such record; fix the field first (dreamteamer check names it)`); continue; }
|
|
845
|
-
const to = this.filePath(d, id, undefined, fields);
|
|
846
|
-
if (to !== file) plan(id, file, to, 'placement');
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
if (storageOf(d).shape === 'folder' && fs.existsSync(this.dir(d))) {
|
|
850
|
-
// legacy file-shape records sit at the TOP of the folder — a folder id is one segment
|
|
851
|
-
const asFile = { ...d, storage: { ...d.storage, shape: 'file' } };
|
|
852
|
-
for (const name of fs.readdirSync(this.dir(d)).sort()) {
|
|
853
|
-
const p = path.join(this.dir(d), name);
|
|
854
|
-
if (name.startsWith('.') || fs.statSync(p).isDirectory()) continue;
|
|
855
|
-
const id = idFromRecordPath(asFile, name);
|
|
856
|
-
if (id === null || (wanted && !wanted.has(id))) continue;
|
|
857
|
-
plan(id, p, path.join(this.dir(d), id, storageOf(d).entry), 'shape');
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
return { collection, moves, problems };
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* Reconcile files to the compiled descriptor — the explicit operation that turns a `check`
|
|
865
|
-
* placement report into a clean tree. Ids and references are untouched: only files move. Refuses
|
|
866
|
-
* rather than partially applies: a planned destination that exists, or a source git still has
|
|
867
|
-
* pending changes for, stops the whole plan (publish first — a move on top of an unpublished edit
|
|
868
|
-
* is two changes under one subject, and the second hides the first). A second run after success
|
|
869
|
-
* plans nothing and does nothing.
|
|
870
|
-
*/
|
|
871
|
-
relocate(collection, { only = null, dryRun = false, toRoot = false } = {}) {
|
|
872
|
-
const d = this.writableDescriptor(collection);
|
|
873
|
-
const planned = this.relocatePlan(collection, only, { toRoot });
|
|
874
|
-
// problems FIRST, moves or not: a plan with a dangling owner in it is refused whole, and a dry run
|
|
875
|
-
// of it reports the problem rather than the empty success it would otherwise read as
|
|
876
|
-
if (planned.problems.length && !dryRun) throw new Error(`relocate refused:\n ${planned.problems.join('\n ')}\nnothing was moved.`);
|
|
877
|
-
if (dryRun || !planned.moves.length) return { ...planned, applied: false };
|
|
878
|
-
const cwd = path.resolve(this.root, storageOf(d).repo);
|
|
879
|
-
const sources = planned.moves.map((m) => path.relative(cwd, m.from));
|
|
880
|
-
let dirty = '';
|
|
881
|
-
try { dirty = execFileSync('git', ['status', '--porcelain', '--', ...sources], { cwd, stdio: QUIET }).toString().trim(); } catch { /* not a git repo — nothing to protect */ }
|
|
882
|
-
if (dirty) throw new Error(`relocate refused — these records have unpublished changes, and a move on top of them would hide the edit under the move:\n${dirty.split('\n').map((l) => ` ${l}`).join('\n')}\nrun \`dreamteamer commit ${collection}\` first. nothing was moved.`);
|
|
883
|
-
return this.withWriteLock(() => {
|
|
884
|
-
this._idsCache.delete(collection);
|
|
885
|
-
this._dropPlacedUnder(collection);
|
|
886
|
-
const undos = [];
|
|
887
|
-
const rollback = () => { for (const u of [...undos].reverse()) u(); this._idsCache.delete(collection); this._dropPlacedUnder(collection); };
|
|
888
|
-
try {
|
|
889
|
-
for (const m of planned.moves) undos.push(this._moveRecord(d, m.from, m.to));
|
|
890
|
-
} catch (e) {
|
|
891
|
-
rollback();
|
|
892
|
-
throw e;
|
|
893
|
-
}
|
|
894
|
-
const files = planned.moves.flatMap((m) => [m.from, m.to]);
|
|
895
|
-
this.commit(files, `dreamteamer: ${collection} relocate ${planned.moves.length} record(s)${toRoot ? ' to root' : ''}`, rollback, storageOf(d).repo);
|
|
896
|
-
return { ...planned, applied: true };
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
// ---- validation (hard) ---------------------------------------------------
|
|
901
|
-
|
|
902
|
-
validate(d, fields, { skipRefs = false, repo = null } = {}) {
|
|
903
|
-
// hard at the tools includes UNKNOWN fields: a typo'd key must never land on disk
|
|
904
|
-
const unknown = unknownFields(d, fields);
|
|
905
|
-
if (unknown.length) throw new Error(`unknown field(s) for this collection: ${unknown.join(', ')} — nothing was written.`);
|
|
906
|
-
// BEFORE ajv, and deliberately inside validate() rather than in each verb: this is the one
|
|
907
|
-
// choke point add/set/revert all pass through, so `--starts "2026-07-28 12:00"` from a CLI
|
|
908
|
-
// session and a `datetime-local` widget's `2026-07-28T12:00` reach disk as the same
|
|
909
|
-
// canonical, offset-carrying value. ajv's `date-time` accepts exactly one spelling; without
|
|
910
|
-
// this every human-shaped input is a validation error (see src/temporal.js).
|
|
911
|
-
normalizeRecord(jsonSchemaOf(d), fields);
|
|
912
|
-
// qualifyBareRefs must ALSO run before the validator below, for the same "one choke
|
|
913
|
-
// point" reason but a different consequence: `validate(fields)` is what triggers useDefaults,
|
|
914
|
-
// materializing any schema `default:` onto `fields` for the first time — a bare value sitting
|
|
915
|
-
// in a single-target ref field's `default:` is never seen by qualifyBareRefs and would reach
|
|
916
|
-
// checkRefs unqualified, failing as malformed rather than as the dangling reference it should
|
|
917
|
-
// read as. In practice no shipped descriptor defaults a ref field, so this is latent, not hit.
|
|
918
|
-
this.qualifyBareRefs(d, fields);
|
|
919
|
-
const validate = this.ajv.compile(jsonSchemaOf(d)); // useDefaults mutates: defaults materialize
|
|
920
|
-
if (!validate(fields)) {
|
|
921
|
-
const msgs = validate.errors.map((e) => ' ' + fmtAjvError(e, fields));
|
|
922
|
-
// The remedy line, when the cause is a generated mirror — see mirrorRemedy below.
|
|
923
|
-
const remedy = mirrorRemedy(d, validate.errors.map((e) => e.instancePath.split('/')[1]));
|
|
924
|
-
throw new Error(`validation failed:\n${msgs.join('\n')}${remedy}\nnothing was written.`);
|
|
925
|
-
}
|
|
926
|
-
if (!skipRefs) this.checkRefs(d, fields, [], repo);
|
|
927
|
-
return fields;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// Bare ids are accepted on INPUT for a field whose target set has exactly one member, and
|
|
931
|
-
// qualified HERE — the same choke point that canonicalizes datetimes (normalizeRecord), for the
|
|
932
|
-
// same reason: add/set reach disk through validate(), so the file always carries the one
|
|
933
|
-
// canonical spelling. The deliberate exception is `revert`: it restores committed historical
|
|
934
|
-
// BYTES verbatim (that is the whole point of a revert), calling validate() only to prove the
|
|
935
|
-
// historical content still parses — never on the text that actually reaches atomicWrite. So a
|
|
936
|
-
// bare ref that was committed past this choke point (hand-edited, or written by an older engine)
|
|
937
|
-
// stays bare when reverted TO; `check` is what flags it, not this method. Union and '*' fields
|
|
938
|
-
// never qualify: the prefix is the only type information those values carry. A value that
|
|
939
|
-
// already parses as a ref is never rewritten — so a qualified-but-wrong id fails downstream as a
|
|
940
|
-
// precise dangling reference, not as malformed syntax. Known limit: a slash-carrying bare id
|
|
941
|
-
// (path-shaped ids) parses as a ref and is not qualified; the checkRefs error then names the
|
|
942
|
-
// misread collection.
|
|
943
|
-
qualifyBareRefs(d, fields) {
|
|
944
|
-
for (const [key, f] of Object.entries(fieldsOf(d))) {
|
|
945
|
-
const targets = targetsOf(f);
|
|
946
|
-
if (!targets || targets === '*' || targets.length !== 1) continue;
|
|
947
|
-
const raw = fields[key];
|
|
948
|
-
if (raw == null) continue;
|
|
949
|
-
const qualify = (v) =>
|
|
950
|
-
typeof v === 'string' && v !== '' && !v.startsWith('@') && !parseRef(v, this.namespaces)
|
|
951
|
-
? `${targets[0]}/${v}`
|
|
952
|
-
: v;
|
|
953
|
-
fields[key] = Array.isArray(raw) ? raw.map(qualify) : qualify(raw);
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
/** `repo` is the referring record's: the layer that holds it, null for the write root — whose exports
|
|
958
|
-
* manifest may vouch for an id no root here holds, exactly as `check` reads it. */
|
|
959
|
-
checkRefs(d, fields, prefix = [], repo = null) {
|
|
960
|
-
for (const [key, f] of Object.entries(fieldsOf(d))) {
|
|
961
|
-
const targets = targetsOf(f);
|
|
962
|
-
if (!targets) continue;
|
|
963
|
-
const raw = fields[key];
|
|
964
|
-
if (raw == null) continue;
|
|
965
|
-
for (const value of Array.isArray(raw) ? raw : [raw]) {
|
|
966
|
-
if (typeof value !== 'string' || value.startsWith('@')) continue;
|
|
967
|
-
// ONE parser for the collection/id boundary, shared with `check` and the extension —
|
|
968
|
-
// a namespace that meant one thing on write and another on read would be worse than
|
|
969
|
-
// no namespaces at all.
|
|
970
|
-
const parsed = parseRef(value, this.namespaces);
|
|
971
|
-
if (!parsed) throw new Error(`${key}: reference "${value}" is not <collection>/<id> — nothing was written.${mirrorRemedy(d, [key])}`);
|
|
972
|
-
const { collection: coll, id } = parsed;
|
|
973
|
-
if (targets !== '*' && !targets.includes(coll)) {
|
|
974
|
-
const want = targets.length === 1 ? `collection "${targets[0]}"` : `one of: ${targets.join(', ')}`;
|
|
975
|
-
throw new Error(`${key}: reference "${value}" must target ${want} — nothing was written.`);
|
|
976
|
-
}
|
|
977
|
-
// A SOFT reference resolves if the target is present and is ignored if it is absent
|
|
978
|
-
// (see ref.js). Honoured HERE as well as in `check` on purpose: the two paths reaching
|
|
979
|
-
// different verdicts on identical bytes is the divergence this validator was aligned
|
|
980
|
-
// with `check` to prevent in the first place.
|
|
981
|
-
const soft = isSoft(f);
|
|
982
|
-
if (!this.descriptors.has(coll)) {
|
|
983
|
-
// A collection the owning module DECLARED as a peer and nothing installed provides is
|
|
984
|
-
// the normal state of a module opened on its own. `check` excuses it via the same
|
|
985
|
-
// `unresolved_peers` compile stamps onto this descriptor, and this refused it — so the
|
|
986
|
-
// module could VALIDATE records it could not WRITE, and the workaround was to hand-edit
|
|
987
|
-
// the file the store exists to write. Same semantics as a soft ref ("resolve if present,
|
|
988
|
-
// ignore if absent"); the collection is absent, so the value passes through unresolved.
|
|
989
|
-
if (unresolvedPeersOf(d).includes(coll)) continue;
|
|
990
|
-
if (soft) continue;
|
|
991
|
-
throw new Error(`${key}: reference "${value}" targets unknown collection "${coll}" — nothing was written.`);
|
|
992
|
-
}
|
|
993
|
-
if (soft) continue;
|
|
994
|
-
// a collection whose env-pointed root cannot render here is unread, not empty — `check` passes it
|
|
995
|
-
if (storageOf(this.descriptors.get(coll)).unavailable) continue;
|
|
996
|
-
if (this.ids(coll).has(id)) continue;
|
|
997
|
-
// an id no root here holds, vouched for by the referring repo's exports manifest, is
|
|
998
|
-
// external (cr-dt-004) — accepted, as `check` accepts it. The manifest is read only here,
|
|
999
|
-
// on the way to a refusal, so a write naming a held id never pays for it.
|
|
1000
|
-
const v = this.vouched(coll, id, repo);
|
|
1001
|
-
if (v && !v.seen) continue;
|
|
1002
|
-
throw new Error(`${key}: dangling reference "${value}" — no such record${v ? ` (its holder ${v.from} is read here and does not have it)` : ''}. nothing was written.${mirrorRemedy(d, [key])}`);
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
// ---- verbs -----------------------------------------------------------------
|
|
1008
|
-
|
|
1009
|
-
add(collection, fields, { id: explicitId } = {}) {
|
|
1010
|
-
const d = this.writableDescriptor(collection);
|
|
1011
|
-
// before validate: a mirror value is refused on its own terms, not as a schema error
|
|
1012
|
-
this.refuseMirrorWrites(collection, null, Object.keys(fields));
|
|
1013
|
-
this.refuseEngineWrites(d, Object.keys(fields));
|
|
1014
|
-
// descriptor v2: `created` is stamped here, before the id is made, so `ids.from` can name it
|
|
1015
|
-
if (d.compiled?.fields?.created) fields.created = nowStamp();
|
|
1016
|
-
const deprecated = Object.keys(fields).filter((k) => d.compiled?.fields?.[k]?.deprecated);
|
|
1017
|
-
this.validate(d, fields);
|
|
1018
|
-
// the KEYS, not a copy of them: `generateId` iterates this once and only for a `{{ seq }}`
|
|
1019
|
-
// template, so materializing the whole id list was an O(N) allocation per add that almost
|
|
1020
|
-
// every collection threw away unread.
|
|
1021
|
-
// An id derived from a hash rather than from readable text is reported back to the caller, not
|
|
1022
|
-
// swallowed — see the `slug` filter's note. The write still happens: an id must be produced,
|
|
1023
|
-
// and refusing here would break every workspace whose values are not latin. What must not
|
|
1024
|
-
// happen is that nobody is told.
|
|
1025
|
-
let idFallback = null;
|
|
1026
|
-
const id = explicitId ?? generateId(
|
|
1027
|
-
idsOf(d).from ?? '{{ name | slug }}', fields, this.ids(collection).keys(),
|
|
1028
|
-
{ onFallback: (f) => { idFallback = f; } },
|
|
1029
|
-
);
|
|
1030
|
-
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
1031
|
-
throw new Error(`id "${id}" does not match pattern ${idsOf(d).pattern} — nothing was written.`);
|
|
1032
|
-
}
|
|
1033
|
-
// after the id is known: another root's record OF THIS ID does not take a unique value from it
|
|
1034
|
-
this.refuseDuplicateValues(d, collection, id, fields, Object.keys(fields));
|
|
1035
|
-
// The fields decide the folder for a placed collection (rootFor), and existence is asked of the
|
|
1036
|
-
// INDEX, not of one path: the same id already sitting under another parent is the duplicate
|
|
1037
|
-
// `check` would report, and refusing it here is what keeps the id unique across every root.
|
|
1038
|
-
const file = this.filePath(d, id, undefined, fields);
|
|
1039
|
-
this._assertContained(d, file);
|
|
1040
|
-
if (fs.existsSync(file) || ((placementOf(d) || this.layered(d)) && this.ids(collection).has(id))) throw new Error(`${collection}/${id} already exists — nothing was written.`);
|
|
1041
|
-
return this.withWriteLock(() => {
|
|
1042
|
-
// captured before the invalidation and handed back, one entry richer, on the success path
|
|
1043
|
-
// below — see _indexAdd for why an add that throws it away is the expensive shape.
|
|
1044
|
-
const memo = this._idsCache.get(collection);
|
|
1045
|
-
this._idsCache.delete(collection);
|
|
1046
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1047
|
-
atomicWrite(file, serialize(d, fields));
|
|
1048
|
-
// OWNER FIRST, then the mirrors, then undo the owner if they refuse. The order matters: the
|
|
1049
|
-
// mirror pass reads targets through `ids()`, and a relation whose target IS this collection
|
|
1050
|
-
// (a record linking to its own kind) has to be able to see the record it is attaching. The
|
|
1051
|
-
// alternative — a dry pass that computes the edits without writing them — is the same loop
|
|
1052
|
-
// twice to save one `rmSync`, and two copies of it is how the two would drift apart.
|
|
1053
|
-
let mirrors;
|
|
1054
|
-
try {
|
|
1055
|
-
mirrors = this.applyMirrorEdits(d, id, null, fields, file);
|
|
1056
|
-
} catch (e) {
|
|
1057
|
-
fs.rmSync(file, { force: true });
|
|
1058
|
-
this._pruneAround(d, file);
|
|
1059
|
-
// ⚠ AND THE MEMO, or the removal is only half done. applyMirrorEdits reads targets through
|
|
1060
|
-
// `ids()`, so a relation whose target is this same collection re-cached it WITH the record
|
|
1061
|
-
// just written — and the memo key (HEAD + the collection's TOP directory mtime) does not
|
|
1062
|
-
// move for a record created and removed inside an existing sub-directory. This Store then
|
|
1063
|
-
// lists an id that is not on disk, and the next write's checkRefs accepts a reference to
|
|
1064
|
-
// it: a verb reporting success and landing a dangling ref.
|
|
1065
|
-
this._idsCache.delete(collection);
|
|
1066
|
-
throw e; // applyMirrorEdits already undid its own partial work — "nothing was written" is true again
|
|
1067
|
-
}
|
|
1068
|
-
// ONE commit, owner and mirrors together: a commit where only half a relation moved is a
|
|
1069
|
-
// history that never held a consistent workspace.
|
|
1070
|
-
this.commit([file, ...mirrors.files], `dreamteamer: ${collection} add ${id}`, () => {
|
|
1071
|
-
mirrors.undo();
|
|
1072
|
-
fs.rmSync(file, { force: true });
|
|
1073
|
-
this._pruneAround(d, file);
|
|
1074
|
-
this._idsCache.delete(collection); // same phantom as the catch above — see the note there
|
|
1075
|
-
}, storageOf(d).repo);
|
|
1076
|
-
// LAST, after the commit: the key it is re-stated under carries the sha, and `commit` moves it
|
|
1077
|
-
this._indexAdd(collection, memo, id, file);
|
|
1078
|
-
return { id, file, idFallback, ...(deprecated.length && { deprecated }) };
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
/** Import a file AS a record. There are no fields to validate and nothing to serialize, which is
|
|
1083
|
-
* why this is a sibling of add() rather than a branch inside it — the two share their last three
|
|
1084
|
-
* lines and nothing else. */
|
|
1085
|
-
addFile(collection, id, srcPath, { force = false } = {}) {
|
|
1086
|
-
const d = this.writableDescriptor(collection);
|
|
1087
|
-
if (storageOf(d).format !== 'binary') throw new Error(`"${collection}" is not a \`format: binary\` collection — add its records with --<field> values, not --from`);
|
|
1088
|
-
assertSafeId(id);
|
|
1089
|
-
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(id)) {
|
|
1090
|
-
throw new Error(`id "${id}" does not match pattern ${idsOf(d).pattern} — nothing was written.`);
|
|
1091
|
-
}
|
|
1092
|
-
const ext = path.extname(srcPath).slice(1).toLowerCase();
|
|
1093
|
-
if (!ext) throw new Error(`${srcPath} has no extension — a file record is named by one. Nothing was written.`);
|
|
1094
|
-
const allowed = storageOf(d).accept;
|
|
1095
|
-
if (allowed && !allowed.includes(ext)) throw new Error(`"${collection}" does not accept .${ext} — its declared extensions are ${allowed.join(', ')}. Nothing was written.`);
|
|
1096
|
-
const size = fs.statSync(srcPath).size;
|
|
1097
|
-
const max = storageOf(d).max_bytes ?? MAX_RECORD_BYTES;
|
|
1098
|
-
if (size > max) throw new Error(`${srcPath} is ${size} bytes, over "${collection}"'s max_bytes of ${max} — a record is a small file. Nothing was written.`);
|
|
1099
|
-
const existing = this.ids(collection).get(id);
|
|
1100
|
-
if (existing && !force) throw new Error(`${collection}/${id} already exists — pass --force to replace it. Nothing was written.`);
|
|
1101
|
-
const file = this.filePath(d, id, ext);
|
|
1102
|
-
return this.withWriteLock(() => {
|
|
1103
|
-
this._idsCache.delete(collection);
|
|
1104
|
-
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1105
|
-
// A replacement whose extension changed would otherwise leave its predecessor behind, and
|
|
1106
|
-
// two files under one id is the ambiguity `check` reports. One id is one file.
|
|
1107
|
-
const stale = existing && existing !== file ? existing : null;
|
|
1108
|
-
const restore = snapshot([file, ...(stale ? [stale] : [])]);
|
|
1109
|
-
if (stale) fs.rmSync(stale, { force: true });
|
|
1110
|
-
fs.copyFileSync(srcPath, file);
|
|
1111
|
-
this.commit([file, ...(stale ? [stale] : [])], `dreamteamer: ${collection} add ${id}`, restore, storageOf(d).repo);
|
|
1112
|
-
return { id, file };
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
set(collection, id, changes) {
|
|
1117
|
-
const d = this.writableDescriptor(collection);
|
|
1118
|
-
// first: on a file record every field is read from the file, so the answer is the replacement
|
|
1119
|
-
if (storageOf(d).format === 'binary') {
|
|
1120
|
-
throw new Error(`${collection}/${id} is a file record — its fields are derived from the file, so there is nothing to set. Replace it with \`dreamteamer add ${collection} ${id} --from <path> --force\`.`);
|
|
1121
|
-
}
|
|
1122
|
-
this.refuseMirrorWrites(collection, id, Object.keys(changes));
|
|
1123
|
-
this.refuseEngineWrites(d, Object.keys(changes));
|
|
1124
|
-
this.assertUnambiguous(collection, id);
|
|
1125
|
-
const { fields, file } = this.read(collection, id);
|
|
1126
|
-
const nestedUnder = placementOf(d);
|
|
1127
|
-
if (isNested(nestedUnder) && Object.hasOwn(changes, nestedUnder.parent) && changes[nestedUnder.parent] !== fields[nestedUnder.parent]) {
|
|
1128
|
-
throw new Error(`${collection}/${id}: ids of ${collection} begin with their ${nestedUnder.parent}'s id, so changing ${nestedUnder.parent} changes the id — rename it instead: dreamteamer rename ${collection}/${id} <new parent id>/${localOfNestedId(id)}. nothing was written.`);
|
|
1129
|
-
}
|
|
1130
|
-
const previous = fs.readFileSync(file, 'utf8');
|
|
1131
|
-
const next = { ...fields, ...changes };
|
|
1132
|
-
for (const [k, v] of Object.entries(changes)) if (v === null || v === '') delete next[k];
|
|
1133
|
-
this.validate(d, next, { repo: this.layerOfFile(d, file)?.layer ?? null });
|
|
1134
|
-
this.refuseDuplicateValues(d, collection, id, next, Object.keys(changes));
|
|
1135
|
-
// A placed record FOLLOWS ITS OWNER FIELD: changing it moves the file to the new parent's folder
|
|
1136
|
-
// (or back to the fallback root) in this same write, id unchanged. Only a change to THAT field
|
|
1137
|
-
// moves anything — a record found in the wrong folder stays there when some other field is
|
|
1138
|
-
// edited, and `check` keeps reporting the mismatch until `relocate` is asked. Moving it as a
|
|
1139
|
-
// side effect of an unrelated edit would make a rename of a meeting relocate a file nobody
|
|
1140
|
-
// mentioned, in a commit whose subject says otherwise.
|
|
1141
|
-
this._assertContained(d, file); // the existing file, not only a new destination (R2b)
|
|
1142
|
-
const target = this.ownerChanged(d, fields, next) ? this.filePath(d, id, undefined, next) : file;
|
|
1143
|
-
if (target !== file) this._assertContained(d, target);
|
|
1144
|
-
if (target !== file && fs.existsSync(target)) throw new Error(`${collection}/${id}: ${path.relative(this.root, target)} already exists — nothing was written.`);
|
|
1145
|
-
return this.withWriteLock(() => {
|
|
1146
|
-
this._idsCache.delete(collection);
|
|
1147
|
-
// ONE rollback boundary for the bytes, the move and the mirrors (R1): the field write used to
|
|
1148
|
-
// sit before the move and outside any try, so a rename refused by the filesystem left a file
|
|
1149
|
-
// in the OLD folder saying it belonged to the NEW owner — a record `check` reports and a
|
|
1150
|
-
// verb that threw. Whatever fails, `undo` puts the original bytes back where they were.
|
|
1151
|
-
let unmove = null;
|
|
1152
|
-
const undo = () => { unmove?.(); atomicWrite(file, previous); };
|
|
1153
|
-
try {
|
|
1154
|
-
atomicWrite(file, serialize(d, next, previous));
|
|
1155
|
-
if (target !== file) unmove = this._moveRecord(d, file, target);
|
|
1156
|
-
} catch (e) {
|
|
1157
|
-
undo();
|
|
1158
|
-
throw e;
|
|
1159
|
-
}
|
|
1160
|
-
// `fields` is the record as it was ON DISK and `next` as it will be, which is exactly the
|
|
1161
|
-
// before/after pair a mirror edit is: an FK that moved detaches from the old target and
|
|
1162
|
-
// attaches to the new one, in this same write. Same ordering as `add` — see the note there.
|
|
1163
|
-
let mirrors;
|
|
1164
|
-
try {
|
|
1165
|
-
mirrors = this.applyMirrorEdits(d, id, fields, next, file);
|
|
1166
|
-
} catch (e) {
|
|
1167
|
-
undo();
|
|
1168
|
-
throw e;
|
|
1169
|
-
}
|
|
1170
|
-
// both paths of a move, so a commit stages the deletion and the addition together
|
|
1171
|
-
this.commit([target, ...(unmove ? [file] : []), ...mirrors.files], `dreamteamer: ${collection} set ${id}`, () => {
|
|
1172
|
-
mirrors.undo();
|
|
1173
|
-
undo();
|
|
1174
|
-
}, this.repoOfFile(d, file));
|
|
1175
|
-
return { id, file: target };
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
/** Where a placed record's file was at `hash`, workspace-relative — or null when the commit holds no
|
|
1180
|
-
* file for that id (or the collection is conventional, where today's path IS the historical one).
|
|
1181
|
-
* One `git ls-tree` over the roots the collection can occupy, mapped back through the same
|
|
1182
|
-
* path→record rule `commit` and `changes` use. */
|
|
1183
|
-
pathAt(d, id, hash) {
|
|
1184
|
-
if (!placementOf(d)) return null;
|
|
1185
|
-
const cwd = path.resolve(this.root, storageOf(d).repo);
|
|
1186
|
-
const dirs = this.recordDirs(d).map((p) => path.relative(cwd, p));
|
|
1187
|
-
let out = '';
|
|
1188
|
-
try { out = execFileSync('git', ['ls-tree', '-r', '--name-only', '--end-of-options', hash, '--', ...dirs], { cwd, stdio: QUIET }).toString(); } catch { return null; }
|
|
1189
|
-
const prefix = (storageOf(d).repo) === '.' ? '' : `${storageOf(d).repo}/`;
|
|
1190
|
-
for (const p of out.split('\n').filter(Boolean)) {
|
|
1191
|
-
const rec = pathToRecord(this.descriptors, prefix + p);
|
|
1192
|
-
if (rec && rec.collection === d.name && rec.id === id) return p;
|
|
1193
|
-
}
|
|
1194
|
-
return null;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
/** Refuse to WRITE to an id that two files claim. The index keeps the first claimant so reads
|
|
1198
|
-
* still answer, but a write would land on one copy and leave the other saying something else —
|
|
1199
|
-
* the exact ambiguity `check` reports, made worse under a verb that printed ✔. */
|
|
1200
|
-
assertUnambiguous(collection, id) {
|
|
1201
|
-
const d = this.descriptor(collection);
|
|
1202
|
-
if (!placementOf(d) && !this.layered(d)) return;
|
|
1203
|
-
this.ids(collection); // ensures the duplicate memo is current
|
|
1204
|
-
const dupes = this._duplicates.get(collection)?.get(id);
|
|
1205
|
-
if (dupes) throw new Error(`${collection}/${id} is held by ${dupes.length} files — ${dupes.map((f) => path.relative(this.root, f)).join(' and ')}. Remove one before writing to it (dreamteamer check names them). nothing was written.`);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
/** Did the owner field of a placed record change between two versions of it? Compared as PARSED
|
|
1209
|
-
* owner ids, because `before` comes off disk and may spell the reference bare. */
|
|
1210
|
-
ownerChanged(d, before, after) {
|
|
1211
|
-
const under = placementOf(d);
|
|
1212
|
-
if (!under) return false;
|
|
1213
|
-
const prior = { ...before };
|
|
1214
|
-
this.qualifyBareRefs(d, prior);
|
|
1215
|
-
const parse = (v) => parseRef(v, this.namespaces);
|
|
1216
|
-
return ownerIdOf(prior, under, parse) !== ownerIdOf(after, under, parse);
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
/** Removal, against relations. `rm`'s guard is a TEXT SCAN over every record file — any file whose
|
|
1220
|
-
* bytes contain `<collection>/<id>` refuses the removal — and that was exactly right while every
|
|
1221
|
-
* inbound reference was somebody's hand-written data. It stopped being right the day the engine
|
|
1222
|
-
* started writing references of its own: the scan cannot tell a mirror it wrote from a value a
|
|
1223
|
-
* human typed, so it refused on the strength of its own bookkeeping and left `--force` — which
|
|
1224
|
-
* removes the record AND leaves the mirror pointing at nothing — as the only way through.
|
|
1225
|
-
*
|
|
1226
|
-
* So inbound references split three ways, and only the third refuses:
|
|
1227
|
-
*
|
|
1228
|
-
* MINE — the mirror entries this record's own FKs put on their targets. Detached here, through the
|
|
1229
|
-
* SAME pass add/set/revert use: `applyMirrorEdits(d, id, fields, null)` is precisely "this owner
|
|
1230
|
-
* now claims nothing", so there is one implementation of what a detach means, not two.
|
|
1231
|
-
*
|
|
1232
|
-
* THEIRS, UNDER A RULE — an owner's FK pointing AT this record where the relation declares
|
|
1233
|
-
* `x-on-delete: set-null`. The schema author has already said what should happen; do it, in this
|
|
1234
|
-
* same commit.
|
|
1235
|
-
*
|
|
1236
|
-
* THEIRS — everything else: `x-on-delete: restrict` (the default), and every prose or unmodelled
|
|
1237
|
-
* reference the scan finds. Still refused, still escapable with `--force`, which still reports how
|
|
1238
|
-
* many references it left dangling.
|
|
1239
|
-
*/
|
|
1240
|
-
rm(collection, id, { force = false } = {}) {
|
|
1241
|
-
const d = this.writableDescriptor(collection);
|
|
1242
|
-
this.assertUnambiguous(collection, id);
|
|
1243
|
-
const self = `${collection}/${id}`;
|
|
1244
|
-
const unit = this.recordRoot(d, id); // folder-shape: the whole folder goes, not just the entry file
|
|
1245
|
-
this._assertContained(d, unit);
|
|
1246
|
-
// A PARENT with records placed inside its folder is refused OUTRIGHT — `--force` included. The
|
|
1247
|
-
// folder delete below would erase every one of those records, each of them somebody's own
|
|
1248
|
-
// record with its own references, under the subject of removing one thing. There is no honest
|
|
1249
|
-
// force here: reassign them (or clear their owner) first, and the deletion is then an ordinary one.
|
|
1250
|
-
const held = this.placedChildrenIn(d, unit);
|
|
1251
|
-
if (held.length) {
|
|
1252
|
-
const lines = held.map((h) => ` ${h.count} ${h.collection} record(s) under ${h.under.subfolder}/ — dreamteamer set ${h.collection}/<id> ${h.under.parent}=<another ${collection}> (or ${h.under.parent}= to clear)`);
|
|
1253
|
-
throw new Error(`${self} holds records of other collections inside its folder:\n${lines.join('\n')}\nmove them first, then remove the ${collection}. nothing was removed.`);
|
|
1254
|
-
}
|
|
1255
|
-
// the existence check, and the FKs whose mirrors are detached below. Qualified on a COPY for the
|
|
1256
|
-
// same reason applyMirrorEdits qualifies `before`: a hand-edited or pre-namespace record can
|
|
1257
|
-
// hold `standup` where the engine writes `meetings/standup`, and a raw string compare misses it.
|
|
1258
|
-
const own = { ...this.read(collection, id).fields };
|
|
1259
|
-
this.qualifyBareRefs(d, own);
|
|
1260
|
-
const toArr = (v) => (v == null ? [] : Array.isArray(v) ? v : [v]);
|
|
1261
|
-
// `bare` is whether this field's target set has exactly one member — the only case where
|
|
1262
|
-
// qualifyBareRefs would have expanded an unqualified value, so the only case where an
|
|
1263
|
-
// unqualified value on disk can be assumed to mean this collection.
|
|
1264
|
-
const isSelf = (v, bare) => {
|
|
1265
|
-
if (typeof v !== 'string') return false;
|
|
1266
|
-
const p = parseRef(v, this.namespaces);
|
|
1267
|
-
return p ? `${p.collection}/${p.id}` === self : bare && `${collection}/${v}` === self;
|
|
1268
|
-
};
|
|
1269
|
-
|
|
1270
|
-
// ---- who points AT this record, and under what rule -------------------------------
|
|
1271
|
-
const setNullEdits = [];
|
|
1272
|
-
const restrictHits = [];
|
|
1273
|
-
for (const rel of this.relations()) {
|
|
1274
|
-
if (rel.target !== collection) continue;
|
|
1275
|
-
const targets = targetsOf(fieldsOf(this.descriptor(rel.owner))[rel.field]);
|
|
1276
|
-
const bare = Array.isArray(targets) && targets.length === 1;
|
|
1277
|
-
// An owner the store cannot REWRITE cannot be set to null — and the honest fallback is
|
|
1278
|
-
// `restrict`, not silence: refusing is a sentence someone can act on, a skipped set-null is a
|
|
1279
|
-
// dangling reference from a verb that reported success.
|
|
1280
|
-
const clearable = rel.onDelete === 'set-null' && this.canRewrite(rel.owner);
|
|
1281
|
-
for (const { id: oid, file, fields: of } of this.readAll(rel.owner)) {
|
|
1282
|
-
if (!toArr(of[rel.field]).some((v) => isSelf(v, bare))) continue;
|
|
1283
|
-
if (clearable) setNullEdits.push({ rel, oid, file, of, bare });
|
|
1284
|
-
else restrictHits.push({ ref: `${rel.owner}/${oid}`, field: rel.field, file: path.relative(this.root, file) });
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
// ---- what the text scan finds that is NOT the engine's own bookkeeping -------------
|
|
1289
|
-
// The scan is per FILE, and one file can name this record TWICE — a mirror the engine wrote, and
|
|
1290
|
-
// a wikilink somebody typed in the same record's body. So excluding a file WHOLESALE is wrong:
|
|
1291
|
-
// it drops the prose reference along with the managed one, and `check` reads frontmatter and
|
|
1292
|
-
// never prose, so the survivor dangles in silence. A file is excluded only when the edits below
|
|
1293
|
-
// account for every occurrence in it.
|
|
1294
|
-
//
|
|
1295
|
-
// Paths come through `ids()` so a planned path is the exact file the mirror pass rewrites — a
|
|
1296
|
-
// folder-shape record's ENTRY file, not its folder — which is also the shape findInboundRefs
|
|
1297
|
-
// reports. A target the mirror pass would bail on (`format: binary`, runtime-based) never received
|
|
1298
|
-
// a mirror, so nothing is planned there and a hit in it is real.
|
|
1299
|
-
const planned = new Map(); // workspace-relative path -> occurrences of `self` this write removes
|
|
1300
|
-
const plan = (file, n) => { const k = path.relative(this.root, file); planned.set(k, (planned.get(k) ?? 0) + n); };
|
|
1301
|
-
const memoized = new Set([collection]); // every collection whose id index this write invalidates
|
|
1302
|
-
for (const rel of this.relations()) {
|
|
1303
|
-
if (rel.owner !== collection || !this.canRewrite(rel.target)) continue;
|
|
1304
|
-
memoized.add(rel.target);
|
|
1305
|
-
for (const v of toArr(own[rel.field])) {
|
|
1306
|
-
const p = parseRef(v, this.namespaces);
|
|
1307
|
-
if (!p || p.collection !== rel.target) continue; // malformed, or another union member
|
|
1308
|
-
const f = this.mirrorFileFor(rel.target, p.id, this.repoOfFile(d, unit));
|
|
1309
|
-
if (f) plan(f, 1); // the one mirror entry naming this record, which the detach removes
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
// LITERALLY, not semantically. The two numbers compared below are counted in different places —
|
|
1313
|
-
// this one off parsed FIELDS, `occurrences` off the file's raw BYTES — so they have to be
|
|
1314
|
-
// counted in the same UNIT, and the unit `occurrences` can see is "the fully-qualified string
|
|
1315
|
-
// `self`, present in the text". A single-target FK is legally stored BARE (`meetings: [one]` in
|
|
1316
|
-
// a hand-authored record: the store qualifies on write, but only through its own write path),
|
|
1317
|
-
// and `isSelf` matches that by design — crediting it here would claim a removal that deletes no
|
|
1318
|
-
// text, and the slack would swallow a real, separate wikilink in the same record: rm green, link
|
|
1319
|
-
// dangling, `check` silent about it because it reads frontmatter and never prose. A bare value
|
|
1320
|
-
// is invisible to the scan on both sides, which is the consistent answer: it contributes 0 here
|
|
1321
|
-
// and 0 there, and a record holding ONLY a bare FK is never named by the scan at all.
|
|
1322
|
-
for (const { rel, file, of } of setNullEdits) {
|
|
1323
|
-
memoized.add(rel.owner);
|
|
1324
|
-
plan(file, toArr(of[rel.field]).filter((v) => v === self).length);
|
|
1325
|
-
}
|
|
1326
|
-
const occurrences = (f) => (fs.readFileSync(path.join(this.root, f), 'utf8').match(this.refRegex(self)) ?? []).length;
|
|
1327
|
-
const inbound = this.findInboundRefs(self).filter((f) => !planned.has(f) || occurrences(f) > planned.get(f));
|
|
1328
|
-
// A restrict hit the scan already named is ONE reference described twice — keep the scan's
|
|
1329
|
-
// shape, which is what this sentence has always said. What the scan misses (a bare FK, or an
|
|
1330
|
-
// owner file excluded because it also holds a mirror of ours) is named as record + field.
|
|
1331
|
-
const extraRestrict = restrictHits.filter((h) => !inbound.includes(h.file));
|
|
1332
|
-
if ((inbound.length || extraRestrict.length) && !force) {
|
|
1333
|
-
const all = [...inbound, ...extraRestrict.map((h) => `${h.file} (${h.ref}.${h.field})`)];
|
|
1334
|
-
throw new Error(`${self} is referenced by:\n${all.map((f) => ` ${f}`).join('\n')}\nfix the references or pass --force. nothing was removed.`);
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
// snapshot BEFORE the delete, or there is nothing left to read
|
|
1338
|
-
const restore = snapshot([unit]);
|
|
1339
|
-
// ⚠ THE MEMO, on the way in AND on every way back out. `ids()` keys its cache on HEAD plus the
|
|
1340
|
-
// collection's TOP directory mtime, neither of which moves for a record inside an existing
|
|
1341
|
-
// sub-directory — so an entry populated mid-write survives a rollback, and this Store then lists
|
|
1342
|
-
// an id that is not on disk (or omits one that is) for the rest of the process.
|
|
1343
|
-
const dropMemos = () => { for (const c of memoized) this._idsCache.delete(c); };
|
|
1344
|
-
return this.withWriteLock(() => {
|
|
1345
|
-
dropMemos();
|
|
1346
|
-
// MIRRORS FIRST, then the owners, then the delete. The mirror pass reads its targets through
|
|
1347
|
-
// `ids()`, and a self-referencing relation has to still see the record it is detaching from.
|
|
1348
|
-
const mirrors = this.applyMirrorEdits(d, id, own, null, unit);
|
|
1349
|
-
const nullFiles = [];
|
|
1350
|
-
const nullUndos = [];
|
|
1351
|
-
// ONE rollback for all three mutations, used by the catch below AND handed to `commit`.
|
|
1352
|
-
// Order is reverse-chronological, because one file can be written twice (a mirror detach and
|
|
1353
|
-
// then an FK clear) and undoing the earlier write first would leave the later one standing —
|
|
1354
|
-
// except `restore`, which goes LAST because its snapshot of the removed record predates
|
|
1355
|
-
// everything, and so wins over a self-referencing edit to that same file. A COPY before
|
|
1356
|
-
// reversing, exactly as applyMirrorEdits does: `undo` may be called twice.
|
|
1357
|
-
const rollback = () => {
|
|
1358
|
-
for (const u of [...nullUndos].reverse()) u();
|
|
1359
|
-
mirrors.undo();
|
|
1360
|
-
restore();
|
|
1361
|
-
dropMemos();
|
|
1362
|
-
};
|
|
1363
|
-
try {
|
|
1364
|
-
for (const { rel, oid, file, bare } of setNullEdits) {
|
|
1365
|
-
// re-read INSIDE the lock: the mirror pass above may have just rewritten this very file
|
|
1366
|
-
// (two collections can point at each other), and `previous` has to be what is on disk
|
|
1367
|
-
// NOW or the undo below would resurrect a mirror that was correctly detached.
|
|
1368
|
-
const { fields: cur, descriptor: od } = this.read(rel.owner, oid);
|
|
1369
|
-
const previous = fs.readFileSync(file, 'utf8');
|
|
1370
|
-
if (Array.isArray(cur[rel.field])) {
|
|
1371
|
-
cur[rel.field] = cur[rel.field].filter((v) => !isSelf(v, bare));
|
|
1372
|
-
// the last element takes the KEY with it — `[]` is derived state leaking into a source
|
|
1373
|
-
if (!cur[rel.field].length) delete cur[rel.field];
|
|
1374
|
-
} else {
|
|
1375
|
-
delete cur[rel.field]; // `field: null` is not a cleared reference, it is a type error
|
|
1376
|
-
}
|
|
1377
|
-
atomicWrite(file, serialize(od, cur));
|
|
1378
|
-
this._idsCache.delete(rel.owner);
|
|
1379
|
-
nullFiles.push(file);
|
|
1380
|
-
nullUndos.push(() => atomicWrite(file, previous));
|
|
1381
|
-
}
|
|
1382
|
-
// ⚠ THE DELETE IS INSIDE THE TRY, and it has to be. It used to be rm's FIRST mutation, so a
|
|
1383
|
-
// failing unlink left the tree untouched; it is now the LAST of three, and outside the
|
|
1384
|
-
// rollback an EACCES here (a read-only mount, `chflags uchg`, a folder-shape record raced
|
|
1385
|
-
// by another writer) left the record in place with a mirror already detached and an FK
|
|
1386
|
-
// already cleared — two stale records behind a verb that threw.
|
|
1387
|
-
fs.rmSync(unit, { recursive: true });
|
|
1388
|
-
// a placed record takes its emptied folders with it — a company's `meetings/` does not
|
|
1389
|
-
// outlive its last meeting; a conventional root's date folders are left as they always were
|
|
1390
|
-
if (placementOf(d)) this._pruneAround(d, unit);
|
|
1391
|
-
} catch (e) {
|
|
1392
|
-
rollback();
|
|
1393
|
-
throw e; // …and now "nothing was removed" is true of everything, not just the record
|
|
1394
|
-
}
|
|
1395
|
-
// ONE commit, the record and every reference the engine moved with it: a commit where the
|
|
1396
|
-
// target is gone but its owners still name it is a history that never held a consistent
|
|
1397
|
-
// workspace.
|
|
1398
|
-
this.commit([unit, ...mirrors.files, ...nullFiles], `dreamteamer: ${collection} rm ${id}`, rollback, this.repoOfFile(d, unit));
|
|
1399
|
-
const inboundCount = inbound.length + extraRestrict.length;
|
|
1400
|
-
return { id, inboundIgnored: force ? inboundCount : 0 };
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
rename(collection, oldId, newId) {
|
|
1405
|
-
const d = this.writableDescriptor(collection);
|
|
1406
|
-
this.assertUnambiguous(collection, oldId);
|
|
1407
|
-
this.read(collection, oldId); // existence check
|
|
1408
|
-
if (oldId === newId) return { id: newId, rewrites: 0 };
|
|
1409
|
-
if (idsOf(d).pattern && !patternRe(idsOf(d).pattern).test(newId)) {
|
|
1410
|
-
throw new Error(`id "${newId}" does not match pattern ${idsOf(d).pattern} — nothing was renamed.`);
|
|
1411
|
-
}
|
|
1412
|
-
const oldUnit = this.recordRoot(d, oldId); // folder-shape: move the WHOLE folder
|
|
1413
|
-
this._assertContained(d, oldUnit);
|
|
1414
|
-
// A rename rewrites every inbound reference — in THIS workspace. The layer's own workspace holds
|
|
1415
|
-
// references this one cannot see, and a unit moved out of the layer would land in our root
|
|
1416
|
-
// across two repos. Both are the layer's business.
|
|
1417
|
-
const inLayer = this.layerOfFile(d, oldUnit);
|
|
1418
|
-
if (inLayer) throw new Error(`${collection}/${oldId} is held by layer ${inLayer.layer} (${inLayer.path}) — a layer's record is renamed in its own workspace, never from here. nothing was renamed.`);
|
|
1419
|
-
// a placed record keeps the folder it is in: a rename changes the id, never the owner — except a
|
|
1420
|
-
// NESTED one, whose id begins with its parent's: renaming it to another parent moves it there
|
|
1421
|
-
const under = placementOf(d);
|
|
1422
|
-
const nested = isNested(under);
|
|
1423
|
-
const newParent = nested ? parentOfNestedId(newId) : null;
|
|
1424
|
-
const parentChanged = nested && newParent !== parentOfNestedId(oldId);
|
|
1425
|
-
if (nested && !newId.includes('/')) throw new Error(`${collection}/${newId}: ids of ${collection} begin with their ${under.parent}'s id — nothing was renamed.`);
|
|
1426
|
-
if (parentChanged && !this.ids(under.collection).has(newParent)) throw new Error(`${collection}/${newId}: there is no ${under.collection}/${newParent} to move it under — nothing was renamed.`);
|
|
1427
|
-
// ⚠ The destination is DERIVED, never looked up: recordRoot answers for a record that EXISTS —
|
|
1428
|
-
// from the index for a layered collection and for an opaque one — so asking it for the new id
|
|
1429
|
-
// threw "no such record" on every rename of a workspace-own record once any layer contributed
|
|
1430
|
-
// to the collection (clone on disk or not), and on every rename of a `format: binary` record.
|
|
1431
|
-
// The record is in the write root (a layer's was refused above), so its new unit is the write
|
|
1432
|
-
// root's: the folder for a folder shape, the file otherwise — keeping the extension an opaque
|
|
1433
|
-
// record carries, which only its current file name knows.
|
|
1434
|
-
const newUnit = nested
|
|
1435
|
-
? path.join(placedRoot(under, this.dir(d), this.parentDir(d), newParent), recordFileName(d, localOfNestedId(newId)))
|
|
1436
|
-
: placementOf(d) ? path.join(this.rootOfFile(d, oldUnit), recordFileName(d, newId))
|
|
1437
|
-
: storageOf(d).shape === 'folder' ? path.join(this.dir(d), newId)
|
|
1438
|
-
: storageOf(d).format === 'binary' ? path.join(this.dir(d), `${newId}.${storageOf(d).suffix}${path.extname(oldUnit)}`)
|
|
1439
|
-
: path.join(this.dir(d), recordFileName(d, newId));
|
|
1440
|
-
this._assertContained(d, newUnit);
|
|
1441
|
-
if (fs.existsSync(newUnit) || (placementOf(d) && this.ids(collection).has(newId))) throw new Error(`${collection}/${newId} already exists — nothing was renamed.`);
|
|
1442
|
-
return this.withWriteLock(() => {
|
|
1443
|
-
this._idsCache.delete(collection);
|
|
1444
|
-
// a folder-shape PARENT carries the records placed inside it along — their files move,
|
|
1445
|
-
// their ids do not, and their id memos are stale the moment the folder is
|
|
1446
|
-
this._dropPlacedUnder(collection);
|
|
1447
|
-
fs.mkdirSync(path.dirname(newUnit), { recursive: true });
|
|
1448
|
-
const oldBytes = parentChanged ? fs.readFileSync(oldUnit, 'utf8') : null;
|
|
1449
|
-
fs.renameSync(oldUnit, newUnit);
|
|
1450
|
-
// the owner field follows the id's new first segment, in the same write
|
|
1451
|
-
if (parentChanged) {
|
|
1452
|
-
const f = parseRecordText(oldBytes, d, bodyField(d));
|
|
1453
|
-
f[under.parent] = `${under.collection}/${newParent}`;
|
|
1454
|
-
atomicWrite(newUnit, serialize(d, f, oldBytes));
|
|
1455
|
-
}
|
|
1456
|
-
pruneEmptyDirs(path.dirname(oldUnit), this.rootOfFile(d, oldUnit)); // cross-partition renames leave empty date dirs
|
|
1457
|
-
// rewrite inbound references (frontmatter/structured always; prose only via wikilinks). It
|
|
1458
|
-
// snapshots what it writes as it writes it — see rewriteRefs for why the caller cannot.
|
|
1459
|
-
const { touched, rewrites, skipped, ambiguous, restore } = this.rewriteRefs(`${collection}/${oldId}`, `${collection}/${newId}`);
|
|
1460
|
-
this.commit([oldUnit, newUnit, ...touched], `dreamteamer: ${collection} rename ${oldId} → ${newId}`, () => {
|
|
1461
|
-
fs.mkdirSync(path.dirname(oldUnit), { recursive: true });
|
|
1462
|
-
fs.renameSync(newUnit, oldUnit);
|
|
1463
|
-
if (oldBytes !== null) atomicWrite(oldUnit, oldBytes);
|
|
1464
|
-
pruneEmptyDirs(path.dirname(newUnit), this.rootOfFile(d, newUnit));
|
|
1465
|
-
this._dropPlacedUnder(collection);
|
|
1466
|
-
restore();
|
|
1467
|
-
}, storageOf(d).repo);
|
|
1468
|
-
// each entry names the PAIR it came from, because a batch has more than one — see rewriteRefsBatch
|
|
1469
|
-
for (const s of skipped) {
|
|
1470
|
-
console.warn(`⚠ ${path.relative(this.root, s.file)}: ${s.count} raw-prose occurrence(s) of ${s.oldRef} left untouched — only [[wikilinks]] are maintained in bodies (decision 7)`);
|
|
1471
|
-
}
|
|
1472
|
-
for (const a of ambiguous) {
|
|
1473
|
-
console.warn(`⚠ ${path.relative(this.root, a.file)}: ${a.count} bare [[${a.base}]] wikilink(s) left untouched — ${a.claimants.join(', ')} also ends in "${a.base}", so nothing here can tell which record the link means. Rewrite by hand, or spell it [[${a.newRef}]].`);
|
|
1474
|
-
}
|
|
1475
|
-
return { id: newId, rewrites, touched: touched.length, skipped: skipped.length, ambiguous: ambiguous.length };
|
|
1476
|
-
});
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
// exact-ref matching with a boundary so contacts/jane never matches contacts/jane-doe
|
|
1480
|
-
refRegex(ref) {
|
|
1481
|
-
return new RegExp(`${escapeRe(ref)}(?![\\w/-])`, 'g');
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
/** Every record in the workspace whose id ENDS in `base`, as `<collection>/<id>`. What decides
|
|
1485
|
-
* whether a bare `[[base]]` wikilink names one thing — see rewriteRefs. Asked of the id index of
|
|
1486
|
-
* every collection rather than of a text scan, because the question is about records, not files. */
|
|
1487
|
-
basenameOwners(base) {
|
|
1488
|
-
const out = [];
|
|
1489
|
-
for (const name of this.descriptors.keys()) {
|
|
1490
|
-
for (const id of this.ids(name).keys()) if (id.split('/').pop() === base) out.push(`${name}/${id}`);
|
|
1491
|
-
}
|
|
1492
|
-
return out;
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
// ⚠ EACH FILE EXACTLY ONCE. The `modules` collection's storage.path is `modules` and
|
|
1496
|
-
// `sourceRoots()` includes the workspace root, so walking it RE-YIELDS every module source that
|
|
1497
|
-
// its own kind's walk already produced — 173 files in one real vault, every module source
|
|
1498
|
-
// among them.
|
|
1499
|
-
//
|
|
1500
|
-
// That was harmless while every rewrite was idempotent, and stopped being harmless the day
|
|
1501
|
-
// namespaces arrived: replacing `draft-docs/x` with `rnd/draft-docs/x` is NOT idempotent,
|
|
1502
|
-
// because the result still contains the pattern. A second pass wrote
|
|
1503
|
-
// `data/rnd/rnd/draft-docs/x` into module-source comments during a real migration. Dedupe HERE
|
|
1504
|
-
// rather than making each caller idempotent — `findInboundRefs` is a caller too, and its counts
|
|
1505
|
-
// were quietly doubled by the same walk.
|
|
1506
|
-
*recordFiles() {
|
|
1507
|
-
const seen = new Set();
|
|
1508
|
-
for (const d of this.descriptors.values()) {
|
|
1509
|
-
if (storageOf(d).unavailable) continue; // an env-pointed root this machine cannot render: nothing to walk
|
|
1510
|
-
// for runtime-based collections, inbound-ref surgery targets SOURCES, not the runtime
|
|
1511
|
-
// a layer's records name records of this workspace too, so a removal or a rename must see them
|
|
1512
|
-
const dirs = storageOf(d).runtime ? this.sourceRoots().map((r) => path.join(r, storageOf(d).path)) : this.rootsOf(d).map((r) => r.abs);
|
|
1513
|
-
for (const dir of dirs) {
|
|
1514
|
-
if (!fs.existsSync(dir)) continue;
|
|
1515
|
-
for (const f of walk(dir)) {
|
|
1516
|
-
const key = path.resolve(f);
|
|
1517
|
-
if (seen.has(key)) continue;
|
|
1518
|
-
seen.add(key);
|
|
1519
|
-
yield f;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
// every compiled module (review finding 10: this layer never learned decision 24 — rename
|
|
1526
|
-
// silently skipped git_modules sources), read off the manifest rather than by re-discovering
|
|
1527
|
-
// modules, which is what used to make the store import the compiler. See runtime.js.
|
|
1528
|
-
sourceRoots() {
|
|
1529
|
-
return compiledSourceRoots(this.root);
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
findInboundRefs(ref) {
|
|
1533
|
-
const re = this.refRegex(ref);
|
|
1534
|
-
const hits = [];
|
|
1535
|
-
for (const f of this.recordFiles()) {
|
|
1536
|
-
const text = fs.readFileSync(f, 'utf8');
|
|
1537
|
-
re.lastIndex = 0;
|
|
1538
|
-
if (re.test(text)) hits.push(path.relative(this.root, f));
|
|
1539
|
-
}
|
|
1540
|
-
return hits;
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
/**
|
|
1544
|
-
* decision 7 (un-parked): structured surfaces (frontmatter, yaml/json records) rewrite
|
|
1545
|
-
* unconditionally; PROSE bodies rewrite only inside `[[…]]` wikilinks — raw-text matching
|
|
1546
|
-
* corrupted look-alike URLs (review finding 4). raw body occurrences are counted and reported,
|
|
1547
|
-
* never touched.
|
|
1548
|
-
*
|
|
1549
|
-
* ⚠ A WIKILINK IS BARE MORE OFTEN THAN IT IS QUALIFIED. `[[ada]]` is what a person types and what
|
|
1550
|
-
* every wikilink editor writes; `[[people/ada]]` is the disciplined spelling. Only the qualified
|
|
1551
|
-
* form was followed, and the failure was SILENT in both directions — the link dangled, and the
|
|
1552
|
-
* skipped-prose counter matched the qualified form too, so it was not even reported as skipped.
|
|
1553
|
-
* "Wikilinks are maintained" was true of the shape nobody writes.
|
|
1554
|
-
*
|
|
1555
|
-
* So a rename that changes the BASENAME runs a second pass over bodies, and it refuses to guess:
|
|
1556
|
-
* `[[ada]]` follows the rename only when `ada` is the basename of exactly one record in the whole
|
|
1557
|
-
* workspace (`basenameOwners`, asked AFTER the move, so the renamed record is no longer among
|
|
1558
|
-
* them). When something else claims it too the link is left exactly as it is and counted into
|
|
1559
|
-
* `ambiguous`, which `rename` reports by file — an unfollowed link somebody knows about is a
|
|
1560
|
-
* different thing from one nobody does. A rename that keeps the basename (`collections rename`,
|
|
1561
|
-
* where only the collection moves) runs no bare pass at all: those links still name what they
|
|
1562
|
-
* always named.
|
|
1563
|
-
*/
|
|
1564
|
-
rewriteRefs(oldRef, newRef) {
|
|
1565
|
-
return this.rewriteRefsBatch([[oldRef, newRef]]);
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* The same rewrite, for MANY old→new pairs at once: each record file is opened ONCE and every
|
|
1570
|
-
* pair is applied to the bytes in hand, in the order given.
|
|
1571
|
-
*
|
|
1572
|
-
* ⚠ THIS IS THE WHOLE IMPLEMENTATION — `rewriteRefs` is the batch of one. A second single-pair
|
|
1573
|
-
* copy of the rules above (prose scoping, the bare-basename ambiguity test, the boundary) is
|
|
1574
|
-
* exactly the drift this method exists to avoid.
|
|
1575
|
-
*
|
|
1576
|
-
* ⚠ WHY A BATCH, MEASURED. `collections rename` called this once per record id, and walked every
|
|
1577
|
-
* record file a second time before that to snapshot them for rollback: `npm run perf --
|
|
1578
|
-
* --records=400 --filler=100` cost 410,678 reads and 6.39s for 400 ids over 504 files — ~800
|
|
1579
|
-
* passes over the same bytes to rewrite 4 references. One pass answers every pair: 1,075 and
|
|
1580
|
-
* 0.16s.
|
|
1581
|
-
*
|
|
1582
|
-
* The pre-filter is a NEGATIVE one and nothing else: a file whose text lacks the prefix every
|
|
1583
|
-
* needle starts with cannot contain any of them, so it is skipped unread-twice — but a file that
|
|
1584
|
-
* has it is still matched by the boundary-aware regexes below, never by the prefix. A prefix
|
|
1585
|
-
* match would follow `data/tasks/` in a path and `…/ledger/alpha-x` in a URL.
|
|
1586
|
-
*
|
|
1587
|
-
* ⚠ THE SNAPSHOT IS TAKEN HERE, not by the caller. `rename` used to snapshot what
|
|
1588
|
-
* `findInboundRefs` reported — the QUALIFIED occurrences — which is not the set this method
|
|
1589
|
-
* writes: a body holding only `[[ada]]` is rewritten below and was in nobody's rollback. The
|
|
1590
|
-
* bytes are already in hand at the point of the write, so this is the one place that cannot be
|
|
1591
|
-
* out of step with it — and a failure part-way through undoes what it already wrote before it
|
|
1592
|
-
* throws, so a caller's own rollback never has to guess how far it got.
|
|
1593
|
-
*
|
|
1594
|
-
* `skipped` and `ambiguous` entries carry the pair that produced them (`oldRef`/`newRef`, plus
|
|
1595
|
-
* the `base` and its `claimants`), because in a batch there is no single one to imply.
|
|
1596
|
-
*/
|
|
1597
|
-
rewriteRefsBatch(pairs) {
|
|
1598
|
-
const plans = pairs.map(([oldRef, newRef]) => {
|
|
1599
|
-
const oldBase = oldRef.split('/').pop();
|
|
1600
|
-
const newBase = newRef.split('/').pop();
|
|
1601
|
-
const bareRe = oldBase === newBase ? null : new RegExp(`\\[\\[${escapeRe(oldBase)}${ANCHOR_AND_LABEL}\\]\\]`, 'g');
|
|
1602
|
-
return {
|
|
1603
|
-
oldRef, newRef, newBase, base: oldBase, bareRe,
|
|
1604
|
-
refRe: this.refRegex(oldRef),
|
|
1605
|
-
// ⚠ `newRef` MAY END IN `oldRef` — `ledger/beta` → `finance/ledger/beta` is the ordinary
|
|
1606
|
-
// shape of `collections rename`. Every occurrence this pass has just rewritten then still
|
|
1607
|
-
// matches the old needle at a legal boundary, so the raw-prose counter reported bytes that
|
|
1608
|
-
// are already correct: a warning naming work nobody needs to do. The guard is the
|
|
1609
|
-
// `endsWith`, and the second scan only runs for the pairs that fail it.
|
|
1610
|
-
newRefRe: newRef !== oldRef && newRef.endsWith(`/${oldRef}`) ? this.refRegex(newRef) : null,
|
|
1611
|
-
wikiRe: new RegExp(`\\[\\[${escapeRe(oldRef)}${ANCHOR_AND_LABEL}\\]\\]`, 'g'),
|
|
1612
|
-
// asked of the id index, not of a text scan — and only when a bare pass can happen at all
|
|
1613
|
-
claimants: bareRe ? this.basenameOwners(oldBase) : [],
|
|
1614
|
-
};
|
|
1615
|
-
});
|
|
1616
|
-
// a bare pass matches `[[base]]`, which does NOT contain the ref — so the basename is a needle too
|
|
1617
|
-
const probe = commonPrefix(plans.flatMap((p) => (p.bareRe ? [p.oldRef, p.base] : [p.oldRef])));
|
|
1618
|
-
|
|
1619
|
-
const touched = [];
|
|
1620
|
-
const skipped = [];
|
|
1621
|
-
const ambiguous = [];
|
|
1622
|
-
const undos = [];
|
|
1623
|
-
let rewrites = 0;
|
|
1624
|
-
// a COPY before reversing, as applyMirrorEdits does: `restore` may be called twice
|
|
1625
|
-
const restore = () => { for (const u of [...undos].reverse()) u(); };
|
|
1626
|
-
try {
|
|
1627
|
-
for (const f of this.recordFiles()) {
|
|
1628
|
-
const text = fs.readFileSync(f, 'utf8');
|
|
1629
|
-
if (probe && !text.includes(probe)) continue;
|
|
1630
|
-
// prose scoping applies to EVERY .md — a frontmatter-less file is all body
|
|
1631
|
-
// (docs-audit catch: it used to fall through to raw replacement)
|
|
1632
|
-
const prose = f.endsWith('.md');
|
|
1633
|
-
const fm = prose ? /^(---\r?\n[\s\S]*?\r?\n---\r?\n?)([\s\S]*)$/.exec(text) : null;
|
|
1634
|
-
let head = prose ? (fm ? fm[1] : '') : text;
|
|
1635
|
-
let body = prose ? (fm ? fm[2] : text) : '';
|
|
1636
|
-
let count = 0;
|
|
1637
|
-
for (const p of plans) {
|
|
1638
|
-
head = head.replace(p.refRe, () => (count++, p.newRef));
|
|
1639
|
-
if (!prose) continue;
|
|
1640
|
-
// the qualified pass FIRST: it turns `[[people/ada]]` into `[[people/ada-l]]`, which the
|
|
1641
|
-
// bare pattern cannot match either before or after, so the two never see each other's work
|
|
1642
|
-
body = body.replace(p.wikiRe, (_, anchor, label) => (count++, `[[${p.newRef}${anchor ?? ''}${label ?? ''}]]`));
|
|
1643
|
-
if (p.bareRe && !p.claimants.length) body = body.replace(p.bareRe, (_, anchor, label) => (count++, `[[${p.newBase}${anchor ?? ''}${label ?? ''}]]`));
|
|
1644
|
-
else if (p.bareRe) { const n = (body.match(p.bareRe) ?? []).length; if (n) ambiguous.push({ file: f, count: n, base: p.base, claimants: p.claimants, oldRef: p.oldRef, newRef: p.newRef }); }
|
|
1645
|
-
// counted on the body this pair leaves behind, so a later pair sees what an on-disk
|
|
1646
|
-
// pass would have seen — raw prose is reported, never rewritten (decision 7)
|
|
1647
|
-
const raw = countRawOccurrences(body, p);
|
|
1648
|
-
if (raw) skipped.push({ file: f, count: raw, oldRef: p.oldRef, newRef: p.newRef });
|
|
1649
|
-
}
|
|
1650
|
-
if (count === 0) continue;
|
|
1651
|
-
rewrites += count;
|
|
1652
|
-
undos.push(() => atomicWrite(f, text));
|
|
1653
|
-
atomicWrite(f, head + body);
|
|
1654
|
-
touched.push(f);
|
|
1655
|
-
}
|
|
1656
|
-
} catch (e) {
|
|
1657
|
-
restore(); // "nothing was rewritten" stays true of a batch that died half way through it
|
|
1658
|
-
throw e;
|
|
1659
|
-
}
|
|
1660
|
-
return { touched, rewrites, skipped, ambiguous, restore };
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
/** Where the cross-process write lock lives.
|
|
1664
|
-
*
|
|
1665
|
-
* ⚠ IT BELONGS TO THE REPOSITORY, NOT TO THE CHECKOUT. What it protects is `.git/index.lock`
|
|
1666
|
-
* and `HEAD` — both of which are SHARED by every worktree of a repo, while `.dreamteamer/` is
|
|
1667
|
-
* gitignored build output that each checkout has its own copy of. A lock in the runtime folder
|
|
1668
|
-
* therefore serialized a single checkout against itself and left two worktrees of one repo free
|
|
1669
|
-
* to collide on exactly the files it exists to guard. `--git-common-dir` is the one path that
|
|
1670
|
-
* resolves to the same place from the primary and from every linked worktree.
|
|
1671
|
-
*
|
|
1672
|
-
* The runtime folder stays the fallback, because a workspace need not be a git repo at all and
|
|
1673
|
-
* a store that cannot lock is worse than one that locks narrowly. */
|
|
1674
|
-
writeLockPath() {
|
|
1675
|
-
if (this._lockPath) return this._lockPath;
|
|
1676
|
-
let dir = null;
|
|
1677
|
-
try {
|
|
1678
|
-
const common = execFileSync('git', ['rev-parse', '--git-common-dir'], { cwd: this.root, stdio: QUIET }).toString().trim();
|
|
1679
|
-
if (common) dir = path.resolve(this.root, common);
|
|
1680
|
-
} catch { /* not a git repo — fall back to the runtime folder */ }
|
|
1681
|
-
this._lockPath = path.join(dir ?? this.runtime, '.dreamteamer-write-lock');
|
|
1682
|
-
return this._lockPath;
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
// ---- write serialization + rollback (review finding 3; reinstates the v2 commit
|
|
1686
|
-
// queue idea in sync form). within ONE process Node's sync fs/exec already serializes;
|
|
1687
|
-
// the lock guards CLI-beside-server cross-process races on .git/index.lock. a commit
|
|
1688
|
-
// failure UNDOES the write, so "one mutation = one commit" fails CLOSED and
|
|
1689
|
-
// "nothing was written" stays true.
|
|
1690
|
-
withWriteLock(fn) {
|
|
1691
|
-
const lock = this.writeLockPath();
|
|
1692
|
-
fs.mkdirSync(path.dirname(lock), { recursive: true });
|
|
1693
|
-
const deadline = Date.now() + 5000;
|
|
1694
|
-
for (;;) {
|
|
1695
|
-
try { fs.mkdirSync(lock); break; } catch (e) {
|
|
1696
|
-
if (e.code !== 'EEXIST') throw e;
|
|
1697
|
-
try { if (Date.now() - fs.statSync(lock).mtimeMs > 30_000) { fs.rmdirSync(lock); continue; } } catch { /* raced the holder */ }
|
|
1698
|
-
if (Date.now() > deadline) throw new Error('another dreamteamer process holds the write lock (.dreamteamer/.write-lock) — retry, or remove it if nothing is running.');
|
|
1699
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50); // sync sleep, no busy spin
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
try {
|
|
1703
|
-
return fn();
|
|
1704
|
-
} finally {
|
|
1705
|
-
try { fs.rmdirSync(lock); } catch { /* already gone */ }
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
/** Persist, or don't — `auto-commit` decides. The files are already on disk in both cases;
|
|
1710
|
-
* this only chooses whether they are published now or by a later `dt commit`.
|
|
1711
|
-
* `repo` is the workspace-relative root of the git repo that owns them ('.' = workspace). */
|
|
1712
|
-
commit(files, subject, undo, repo = '.') {
|
|
1713
|
-
if (!this.autoCommit) return;
|
|
1714
|
-
// A file under an env-pointed root outside the workspace is outside every repo here BY DESIGN
|
|
1715
|
-
// — never handed to git, which would refuse it and roll the write back.
|
|
1716
|
-
const outside = (this._outside ??= [...this.descriptors.values()].filter((d) => storageOf(d).external).map((d) => path.resolve(this.root, storageOf(d).path) + path.sep));
|
|
1717
|
-
files = files.filter((f) => !outside.some((o) => path.resolve(f).startsWith(o)));
|
|
1718
|
-
if (!files.length) return;
|
|
1719
|
-
// ONE COMMIT PER REPO. The record's own repo is `repo`; a file a rename rewrote in a record
|
|
1720
|
-
// layer belongs to that layer's clone, so the files are grouped by the longest known repo that
|
|
1721
|
-
// holds each. A failure in a later group leaves an earlier group's commit standing — the same
|
|
1722
|
-
// per-repo truth `dt commit` prints, stated here rather than pretended away.
|
|
1723
|
-
// ⚠ A file under NO known clone is the workspace's — never the caller's repo. The fallback used
|
|
1724
|
-
// to be `repo`, so renaming a module-owned record that a workspace record named sent the
|
|
1725
|
-
// workspace's rewritten `data/tasks/…` to `git add` inside the module clone as `../../data/…`,
|
|
1726
|
-
// which git refuses, and the rename rolled back every time auto-commit was on.
|
|
1727
|
-
const repos = (this._repos ??= [...new Set([...this.descriptors.values()].flatMap((d) => storageOf(d).roots.map((r) => r.repo)))].filter((r) => r !== '.').sort((a, b) => b.length - a.length));
|
|
1728
|
-
const repoOf = (f) => { const rel = path.relative(this.root, f).split(path.sep).join('/'); return [...repos, repo].find((r) => r !== '.' && rel.startsWith(`${r}/`)) ?? '.'; };
|
|
1729
|
-
const groups = new Map();
|
|
1730
|
-
for (const f of files) { const r = repoOf(f); if (!groups.has(r)) groups.set(r, []); groups.get(r).push(f); }
|
|
1731
|
-
for (const [r, group] of groups) this._commitIn(path.resolve(this.root, r), group, subject, undo);
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
_commitIn(cwd, files, subject, undo) {
|
|
1735
|
-
const rel = files.map((f) => path.relative(cwd, f));
|
|
1736
|
-
try {
|
|
1737
|
-
// QUIET, per the rule at the top of this file: a failure we CATCH must not also print git's
|
|
1738
|
-
// own error. These three were the exception — a caught `git add` failure dumped git's raw
|
|
1739
|
-
// multi-line advice ("Another git process seems to be running…") on top of the clean message
|
|
1740
|
-
// this function throws, so the user read the scary one and not the accurate one.
|
|
1741
|
-
execFileSync('git', ['add', '--all', '--', ...rel], { cwd, stdio: QUIET });
|
|
1742
|
-
execFileSync('git', ['commit', '--quiet', '-m', subject, '--', ...rel], { cwd, stdio: QUIET });
|
|
1743
|
-
} catch (e) {
|
|
1744
|
-
try { execFileSync('git', ['reset', '--quiet', '--', ...rel], { cwd, stdio: QUIET }); } catch { /* nothing staged */ }
|
|
1745
|
-
if (undo) {
|
|
1746
|
-
try { undo(); } catch (u) {
|
|
1747
|
-
throw new Error(`git commit failed AND rollback failed (${u.message}) — inspect the working tree. original: ${e.message.split('\n')[0]}`);
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
throw new Error(`git commit failed — the write was rolled back, nothing was changed. (${e.message.split('\n')[0]})`);
|
|
1751
|
-
} finally {
|
|
1752
|
-
// ⚠ WHETHER IT LANDED OR NOT. The failure path resets the index and undoes the write, but a
|
|
1753
|
-
// commit that threw may still have created one — and a HEAD memo naming the previous sha
|
|
1754
|
-
// would keep serving id maps from before it. See gitHead.
|
|
1755
|
-
this.headMoved();
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
/** A literal, for a pattern built out of an id or a ref. */
|
|
1761
|
-
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1762
|
-
|
|
1763
|
-
/** What may sit between a wikilink's TARGET and its closing `]]`: an optional `#anchor`, then an
|
|
1764
|
-
* optional `|label`. Two capture groups, in that order, both handed back verbatim by the rewrite.
|
|
1765
|
-
*
|
|
1766
|
-
* ⚠ THE ANCHOR IS PART OF THE LINK, NOT OF THE TARGET. Both passes used to stop at the `]]` or the
|
|
1767
|
-
* `|`, so `[[id#heading]]` survived a rename of `id` untouched — the bare form silently, the
|
|
1768
|
-
* qualified form counted only as raw prose. Only the record moved; the heading inside it did not,
|
|
1769
|
-
* so the anchor rides through byte for byte, whatever is in it (a heading slug is not an id — it
|
|
1770
|
-
* holds spaces, case and punctuation). `[^\]|]` on the anchor is what keeps the two groups from
|
|
1771
|
-
* swallowing each other. */
|
|
1772
|
-
const ANCHOR_AND_LABEL = '(#[^\\]|]*)?(\\|[^\\]]*)?';
|
|
1773
|
-
|
|
1774
|
-
/** Raw occurrences of a pair's OLD ref in a body — what `rewriteRefsBatch` reports as skipped prose.
|
|
1775
|
-
* An occurrence lying INSIDE one of `newRef` is not prose that was skipped, it is the rewrite this
|
|
1776
|
-
* pass just made: `finance/ledger/beta` ends in `ledger/beta` and the boundary allows it. Only the
|
|
1777
|
-
* pairs whose new spelling ends in the old one (`p.newRefRe`) pay for the second scan. */
|
|
1778
|
-
function countRawOccurrences(body, p) {
|
|
1779
|
-
p.refRe.lastIndex = 0;
|
|
1780
|
-
if (!p.newRefRe) return (body.match(p.refRe) ?? []).length;
|
|
1781
|
-
const spans = [];
|
|
1782
|
-
p.newRefRe.lastIndex = 0;
|
|
1783
|
-
for (let m; (m = p.newRefRe.exec(body)) !== null;) spans.push([m.index, m.index + m[0].length]);
|
|
1784
|
-
let n = 0;
|
|
1785
|
-
for (let m; (m = p.refRe.exec(body)) !== null;) {
|
|
1786
|
-
const [start, end] = [m.index, m.index + m[0].length];
|
|
1787
|
-
if (!spans.some(([s, e]) => start >= s && end <= e)) n++;
|
|
1788
|
-
}
|
|
1789
|
-
return n;
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
/** The longest prefix every needle shares, or '' if they share none. Used ONLY as a negative filter
|
|
1793
|
-
* (see rewriteRefsBatch): anything containing a needle contains this, so anything without it
|
|
1794
|
-
* contains no needle — and a hit means nothing at all. */
|
|
1795
|
-
function commonPrefix(needles) {
|
|
1796
|
-
let p = needles[0] ?? '';
|
|
1797
|
-
for (const n of needles) {
|
|
1798
|
-
let i = 0;
|
|
1799
|
-
while (i < p.length && p[i] === n[i]) i++;
|
|
1800
|
-
p = p.slice(0, i);
|
|
1801
|
-
if (!p) break;
|
|
1802
|
-
}
|
|
1803
|
-
return p;
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1806
|
-
/** Is `a` yielded before `b` by `walk()`? It sorts each directory level and DESCENDS before it
|
|
1807
|
-
* yields, so the order is a segment-wise compare of the relative paths and never a plain string
|
|
1808
|
-
* one: `2026-01.entry.md` sorts before `2026/x.entry.md` as a string ('-' < '/') and after it in
|
|
1809
|
-
* the walk, because readdir meets the directory `2026` first and empties it on the way past. */
|
|
1810
|
-
function beforeInWalk(a, b) {
|
|
1811
|
-
const A = a.split(path.sep);
|
|
1812
|
-
const B = b.split(path.sep);
|
|
1813
|
-
for (let i = 0; i < Math.min(A.length, B.length); i++) if (A[i] !== B[i]) return A[i] < B[i];
|
|
1814
|
-
return A.length < B.length;
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
/**
|
|
1818
|
-
* The remedy line for a refusal whose cause is a GENERATED MIRROR — `dreamteamer relations rebuild
|
|
1819
|
-
* <collection>`, the same repair `check`'s staleness message names, and for the same reason: a
|
|
1820
|
-
* mirror's value is derived state the engine wrote, not the caller's to edit.
|
|
1821
|
-
*
|
|
1822
|
-
* Without it, a legacy duplicate in a mirror array made an ORDINARY write to an unrelated field on
|
|
1823
|
-
* the same record fail with somebody else's bookkeeping and no way out:
|
|
1824
|
-
*
|
|
1825
|
-
* dt set meetings/kickoff name="Kickoff 2"
|
|
1826
|
-
* ✖ validation failed:
|
|
1827
|
-
* field recordings: [...,...] must NOT have duplicate items (items ## 1 and 0 are identical)
|
|
1828
|
-
* nothing was written.
|
|
1829
|
-
*
|
|
1830
|
-
* The generated mirror carries `uniqueItems`, so a duplicate in one is never a value this engine
|
|
1831
|
-
* produced — it arrived by hand, or from a workspace written before the keyword existed. Naming the
|
|
1832
|
-
* one command that repairs it is the difference between a wall and a step.
|
|
1833
|
-
*/
|
|
1834
|
-
export function mirrorRemedy(d, fieldNames) {
|
|
1835
|
-
const mirrors = [...new Set(fieldNames)].filter((f) => f && fieldsOf(d)[f]?.mirror_of !== undefined);
|
|
1836
|
-
if (!mirrors.length) return '';
|
|
1837
|
-
return `\n ${mirrors.join(', ')}: a GENERATED mirror — its value is derived from the owning side, not yours to set. Repair it with: dreamteamer relations rebuild ${d.name}`;
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
export function bodyField(d) {
|
|
1841
|
-
return bodyFieldOf(d);
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
/** `<id>.<suffix>.<ext>` — the filename of a text record, wherever its root is. */
|
|
1845
|
-
function recordFileName(d, id) {
|
|
1846
|
-
return `${id}.${storageOf(d).suffix}${EXT[storageOf(d).format]}`;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
// remove now-empty parent dirs up to (not including) the collection root
|
|
1851
|
-
// ⚠ NEVER THROWS. An empty directory left behind is cosmetic; a rename that already happened being
|
|
1852
|
-
// reported as a failure because its leftover folder would not go is a duplicate record (R1b). The
|
|
1853
|
-
// loop stops at the first directory it cannot remove — a permission, a concurrent write — and says
|
|
1854
|
-
// nothing, because there is nothing a caller could do about it that would be better.
|
|
1855
|
-
function pruneEmptyDirs(dir, stopAt) {
|
|
1856
|
-
try {
|
|
1857
|
-
while (dir !== stopAt && dir.startsWith(stopAt) && fs.existsSync(dir) && fs.readdirSync(dir).length === 0) {
|
|
1858
|
-
fs.rmdirSync(dir);
|
|
1859
|
-
dir = path.dirname(dir);
|
|
1860
|
-
}
|
|
1861
|
-
} catch { /* left in place */ }
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
export function serialize(d, fields, previousText) {
|
|
1865
|
-
const format = storageOf(d).format;
|
|
1866
|
-
if (format === 'json') return JSON.stringify(fields, null, 2) + '\n';
|
|
1867
|
-
if (format === 'yaml') return dump(fields);
|
|
1868
|
-
const bf = bodyField(d);
|
|
1869
|
-
const fm = { ...fields };
|
|
1870
|
-
let body = '';
|
|
1871
|
-
if (bf && fm[bf] !== undefined) {
|
|
1872
|
-
body = String(fm[bf]).trim();
|
|
1873
|
-
delete fm[bf];
|
|
1874
|
-
}
|
|
1875
|
-
// ⚠ BYTE-RESTORING WHEN WE HAVE THE PREVIOUS TEXT (issue 2026-08-31). Building the whole document
|
|
1876
|
-
// from the parsed fields means a one-field `dt set` re-emits every key — so quoting, key order and
|
|
1877
|
-
// any hand-folded scalar are normalised, and the diff a human reviews is the whole record rather
|
|
1878
|
-
// than the change. `writeSource` restores every unchanged node from the bytes it was parsed out
|
|
1879
|
-
// of; only the mutated ones are re-emitted.
|
|
1880
|
-
//
|
|
1881
|
-
// ⚠ AND IT COSTS A SECOND PARSE PER WRITE. `parseDocument` twice is heavier than js-yaml, so the
|
|
1882
|
-
// third argument is passed by `set` ALONE — the one write where a previous document exists and
|
|
1883
|
-
// the diff is what the operator reads. Every other caller hits the `dump` path unchanged.
|
|
1884
|
-
const frontText = previousText === undefined ? dump(fm) : `${writeSource(frontMatterOf(previousText) ?? '', fm).replace(/\n+$/, '')}\n`;
|
|
1885
|
-
return `---\n${frontText}---\n${body ? body + '\n' : ''}`;
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
/** The YAML between the `---` fences, or null when the text has none. */
|
|
1889
|
-
function frontMatterOf(text) {
|
|
1890
|
-
return /^---\r?\n([\s\S]*?)\r?\n---/.exec(String(text))?.[1] ?? null;
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
export function atomicWrite(file, content) {
|
|
1894
|
-
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === content) return false; // true no-op
|
|
1895
|
-
const tmp = `${file}.tmp-${process.pid}`;
|
|
1896
|
-
fs.writeFileSync(tmp, content);
|
|
1897
|
-
fs.renameSync(tmp, file);
|
|
1898
|
-
return true;
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
function readPkg(root) {
|
|
1902
|
-
try { return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); } catch { return {}; }
|
|
1903
|
-
}
|
|
1904
|
-
|
|
1905
|
-
/** Byte snapshot of a set of files OR DIRECTORIES, and a restore closure. The undo mechanism
|
|
1906
|
-
* schema-ops has used for source writes since it was written (schema-ops.js:20). Record writes used
|
|
1907
|
-
* `git checkout HEAD -- <paths>` instead, which is only correct while HEAD is guaranteed to be
|
|
1908
|
-
* the last good state — it is not, once writes stop committing, and it silently discarded
|
|
1909
|
-
* uncommitted hand-edits even before that.
|
|
1910
|
-
*
|
|
1911
|
-
* A DIRECTORY unit is snapshotted recursively. It used to be skipped with a comment arguing the case
|
|
1912
|
-
* could not occur — the only folder-shape collection was `skills`, which is system-stored, so
|
|
1913
|
-
* `writableDescriptor` refused before `rm` was reached. That reasoning was true and is the wrong kind
|
|
1914
|
-
* of true: it depended on a fact about the CURRENT set of collections rather than on anything the code
|
|
1915
|
-
* enforces, and `shape: folder` is an ordinary descriptor option any workspace can choose. The failure
|
|
1916
|
-
* it left behind was silent and total — `rm` would delete the folder and the "restore" closure would
|
|
1917
|
-
* do nothing, so a failed commit meant the record was simply gone. Twelve lines, no such hole. */
|
|
1918
|
-
function snapshot(units) {
|
|
1919
|
-
const snaps = units.map((u) => {
|
|
1920
|
-
const existed = fs.existsSync(u);
|
|
1921
|
-
const isDir = existed && fs.statSync(u).isDirectory();
|
|
1922
|
-
return {
|
|
1923
|
-
u, existed, isDir,
|
|
1924
|
-
prev: existed && !isDir ? fs.readFileSync(u) : null,
|
|
1925
|
-
tree: isDir ? snapshotTree(u) : null,
|
|
1926
|
-
};
|
|
1927
|
-
});
|
|
1928
|
-
return () => {
|
|
1929
|
-
for (const { u, prev, tree, existed, isDir } of snaps) {
|
|
1930
|
-
if (!existed) { fs.rmSync(u, { force: true, recursive: true }); continue; }
|
|
1931
|
-
if (isDir) {
|
|
1932
|
-
fs.rmSync(u, { force: true, recursive: true }); // partial state from a failed op
|
|
1933
|
-
fs.mkdirSync(u, { recursive: true });
|
|
1934
|
-
for (const [rel, bytes] of tree) {
|
|
1935
|
-
const dest = path.join(u, rel);
|
|
1936
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
1937
|
-
fs.writeFileSync(dest, bytes);
|
|
1938
|
-
}
|
|
1939
|
-
continue;
|
|
1940
|
-
}
|
|
1941
|
-
if (prev !== null) { fs.mkdirSync(path.dirname(u), { recursive: true }); fs.writeFileSync(u, prev); }
|
|
1942
|
-
}
|
|
1943
|
-
};
|
|
1944
|
-
}
|
|
1945
|
-
|
|
1946
|
-
/** Every file under `dir` as [relative path, bytes] — the whole of a folder-shape record. */
|
|
1947
|
-
function snapshotTree(dir) {
|
|
1948
|
-
const out = [];
|
|
1949
|
-
for (const file of walk(dir)) out.push([path.relative(dir, file), fs.readFileSync(file)]);
|
|
1950
|
-
return out;
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
/** Now, as the one canonical date-time spelling: local wall clock with its offset. */
|
|
1954
|
-
/** A `%aI` author date as a record's `created`: git prints a UTC date as `…Z` on some builds, and a
|
|
1955
|
-
* record's stamp is always offset-spelled, so the two spellings must read as the one value. */
|
|
1956
|
-
export function gitDateToStamp(iso) {
|
|
1957
|
-
return iso.replace(/Z$/, '+00:00');
|
|
1958
|
-
}
|
|
1959
|
-
|
|
1960
|
-
function nowStamp() {
|
|
1961
|
-
const t = new Date();
|
|
1962
|
-
const p = (n) => String(n).padStart(2, '0');
|
|
1963
|
-
return normalizeTemporal(`${t.getFullYear()}-${p(t.getMonth() + 1)}-${p(t.getDate())}T${p(t.getHours())}:${p(t.getMinutes())}:${p(t.getSeconds())}`, 'date-time');
|
|
1964
|
-
}
|