@ai-primitives-hub/app 0.2.1 → 0.2.2-next.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/README.md +5 -1
- package/dist/collection/affected-collections.d.ts +11 -0
- package/dist/collection/affected-collections.d.ts.map +1 -0
- package/dist/collection/affected-collections.js +90 -0
- package/dist/collection/affected-collections.js.map +1 -0
- package/dist/collection/create-plugin.d.ts +35 -0
- package/dist/collection/create-plugin.d.ts.map +1 -0
- package/dist/collection/create-plugin.js +118 -0
- package/dist/collection/create-plugin.js.map +1 -0
- package/dist/collection/index.d.ts +4 -2
- package/dist/collection/index.d.ts.map +1 -1
- package/dist/collection/index.js +8 -4
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/kind-route-warning.d.ts +13 -0
- package/dist/collection/kind-route-warning.d.ts.map +1 -0
- package/dist/collection/kind-route-warning.js +40 -0
- package/dist/collection/kind-route-warning.js.map +1 -0
- package/dist/collection/plugin-item-issues.d.ts +36 -0
- package/dist/collection/plugin-item-issues.d.ts.map +1 -0
- package/dist/collection/plugin-item-issues.js +31 -0
- package/dist/collection/plugin-item-issues.js.map +1 -0
- package/dist/collection/read-collection.d.ts +1 -1
- package/dist/collection/read-collection.d.ts.map +1 -1
- package/dist/collection/read-collection.js +14 -15
- package/dist/collection/read-collection.js.map +1 -1
- package/dist/collection-editor/collection-contribution-workflow.d.ts +96 -0
- package/dist/collection-editor/collection-contribution-workflow.d.ts.map +1 -0
- package/dist/collection-editor/collection-contribution-workflow.js +479 -0
- package/dist/collection-editor/collection-contribution-workflow.js.map +1 -0
- package/dist/collection-editor/collection-editor-service.d.ts +232 -0
- package/dist/collection-editor/collection-editor-service.d.ts.map +1 -0
- package/dist/collection-editor/collection-editor-service.js +868 -0
- package/dist/collection-editor/collection-editor-service.js.map +1 -0
- package/dist/collection-editor/index.d.ts +7 -0
- package/dist/collection-editor/index.d.ts.map +1 -0
- package/dist/collection-editor/index.js +12 -0
- package/dist/collection-editor/index.js.map +1 -0
- package/dist/diagnostics/find-ancestor-file.d.ts +13 -0
- package/dist/diagnostics/find-ancestor-file.d.ts.map +1 -0
- package/dist/diagnostics/find-ancestor-file.js +85 -0
- package/dist/diagnostics/find-ancestor-file.js.map +1 -0
- package/dist/diagnostics/index.d.ts +10 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +26 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/diagnostics/run-primitive-diagnostics.d.ts +43 -0
- package/dist/diagnostics/run-primitive-diagnostics.d.ts.map +1 -0
- package/dist/diagnostics/run-primitive-diagnostics.js +413 -0
- package/dist/diagnostics/run-primitive-diagnostics.js.map +1 -0
- package/dist/diagnostics/sandbox-snapshot.d.ts +20 -0
- package/dist/diagnostics/sandbox-snapshot.d.ts.map +1 -0
- package/dist/diagnostics/sandbox-snapshot.js +117 -0
- package/dist/diagnostics/sandbox-snapshot.js.map +1 -0
- package/dist/governance/generate-catalogue.d.ts +16 -0
- package/dist/governance/generate-catalogue.d.ts.map +1 -0
- package/dist/governance/generate-catalogue.js +67 -0
- package/dist/governance/generate-catalogue.js.map +1 -0
- package/dist/governance/hub-scoped-governance.d.ts +37 -0
- package/dist/governance/hub-scoped-governance.d.ts.map +1 -0
- package/dist/governance/hub-scoped-governance.js +110 -0
- package/dist/governance/hub-scoped-governance.js.map +1 -0
- package/dist/governance/index.d.ts +10 -0
- package/dist/governance/index.d.ts.map +1 -0
- package/dist/governance/index.js +26 -0
- package/dist/governance/index.js.map +1 -0
- package/dist/governance/load-config.d.ts +45 -0
- package/dist/governance/load-config.d.ts.map +1 -0
- package/dist/governance/load-config.js +137 -0
- package/dist/governance/load-config.js.map +1 -0
- package/dist/governance/pr-scope.d.ts +23 -0
- package/dist/governance/pr-scope.d.ts.map +1 -0
- package/dist/governance/pr-scope.js +22 -0
- package/dist/governance/pr-scope.js.map +1 -0
- package/dist/governance/report.d.ts +23 -0
- package/dist/governance/report.d.ts.map +1 -0
- package/dist/governance/report.js +177 -0
- package/dist/governance/report.js.map +1 -0
- package/dist/governance/run-governance.d.ts +22 -0
- package/dist/governance/run-governance.d.ts.map +1 -0
- package/dist/governance/run-governance.js +78 -0
- package/dist/governance/run-governance.js.map +1 -0
- package/dist/governance/source-checks.d.ts +29 -0
- package/dist/governance/source-checks.d.ts.map +1 -0
- package/dist/governance/source-checks.js +80 -0
- package/dist/governance/source-checks.js.map +1 -0
- package/dist/governance/validate-collection-governance.d.ts +46 -0
- package/dist/governance/validate-collection-governance.d.ts.map +1 -0
- package/dist/governance/validate-collection-governance.js +291 -0
- package/dist/governance/validate-collection-governance.js.map +1 -0
- package/dist/hub-editor/hub-config-editor-service.d.ts +94 -0
- package/dist/hub-editor/hub-config-editor-service.d.ts.map +1 -0
- package/dist/hub-editor/hub-config-editor-service.js +289 -0
- package/dist/hub-editor/hub-config-editor-service.js.map +1 -0
- package/dist/hub-editor/hub-contribution-workflow.d.ts +99 -0
- package/dist/hub-editor/hub-contribution-workflow.d.ts.map +1 -0
- package/dist/hub-editor/hub-contribution-workflow.js +385 -0
- package/dist/hub-editor/hub-contribution-workflow.js.map +1 -0
- package/dist/hub-editor/index.d.ts +7 -0
- package/dist/hub-editor/index.d.ts.map +1 -0
- package/dist/hub-editor/index.js +23 -0
- package/dist/hub-editor/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/install/index.d.ts +2 -0
- package/dist/install/index.d.ts.map +1 -1
- package/dist/install/index.js +3 -1
- package/dist/install/index.js.map +1 -1
- package/dist/install/partial-target-write.d.ts +63 -0
- package/dist/install/partial-target-write.d.ts.map +1 -0
- package/dist/install/partial-target-write.js +128 -0
- package/dist/install/partial-target-write.js.map +1 -0
- package/dist/install/pipeline.d.ts +2 -1
- package/dist/install/pipeline.d.ts.map +1 -1
- package/dist/install/pipeline.js +4 -3
- package/dist/install/pipeline.js.map +1 -1
- package/dist/install/target-write.d.ts +10 -0
- package/dist/install/target-write.d.ts.map +1 -1
- package/dist/install/target-write.js +3 -2
- package/dist/install/target-write.js.map +1 -1
- package/dist/install/uninstall-pipeline.d.ts +11 -10
- package/dist/install/uninstall-pipeline.d.ts.map +1 -1
- package/dist/install/uninstall-pipeline.js +10 -11
- package/dist/install/uninstall-pipeline.js.map +1 -1
- package/dist/records/atomic-write.d.ts +11 -0
- package/dist/records/atomic-write.d.ts.map +1 -0
- package/dist/records/atomic-write.js +66 -0
- package/dist/records/atomic-write.js.map +1 -0
- package/dist/records/confine-path.d.ts +35 -0
- package/dist/records/confine-path.d.ts.map +1 -0
- package/dist/records/confine-path.js +140 -0
- package/dist/records/confine-path.js.map +1 -0
- package/dist/records/git-root.d.ts +66 -0
- package/dist/records/git-root.d.ts.map +1 -0
- package/dist/records/git-root.js +208 -0
- package/dist/records/git-root.js.map +1 -0
- package/dist/records/index.d.ts +30 -0
- package/dist/records/index.d.ts.map +1 -0
- package/dist/records/index.js +46 -0
- package/dist/records/index.js.map +1 -0
- package/dist/records/install-record-service.d.ts +496 -0
- package/dist/records/install-record-service.d.ts.map +1 -0
- package/dist/records/install-record-service.js +1365 -0
- package/dist/records/install-record-service.js.map +1 -0
- package/dist/records/install-record-services.d.ts +29 -0
- package/dist/records/install-record-services.d.ts.map +1 -0
- package/dist/records/install-record-services.js +17 -0
- package/dist/records/install-record-services.js.map +1 -0
- package/dist/records/legacy-shapes.d.ts +18 -0
- package/dist/records/legacy-shapes.d.ts.map +1 -0
- package/dist/records/legacy-shapes.js +30 -0
- package/dist/records/legacy-shapes.js.map +1 -0
- package/dist/records/map-tool-to-target.d.ts +33 -0
- package/dist/records/map-tool-to-target.d.ts.map +1 -0
- package/dist/records/map-tool-to-target.js +98 -0
- package/dist/records/map-tool-to-target.js.map +1 -0
- package/dist/records/mcp-servers.d.ts +116 -0
- package/dist/records/mcp-servers.d.ts.map +1 -0
- package/dist/records/mcp-servers.js +268 -0
- package/dist/records/mcp-servers.js.map +1 -0
- package/dist/records/modified-files.d.ts +32 -0
- package/dist/records/modified-files.d.ts.map +1 -0
- package/dist/records/modified-files.js +146 -0
- package/dist/records/modified-files.js.map +1 -0
- package/dist/records/plan-record-entries.d.ts +76 -0
- package/dist/records/plan-record-entries.d.ts.map +1 -0
- package/dist/records/plan-record-entries.js +84 -0
- package/dist/records/plan-record-entries.js.map +1 -0
- package/dist/records/read-record-text.d.ts +15 -0
- package/dist/records/read-record-text.d.ts.map +1 -0
- package/dist/records/read-record-text.js +36 -0
- package/dist/records/read-record-text.js.map +1 -0
- package/dist/records/record-entry.d.ts +31 -0
- package/dist/records/record-entry.d.ts.map +1 -0
- package/dist/records/record-entry.js +81 -0
- package/dist/records/record-entry.js.map +1 -0
- package/dist/records/record-file-shape.d.ts +90 -0
- package/dist/records/record-file-shape.d.ts.map +1 -0
- package/dist/records/record-file-shape.js +288 -0
- package/dist/records/record-file-shape.js.map +1 -0
- package/dist/records/record-hub.d.ts +42 -0
- package/dist/records/record-hub.d.ts.map +1 -0
- package/dist/records/record-hub.js +85 -0
- package/dist/records/record-hub.js.map +1 -0
- package/dist/records/record-identity.d.ts +14 -0
- package/dist/records/record-identity.d.ts.map +1 -0
- package/dist/records/record-identity.js +41 -0
- package/dist/records/record-identity.js.map +1 -0
- package/dist/records/record-migration.d.ts +118 -0
- package/dist/records/record-migration.d.ts.map +1 -0
- package/dist/records/record-migration.js +454 -0
- package/dist/records/record-migration.js.map +1 -0
- package/dist/records/record-store.d.ts +123 -0
- package/dist/records/record-store.d.ts.map +1 -0
- package/dist/records/record-store.js +291 -0
- package/dist/records/record-store.js.map +1 -0
- package/dist/records/resolve-record-source.d.ts +64 -0
- package/dist/records/resolve-record-source.d.ts.map +1 -0
- package/dist/records/resolve-record-source.js +160 -0
- package/dist/records/resolve-record-source.js.map +1 -0
- package/dist/records/sanitize-source.d.ts +18 -0
- package/dist/records/sanitize-source.d.ts.map +1 -0
- package/dist/records/sanitize-source.js +90 -0
- package/dist/records/sanitize-source.js.map +1 -0
- package/dist/records/select-record.d.ts +54 -0
- package/dist/records/select-record.d.ts.map +1 -0
- package/dist/records/select-record.js +180 -0
- package/dist/records/select-record.js.map +1 -0
- package/dist/records/serialize-record.d.ts +20 -0
- package/dist/records/serialize-record.d.ts.map +1 -0
- package/dist/records/serialize-record.js +100 -0
- package/dist/records/serialize-record.js.map +1 -0
- package/dist/records/source-fields.d.ts +21 -0
- package/dist/records/source-fields.d.ts.map +1 -0
- package/dist/records/source-fields.js +28 -0
- package/dist/records/source-fields.js.map +1 -0
- package/dist/records/to-record-source.d.ts +23 -0
- package/dist/records/to-record-source.d.ts.map +1 -0
- package/dist/records/to-record-source.js +39 -0
- package/dist/records/to-record-source.js.map +1 -0
- package/dist/records/user-home.d.ts +16 -0
- package/dist/records/user-home.d.ts.map +1 -0
- package/dist/records/user-home.js +84 -0
- package/dist/records/user-home.js.map +1 -0
- package/dist/records/writer-group.d.ts +7 -0
- package/dist/records/writer-group.d.ts.map +1 -0
- package/dist/records/writer-group.js +31 -0
- package/dist/records/writer-group.js.map +1 -0
- package/dist/registry/activate-registry-profile.d.ts.map +1 -1
- package/dist/registry/activate-registry-profile.js +4 -1
- package/dist/registry/activate-registry-profile.js.map +1 -1
- package/dist/registry/batch-install-profile.d.ts +76 -0
- package/dist/registry/batch-install-profile.d.ts.map +1 -0
- package/dist/registry/batch-install-profile.js +67 -0
- package/dist/registry/batch-install-profile.js.map +1 -0
- package/dist/registry/create-source-adapter.d.ts +16 -1
- package/dist/registry/create-source-adapter.d.ts.map +1 -1
- package/dist/registry/create-source-adapter.js +76 -3
- package/dist/registry/create-source-adapter.js.map +1 -1
- package/dist/registry/hub-manager.d.ts +41 -0
- package/dist/registry/hub-manager.d.ts.map +1 -1
- package/dist/registry/hub-manager.js +82 -4
- package/dist/registry/hub-manager.js.map +1 -1
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -0
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/install-registry-bundle.js +4 -3
- package/dist/registry/install-registry-bundle.js.map +1 -1
- package/dist/registry/list-installed-bundles.d.ts +2 -3
- package/dist/registry/list-installed-bundles.d.ts.map +1 -1
- package/dist/registry/list-installed-bundles.js.map +1 -1
- package/dist/registry/load-hub-sources.d.ts +8 -0
- package/dist/registry/load-hub-sources.d.ts.map +1 -1
- package/dist/registry/load-hub-sources.js +70 -3
- package/dist/registry/load-hub-sources.js.map +1 -1
- package/dist/registry/profile-lifecycle.d.ts +7 -2
- package/dist/registry/profile-lifecycle.d.ts.map +1 -1
- package/dist/registry/profile-lifecycle.js +82 -11
- package/dist/registry/profile-lifecycle.js.map +1 -1
- package/dist/registry/uninstall-installed-bundle.d.ts +2 -3
- package/dist/registry/uninstall-installed-bundle.d.ts.map +1 -1
- package/dist/registry/uninstall-installed-bundle.js.map +1 -1
- package/dist/registry/update-registry-bundle.d.ts +2 -2
- package/dist/registry/update-registry-bundle.js +2 -2
- package/dist/registry/update-registry-bundle.js.map +1 -1
- package/dist/registry/validate-hub-config-file.d.ts +14 -1
- package/dist/registry/validate-hub-config-file.d.ts.map +1 -1
- package/dist/registry/validate-hub-config-file.js +81 -44
- package/dist/registry/validate-hub-config-file.js.map +1 -1
- package/dist/release/plan-bundle-release.d.ts +6 -12
- package/dist/release/plan-bundle-release.d.ts.map +1 -1
- package/dist/release/plan-bundle-release.js +178 -7
- package/dist/release/plan-bundle-release.js.map +1 -1
- package/dist/replicate/replicate.d.ts +5 -2
- package/dist/replicate/replicate.d.ts.map +1 -1
- package/dist/replicate/replicate.js +121 -17
- package/dist/replicate/replicate.js.map +1 -1
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +22 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/rating/bundle-discovery.d.ts +19 -0
- package/dist/security/rating/bundle-discovery.d.ts.map +1 -0
- package/dist/security/rating/bundle-discovery.js +244 -0
- package/dist/security/rating/bundle-discovery.js.map +1 -0
- package/dist/security/rating/index.d.ts +5 -0
- package/dist/security/rating/index.d.ts.map +1 -0
- package/dist/security/rating/index.js +21 -0
- package/dist/security/rating/index.js.map +1 -0
- package/dist/security/rating/security-rating-markdown.d.ts +17 -0
- package/dist/security/rating/security-rating-markdown.d.ts.map +1 -0
- package/dist/security/rating/security-rating-markdown.js +131 -0
- package/dist/security/rating/security-rating-markdown.js.map +1 -0
- package/dist/security/rating/security-rating-scan.d.ts +23 -0
- package/dist/security/rating/security-rating-scan.d.ts.map +1 -0
- package/dist/security/rating/security-rating-scan.js +40 -0
- package/dist/security/rating/security-rating-scan.js.map +1 -0
- package/dist/security/rating/security-rating-templates.d.ts +40 -0
- package/dist/security/rating/security-rating-templates.d.ts.map +1 -0
- package/dist/security/rating/security-rating-templates.js +83 -0
- package/dist/security/rating/security-rating-templates.js.map +1 -0
- package/dist/security/rating/security-rating.d.ts +32 -0
- package/dist/security/rating/security-rating.d.ts.map +1 -0
- package/dist/security/rating/security-rating.js +94 -0
- package/dist/security/rating/security-rating.js.map +1 -0
- package/dist/security/security-scan-use-case.d.ts +101 -0
- package/dist/security/security-scan-use-case.d.ts.map +1 -0
- package/dist/security/security-scan-use-case.js +185 -0
- package/dist/security/security-scan-use-case.js.map +1 -0
- package/dist/stores/json-lockfile-store.d.ts.map +1 -1
- package/dist/stores/json-lockfile-store.js +6 -32
- package/dist/stores/json-lockfile-store.js.map +1 -1
- package/dist/transform/transformer-registry.d.ts.map +1 -1
- package/dist/transform/transformer-registry.js +3 -0
- package/dist/transform/transformer-registry.js.map +1 -1
- package/dist/transform/transformers/windsurf-transformer.d.ts +5 -0
- package/dist/transform/transformers/windsurf-transformer.d.ts.map +1 -1
- package/dist/transform/transformers/windsurf-transformer.js.map +1 -1
- package/dist/writers/file-tree-writer.d.ts +14 -1
- package/dist/writers/file-tree-writer.d.ts.map +1 -1
- package/dist/writers/file-tree-writer.js +23 -71
- package/dist/writers/file-tree-writer.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RecordStore = exports.createEmptyRecord = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Install record store: locate, load and atomically save record files.
|
|
39
|
+
*
|
|
40
|
+
* `load` checks the file type and size, parses, validates the schema, then
|
|
41
|
+
* confines every recorded path. `save` only writes a location whose last load
|
|
42
|
+
* succeeded, so a rejected file is never overwritten. The repository root is
|
|
43
|
+
* the git root, not `AppStorage`.
|
|
44
|
+
* @module records/record-store
|
|
45
|
+
*/
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
const core_1 = require("@ai-primitives-hub/core");
|
|
48
|
+
const atomic_write_1 = require("./atomic-write");
|
|
49
|
+
const confine_path_1 = require("./confine-path");
|
|
50
|
+
const git_root_1 = require("./git-root");
|
|
51
|
+
const read_record_text_1 = require("./read-record-text");
|
|
52
|
+
const record_file_shape_1 = require("./record-file-shape");
|
|
53
|
+
const serialize_record_1 = require("./serialize-record");
|
|
54
|
+
const LARGE_RECORD_HINT = 'The record is larger than 10 MB. Fix or remove the file, then run the command again.';
|
|
55
|
+
/**
|
|
56
|
+
* Build an empty, prototype-free record for a level.
|
|
57
|
+
* @param level - Record level.
|
|
58
|
+
* @param generatedBy - Writer stamp.
|
|
59
|
+
* @param now - Time stamped as `generatedAt`.
|
|
60
|
+
*/
|
|
61
|
+
const createEmptyRecord = (level, generatedBy, now) => {
|
|
62
|
+
const record = Object.create(null);
|
|
63
|
+
record.$schema = core_1.RECORD_SCHEMA_URL;
|
|
64
|
+
record.version = core_1.RECORD_FORMAT_VERSION;
|
|
65
|
+
record.level = level;
|
|
66
|
+
record.generatedAt = now.toISOString();
|
|
67
|
+
record.generatedBy = generatedBy;
|
|
68
|
+
record.bundles = Object.create(null);
|
|
69
|
+
record.sources = Object.create(null);
|
|
70
|
+
return record;
|
|
71
|
+
};
|
|
72
|
+
exports.createEmptyRecord = createEmptyRecord;
|
|
73
|
+
/** Locates, loads and saves install record files. */
|
|
74
|
+
class RecordStore {
|
|
75
|
+
fs;
|
|
76
|
+
validator;
|
|
77
|
+
generatedBy;
|
|
78
|
+
now;
|
|
79
|
+
/** Paths whose last load succeeded; only these may be saved. */
|
|
80
|
+
loadedPaths = new Set();
|
|
81
|
+
constructor(options) {
|
|
82
|
+
this.fs = options.fs;
|
|
83
|
+
this.validator = options.validator;
|
|
84
|
+
this.generatedBy = options.generatedBy;
|
|
85
|
+
this.now = options.now ?? (() => new Date());
|
|
86
|
+
}
|
|
87
|
+
labelOf(location) {
|
|
88
|
+
return (0, core_1.relativeInside)(location.root, location.path) ?? location.path;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The path to read: a regular file, or a symlink to one inside the root; `undefined` when missing.
|
|
92
|
+
* @param location - Record location.
|
|
93
|
+
* @param file - Record file to name in errors.
|
|
94
|
+
*/
|
|
95
|
+
async gateRecordFile(location, file) {
|
|
96
|
+
const stat = await this.fs.lstat(location.path);
|
|
97
|
+
if (stat === undefined) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
if (stat.kind === 'symlink') {
|
|
101
|
+
const target = await this.resolveAllowedLink(location, file);
|
|
102
|
+
if ((await this.fs.lstat(target))?.kind !== 'file') {
|
|
103
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { file, detail: 'not a regular file (symlink target)' });
|
|
104
|
+
}
|
|
105
|
+
return target;
|
|
106
|
+
}
|
|
107
|
+
if (stat.kind !== 'file') {
|
|
108
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { file, detail: 'not a regular file' });
|
|
109
|
+
}
|
|
110
|
+
return location.path;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Realpath of a record symlink, required to be inside the root.
|
|
114
|
+
* @param location - Record location.
|
|
115
|
+
* @param file - Record file to name in errors.
|
|
116
|
+
*/
|
|
117
|
+
async resolveAllowedLink(location, file) {
|
|
118
|
+
let target;
|
|
119
|
+
let realRoot;
|
|
120
|
+
try {
|
|
121
|
+
target = await this.fs.realpath(location.path);
|
|
122
|
+
realRoot = await this.fs.realpath(location.root);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { file, detail: 'symlink does not resolve', cause: error });
|
|
126
|
+
}
|
|
127
|
+
if ((0, core_1.relativeInside)(realRoot, target) === undefined) {
|
|
128
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { file, detail: 'symlink target is outside the root' });
|
|
129
|
+
}
|
|
130
|
+
return target;
|
|
131
|
+
}
|
|
132
|
+
async readAndCheck(location, readPath, file) {
|
|
133
|
+
const text = await (0, read_record_text_1.readRecordText)(this.fs, readPath, file, LARGE_RECORD_HINT);
|
|
134
|
+
const record = (0, record_file_shape_1.fromRecordFile)(this.validator.validate((0, core_1.parseRecord)(text, file), file));
|
|
135
|
+
await this.checkPaths(location, record, file);
|
|
136
|
+
this.checkSourceIds(record, file);
|
|
137
|
+
return record;
|
|
138
|
+
}
|
|
139
|
+
async checkPaths(location, record, file) {
|
|
140
|
+
for (const bundle of Object.values(record.bundles)) {
|
|
141
|
+
for (const entry of Object.values(bundle.tools)) {
|
|
142
|
+
for (const recorded of entry.files) {
|
|
143
|
+
await (0, confine_path_1.confinePath)(this.fs, location.root, recorded.path, file);
|
|
144
|
+
// `/` is the stored separator; a `\` written by hand is read as one, so ownership compares one spelling.
|
|
145
|
+
recorded.path = recorded.path.replaceAll('\\', '/');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
checkSourceIds(record, file) {
|
|
151
|
+
for (const [bundleId, bundle] of Object.entries(record.bundles)) {
|
|
152
|
+
for (const [tool, entry] of Object.entries(bundle.tools)) {
|
|
153
|
+
if (!Object.hasOwn(record.sources, entry.sourceId)) {
|
|
154
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', {
|
|
155
|
+
file,
|
|
156
|
+
detail: `bundles.${bundleId}.tools.${tool}.sourceId ${JSON.stringify(entry.sourceId)} is not a key of sources`
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Prototype-free shallow copy with the writer fields set.
|
|
164
|
+
* @param location - Record location.
|
|
165
|
+
* @param record - Record to write.
|
|
166
|
+
*/
|
|
167
|
+
stamp(location, record) {
|
|
168
|
+
const stamped = (0, core_1.nullPrototypeCopy)(record);
|
|
169
|
+
stamped.version = core_1.RECORD_FORMAT_VERSION;
|
|
170
|
+
stamped.level = location.level;
|
|
171
|
+
stamped.generatedAt = this.now().toISOString();
|
|
172
|
+
stamped.generatedBy = this.generatedBy;
|
|
173
|
+
if (!(0, core_1.isJsonObject)(stamped.bundles)) {
|
|
174
|
+
stamped.bundles = Object.create(null);
|
|
175
|
+
}
|
|
176
|
+
if (!(0, core_1.isJsonObject)(stamped.sources)) {
|
|
177
|
+
stamped.sources = Object.create(null);
|
|
178
|
+
}
|
|
179
|
+
return stamped;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Write atomically; an allowed symlink keeps its link and has its target replaced.
|
|
183
|
+
* @param location - Record location.
|
|
184
|
+
* @param text - Serialized record.
|
|
185
|
+
* @param file - Record file to name in errors.
|
|
186
|
+
*/
|
|
187
|
+
async writeAtomically(location, text, file) {
|
|
188
|
+
try {
|
|
189
|
+
const target = (await this.fs.lstat(location.path))?.kind === 'symlink'
|
|
190
|
+
? await this.resolveAllowedLink(location, file)
|
|
191
|
+
: location.path;
|
|
192
|
+
// The user record's folder may not exist yet on a new machine.
|
|
193
|
+
await this.fs.mkdir(path.dirname(target), { recursive: true });
|
|
194
|
+
await (0, atomic_write_1.writeFileAtomically)(this.fs, target, text);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if ((0, core_1.isRecordError)(error)) {
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
throw (0, core_1.recordError)('RECORD.WRITE_FAILED', { file, cause: error });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Both repository record locations at the git root above `start` (or `start` itself), committed first.
|
|
205
|
+
* @param input - Where the git-root walk starts.
|
|
206
|
+
* @param input.start - Target root, or the current folder.
|
|
207
|
+
*/
|
|
208
|
+
async resolveRepository(input) {
|
|
209
|
+
const root = await (0, git_root_1.resolveRepositoryRoot)(this.fs, input.start);
|
|
210
|
+
return (0, core_1.repositoryLocations)(root);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Both repository record files for a start folder, loaded and checked, with
|
|
214
|
+
* the one the commit mode records in.
|
|
215
|
+
* @param input - Where the git-root walk starts and the install's commit mode.
|
|
216
|
+
* @param input.start - The target's root path, or the current folder.
|
|
217
|
+
* @param input.commitMode - `local-only` picks the local-only file; anything else the committed one.
|
|
218
|
+
* @throws {RegistryError} Any `RECORD.*` error from loading either file.
|
|
219
|
+
*/
|
|
220
|
+
async loadRepository(input) {
|
|
221
|
+
const locations = await this.resolveRepository(input);
|
|
222
|
+
for (const location of locations) {
|
|
223
|
+
await this.load(location);
|
|
224
|
+
}
|
|
225
|
+
return { locations, location: input.commitMode === 'local-only' ? locations[1] : locations[0] };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The user-level record location, rooted at the home folder.
|
|
229
|
+
* @param input - Home folder and record file.
|
|
230
|
+
* @param input.home - Absolute home folder.
|
|
231
|
+
* @param input.path - Absolute path of the user record.
|
|
232
|
+
*/
|
|
233
|
+
resolveUser(input) {
|
|
234
|
+
return { level: 'user', root: input.home, path: input.path };
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Load and check a record file. A missing file gives an empty record.
|
|
238
|
+
* @param location - Record location.
|
|
239
|
+
* @throws {RegistryError} A `RECORD.*` error; the file is left untouched.
|
|
240
|
+
*/
|
|
241
|
+
async load(location) {
|
|
242
|
+
this.loadedPaths.delete(location.path);
|
|
243
|
+
const file = this.labelOf(location);
|
|
244
|
+
try {
|
|
245
|
+
const readPath = await this.gateRecordFile(location, file);
|
|
246
|
+
const loaded = readPath === undefined
|
|
247
|
+
? { location, record: (0, exports.createEmptyRecord)(location.level, this.generatedBy, this.now()), exists: false }
|
|
248
|
+
: { location, record: await this.readAndCheck(location, readPath, file), exists: true };
|
|
249
|
+
this.loadedPaths.add(location.path);
|
|
250
|
+
return loaded;
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if ((0, core_1.isRecordError)(error)) {
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { file, detail: 'the file could not be read', cause: error });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Stamp, validate and atomically write a record whose location was loaded first.
|
|
261
|
+
* @param location - Record location.
|
|
262
|
+
* @param record - Record to write; left unchanged.
|
|
263
|
+
* @throws {RegistryError} `RECORD.MALFORMED` or `RECORD.WRITE_FAILED`; the previous file is intact.
|
|
264
|
+
*/
|
|
265
|
+
async save(location, record) {
|
|
266
|
+
const file = this.labelOf(location);
|
|
267
|
+
if (!this.loadedPaths.has(location.path)) {
|
|
268
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { file, detail: 'the record was not loaded successfully, so it is not overwritten' });
|
|
269
|
+
}
|
|
270
|
+
const stamped = this.stamp(location, record);
|
|
271
|
+
const stored = (0, record_file_shape_1.toRecordFile)(stamped);
|
|
272
|
+
this.validator.validate(stored, file);
|
|
273
|
+
const text = (0, serialize_record_1.serializeRecord)(stored);
|
|
274
|
+
// A file `load` would refuse is never written: the previous one stays usable.
|
|
275
|
+
if (new TextEncoder().encode(text).byteLength > core_1.RECORD_MAX_BYTES) {
|
|
276
|
+
throw (0, core_1.recordError)('RECORD.WRITE_FAILED', { file, detail: 'the record would be larger than 10 MB' });
|
|
277
|
+
}
|
|
278
|
+
const warnings = [];
|
|
279
|
+
// Exclude a local-only file before it exists, so it is never on disk unexcluded.
|
|
280
|
+
if (location.level === 'repository' && location.commitMode === 'local-only') {
|
|
281
|
+
const exclude = await (0, git_root_1.ensureExcluded)(this.fs, location.root, path.basename(location.path));
|
|
282
|
+
if (exclude.warning !== undefined) {
|
|
283
|
+
warnings.push(exclude.warning);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
await this.writeAtomically(location, text, file);
|
|
287
|
+
return { warnings };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.RecordStore = RecordStore;
|
|
291
|
+
//# sourceMappingURL=record-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-store.js","sourceRoot":"","sources":["../../src/records/record-store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,gDAAkC;AAClC,kDAgBiC;AACjC,iDAEwB;AACxB,iDAEwB;AACxB,yCAGoB;AACpB,yDAE4B;AAC5B,2DAG6B;AAC7B,yDAE4B;AAmC5B,MAAM,iBAAiB,GAAG,sFAAsF,CAAC;AAEjH;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAAkB,EAAE,WAAmB,EAAE,GAAS,EAAiB,EAAE;IACrG,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAkB,CAAC;IACpD,MAAM,CAAC,OAAO,GAAG,wBAAiB,CAAC;IACnC,MAAM,CAAC,OAAO,GAAG,4BAAqB,CAAC;IACvC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IACvC,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA6B,CAAC;IACjE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA6B,CAAC;IACjE,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B;AAEF,qDAAqD;AACrD,MAAa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AAe,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,OAAO,EAAE,QAAQ,EAAE,CAAC;IACtB,CAAC;CACF;AArOD,kCAqOC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type RecordFs, type RegistrySource, type SourceRecord } from '@ai-primitives-hub/core';
|
|
2
|
+
import type { RecordHubInput } from './record-hub';
|
|
3
|
+
/** Outcome of {@link resolveRecordSource}. */
|
|
4
|
+
export type SourceDecision =
|
|
5
|
+
/**
|
|
6
|
+
* Fetch from this source; `sourceId` is the record key. `hub` is the
|
|
7
|
+
* configured source's shareable hub; `configured` marks a configured match.
|
|
8
|
+
*/
|
|
9
|
+
{
|
|
10
|
+
use: SourceRecord & {
|
|
11
|
+
sourceId: string;
|
|
12
|
+
};
|
|
13
|
+
hub?: RecordHubInput;
|
|
14
|
+
configured?: true;
|
|
15
|
+
}
|
|
16
|
+
/** Do not fetch; skip the entry and report the reason. */
|
|
17
|
+
| {
|
|
18
|
+
skip: string;
|
|
19
|
+
};
|
|
20
|
+
/** Reason reported for a `local` record source that leaves the repository. */
|
|
21
|
+
export declare const LOCAL_SOURCE_OUTSIDE_REASON = "local source outside the repository";
|
|
22
|
+
/**
|
|
23
|
+
* Whether a source type reads a folder on disk: `local` and every `local-*` type.
|
|
24
|
+
* @param type - Source type.
|
|
25
|
+
*/
|
|
26
|
+
export declare const isLocalType: (type: string) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a `local` source folder stays inside the repository root once every
|
|
29
|
+
* symlink is resolved.
|
|
30
|
+
* @param fs - Filesystem port.
|
|
31
|
+
* @param root - Repository root.
|
|
32
|
+
* @param localPath - The source's folder, relative to the root or absolute.
|
|
33
|
+
*/
|
|
34
|
+
export declare const isLocalSourceInsideRoot: (fs: RecordFs, root: string, localPath: string) => Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Configured sources in the trust gate's lookup order, one per id: the active
|
|
37
|
+
* hub's, then detached sources, then (with `includeOtherHubs`) any other.
|
|
38
|
+
* @param sources - Configured sources, each with its `hubId`.
|
|
39
|
+
* @param activeHubId - Active hub id, or `null`.
|
|
40
|
+
* @param options - Lookup options.
|
|
41
|
+
* @param options.includeOtherHubs - Keep other hubs' sources, last.
|
|
42
|
+
*/
|
|
43
|
+
export declare const orderConfiguredSources: (sources: readonly RegistrySource[], activeHubId: string | null, options?: {
|
|
44
|
+
includeOtherHubs?: boolean;
|
|
45
|
+
}) => RegistrySource[];
|
|
46
|
+
/** Optional inputs of {@link resolveRecordSource}. */
|
|
47
|
+
export interface ResolveRecordSourceOptions {
|
|
48
|
+
/** Every configured source, of any hub; one with the recorded `hubId` wins. */
|
|
49
|
+
candidates?: readonly RegistrySource[];
|
|
50
|
+
/** Shareable configured hubs by id, recorded with the source. */
|
|
51
|
+
hubs?: ReadonlyMap<string, RecordHubInput>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Decide which source an entry is replayed or updated from.
|
|
55
|
+
* @param sourceId - The entry's `sourceId`.
|
|
56
|
+
* @param fromRecord - The record's copy of that source.
|
|
57
|
+
* @param configured - Configured sources by id, active hub first.
|
|
58
|
+
* @param root - Repository root.
|
|
59
|
+
* @param fs - Filesystem port.
|
|
60
|
+
* @param options - Candidate sources and hubs.
|
|
61
|
+
* @returns The source to use, or why the entry is skipped.
|
|
62
|
+
*/
|
|
63
|
+
export declare const resolveRecordSource: (sourceId: string, fromRecord: SourceRecord, configured: ReadonlyMap<string, RegistrySource>, root: string, fs: RecordFs, options?: ResolveRecordSourceOptions) => Promise<SourceDecision>;
|
|
64
|
+
//# sourceMappingURL=resolve-record-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-record-source.d.ts","sourceRoot":"","sources":["../../src/records/resolve-record-source.ts"],"names":[],"mappings":"AAUA,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,cAAc,EAEnB,KAAK,YAAY,EAClB,MAAM,yBAAyB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+1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveRecordSource = exports.orderConfiguredSources = exports.isLocalSourceInsideRoot = exports.isLocalType = exports.LOCAL_SOURCE_OUTSIDE_REASON = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Source trust gate for record replay and update. A record may come from a
|
|
39
|
+
* cloned repository, so a configured source that is the same source (same
|
|
40
|
+
* readable id) wins, one from the
|
|
41
|
+
* recorded hub first; otherwise
|
|
42
|
+
* the recorded copy is used without credentials, and a `local` folder must stay
|
|
43
|
+
* inside the repository.
|
|
44
|
+
* @module records/resolve-record-source
|
|
45
|
+
*/
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
const core_1 = require("@ai-primitives-hub/core");
|
|
48
|
+
const record_file_shape_1 = require("./record-file-shape");
|
|
49
|
+
const source_fields_1 = require("./source-fields");
|
|
50
|
+
const to_record_source_1 = require("./to-record-source");
|
|
51
|
+
/** Reason reported for a `local` record source that leaves the repository. */
|
|
52
|
+
exports.LOCAL_SOURCE_OUTSIDE_REASON = 'local source outside the repository';
|
|
53
|
+
/**
|
|
54
|
+
* Whether a source type reads a folder on disk: `local` and every `local-*` type.
|
|
55
|
+
* @param type - Source type.
|
|
56
|
+
*/
|
|
57
|
+
const isLocalType = (type) => type === 'local' || type.startsWith('local-');
|
|
58
|
+
exports.isLocalType = isLocalType;
|
|
59
|
+
/**
|
|
60
|
+
* The record's copy without credentials, prototype-free.
|
|
61
|
+
* @param sourceId - Record key.
|
|
62
|
+
* @param fromRecord - Source as recorded.
|
|
63
|
+
* @param url - URL to use.
|
|
64
|
+
*/
|
|
65
|
+
const fromRecordCopy = (sourceId, fromRecord, url) => Object.assign((0, source_fields_1.copySourceFields)(fromRecord, fromRecord.type, url, source_fields_1.SOURCE_FIELDS_WITHOUT_CREDENTIALS), { sourceId });
|
|
66
|
+
/**
|
|
67
|
+
* Realpath of a recorded `local` folder, when it stays inside the repository root.
|
|
68
|
+
* @param fs - Filesystem port.
|
|
69
|
+
* @param root - Repository root.
|
|
70
|
+
* @param recordedPath - Recorded folder path, relative to the root or absolute.
|
|
71
|
+
*/
|
|
72
|
+
const confineLocalFolder = async (fs, root, recordedPath) => {
|
|
73
|
+
try {
|
|
74
|
+
const realRoot = await fs.realpath(root);
|
|
75
|
+
const realFolder = await fs.realpath(path.resolve(root, recordedPath));
|
|
76
|
+
// The repository root itself is an allowed local source folder.
|
|
77
|
+
return (0, core_1.relativeInside)(realRoot, realFolder, { allowRoot: true }) === undefined ? undefined : realFolder;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Whether a `local` source folder stays inside the repository root once every
|
|
85
|
+
* symlink is resolved.
|
|
86
|
+
* @param fs - Filesystem port.
|
|
87
|
+
* @param root - Repository root.
|
|
88
|
+
* @param localPath - The source's folder, relative to the root or absolute.
|
|
89
|
+
*/
|
|
90
|
+
const isLocalSourceInsideRoot = async (fs, root, localPath) => (await confineLocalFolder(fs, root, localPath)) !== undefined;
|
|
91
|
+
exports.isLocalSourceInsideRoot = isLocalSourceInsideRoot;
|
|
92
|
+
/**
|
|
93
|
+
* Configured sources in the trust gate's lookup order, one per id: the active
|
|
94
|
+
* hub's, then detached sources, then (with `includeOtherHubs`) any other.
|
|
95
|
+
* @param sources - Configured sources, each with its `hubId`.
|
|
96
|
+
* @param activeHubId - Active hub id, or `null`.
|
|
97
|
+
* @param options - Lookup options.
|
|
98
|
+
* @param options.includeOtherHubs - Keep other hubs' sources, last.
|
|
99
|
+
*/
|
|
100
|
+
const orderConfiguredSources = (sources, activeHubId, options = {}) => {
|
|
101
|
+
const tier = (source) => {
|
|
102
|
+
if (activeHubId !== null && source.hubId === activeHubId) {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
return source.hubId === core_1.DEFAULT_LOCAL_HUB_ID ? 1 : 2;
|
|
106
|
+
};
|
|
107
|
+
const byId = new Map();
|
|
108
|
+
const ranked = sources.map((source, index) => ({ source, index, rank: tier(source) }))
|
|
109
|
+
.filter(({ rank }) => rank < 2 || options.includeOtherHubs === true)
|
|
110
|
+
.toSorted((left, right) => left.rank - right.rank || left.index - right.index);
|
|
111
|
+
for (const { source } of ranked) {
|
|
112
|
+
if (!byId.has(source.id)) {
|
|
113
|
+
byId.set(source.id, source);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return [...byId.values()];
|
|
117
|
+
};
|
|
118
|
+
exports.orderConfiguredSources = orderConfiguredSources;
|
|
119
|
+
/**
|
|
120
|
+
* Decide which source an entry is replayed or updated from.
|
|
121
|
+
* @param sourceId - The entry's `sourceId`.
|
|
122
|
+
* @param fromRecord - The record's copy of that source.
|
|
123
|
+
* @param configured - Configured sources by id, active hub first.
|
|
124
|
+
* @param root - Repository root.
|
|
125
|
+
* @param fs - Filesystem port.
|
|
126
|
+
* @param options - Candidate sources and hubs.
|
|
127
|
+
* @returns The source to use, or why the entry is skipped.
|
|
128
|
+
*/
|
|
129
|
+
const resolveRecordSource = async (sourceId, fromRecord, configured, root, fs, options = {}) => {
|
|
130
|
+
const recordedHubId = fromRecord.hubId;
|
|
131
|
+
// A record names a source by its readable id; older records by the configured id.
|
|
132
|
+
const isSource = (candidate) => candidate.id === sourceId || ((0, record_file_shape_1.isRecordSourceId)(sourceId) && (0, record_file_shape_1.recordSourceIdOf)((0, to_record_source_1.toRecordSource)(candidate, candidate.id)) === sourceId);
|
|
133
|
+
// A record names a hub by its readable id; older records by the configured id.
|
|
134
|
+
const isRecordedHub = (hubId) => {
|
|
135
|
+
if (hubId === undefined) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const hub = options.hubs?.get(hubId);
|
|
139
|
+
return hubId === recordedHubId || (hub !== undefined && (0, record_file_shape_1.recordHubIdOf)(hub) === recordedHubId);
|
|
140
|
+
};
|
|
141
|
+
const sameHub = typeof recordedHubId === 'string' && recordedHubId !== ''
|
|
142
|
+
? options.candidates?.find((candidate) => isSource(candidate) && isRecordedHub(candidate.hubId))
|
|
143
|
+
: undefined;
|
|
144
|
+
const match = sameHub ?? configured.get(sourceId) ?? [...configured.values()].find((candidate) => isSource(candidate));
|
|
145
|
+
if (match !== undefined) {
|
|
146
|
+
const hub = match.hubId === undefined ? undefined : options.hubs?.get(match.hubId);
|
|
147
|
+
// Normalised as an install records it, so older records are re-recorded the same way.
|
|
148
|
+
return { use: (0, to_record_source_1.toRecordSource)(match, sourceId, hub), configured: true, ...(hub === undefined ? {} : { hub }) };
|
|
149
|
+
}
|
|
150
|
+
if (!(0, exports.isLocalType)(fromRecord.type)) {
|
|
151
|
+
return { use: fromRecordCopy(sourceId, fromRecord, fromRecord.url) };
|
|
152
|
+
}
|
|
153
|
+
// Same check as `isLocalSourceInsideRoot`, keeping the realpath it resolved.
|
|
154
|
+
const folder = await confineLocalFolder(fs, root, fromRecord.url);
|
|
155
|
+
return folder === undefined
|
|
156
|
+
? { skip: exports.LOCAL_SOURCE_OUTSIDE_REASON }
|
|
157
|
+
: { use: fromRecordCopy(sourceId, fromRecord, folder) };
|
|
158
|
+
};
|
|
159
|
+
exports.resolveRecordSource = resolveRecordSource;
|
|
160
|
+
//# sourceMappingURL=resolve-record-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-record-source.js","sourceRoot":"","sources":["../../src/records/resolve-record-source.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;GAQG;AACH,gDAAkC;AAClC,kDAMiC;AACjC,2DAI6B;AAI7B,mDAGyB;AACzB,yDAE4B;AAY5B,8EAA8E;AACjE,QAAA,2BAA2B,GAAG,qCAAqC,CAAC;AAEjF;;;GAGG;AACI,MAAM,WAAW,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AAAvF,QAAA,WAAW,eAA4E;AAEpG;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,UAAwB,EAAE,GAAW,EAAuC,EAAE,CACtH,MAAM,CA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IAAA,iCAAc,EAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IAChH,CAAC;IACD,IAAI,CAAC,IAAA,mBAAW,EAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IACvE,CAAC;IACD,6EAA6E;IAC7E,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAClE,OAAO,MAAM,KAAK,SAAS;QACzB,CAAC,CAAC,EAAE,IAAI,EAAE,mCAA2B,EAAE;QACvC,CAAC,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC;AAC5D,CAAC,CAAC;AArCW,QAAA,mBAAmB,uBAqC9B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source sanitizer for install records: only the known source fields are
|
|
3
|
+
* copied, and credentials are removed from the URL, so no secret reaches a record.
|
|
4
|
+
* @module records/sanitize-source
|
|
5
|
+
*/
|
|
6
|
+
import { type SourceRecord } from '@ai-primitives-hub/core';
|
|
7
|
+
/**
|
|
8
|
+
* Remove the user name, password and token-like query parameters from a source URL; `git@` scp URLs are kept.
|
|
9
|
+
* @param url - Source URL or path.
|
|
10
|
+
*/
|
|
11
|
+
export declare const sanitizeSourceUrl: (url: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Copy the known fields of a source into a prototype-free `SourceRecord` with its URL cleaned.
|
|
14
|
+
* @param source - Source details passed to `recordInstall`.
|
|
15
|
+
* @throws {RegistryError} `RECORD.MALFORMED` when `type` or `url` is missing.
|
|
16
|
+
*/
|
|
17
|
+
export declare const sanitizeSource: (source: Readonly<Record<string, unknown>>) => SourceRecord;
|
|
18
|
+
//# sourceMappingURL=sanitize-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-source.d.ts","sourceRoot":"","sources":["../../src/records/sanitize-source.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAC;AA0DjC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,KAAG,MAc/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAG,YAM1E,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeSource = exports.sanitizeSourceUrl = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Source sanitizer for install records: only the known source fields are
|
|
6
|
+
* copied, and credentials are removed from the URL, so no secret reaches a record.
|
|
7
|
+
* @module records/sanitize-source
|
|
8
|
+
*/
|
|
9
|
+
const core_1 = require("@ai-primitives-hub/core");
|
|
10
|
+
const source_fields_1 = require("./source-fields");
|
|
11
|
+
/** Query parameter names that look like a credential. */
|
|
12
|
+
const TOKEN_PARAM_PATTERN = /token|^sig$|^signature$|^key$|^api[-_]?key$|secret|password|^auth|credential/i;
|
|
13
|
+
/** A URL scheme of two or more characters (one is a drive letter), with any number of slashes after it. */
|
|
14
|
+
const SCHEME_PATTERN = /^[a-z][\d+.a-z-]+:/i;
|
|
15
|
+
/** An absolute local path: drive letter, POSIX root or UNC. */
|
|
16
|
+
const ABSOLUTE_LOCAL_PATH_PATTERN = /^(?:[a-z]:[/\\]|\/|\\\\)/i;
|
|
17
|
+
/** scp-style SSH address: `user@host:path`, with no scheme. */
|
|
18
|
+
const SCP_PATTERN = /^([^\s/:@]+)@([^\s/:@]+):(.*)$/;
|
|
19
|
+
/** The only scp-style user kept, because it is not a secret. */
|
|
20
|
+
const SCP_PUBLIC_USER = 'git';
|
|
21
|
+
const sanitizeStandardUrl = (url) => {
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = new URL(url);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
let changed = false;
|
|
30
|
+
if (parsed.username !== '' || parsed.password !== '') {
|
|
31
|
+
parsed.username = '';
|
|
32
|
+
parsed.password = '';
|
|
33
|
+
changed = true;
|
|
34
|
+
}
|
|
35
|
+
for (const name of new Set(parsed.searchParams.keys())) {
|
|
36
|
+
if (TOKEN_PARAM_PATTERN.test(name)) {
|
|
37
|
+
parsed.searchParams.delete(name);
|
|
38
|
+
changed = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Keep the text exactly as given when nothing secret was in it.
|
|
42
|
+
return changed ? parsed.toString() : url;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Fallback for text that does not parse: drop the user part of the authority.
|
|
46
|
+
* @param url - URL text.
|
|
47
|
+
*/
|
|
48
|
+
const stripAuthorityUser = (url) => {
|
|
49
|
+
const schemeEnd = url.indexOf('://');
|
|
50
|
+
const start = schemeEnd === -1 ? 0 : schemeEnd + 3;
|
|
51
|
+
const rest = url.slice(start);
|
|
52
|
+
const authorityEnd = rest.search(/[#/?]/);
|
|
53
|
+
const authority = authorityEnd === -1 ? rest : rest.slice(0, authorityEnd);
|
|
54
|
+
const at = authority.lastIndexOf('@');
|
|
55
|
+
return at === -1 ? url : `${url.slice(0, start)}${rest.slice(at + 1)}`;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Remove the user name, password and token-like query parameters from a source URL; `git@` scp URLs are kept.
|
|
59
|
+
* @param url - Source URL or path.
|
|
60
|
+
*/
|
|
61
|
+
const sanitizeSourceUrl = (url) => {
|
|
62
|
+
// A local path has no authority: an `@` in it is part of a folder name.
|
|
63
|
+
if (ABSOLUTE_LOCAL_PATH_PATTERN.test(url)) {
|
|
64
|
+
return url;
|
|
65
|
+
}
|
|
66
|
+
if (SCHEME_PATTERN.test(url)) {
|
|
67
|
+
return sanitizeStandardUrl(url) ?? stripAuthorityUser(url);
|
|
68
|
+
}
|
|
69
|
+
const scp = SCP_PATTERN.exec(url);
|
|
70
|
+
if (scp !== null) {
|
|
71
|
+
const [, user, host, rest] = scp;
|
|
72
|
+
return user === SCP_PUBLIC_USER ? url : `${host}:${rest}`;
|
|
73
|
+
}
|
|
74
|
+
return stripAuthorityUser(url);
|
|
75
|
+
};
|
|
76
|
+
exports.sanitizeSourceUrl = sanitizeSourceUrl;
|
|
77
|
+
/**
|
|
78
|
+
* Copy the known fields of a source into a prototype-free `SourceRecord` with its URL cleaned.
|
|
79
|
+
* @param source - Source details passed to `recordInstall`.
|
|
80
|
+
* @throws {RegistryError} `RECORD.MALFORMED` when `type` or `url` is missing.
|
|
81
|
+
*/
|
|
82
|
+
const sanitizeSource = (source) => {
|
|
83
|
+
const { type, url } = source;
|
|
84
|
+
if (typeof type !== 'string' || type === '' || typeof url !== 'string' || url === '') {
|
|
85
|
+
throw (0, core_1.recordError)('RECORD.MALFORMED', { detail: 'a source needs a type and a url' });
|
|
86
|
+
}
|
|
87
|
+
return (0, source_fields_1.copySourceFields)(source, type, (0, exports.sanitizeSourceUrl)(url), source_fields_1.SOURCE_FIELDS);
|
|
88
|
+
};
|
|
89
|
+
exports.sanitizeSource = sanitizeSource;
|
|
90
|
+
//# sourceMappingURL=sanitize-source.js.map
|