handoff-app 1.2.2-7 → 2.0.0-1
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/Changelog.md +37 -15
- package/README.md +372 -118
- package/dist/app-builder/build.d.ts +41 -2
- package/dist/app-builder/build.js +455 -18
- package/dist/app-builder/client-config.d.ts +15 -2
- package/dist/app-builder/client-config.js +43 -4
- package/dist/app-builder/config-diff/snapshot.d.ts +1 -6
- package/dist/app-builder/config-diff/snapshot.js +2 -9
- package/dist/app-builder/index.d.ts +1 -1
- package/dist/app-builder/index.js +3 -1
- package/dist/app-builder/nav-shell.d.ts +23 -0
- package/dist/app-builder/nav-shell.js +80 -0
- package/dist/app-builder/paths.js +25 -1
- package/dist/app-builder/static-export.d.ts +17 -0
- package/dist/app-builder/static-export.js +206 -0
- package/dist/app-builder/vercel-output.d.ts +39 -0
- package/dist/app-builder/vercel-output.js +259 -0
- package/dist/app-builder/watchers/utils.d.ts +2 -0
- package/dist/app-builder/watchers.d.ts +14 -4
- package/dist/app-builder/watchers.js +123 -28
- package/dist/app-builder/websocket.js +1 -1
- package/dist/artifacts/index.d.ts +2 -0
- package/dist/artifacts/index.js +16 -0
- package/dist/artifacts/types.d.ts +136 -0
- package/dist/artifacts/types.js +24 -0
- package/dist/artifacts/url.d.ts +67 -0
- package/dist/artifacts/url.js +116 -0
- package/dist/cache/build-cache.js +48 -4
- package/dist/cli.js +0 -0
- package/dist/commands/build/app.js +1 -2
- package/dist/commands/build/index.d.ts +17 -0
- package/dist/commands/build/index.js +66 -0
- package/dist/commands/checkout/index.d.ts +24 -0
- package/dist/commands/checkout/index.js +71 -0
- package/dist/commands/db/migrate.d.ts +11 -0
- package/dist/commands/db/migrate.js +33 -0
- package/dist/commands/index.js +8 -0
- package/dist/commands/publish/index.d.ts +21 -0
- package/dist/commands/publish/index.js +68 -0
- package/dist/config/defaults.js +15 -1
- package/dist/config/loader.js +6 -1
- package/dist/config/normalizers/declaration.js +4 -1
- package/dist/config/normalizers/page.d.ts +18 -0
- package/dist/config/normalizers/page.js +34 -0
- package/dist/config/normalizers/pattern.js +7 -1
- package/dist/config/runtime.d.ts +4 -0
- package/dist/config/runtime.js +53 -5
- package/dist/index.d.ts +65 -1
- package/dist/index.js +123 -3
- package/dist/nav/index.d.ts +83 -0
- package/dist/nav/index.js +9 -0
- package/dist/nav/registry.d.ts +15 -0
- package/dist/nav/registry.js +42 -0
- package/dist/nav/resolver.d.ts +8 -0
- package/dist/nav/resolver.js +192 -0
- package/dist/nav/workspace.d.ts +18 -0
- package/dist/nav/workspace.js +103 -0
- package/dist/pipeline/styles.js +7 -35
- package/dist/pipeline/token-transformers.d.ts +45 -0
- package/dist/pipeline/token-transformers.js +71 -0
- package/dist/registry/asset-storage/adapters/vercel-blob.d.ts +17 -0
- package/dist/registry/asset-storage/adapters/vercel-blob.js +87 -0
- package/dist/registry/asset-storage/define.d.ts +10 -0
- package/dist/registry/asset-storage/define.js +13 -0
- package/dist/registry/asset-storage/resolve.d.ts +45 -0
- package/dist/registry/asset-storage/resolve.js +36 -0
- package/dist/registry/asset-storage/types.d.ts +51 -0
- package/dist/registry/asset-storage/types.js +9 -0
- package/dist/registry/assets/layout.d.ts +22 -0
- package/dist/registry/assets/layout.js +30 -0
- package/dist/registry/assets/sets.d.ts +18 -0
- package/dist/registry/assets/sets.js +44 -0
- package/dist/registry/assets/transfer.d.ts +45 -0
- package/dist/registry/assets/transfer.js +11 -0
- package/dist/registry/checkout/assets.d.ts +16 -0
- package/dist/registry/checkout/assets.js +150 -0
- package/dist/registry/checkout/index.d.ts +33 -0
- package/dist/registry/checkout/index.js +610 -0
- package/dist/registry/checkout/tokens.d.ts +15 -0
- package/dist/registry/checkout/tokens.js +171 -0
- package/dist/registry/client.d.ts +61 -0
- package/dist/registry/client.js +211 -0
- package/dist/registry/connection.d.ts +30 -0
- package/dist/registry/connection.js +36 -0
- package/dist/registry/db/adapter.d.ts +43 -0
- package/dist/registry/db/adapter.js +59 -0
- package/dist/registry/db/client.d.ts +35 -0
- package/dist/registry/db/client.js +94 -0
- package/dist/registry/db/index.d.ts +5 -0
- package/dist/registry/db/index.js +24 -0
- package/dist/registry/db/migrate.d.ts +23 -0
- package/dist/registry/db/migrate.js +64 -0
- package/dist/registry/db/schema.d.ts +4869 -0
- package/dist/registry/db/schema.js +347 -0
- package/dist/registry/path.d.ts +4 -0
- package/dist/registry/path.js +31 -0
- package/dist/registry/publish/artifacts.d.ts +16 -0
- package/dist/registry/publish/artifacts.js +132 -0
- package/dist/registry/publish/assets.d.ts +16 -0
- package/dist/registry/publish/assets.js +129 -0
- package/dist/registry/publish/errors.d.ts +5 -0
- package/dist/registry/publish/errors.js +26 -0
- package/dist/registry/publish/index.d.ts +27 -0
- package/dist/registry/publish/index.js +126 -0
- package/dist/registry/publish/package.d.ts +27 -0
- package/dist/registry/publish/package.js +257 -0
- package/dist/registry/publish/publish-build.d.ts +12 -0
- package/dist/registry/publish/publish-build.js +43 -0
- package/dist/registry/publish/tokens.d.ts +18 -0
- package/dist/registry/publish/tokens.js +112 -0
- package/dist/registry/tokens/sets.d.ts +59 -0
- package/dist/registry/tokens/sets.js +109 -0
- package/dist/registry/tokens/transfer.d.ts +48 -0
- package/dist/registry/tokens/transfer.js +10 -0
- package/dist/registry/transfer.d.ts +75 -0
- package/dist/registry/transfer.js +11 -0
- package/dist/store/filesystem-assets.d.ts +17 -0
- package/dist/store/filesystem-assets.js +147 -0
- package/dist/store/filesystem.d.ts +76 -0
- package/dist/store/filesystem.js +208 -0
- package/dist/store/index.d.ts +20 -0
- package/dist/store/index.js +38 -0
- package/dist/store/registry.d.ts +77 -0
- package/dist/store/registry.js +350 -0
- package/dist/store/source-files.d.ts +24 -0
- package/dist/store/source-files.js +147 -0
- package/dist/store/types.d.ts +185 -0
- package/dist/store/types.js +12 -0
- package/dist/transformers/plugins/csf-render.js +17 -8
- package/dist/transformers/plugins/handlebars-previews.js +10 -3
- package/dist/transformers/plugins/ssr-render.js +116 -49
- package/dist/transformers/preview/component/api.js +3 -1
- package/dist/transformers/preview/component/artifacts.js +8 -1
- package/dist/transformers/preview/component/builder.js +13 -5
- package/dist/transformers/preview/component/css.js +9 -1
- package/dist/transformers/preview/component/javascript.d.ts +9 -3
- package/dist/transformers/preview/component/javascript.js +45 -17
- package/dist/transformers/preview/component/shared-artifacts.d.ts +83 -0
- package/dist/transformers/preview/component/shared-artifacts.js +92 -0
- package/dist/transformers/preview/component.js +5 -2
- package/dist/transformers/preview/pattern/builder.js +28 -9
- package/dist/transformers/preview/pattern/html.d.ts +13 -10
- package/dist/transformers/preview/pattern/html.js +62 -27
- package/dist/transformers/preview/types.d.ts +38 -0
- package/dist/transformers/utils/handlebars.d.ts +3 -0
- package/dist/transformers/utils/handlebars.js +19 -5
- package/dist/types/config.d.ts +124 -31
- package/dist/utils/menu-shell.d.ts +60 -0
- package/dist/utils/menu-shell.js +221 -0
- package/dist/utils/stable-stringify.d.ts +2 -0
- package/dist/utils/stable-stringify.js +8 -0
- package/docs/cli.md +4 -2
- package/drizzle/0000_init_registry_storage.sql +95 -0
- package/drizzle/0001_add_review_metadata.sql +2 -0
- package/drizzle/0002_add_pages.sql +28 -0
- package/drizzle/0003_add_tokens.sql +29 -0
- package/drizzle/0004_add_assets.sql +37 -0
- package/drizzle/meta/0000_snapshot.json +642 -0
- package/drizzle/meta/0001_snapshot.json +654 -0
- package/drizzle/meta/0002_snapshot.json +835 -0
- package/drizzle/meta/0003_snapshot.json +1023 -0
- package/drizzle/meta/0004_snapshot.json +1252 -0
- package/drizzle/meta/_journal.json +41 -0
- package/drizzle.config.ts +16 -0
- package/package.json +10 -1
- package/src/app/components/Component/Preview.tsx +3 -2
- package/src/app/components/Component/RegistryActions.tsx +150 -0
- package/src/app/components/Foundations/DisplayLogo.tsx +11 -3
- package/src/app/components/Layout/Header.tsx +21 -3
- package/src/app/components/Layout/Main.tsx +11 -3
- package/src/app/components/Navigation/MainNav.tsx +4 -2
- package/src/app/components/Navigation/MobileNav.tsx +4 -2
- package/src/app/components/Navigation/SideNav.tsx +46 -11
- package/src/app/components/NotFound.tsx +24 -0
- package/src/app/components/context/NavProvider.tsx +71 -0
- package/src/app/components/old/Header.tsx +3 -3
- package/src/app/components/util/index.ts +203 -380
- package/src/app/components/util/useCollectionAssets.ts +125 -0
- package/src/app/components/util/useFoundationTokens.ts +67 -0
- package/src/app/generated/default-pages.json +1 -0
- package/src/app/generated/nav-shell.json +1 -0
- package/src/app/lib/api/query.ts +6 -0
- package/src/app/lib/api/redact.ts +46 -0
- package/src/app/lib/asset-storage.ts +81 -0
- package/src/app/lib/docs-api/artifacts.ts +116 -0
- package/src/app/lib/docs-api/backend.ts +151 -0
- package/src/app/lib/docs-api/errors.ts +52 -0
- package/src/app/lib/docs-api/handler.ts +34 -0
- package/src/app/lib/docs-api/index.ts +7 -0
- package/src/app/lib/docs-api/records.ts +189 -0
- package/src/app/lib/docs-api/registry.ts +130 -0
- package/src/app/lib/docs-api/runtime-config.ts +173 -0
- package/src/app/lib/docs-api/serve.ts +37 -0
- package/src/app/lib/docs-api/token-detail.ts +19 -0
- package/src/app/lib/registry-api/allowlist.ts +163 -0
- package/src/app/lib/registry-api/asset-transfer.ts +363 -0
- package/src/app/lib/registry-api/auth.ts +68 -0
- package/src/app/lib/registry-api/entity-routes.ts +197 -0
- package/src/app/lib/registry-api/errors.ts +51 -0
- package/src/app/lib/registry-api/files.ts +135 -0
- package/src/app/lib/registry-api/handler.ts +96 -0
- package/src/app/lib/registry-api/index.ts +4 -0
- package/src/app/lib/registry-api/meta.ts +87 -0
- package/src/app/lib/registry-api/revalidate.ts +36 -0
- package/src/app/lib/registry-api/store.ts +348 -0
- package/src/app/lib/registry-api/token-transfer.ts +231 -0
- package/src/app/lib/registry-api/transfer.ts +513 -0
- package/src/app/lib/registry-api/validation.ts +74 -0
- package/src/app/lib/registry-connection.ts +58 -0
- package/src/app/lib/utils.ts +14 -0
- package/src/app/next.config.mjs +72 -13
- package/src/app/pages/[...slug]/index.tsx +74 -20
- package/src/app/pages/_app.tsx +5 -2
- package/src/app/pages/api/docs/artifacts/[...artifactPath].ts +16 -0
- package/src/app/pages/api/docs/assets/[collection]/[...path].ts +50 -0
- package/src/app/pages/api/docs/assets/[collection]/index.ts +22 -0
- package/src/app/pages/api/docs/components/[id]/assets/[asset].ts +33 -0
- package/src/app/pages/api/docs/components/[id]/inspect/[previewId].ts +20 -0
- package/src/app/pages/api/docs/components/[id]/previews/[previewId].ts +21 -0
- package/src/app/pages/api/docs/components/[id].ts +24 -0
- package/src/app/pages/api/docs/components.json.ts +12 -0
- package/src/app/pages/api/docs/nav.json.ts +48 -0
- package/src/app/pages/api/docs/patterns/[id]/preview.ts +19 -0
- package/src/app/pages/api/docs/patterns/[id].ts +24 -0
- package/src/app/pages/api/docs/patterns.json.ts +12 -0
- package/src/app/pages/api/docs/tokens/components/[id].ts +30 -0
- package/src/app/pages/api/docs/tokens/foundations/[type].ts +32 -0
- package/src/app/pages/api/registry/components/[id]/files/[...filePath].ts +19 -0
- package/src/app/pages/api/registry/components/[id]/files/index.ts +19 -0
- package/src/app/pages/api/registry/components/[id].ts +20 -0
- package/src/app/pages/api/registry/components/index.ts +19 -0
- package/src/app/pages/api/registry/health.ts +20 -0
- package/src/app/pages/api/registry/patterns/[id]/files/[...filePath].ts +19 -0
- package/src/app/pages/api/registry/patterns/[id]/files/index.ts +19 -0
- package/src/app/pages/api/registry/patterns/[id].ts +20 -0
- package/src/app/pages/api/registry/patterns/index.ts +19 -0
- package/src/app/pages/api/registry/transfer/[kind]/[id].ts +39 -0
- package/src/app/pages/api/registry/transfer/assets/[collection].ts +24 -0
- package/src/app/pages/api/registry/transfer/assets/blobs/[hash].ts +23 -0
- package/src/app/pages/api/registry/transfer/assets/blobs/have.ts +11 -0
- package/src/app/pages/api/registry/transfer/assets/index.ts +10 -0
- package/src/app/pages/api/registry/transfer/tokens/[...setId].ts +26 -0
- package/src/app/pages/api/registry/transfer/tokens/index.ts +11 -0
- package/src/app/pages/assets/fonts.tsx +41 -17
- package/src/app/pages/assets/index.tsx +2 -2
- package/src/app/pages/assets/logos.tsx +6 -3
- package/src/app/pages/foundations/colors.tsx +18 -8
- package/src/app/pages/foundations/effects.tsx +18 -8
- package/src/app/pages/foundations/icons/[name]/index.tsx +28 -16
- package/src/app/pages/foundations/icons/index.tsx +18 -12
- package/src/app/pages/foundations/index.tsx +1 -1
- package/src/app/pages/foundations/logo.tsx +12 -8
- package/src/app/pages/foundations/typography.tsx +19 -9
- package/src/app/pages/index.tsx +1 -1
- package/src/app/pages/system/component/[component]/index.tsx +87 -17
- package/src/app/pages/system/index.tsx +13 -4
- package/src/app/pages/system/pattern/[pattern]/index.tsx +70 -14
- package/src/app/pages/system/tokens/components/[component]/index.tsx +42 -14
- package/src/app/pages/system/tokens/foundations/colors.tsx +7 -5
- package/src/app/pages/system/tokens/foundations/effects.tsx +7 -5
- package/src/app/pages/system/tokens/foundations/typography.tsx +8 -4
- package/src/app/tsconfig.json +2 -3
- package/src/app-builder/build.ts +555 -11
- package/src/app-builder/client-config.ts +61 -4
- package/src/app-builder/config-diff/snapshot.ts +1 -11
- package/src/app-builder/index.ts +1 -1
- package/src/app-builder/nav-shell.ts +74 -0
- package/src/app-builder/paths.ts +27 -1
- package/src/app-builder/static-export.ts +242 -0
- package/src/app-builder/vercel-output.ts +297 -0
- package/src/app-builder/watchers/utils.ts +2 -0
- package/src/app-builder/watchers.ts +149 -25
- package/src/app-builder/websocket.ts +2 -2
- package/src/artifacts/README.md +14 -0
- package/src/artifacts/index.ts +24 -0
- package/src/artifacts/types.ts +146 -0
- package/src/artifacts/url.ts +122 -0
- package/src/cache/build-cache.ts +47 -2
- package/src/commands/build/app.ts +1 -2
- package/src/commands/build/index.ts +61 -0
- package/src/commands/checkout/index.ts +66 -0
- package/src/commands/db/migrate.ts +25 -0
- package/src/commands/index.ts +8 -0
- package/src/commands/publish/index.ts +63 -0
- package/src/config/defaults.ts +15 -0
- package/src/config/loader.ts +10 -1
- package/src/config/normalizers/declaration.ts +3 -0
- package/src/config/normalizers/page.ts +45 -0
- package/src/config/normalizers/pattern.ts +4 -1
- package/src/config/runtime.ts +48 -2
- package/src/index.ts +126 -3
- package/src/nav/index.ts +94 -0
- package/src/nav/registry.ts +54 -0
- package/src/nav/resolver.ts +217 -0
- package/src/nav/workspace.ts +87 -0
- package/src/pipeline/styles.ts +4 -35
- package/src/pipeline/token-transformers.ts +97 -0
- package/src/registry/asset-storage/adapters/vercel-blob.ts +51 -0
- package/src/registry/asset-storage/define.ts +15 -0
- package/src/registry/asset-storage/resolve.ts +72 -0
- package/src/registry/asset-storage/types.ts +46 -0
- package/src/registry/assets/layout.ts +38 -0
- package/src/registry/assets/sets.ts +48 -0
- package/src/registry/assets/transfer.ts +50 -0
- package/src/registry/checkout/assets.ts +126 -0
- package/src/registry/checkout/index.ts +596 -0
- package/src/registry/checkout/tokens.ts +152 -0
- package/src/registry/client.ts +234 -0
- package/src/registry/connection.ts +50 -0
- package/src/registry/db/adapter.ts +74 -0
- package/src/registry/db/client.ts +88 -0
- package/src/registry/db/index.ts +35 -0
- package/src/registry/db/migrate.ts +56 -0
- package/src/registry/db/schema.ts +444 -0
- package/src/registry/path.ts +26 -0
- package/src/registry/publish/artifacts.ts +147 -0
- package/src/registry/publish/assets.ts +129 -0
- package/src/registry/publish/errors.ts +34 -0
- package/src/registry/publish/index.ts +128 -0
- package/src/registry/publish/package.ts +272 -0
- package/src/registry/publish/publish-build.ts +51 -0
- package/src/registry/publish/tokens.ts +119 -0
- package/src/registry/tokens/sets.ts +132 -0
- package/src/registry/tokens/transfer.ts +53 -0
- package/src/registry/transfer.ts +82 -0
- package/src/store/filesystem-assets.ts +152 -0
- package/src/store/filesystem.ts +237 -0
- package/src/store/index.ts +62 -0
- package/src/store/registry.ts +334 -0
- package/src/store/source-files.ts +155 -0
- package/src/store/types.ts +210 -0
- package/src/transformers/plugins/csf-render.ts +31 -7
- package/src/transformers/plugins/handlebars-previews.ts +22 -3
- package/src/transformers/plugins/ssr-render.ts +145 -57
- package/src/transformers/preview/component/api.ts +2 -1
- package/src/transformers/preview/component/artifacts.ts +10 -1
- package/src/transformers/preview/component/builder.ts +9 -2
- package/src/transformers/preview/component/css.ts +10 -1
- package/src/transformers/preview/component/javascript.ts +55 -20
- package/src/transformers/preview/component/shared-artifacts.ts +146 -0
- package/src/transformers/preview/component.ts +5 -2
- package/src/transformers/preview/pattern/builder.ts +33 -7
- package/src/transformers/preview/pattern/html.ts +71 -27
- package/src/transformers/preview/types.ts +42 -0
- package/src/transformers/utils/handlebars.ts +31 -5
- package/src/types/config.ts +129 -31
- package/src/utils/menu-shell.ts +241 -0
- package/src/utils/stable-stringify.ts +7 -0
- package/templates/default/package.json.tpl +1 -1
- package/handoff.config.js +0 -90
- package/src/app/components/ComponentSearch.tsx +0 -93
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Database-backed implementation of the normalized store abstraction.
|
|
4
|
+
*
|
|
5
|
+
* Registry mode serves only what was published to it: this store reads normalized component and
|
|
6
|
+
* pattern records — and their checkout/inspection source files — straight from the registry
|
|
7
|
+
* database. It is the registry counterpart to {@link FilesystemComponentStore},
|
|
8
|
+
* so the docs read API and other consumers stay storage-agnostic.
|
|
9
|
+
*
|
|
10
|
+
* Two invariants hold here that the filesystem store does not enforce:
|
|
11
|
+
* - Filesystem workspace declarations are never loaded as registry content; declarations are
|
|
12
|
+
* workspace-only (synthesized on checkout) and the registry text-file tables reject the
|
|
13
|
+
* `declaration` kind at the schema level, so they can never surface through this store.
|
|
14
|
+
* - Reads never materialize source files or run the build pipeline — every record and file is
|
|
15
|
+
* returned exactly as it was published.
|
|
16
|
+
*/
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
27
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
28
|
+
var m = o[Symbol.asyncIterator], i;
|
|
29
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
30
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
31
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.createRegistryStore = exports.RegistryAssetStore = exports.RegistryTokenStore = exports.RegistryPageStore = exports.RegistryPatternStore = exports.RegistryComponentStore = void 0;
|
|
35
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
36
|
+
const schema_1 = require("../registry/db/schema");
|
|
37
|
+
/**
|
|
38
|
+
* Map a persisted file row to a {@link TextFileResource}. Rows whose content is stored externally
|
|
39
|
+
* (a future object-storage `storageRef` with no inline `content`) are skipped — there is nothing to
|
|
40
|
+
* return inline for them yet. Registry records have no filesystem location, so `absolutePath` is
|
|
41
|
+
* empty (it is documented as workspace-store-only on the type).
|
|
42
|
+
*/
|
|
43
|
+
const toTextFileResource = (row) => {
|
|
44
|
+
if (row.content == null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
path: row.path,
|
|
49
|
+
absolutePath: '',
|
|
50
|
+
kind: row.kind,
|
|
51
|
+
content: row.content,
|
|
52
|
+
contentType: row.contentType,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
class RegistryComponentStore {
|
|
56
|
+
constructor(context) {
|
|
57
|
+
this.context = context;
|
|
58
|
+
}
|
|
59
|
+
list() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const rows = yield this.context.db.select({ record: schema_1.components.record }).from(schema_1.components);
|
|
62
|
+
return rows.map((row) => row.record);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
get(id) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const rows = yield this.context.db
|
|
69
|
+
.select({ record: schema_1.components.record })
|
|
70
|
+
.from(schema_1.components)
|
|
71
|
+
.where((0, drizzle_orm_1.eq)(schema_1.components.id, id))
|
|
72
|
+
.limit(1);
|
|
73
|
+
return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.record) !== null && _b !== void 0 ? _b : null;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Registry source files are keyed by `(entity, path)`, not by an absolute filesystem path, so the
|
|
78
|
+
* filesystem-shaped {@link SourceReference} has no resolvable target here. Related files are read
|
|
79
|
+
* through {@link getRelatedSourceFiles}.
|
|
80
|
+
*/
|
|
81
|
+
getSource(_ref) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return null;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getRelatedSourceFiles(id) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const rows = yield this.context.db
|
|
89
|
+
.select({
|
|
90
|
+
path: schema_1.componentFiles.path,
|
|
91
|
+
kind: schema_1.componentFiles.kind,
|
|
92
|
+
content: schema_1.componentFiles.content,
|
|
93
|
+
contentType: schema_1.componentFiles.contentType,
|
|
94
|
+
})
|
|
95
|
+
.from(schema_1.componentFiles)
|
|
96
|
+
.where((0, drizzle_orm_1.eq)(schema_1.componentFiles.componentId, id));
|
|
97
|
+
return rows.map(toTextFileResource).filter((file) => file !== null);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.RegistryComponentStore = RegistryComponentStore;
|
|
102
|
+
class RegistryPatternStore {
|
|
103
|
+
constructor(context) {
|
|
104
|
+
this.context = context;
|
|
105
|
+
}
|
|
106
|
+
list() {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const rows = yield this.context.db.select({ record: schema_1.patterns.record }).from(schema_1.patterns);
|
|
109
|
+
return rows.map((row) => row.record);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
get(id) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const rows = yield this.context.db
|
|
116
|
+
.select({ record: schema_1.patterns.record })
|
|
117
|
+
.from(schema_1.patterns)
|
|
118
|
+
.where((0, drizzle_orm_1.eq)(schema_1.patterns.id, id))
|
|
119
|
+
.limit(1);
|
|
120
|
+
return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.record) !== null && _b !== void 0 ? _b : null;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
getSource(_ref) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
return null;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getRelatedSourceFiles(id) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const rows = yield this.context.db
|
|
131
|
+
.select({
|
|
132
|
+
path: schema_1.patternFiles.path,
|
|
133
|
+
kind: schema_1.patternFiles.kind,
|
|
134
|
+
content: schema_1.patternFiles.content,
|
|
135
|
+
contentType: schema_1.patternFiles.contentType,
|
|
136
|
+
})
|
|
137
|
+
.from(schema_1.patternFiles)
|
|
138
|
+
.where((0, drizzle_orm_1.eq)(schema_1.patternFiles.patternId, id));
|
|
139
|
+
return rows.map(toTextFileResource).filter((file) => file !== null);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.RegistryPatternStore = RegistryPatternStore;
|
|
144
|
+
class RegistryPageStore {
|
|
145
|
+
constructor(context) {
|
|
146
|
+
this.context = context;
|
|
147
|
+
}
|
|
148
|
+
list() {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const rows = yield this.context.db.select({ record: schema_1.pages.record }).from(schema_1.pages);
|
|
151
|
+
return rows.map((row) => row.record);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
get(id) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
const rows = yield this.context.db.select({ record: schema_1.pages.record }).from(schema_1.pages).where((0, drizzle_orm_1.eq)(schema_1.pages.id, id)).limit(1);
|
|
158
|
+
return (_b = (_a = rows[0]) === null || _a === void 0 ? void 0 : _a.record) !== null && _b !== void 0 ? _b : null;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
getSource(_ref) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
return null;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
getRelatedSourceFiles(id) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const rows = yield this.context.db
|
|
169
|
+
.select({
|
|
170
|
+
path: schema_1.pageFiles.path,
|
|
171
|
+
kind: schema_1.pageFiles.kind,
|
|
172
|
+
content: schema_1.pageFiles.content,
|
|
173
|
+
contentType: schema_1.pageFiles.contentType,
|
|
174
|
+
})
|
|
175
|
+
.from(schema_1.pageFiles)
|
|
176
|
+
.where((0, drizzle_orm_1.eq)(schema_1.pageFiles.pageId, id));
|
|
177
|
+
return rows.map(toTextFileResource).filter((file) => file !== null);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.RegistryPageStore = RegistryPageStore;
|
|
182
|
+
class RegistryTokenStore {
|
|
183
|
+
constructor(context) {
|
|
184
|
+
this.context = context;
|
|
185
|
+
}
|
|
186
|
+
listSets() {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const rows = yield this.context.db.select({ id: schema_1.tokenSets.id, kind: schema_1.tokenSets.kind, record: schema_1.tokenSets.record }).from(schema_1.tokenSets);
|
|
189
|
+
return rows.map((row) => ({ id: row.id, kind: row.kind, record: row.record }));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
getSet(id) {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
const rows = yield this.context.db
|
|
195
|
+
.select({ id: schema_1.tokenSets.id, kind: schema_1.tokenSets.kind, record: schema_1.tokenSets.record })
|
|
196
|
+
.from(schema_1.tokenSets)
|
|
197
|
+
.where((0, drizzle_orm_1.eq)(schema_1.tokenSets.id, id))
|
|
198
|
+
.limit(1);
|
|
199
|
+
const row = rows[0];
|
|
200
|
+
return row ? { id: row.id, kind: row.kind, record: row.record } : null;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
getArtifacts(id) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const rows = yield this.context.db
|
|
206
|
+
.select({ path: schema_1.tokenArtifacts.path, format: schema_1.tokenArtifacts.format, content: schema_1.tokenArtifacts.content, contentType: schema_1.tokenArtifacts.contentType })
|
|
207
|
+
.from(schema_1.tokenArtifacts)
|
|
208
|
+
.where((0, drizzle_orm_1.eq)(schema_1.tokenArtifacts.tokenSetId, id));
|
|
209
|
+
return rows
|
|
210
|
+
.filter((row) => row.content != null)
|
|
211
|
+
.map((row) => ({ path: row.path, format: row.format, content: row.content, contentType: row.contentType }));
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
getArtifact(id, format) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
var _a;
|
|
217
|
+
return (_a = (yield this.getArtifacts(id)).find((artifact) => artifact.format === format)) !== null && _a !== void 0 ? _a : null;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.RegistryTokenStore = RegistryTokenStore;
|
|
222
|
+
const readableToBuffer = (stream) => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
+
var _a, stream_1, stream_1_1;
|
|
224
|
+
var _b, e_1, _c, _d;
|
|
225
|
+
const chunks = [];
|
|
226
|
+
try {
|
|
227
|
+
for (_a = true, stream_1 = __asyncValues(stream); stream_1_1 = yield stream_1.next(), _b = stream_1_1.done, !_b; _a = true) {
|
|
228
|
+
_d = stream_1_1.value;
|
|
229
|
+
_a = false;
|
|
230
|
+
const chunk = _d;
|
|
231
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : typeof chunk === 'string' ? Buffer.from(chunk) : Buffer.from(chunk));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
235
|
+
finally {
|
|
236
|
+
try {
|
|
237
|
+
if (!_a && !_b && (_c = stream_1.return)) yield _c.call(stream_1);
|
|
238
|
+
}
|
|
239
|
+
finally { if (e_1) throw e_1.error; }
|
|
240
|
+
}
|
|
241
|
+
return Buffer.concat(chunks);
|
|
242
|
+
});
|
|
243
|
+
class RegistryAssetStore {
|
|
244
|
+
constructor(context) {
|
|
245
|
+
this.context = context;
|
|
246
|
+
}
|
|
247
|
+
listCollections() {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
const rows = yield this.context.db.select({ collection: schema_1.assetCollections.collection }).from(schema_1.assetCollections);
|
|
250
|
+
return rows.map((row) => row.collection);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
listAssets(collection) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
const rows = yield this.context.db
|
|
256
|
+
.select({
|
|
257
|
+
collection: schema_1.assets.collection,
|
|
258
|
+
path: schema_1.assets.path,
|
|
259
|
+
name: schema_1.assets.name,
|
|
260
|
+
contentType: schema_1.assets.contentType,
|
|
261
|
+
size: schema_1.assets.size,
|
|
262
|
+
contentHash: schema_1.assets.contentHash,
|
|
263
|
+
metadata: schema_1.assets.metadata,
|
|
264
|
+
})
|
|
265
|
+
.from(schema_1.assets)
|
|
266
|
+
.where((0, drizzle_orm_1.eq)(schema_1.assets.collection, collection));
|
|
267
|
+
return rows.map((row) => {
|
|
268
|
+
var _a, _b;
|
|
269
|
+
return ({
|
|
270
|
+
collection: row.collection,
|
|
271
|
+
path: row.path,
|
|
272
|
+
name: row.name,
|
|
273
|
+
contentType: row.contentType,
|
|
274
|
+
size: (_a = row.size) !== null && _a !== void 0 ? _a : 0,
|
|
275
|
+
contentHash: row.contentHash,
|
|
276
|
+
metadata: (_b = row.metadata) !== null && _b !== void 0 ? _b : null,
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
getAsset(collection, assetPath) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
var _a;
|
|
284
|
+
return (_a = (yield this.listAssets(collection)).find((asset) => asset.path === assetPath)) !== null && _a !== void 0 ? _a : null;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
getAssetContent(collection, assetPath) {
|
|
288
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
var _a, _b;
|
|
290
|
+
const rows = yield this.context.db
|
|
291
|
+
.select({
|
|
292
|
+
name: schema_1.assets.name,
|
|
293
|
+
contentType: schema_1.assets.contentType,
|
|
294
|
+
size: schema_1.assets.size,
|
|
295
|
+
contentHash: schema_1.assets.contentHash,
|
|
296
|
+
metadata: schema_1.assets.metadata,
|
|
297
|
+
blobContent: schema_1.assetBlobs.content,
|
|
298
|
+
storageRef: schema_1.assetBlobs.storageRef,
|
|
299
|
+
storageProvider: schema_1.assetBlobs.storageProvider,
|
|
300
|
+
})
|
|
301
|
+
.from(schema_1.assets)
|
|
302
|
+
.innerJoin(schema_1.assetBlobs, (0, drizzle_orm_1.eq)(schema_1.assets.blobHash, schema_1.assetBlobs.hash))
|
|
303
|
+
.where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(schema_1.assets.collection, collection), (0, drizzle_orm_1.eq)(schema_1.assets.path, assetPath)))
|
|
304
|
+
.limit(1);
|
|
305
|
+
const row = rows[0];
|
|
306
|
+
if (!row) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
const base = {
|
|
310
|
+
collection,
|
|
311
|
+
path: assetPath,
|
|
312
|
+
name: row.name,
|
|
313
|
+
contentType: row.contentType,
|
|
314
|
+
size: (_a = row.size) !== null && _a !== void 0 ? _a : 0,
|
|
315
|
+
contentHash: row.contentHash,
|
|
316
|
+
metadata: (_b = row.metadata) !== null && _b !== void 0 ? _b : null,
|
|
317
|
+
};
|
|
318
|
+
// Inline (bytea, `database` provider) - return bytes directly.
|
|
319
|
+
if (row.blobContent != null) {
|
|
320
|
+
return Object.assign(Object.assign({}, base), { body: Buffer.from(row.blobContent) });
|
|
321
|
+
}
|
|
322
|
+
// Object-backed - resolve through the provider that stored it.
|
|
323
|
+
if (!row.storageRef || !this.context.resolveAssetAdapter) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
const adapter = yield this.context.resolveAssetAdapter(row.storageProvider);
|
|
327
|
+
if (!adapter) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
const result = yield adapter.get(row.storageRef);
|
|
331
|
+
if (result.kind === 'redirect') {
|
|
332
|
+
return Object.assign(Object.assign({}, base), { redirectUrl: result.url });
|
|
333
|
+
}
|
|
334
|
+
if (result.kind === 'bytes') {
|
|
335
|
+
return Object.assign(Object.assign({}, base), { body: result.bytes });
|
|
336
|
+
}
|
|
337
|
+
return Object.assign(Object.assign({}, base), { body: yield readableToBuffer(result.stream) });
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
exports.RegistryAssetStore = RegistryAssetStore;
|
|
342
|
+
/** Build the database-backed store set for a registry database connection. */
|
|
343
|
+
const createRegistryStore = (context) => ({
|
|
344
|
+
components: new RegistryComponentStore(context),
|
|
345
|
+
patterns: new RegistryPatternStore(context),
|
|
346
|
+
pages: new RegistryPageStore(context),
|
|
347
|
+
tokens: new RegistryTokenStore(context),
|
|
348
|
+
assets: new RegistryAssetStore(context),
|
|
349
|
+
});
|
|
350
|
+
exports.createRegistryStore = createRegistryStore;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-class "related source files for an entity" accessor for the workspace store.
|
|
3
|
+
*
|
|
4
|
+
* Gathers an entity's declaration plus every `entries`-referenced source file for checkout and
|
|
5
|
+
* publish. This centralizes that logic so the store, and later transfer, share one definition of
|
|
6
|
+
* "what travels with an entity".
|
|
7
|
+
*/
|
|
8
|
+
import type { ComponentListObject, PatternListObject } from '../transformers/preview/types';
|
|
9
|
+
import type { RegistryTextFileResource, TextFileResource } from './types';
|
|
10
|
+
/** A normalized record carrying a source directory `path` and resolved absolute `entries`. */
|
|
11
|
+
type SourcedRecord = (ComponentListObject | PatternListObject) & {
|
|
12
|
+
entries?: Record<string, string | undefined>;
|
|
13
|
+
};
|
|
14
|
+
export declare const sourceContentTypeForPath: (filePath: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Gather an entity's declaration plus every `entries`-referenced source file. Files are deduped by
|
|
17
|
+
* normalized absolute path (entries duplicate `template`/`component`/`story` after normalization),
|
|
18
|
+
* and a `templates` directory entry is expanded into its files. Declaration always sorts first.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getRelatedSourceFilesForRecord: (record: SourcedRecord) => TextFileResource[];
|
|
21
|
+
/** Whether a file resource should be excluded from registry source records (declarations only). */
|
|
22
|
+
export declare const isWorkspaceOnlyFile: (file: TextFileResource) => boolean;
|
|
23
|
+
export declare const isRegistrySourceFile: (file: TextFileResource) => file is RegistryTextFileResource;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* First-class "related source files for an entity" accessor for the workspace store.
|
|
4
|
+
*
|
|
5
|
+
* Gathers an entity's declaration plus every `entries`-referenced source file for checkout and
|
|
6
|
+
* publish. This centralizes that logic so the store, and later transfer, share one definition of
|
|
7
|
+
* "what travels with an entity".
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.isRegistrySourceFile = exports.isWorkspaceOnlyFile = exports.getRelatedSourceFilesForRecord = exports.sourceContentTypeForPath = void 0;
|
|
14
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const runtime_1 = require("../config/runtime");
|
|
17
|
+
const path_2 = require("../utils/path");
|
|
18
|
+
/** Maps a component/pattern `entries` key to the source-file kind it contributes. */
|
|
19
|
+
const ENTRY_KIND_BY_KEY = {
|
|
20
|
+
js: 'script',
|
|
21
|
+
scss: 'style',
|
|
22
|
+
component: 'component',
|
|
23
|
+
story: 'story',
|
|
24
|
+
schema: 'schema',
|
|
25
|
+
template: 'template',
|
|
26
|
+
templates: 'template',
|
|
27
|
+
};
|
|
28
|
+
/** Source-text content types keyed by file extension (lowercase, no dot). */
|
|
29
|
+
const SOURCE_CONTENT_TYPE_BY_EXT = {
|
|
30
|
+
ts: 'text/typescript; charset=utf-8',
|
|
31
|
+
tsx: 'text/typescript; charset=utf-8',
|
|
32
|
+
js: 'application/javascript; charset=utf-8',
|
|
33
|
+
jsx: 'application/javascript; charset=utf-8',
|
|
34
|
+
cjs: 'application/javascript; charset=utf-8',
|
|
35
|
+
mjs: 'application/javascript; charset=utf-8',
|
|
36
|
+
json: 'application/json; charset=utf-8',
|
|
37
|
+
css: 'text/css; charset=utf-8',
|
|
38
|
+
scss: 'text/x-scss; charset=utf-8',
|
|
39
|
+
sass: 'text/x-sass; charset=utf-8',
|
|
40
|
+
hbs: 'text/x-handlebars-template; charset=utf-8',
|
|
41
|
+
md: 'text/markdown; charset=utf-8',
|
|
42
|
+
html: 'text/html; charset=utf-8',
|
|
43
|
+
};
|
|
44
|
+
const sourceContentTypeForPath = (filePath) => {
|
|
45
|
+
var _a;
|
|
46
|
+
const ext = path_1.default.extname(filePath).slice(1).toLowerCase();
|
|
47
|
+
return (_a = SOURCE_CONTENT_TYPE_BY_EXT[ext]) !== null && _a !== void 0 ? _a : 'text/plain; charset=utf-8';
|
|
48
|
+
};
|
|
49
|
+
exports.sourceContentTypeForPath = sourceContentTypeForPath;
|
|
50
|
+
/**
|
|
51
|
+
* Read a single text source file into a {@link TextFileResource}, or `null` when it is missing or
|
|
52
|
+
* unreadable. `relativeTo` is the entity source directory used to derive the registry-safe path.
|
|
53
|
+
*/
|
|
54
|
+
const readTextFile = (absolutePath, kind, relativeTo) => {
|
|
55
|
+
try {
|
|
56
|
+
if (!fs_extra_1.default.existsSync(absolutePath) || !fs_extra_1.default.statSync(absolutePath).isFile()) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const content = fs_extra_1.default.readFileSync(absolutePath, 'utf8');
|
|
60
|
+
const relative = path_1.default.relative(relativeTo, absolutePath).split(path_1.default.sep).join('/');
|
|
61
|
+
return {
|
|
62
|
+
path: relative || path_1.default.basename(absolutePath),
|
|
63
|
+
absolutePath,
|
|
64
|
+
kind,
|
|
65
|
+
content,
|
|
66
|
+
contentType: (0, exports.sourceContentTypeForPath)(absolutePath),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (_a) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** Expand a `templates` directory entry into its contained template files. */
|
|
74
|
+
const expandTemplatesDir = (dirPath) => {
|
|
75
|
+
try {
|
|
76
|
+
if (!fs_extra_1.default.existsSync(dirPath) || !fs_extra_1.default.statSync(dirPath).isDirectory()) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
return fs_extra_1.default
|
|
80
|
+
.readdirSync(dirPath, { withFileTypes: true })
|
|
81
|
+
.filter((entry) => entry.isFile())
|
|
82
|
+
.map((entry) => path_1.default.join(dirPath, entry.name));
|
|
83
|
+
}
|
|
84
|
+
catch (_a) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Locate the entity's declaration file within its source directory and read it as a
|
|
90
|
+
* `kind: 'declaration'` resource. Returns `null` when no declaration can be found/read.
|
|
91
|
+
*/
|
|
92
|
+
const readDeclarationFile = (sourceDir) => {
|
|
93
|
+
const declaration = (0, runtime_1.resolveComponentDeclaration)(sourceDir, path_1.default.basename(sourceDir));
|
|
94
|
+
if (!declaration)
|
|
95
|
+
return null;
|
|
96
|
+
const absolutePath = path_1.default.resolve(sourceDir, declaration.fileName);
|
|
97
|
+
return readTextFile(absolutePath, 'declaration', sourceDir);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Gather an entity's declaration plus every `entries`-referenced source file. Files are deduped by
|
|
101
|
+
* normalized absolute path (entries duplicate `template`/`component`/`story` after normalization),
|
|
102
|
+
* and a `templates` directory entry is expanded into its files. Declaration always sorts first.
|
|
103
|
+
*/
|
|
104
|
+
const getRelatedSourceFilesForRecord = (record) => {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
const sourceDir = record.path;
|
|
107
|
+
if (!sourceDir) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const collected = [];
|
|
111
|
+
const seen = new Set();
|
|
112
|
+
const add = (absolutePath, kind) => {
|
|
113
|
+
const key = (0, path_2.normalizePathForCompare)(absolutePath);
|
|
114
|
+
if (seen.has(key))
|
|
115
|
+
return;
|
|
116
|
+
const resource = readTextFile(absolutePath, kind, sourceDir);
|
|
117
|
+
if (!resource)
|
|
118
|
+
return;
|
|
119
|
+
seen.add(key);
|
|
120
|
+
collected.push(resource);
|
|
121
|
+
};
|
|
122
|
+
const declaration = readDeclarationFile(sourceDir);
|
|
123
|
+
if (declaration) {
|
|
124
|
+
seen.add((0, path_2.normalizePathForCompare)(declaration.absolutePath));
|
|
125
|
+
collected.push(declaration);
|
|
126
|
+
}
|
|
127
|
+
const entries = (_a = record.entries) !== null && _a !== void 0 ? _a : {};
|
|
128
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
129
|
+
if (!value)
|
|
130
|
+
continue;
|
|
131
|
+
const kind = (_b = ENTRY_KIND_BY_KEY[key]) !== null && _b !== void 0 ? _b : 'other';
|
|
132
|
+
if (key === 'templates') {
|
|
133
|
+
for (const templateFile of expandTemplatesDir(value)) {
|
|
134
|
+
add(templateFile, 'template');
|
|
135
|
+
}
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
add(value, kind);
|
|
139
|
+
}
|
|
140
|
+
return collected;
|
|
141
|
+
};
|
|
142
|
+
exports.getRelatedSourceFilesForRecord = getRelatedSourceFilesForRecord;
|
|
143
|
+
/** Whether a file resource should be excluded from registry source records (declarations only). */
|
|
144
|
+
const isWorkspaceOnlyFile = (file) => file.kind === 'declaration';
|
|
145
|
+
exports.isWorkspaceOnlyFile = isWorkspaceOnlyFile;
|
|
146
|
+
const isRegistrySourceFile = (file) => !(0, exports.isWorkspaceOnlyFile)(file);
|
|
147
|
+
exports.isRegistrySourceFile = isRegistrySourceFile;
|