@astrale-os/cli 1.0.0-beta.2 → 1.0.0-beta.20
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 +16 -1
- package/dist/astrale.js +51105 -58057
- package/dist/public/connect-core.js +2085 -30702
- package/dist/public/keys/index.js +884 -29476
- package/dist/public/paths/index.js +13101 -41452
- package/dist/types/admin/contract.d.ts +26 -0
- package/dist/types/admin/instance/client.d.ts +20 -0
- package/dist/types/admin/instance/index.d.ts +2 -0
- package/dist/types/admin/instance/model.d.ts +6 -10
- package/dist/types/connection/auth.d.ts +3 -0
- package/dist/types/connection/call.d.ts +3 -0
- package/dist/types/connection/command.d.ts +27 -0
- package/dist/types/connection/credential.d.ts +14 -0
- package/dist/types/connection/errors.d.ts +1 -0
- package/dist/types/connection/exchange.d.ts +9 -0
- package/dist/types/connection/failure/classify.d.ts +2 -0
- package/dist/types/connection/failure/index.d.ts +5 -0
- package/dist/types/connection/failure/model.d.ts +25 -0
- package/dist/types/connection/failure/render.d.ts +3 -0
- package/dist/types/connection/index.d.ts +8 -0
- package/dist/types/connection/reasons.d.ts +37 -0
- package/dist/types/connection/self.d.ts +37 -0
- package/dist/types/connection/session.d.ts +31 -0
- package/dist/types/connection/target.d.ts +38 -0
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/lib/admin-instance.d.ts +17 -0
- package/dist/types/lib/admin-target.d.ts +11 -36
- package/dist/types/lib/config.d.ts +7 -59
- package/dist/types/lib/failure-debug.d.ts +1 -0
- package/dist/types/lib/idp.d.ts +25 -173
- package/dist/types/lib/instance-target.d.ts +1 -1
- package/dist/types/lib/instance.d.ts +30 -88
- package/dist/types/lib/log.d.ts +5 -3
- package/dist/types/lib/output.d.ts +1 -1
- package/dist/types/lib/proc.d.ts +43 -0
- package/dist/types/lib/self.d.ts +9 -0
- package/dist/types/lib/update.d.ts +109 -0
- package/dist/types/lib/validation.d.ts +4 -1
- package/package.json +15 -20
- package/src/__tests__/fixtures/publication.ts +20 -0
- package/src/admin/.spec/architecture.md +12 -5
- package/src/admin/__tests__/fixture.ts +25 -0
- package/src/admin/catalog/.spec/api.d.ts +1 -3
- package/src/admin/catalog/.spec/architecture.md +5 -4
- package/src/admin/catalog/__tests__/client.test.ts +143 -69
- package/src/admin/catalog/client.ts +40 -54
- package/src/admin/catalog/model.ts +3 -4
- package/src/admin/contract.ts +46 -0
- package/src/admin/graph/.spec/api.d.ts +4 -10
- package/src/admin/graph/nodes.ts +1 -1
- package/src/admin/instance/.spec/api.d.ts +5 -9
- package/src/admin/instance/.spec/architecture.md +7 -7
- package/src/admin/instance/__tests__/client.test.ts +157 -175
- package/src/admin/instance/client.ts +39 -128
- package/src/admin/instance/index.ts +1 -2
- package/src/admin/instance/model.ts +12 -18
- package/src/commands/__tests__/admin-instance.test.ts +11 -8
- package/src/commands/__tests__/call-describe.test.ts +46 -33
- package/src/commands/__tests__/call.test.ts +34 -0
- package/src/commands/__tests__/domain-install-operation.test.ts +7 -22
- package/src/commands/__tests__/domain-install-owned.test.ts +1 -1
- package/src/commands/__tests__/domain-list.test.ts +5 -25
- package/src/commands/__tests__/install-direct.test.ts +115 -8
- package/src/commands/__tests__/install-identity-override.test.ts +3 -14
- package/src/commands/__tests__/instance-list-rows.test.ts +1 -1
- package/src/commands/__tests__/instance-status.test.ts +139 -0
- package/src/commands/__tests__/introspect-parse.test.ts +80 -1
- package/src/commands/__tests__/logs.test.ts +250 -2
- package/src/commands/__tests__/read-commands.test.ts +62 -10
- package/src/commands/__tests__/token-ttl.test.ts +49 -4
- package/src/commands/__tests__/update.test.ts +25 -3
- package/src/commands/__tests__/view.test.ts +49 -0
- package/src/commands/call-describe.ts +60 -68
- package/src/commands/call.ts +71 -59
- package/src/commands/domain/install.ts +54 -35
- package/src/commands/domain/list.ts +1 -1
- package/src/commands/domain/publish.ts +14 -11
- package/src/commands/domain/uninstall.ts +2 -2
- package/src/commands/get.ts +14 -15
- package/src/commands/identity/__tests__/register.test.ts +3 -3
- package/src/commands/identity/register.ts +5 -4
- package/src/commands/instance/create.ts +8 -16
- package/src/commands/instance/delete.ts +12 -9
- package/src/commands/instance/list.ts +2 -2
- package/src/commands/instance/status.ts +66 -20
- package/src/commands/instance/use.ts +16 -12
- package/src/commands/introspect.ts +48 -35
- package/src/commands/logs.ts +123 -33
- package/src/commands/mutate.ts +6 -5
- package/src/commands/query.ts +35 -32
- package/src/commands/token.ts +42 -27
- package/src/commands/ui/__tests__/commands.test.ts +152 -0
- package/src/commands/ui/add.ts +51 -0
- package/src/commands/ui/doctor.ts +13 -0
- package/src/commands/ui/init.ts +38 -0
- package/src/commands/ui/list.ts +26 -0
- package/src/commands/ui/preset-apply.ts +19 -0
- package/src/commands/ui/preset-list.ts +12 -0
- package/src/commands/ui/shared.ts +25 -0
- package/src/commands/update.ts +31 -11
- package/src/commands/view.ts +82 -37
- package/src/connection/.spec/api.d.ts +7 -8
- package/src/connection/.spec/architecture.md +5 -4
- package/src/connection/.spec/flows/session.ts +2 -2
- package/src/connection/.spec/laws/connection.ts +6 -2
- package/src/connection/.spec/layout.ts +1 -0
- package/src/connection/__tests__/credential.test.ts +20 -1
- package/src/connection/__tests__/errors.test.ts +27 -20
- package/src/connection/__tests__/exchange.test.ts +30 -1
- package/src/connection/__tests__/failure-fixtures.ts +39 -0
- package/src/connection/__tests__/failure-safety.test.ts +75 -0
- package/src/connection/__tests__/self.test.ts +31 -11
- package/src/connection/__tests__/session.test.ts +3 -3
- package/src/connection/__tests__/target.test.ts +1 -0
- package/src/connection/auth.ts +13 -0
- package/src/connection/call.ts +1 -1
- package/src/connection/credential.ts +2 -2
- package/src/connection/errors.ts +1 -355
- package/src/connection/exchange.ts +47 -23
- package/src/connection/failure/classify.ts +110 -0
- package/src/connection/failure/index.ts +18 -0
- package/src/connection/failure/model.ts +28 -0
- package/src/connection/failure/render.ts +116 -0
- package/src/connection/reasons.ts +16 -0
- package/src/connection/self.ts +39 -21
- package/src/connection/session.ts +19 -8
- package/src/errors.ts +3 -2
- package/src/graph/.spec/api.d.ts +12 -5
- package/src/graph/.spec/layout.ts +9 -1
- package/src/graph/__tests__/mutation.test.ts +2 -2
- package/src/graph/__tests__/query.test.ts +25 -6
- package/src/graph/class.ts +30 -0
- package/src/graph/index.ts +1 -0
- package/src/graph/query.ts +21 -32
- package/src/identity/.spec/api.d.ts +2 -2
- package/src/identity/__tests__/registration.test.ts +1 -1
- package/src/identity/registration.ts +3 -3
- package/src/keys/__tests__/keys.test.ts +4 -0
- package/src/keys/credential.ts +1 -0
- package/src/lib/__tests__/admin-target.test.ts +12 -0
- package/src/lib/__tests__/binary.test.ts +16 -1
- package/src/lib/__tests__/command-dx.test.ts +1 -1
- package/src/lib/__tests__/domain-publication.test.ts +10 -16
- package/src/lib/__tests__/idp.test.ts +34 -4
- package/src/lib/__tests__/instance-candidates.test.ts +1 -3
- package/src/lib/__tests__/instance-target.test.ts +7 -39
- package/src/lib/__tests__/log-errors.test.ts +64 -0
- package/src/lib/__tests__/studio-server-deps.test.ts +1 -1
- package/src/lib/__tests__/update.test.ts +264 -11
- package/src/lib/__tests__/view-assets.test.ts +14 -0
- package/src/lib/__tests__/view-external-open-intent.test.ts +150 -0
- package/src/lib/__tests__/view-external-open-origins.test.ts +27 -0
- package/src/lib/__tests__/view-open-intent.test.ts +0 -2
- package/src/lib/__tests__/view-server.test.ts +26 -3
- package/src/lib/__tests__/view-session.test.ts +2 -1
- package/src/lib/admin-instance.ts +14 -8
- package/src/lib/admin-target.ts +21 -2
- package/src/lib/binary.ts +22 -5
- package/src/lib/command-dx.ts +9 -9
- package/src/lib/domain-publication.ts +9 -7
- package/src/lib/failure-debug.ts +26 -0
- package/src/lib/idp.ts +34 -3
- package/src/lib/instance-candidates.ts +2 -2
- package/src/lib/instance-target.ts +3 -14
- package/src/lib/instance.ts +16 -11
- package/src/lib/log.ts +16 -9
- package/src/lib/output.ts +1 -1
- package/src/lib/proc.ts +7 -2
- package/src/lib/provision-instance.ts +34 -57
- package/src/lib/update.ts +298 -45
- package/src/lib/validation.ts +2 -2
- package/src/lib/view/assets.ts +11 -2
- package/src/lib/view/external-open-intent.ts +41 -0
- package/src/lib/view/external-open-origins.ts +37 -0
- package/src/lib/view/host-capabilities.ts +17 -0
- package/src/lib/view/resolve.ts +1 -1
- package/src/lib/view/server.ts +18 -3
- package/src/lib/view/session.ts +2 -0
- package/src/program/.spec/api.d.ts +1 -0
- package/src/program/__tests__/program.test.ts +163 -6
- package/src/program/argv.ts +14 -0
- package/src/program/build.ts +26 -4
- package/src/program/command.ts +1 -0
- package/src/program/index.ts +1 -0
- package/src/program/registry.ts +2 -1
- package/src/setup/__tests__/instance-step.test.ts +27 -10
- package/src/setup/steps/instance.ts +22 -15
- package/src/telemetry/__tests__/recorder.test.ts +1 -0
- package/src/telemetry/recorder.ts +9 -1
- package/src/ui/.spec/api.d.ts +14 -0
- package/src/ui/.spec/architecture.md +10 -0
- package/src/ui/.spec/laws.ts +36 -0
- package/src/ui/.spec/layout.ts +16 -0
- package/src/ui/__tests__/ui.test.ts +981 -0
- package/src/ui/index.ts +13 -0
- package/src/ui/lock.ts +87 -0
- package/src/ui/model.ts +83 -0
- package/src/ui/operations.ts +710 -0
- package/src/ui/project.ts +219 -0
- package/src/ui/release.ts +321 -0
- package/src/ui/runner.ts +18 -0
- package/studio/client/dist/assets/elk-api-DjmKsHXc.js +1 -0
- package/studio/client/dist/assets/index-7YHdeCxp.js +81 -0
- package/studio/client/dist/assets/index-C0FAnwNw.css +2 -0
- package/studio/client/dist/assets/rolldown-runtime-Dd_uD5pT.js +1 -0
- package/studio/client/dist/assets/schema-studio-BilUNb6Z.css +1 -0
- package/studio/client/dist/assets/schema-studio-CABpTfvH.js +8 -0
- package/studio/client/dist/index.html +3 -2
- package/studio/package.json +7 -13
- package/studio/server/agent/ask.test.ts +1 -1
- package/studio/server/agent/bridge/grant.test.ts +1 -1
- package/studio/server/agent/bridge/routes.test.ts +1 -1
- package/studio/server/agent/harness/claude/adapter.test.ts +15 -5
- package/studio/server/agent/harness/gateway/token.test.ts +1 -1
- package/studio/server/agent/harness/gateway/token.ts +3 -3
- package/studio/server/agent/prompts/anchors.test.ts +32 -36
- package/studio/server/agent/prompts/anchors.ts +20 -49
- package/studio/server/agent/prompts/system.test.ts +3 -2
- package/studio/server/agent/prompts/system.ts +3 -3
- package/studio/server/agent/routes.test.ts +1 -1
- package/studio/server/agent/run/coordinator.test.ts +1 -1
- package/studio/server/api/canvas.ts +0 -1
- package/studio/server/api-agent-loadout.test.ts +1 -1
- package/studio/server/api.test.ts +1 -1
- package/studio/server/cache.test.ts +23 -12
- package/studio/server/cache.ts +12 -15
- package/studio/server/domain.test.ts +50 -68
- package/studio/server/domain.ts +82 -63
- package/studio/server/handoff/copy.ts +1 -1
- package/studio/server/index.ts +1 -1
- package/studio/server/instances/probe.test.ts +1 -1
- package/studio/server/introspect/anatomy/views/routes.ts +46 -37
- package/studio/server/introspect/anatomy/views.ts +9 -14
- package/studio/server/introspect/anatomy-extras.test.ts +26 -42
- package/studio/server/introspect/anatomy.test.ts +22 -14
- package/studio/server/introspect/anatomy.ts +6 -9
- package/studio/server/introspect/bundle.ts +0 -3
- package/studio/server/introspect/canonical-schema.test.ts +94 -389
- package/studio/server/introspect/canonical-schema.ts +227 -457
- package/studio/server/introspect/core-extractor.ts +18 -127
- package/studio/server/introspect/core.ts +1 -2
- package/studio/server/introspect/diff.test.ts +11 -7
- package/studio/server/introspect/diff.ts +18 -55
- package/studio/server/introspect/extractor.ts +22 -117
- package/studio/server/introspect/overlay-tsmorph.test.ts +119 -240
- package/studio/server/introspect/overlay.test.ts +26 -54
- package/studio/server/introspect/overlay.ts +10 -37
- package/studio/server/introspect/revision.test.ts +1 -1
- package/studio/server/introspect/revision.ts +1 -1
- package/studio/server/introspect/runtime.test.ts +65 -183
- package/studio/server/introspect/runtime.ts +8 -25
- package/studio/server/introspect/schema-ir-json.test.ts +70 -0
- package/studio/server/introspect/schema-ir-json.ts +38 -68
- package/studio/server/introspect/schema-refs.test.ts +43 -88
- package/studio/server/introspect/schema-refs.ts +14 -49
- package/studio/server/introspect/source-overlay/handlers.ts +116 -636
- package/studio/server/introspect/source-overlay/kernel-calls.ts +0 -3
- package/studio/server/introspect/source-overlay/spans.ts +15 -45
- package/studio/server/state/baseline.test.ts +14 -9
- package/studio/server/state/baseline.ts +3 -5
- package/studio/server/state/visibility.ts +1 -5
- package/studio/server/views/model.ts +3 -3
- package/studio/server/views/target.test.ts +17 -74
- package/studio/server/views/target.ts +24 -50
- package/studio/server/watch.test.ts +11 -11
- package/studio/server/watch.ts +8 -4
- package/studio/server/workspace-watch.ts +2 -2
- package/studio/shared/contracts/schema.ts +38 -107
- package/studio/shared/contracts/surface.test.ts +13 -15
- package/studio/shared/contracts/workspace.ts +2 -11
- package/studio/shared/schema/identity.test.ts +20 -44
- package/studio/shared/schema/identity.ts +9 -23
- package/viewer/dist/main.js +30 -51
- package/.check-workspace.cjs +0 -40
- package/src/admin/binding.ts +0 -168
- package/src/commands/__tests__/instance-create-hosts.test.ts +0 -29
- package/studio/client/dist/assets/elk-api-lwhFo7vB.js +0 -1
- package/studio/client/dist/assets/index-B-c-smo9.js +0 -8
- package/studio/client/dist/assets/index-BckHuAWk.js +0 -81
- package/studio/client/dist/assets/index-C4aNQ6dz.css +0 -1
- package/studio/client/dist/assets/index-ChOr3yP0.css +0 -1
- package/studio/server/introspect/anatomy/views/legacy.ts +0 -232
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { access, lstat, readFile, realpath } from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { UiError, type PackageManager } from './model'
|
|
5
|
+
|
|
6
|
+
export type UiProject = {
|
|
7
|
+
root: string
|
|
8
|
+
packageJsonPath: string
|
|
9
|
+
packageJson: Record<string, unknown>
|
|
10
|
+
manager: PackageManager
|
|
11
|
+
lockPath?: string
|
|
12
|
+
cssPath: string
|
|
13
|
+
componentsPath: string
|
|
14
|
+
uiLockPath: string
|
|
15
|
+
isAstraleDomain: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const MANAGERS: readonly [string, PackageManager][] = [
|
|
19
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
20
|
+
['bun.lock', 'bun'],
|
|
21
|
+
['bun.lockb', 'bun'],
|
|
22
|
+
['yarn.lock', 'yarn'],
|
|
23
|
+
['package-lock.json', 'npm'],
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
async function exists(target: string): Promise<boolean> {
|
|
27
|
+
return access(target).then(
|
|
28
|
+
() => true,
|
|
29
|
+
() => false,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function readManifest(target: string): Promise<Record<string, unknown>> {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(await readFile(target, 'utf8')) as Record<string, unknown>
|
|
36
|
+
} catch (cause) {
|
|
37
|
+
throw new UiError('UI_PROJECT_UNSUPPORTED', 'package.json is not valid JSON.', undefined, {
|
|
38
|
+
cause,
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function hasReactTailwind(manifest: Record<string, unknown>): boolean {
|
|
44
|
+
const dependencies = {
|
|
45
|
+
...(manifest.dependencies as Record<string, string> | undefined),
|
|
46
|
+
...(manifest.devDependencies as Record<string, string> | undefined),
|
|
47
|
+
...(manifest.peerDependencies as Record<string, string> | undefined),
|
|
48
|
+
}
|
|
49
|
+
return Boolean(dependencies.react && dependencies['react-dom'] && dependencies.tailwindcss)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function assertPhysicalProjectPath(root: string, target: string): Promise<void> {
|
|
53
|
+
const physicalRoot = await realpath(root)
|
|
54
|
+
let existing = target
|
|
55
|
+
while (!(await exists(existing))) {
|
|
56
|
+
const parent = path.dirname(existing)
|
|
57
|
+
if (parent === existing) break
|
|
58
|
+
existing = parent
|
|
59
|
+
}
|
|
60
|
+
const physicalTarget = await realpath(existing)
|
|
61
|
+
const relative = path.relative(physicalRoot, physicalTarget)
|
|
62
|
+
if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
|
|
63
|
+
throw new UiError('UI_PROJECT_UNSUPPORTED', 'components.json CSS path escapes the project.')
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function discoverUiProject(input = process.cwd()): Promise<UiProject> {
|
|
68
|
+
let root = path.resolve(input)
|
|
69
|
+
if (!(await exists(root))) {
|
|
70
|
+
throw new UiError('UI_PROJECT_UNSUPPORTED', 'Project path does not exist: ' + root)
|
|
71
|
+
}
|
|
72
|
+
if (!(await lstat(root)).isDirectory()) root = path.dirname(root)
|
|
73
|
+
|
|
74
|
+
while (true) {
|
|
75
|
+
const manifestPath = path.join(root, 'package.json')
|
|
76
|
+
if (await exists(manifestPath)) {
|
|
77
|
+
const manifest = await readManifest(manifestPath)
|
|
78
|
+
const parent = path.dirname(root)
|
|
79
|
+
if (hasReactTailwind(manifest) || parent === root) break
|
|
80
|
+
if (await exists(path.join(parent, 'package.json'))) {
|
|
81
|
+
root = parent
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
break
|
|
85
|
+
}
|
|
86
|
+
const parent = path.dirname(root)
|
|
87
|
+
if (parent === root) {
|
|
88
|
+
throw new UiError(
|
|
89
|
+
'UI_PROJECT_UNSUPPORTED',
|
|
90
|
+
'No package.json found from ' + path.resolve(input),
|
|
91
|
+
'Run the command inside an existing React application or pass its path.',
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
root = parent
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const packageJsonPath = path.join(root, 'package.json')
|
|
98
|
+
const packageJson = await readManifest(packageJsonPath)
|
|
99
|
+
|
|
100
|
+
let manager: PackageManager = 'npm'
|
|
101
|
+
let lockPath: string | undefined
|
|
102
|
+
for (const [file, candidate] of MANAGERS) {
|
|
103
|
+
const target = path.join(root, file)
|
|
104
|
+
if (await exists(target)) {
|
|
105
|
+
manager = candidate
|
|
106
|
+
lockPath = target
|
|
107
|
+
break
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const declared = packageJson.packageManager
|
|
111
|
+
if (!lockPath && typeof declared === 'string') {
|
|
112
|
+
const candidate = declared.split('@')[0]
|
|
113
|
+
if (
|
|
114
|
+
candidate === 'pnpm' ||
|
|
115
|
+
candidate === 'npm' ||
|
|
116
|
+
candidate === 'yarn' ||
|
|
117
|
+
candidate === 'bun'
|
|
118
|
+
) {
|
|
119
|
+
manager = candidate
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!lockPath) {
|
|
123
|
+
const expectedLock = {
|
|
124
|
+
pnpm: 'pnpm-lock.yaml',
|
|
125
|
+
npm: 'package-lock.json',
|
|
126
|
+
yarn: 'yarn.lock',
|
|
127
|
+
bun: 'bun.lock',
|
|
128
|
+
}[manager]
|
|
129
|
+
lockPath = path.join(root, expectedLock)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const rootCssCandidates = ['src/index.css', 'src/app.css', 'app/globals.css', 'src/styles.css']
|
|
133
|
+
const frontendCssCandidates = [
|
|
134
|
+
'frontend/src/index.css',
|
|
135
|
+
'frontend/src/app.css',
|
|
136
|
+
'frontend/src/styles.css',
|
|
137
|
+
]
|
|
138
|
+
const componentsPath = path.join(root, 'components.json')
|
|
139
|
+
const configuredCss = await readFile(componentsPath, 'utf8')
|
|
140
|
+
.then((value) => {
|
|
141
|
+
const components = JSON.parse(value) as { tailwind?: { css?: unknown } }
|
|
142
|
+
const css = components.tailwind?.css
|
|
143
|
+
if (typeof css !== 'string' || css.length === 0) return undefined
|
|
144
|
+
const target = path.resolve(root, css)
|
|
145
|
+
const relative = path.relative(root, target)
|
|
146
|
+
if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
|
|
147
|
+
throw new UiError('UI_PROJECT_UNSUPPORTED', 'components.json CSS path escapes the project.')
|
|
148
|
+
}
|
|
149
|
+
return { relative: relative.split(path.sep).join('/'), target }
|
|
150
|
+
})
|
|
151
|
+
.catch((error: unknown) => {
|
|
152
|
+
if (error instanceof UiError) throw error
|
|
153
|
+
return undefined
|
|
154
|
+
})
|
|
155
|
+
const configuredCssRelative = configuredCss?.relative
|
|
156
|
+
const cssCandidates =
|
|
157
|
+
configuredCssRelative !== undefined
|
|
158
|
+
? [configuredCssRelative]
|
|
159
|
+
: (await exists(path.join(root, 'frontend/package.json')))
|
|
160
|
+
? [...frontendCssCandidates, ...rootCssCandidates]
|
|
161
|
+
: [...rootCssCandidates, ...frontendCssCandidates]
|
|
162
|
+
const resolvedCss = await Promise.all(
|
|
163
|
+
cssCandidates.map(async (file) => ((await exists(path.join(root, file))) ? file : undefined)),
|
|
164
|
+
)
|
|
165
|
+
const cssRelative = configuredCssRelative ?? resolvedCss.find(Boolean) ?? 'src/astrale-ui.css'
|
|
166
|
+
await assertPhysicalProjectPath(root, path.join(root, cssRelative))
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
root,
|
|
170
|
+
packageJsonPath,
|
|
171
|
+
packageJson,
|
|
172
|
+
manager,
|
|
173
|
+
lockPath,
|
|
174
|
+
cssPath: path.join(root, cssRelative),
|
|
175
|
+
componentsPath,
|
|
176
|
+
uiLockPath: path.join(root, 'astrale-ui.lock.json'),
|
|
177
|
+
isAstraleDomain:
|
|
178
|
+
(await exists(path.join(root, 'astrale.config.ts'))) &&
|
|
179
|
+
(await exists(path.join(root, 'ui/index.ts'))) &&
|
|
180
|
+
(await exists(path.join(root, 'frontend/package.json'))),
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function assertSupportedUiProject(project: UiProject): void {
|
|
185
|
+
const manifest = project.packageJson
|
|
186
|
+
const dependencies = {
|
|
187
|
+
...(manifest.dependencies as Record<string, string> | undefined),
|
|
188
|
+
...(manifest.devDependencies as Record<string, string> | undefined),
|
|
189
|
+
...(manifest.peerDependencies as Record<string, string> | undefined),
|
|
190
|
+
}
|
|
191
|
+
if (!dependencies.react || !dependencies['react-dom']) {
|
|
192
|
+
throw new UiError(
|
|
193
|
+
'UI_PROJECT_UNSUPPORTED',
|
|
194
|
+
'Astrale UI requires an existing React application.',
|
|
195
|
+
'Install React first or choose a non-UI project scaffold.',
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
const tailwind = dependencies.tailwindcss
|
|
199
|
+
if (!tailwind || !/(?:^|[^0-9])4(?:\.|$)/u.test(tailwind)) {
|
|
200
|
+
throw new UiError(
|
|
201
|
+
'UI_PROJECT_UNSUPPORTED',
|
|
202
|
+
'Astrale UI V1 requires Tailwind CSS 4.',
|
|
203
|
+
'Upgrade Tailwind to v4 before initializing Astrale UI.',
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function projectRelative(project: UiProject, target: string): string {
|
|
209
|
+
const relative = path.relative(project.root, target)
|
|
210
|
+
if (
|
|
211
|
+
relative === '' ||
|
|
212
|
+
relative === '..' ||
|
|
213
|
+
relative.startsWith('..' + path.sep) ||
|
|
214
|
+
path.isAbsolute(relative)
|
|
215
|
+
) {
|
|
216
|
+
throw new UiError('UI_LOCK_INVALID', 'Path escapes the project root: ' + target)
|
|
217
|
+
}
|
|
218
|
+
return relative.split(path.sep).join('/')
|
|
219
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { UiError, type UiCompatibility, type UiRegistry, type UiRelease } from './model'
|
|
2
|
+
|
|
3
|
+
const NPM_PACKAGE = 'https://registry.npmjs.org/@astrale-os/ui'
|
|
4
|
+
const GITHUB_API = 'https://api.github.com/repos/astrale-os/ui'
|
|
5
|
+
const RAW = 'https://raw.githubusercontent.com/astrale-os/ui'
|
|
6
|
+
const MAX_DOCUMENT_BYTES = 1_048_576
|
|
7
|
+
const MAX_REGISTRY_DOCUMENTS = 100
|
|
8
|
+
|
|
9
|
+
type Fetch = typeof fetch
|
|
10
|
+
type RegistrySource = {
|
|
11
|
+
name?: string
|
|
12
|
+
homepage?: string
|
|
13
|
+
include?: string[]
|
|
14
|
+
items?: unknown[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function json<T>(fetcher: Fetch, url: string, label: string): Promise<T> {
|
|
18
|
+
let response: Response
|
|
19
|
+
try {
|
|
20
|
+
response = await fetcher(url, { headers: { accept: 'application/json' } })
|
|
21
|
+
} catch (cause) {
|
|
22
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'Unable to reach ' + label + '.', undefined, {
|
|
23
|
+
cause,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', label + ' returned HTTP ' + response.status + '.')
|
|
28
|
+
}
|
|
29
|
+
const declaredLength = Number(response.headers.get('content-length'))
|
|
30
|
+
if (Number.isFinite(declaredLength) && declaredLength > MAX_DOCUMENT_BYTES) {
|
|
31
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', label + ' exceeds the supported response size.')
|
|
32
|
+
}
|
|
33
|
+
if (!response.body) {
|
|
34
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', label + ' returned an empty response.')
|
|
35
|
+
}
|
|
36
|
+
const reader = response.body.getReader()
|
|
37
|
+
const chunks: Uint8Array[] = []
|
|
38
|
+
let bytes = 0
|
|
39
|
+
while (true) {
|
|
40
|
+
const result = await reader.read()
|
|
41
|
+
if (result.done) break
|
|
42
|
+
bytes += result.value.byteLength
|
|
43
|
+
if (bytes > MAX_DOCUMENT_BYTES) {
|
|
44
|
+
await reader.cancel()
|
|
45
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', label + ' exceeds the supported response size.')
|
|
46
|
+
}
|
|
47
|
+
chunks.push(result.value)
|
|
48
|
+
}
|
|
49
|
+
const body = new Uint8Array(bytes)
|
|
50
|
+
let offset = 0
|
|
51
|
+
for (const chunk of chunks) {
|
|
52
|
+
body.set(chunk, offset)
|
|
53
|
+
offset += chunk.byteLength
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(new TextDecoder().decode(body)) as T
|
|
57
|
+
} catch (cause) {
|
|
58
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', label + ' returned malformed JSON.', undefined, {
|
|
59
|
+
cause,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function resolveUiRelease(
|
|
65
|
+
requested?: string,
|
|
66
|
+
fetcher: Fetch = fetch,
|
|
67
|
+
): Promise<UiRelease> {
|
|
68
|
+
const versionDocument = requested
|
|
69
|
+
? { version: requested.replace(/^v/u, '') }
|
|
70
|
+
: await json<{ version: string }>(fetcher, NPM_PACKAGE + '/beta', 'npm UI release')
|
|
71
|
+
const version = versionDocument.version
|
|
72
|
+
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(version)) {
|
|
73
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'Invalid UI release version: ' + version)
|
|
74
|
+
}
|
|
75
|
+
if (!requested && !/-beta\.\d+$/u.test(version)) {
|
|
76
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'Invalid UI beta release version: ' + version)
|
|
77
|
+
}
|
|
78
|
+
const ref = 'v' + version
|
|
79
|
+
const reference = await json<{
|
|
80
|
+
object: { type: 'commit' | 'tag'; sha: string; url: string }
|
|
81
|
+
}>(fetcher, GITHUB_API + '/git/ref/tags/' + encodeURIComponent(ref), 'UI ref ' + ref)
|
|
82
|
+
const commit =
|
|
83
|
+
reference.object.type === 'commit'
|
|
84
|
+
? reference.object.sha
|
|
85
|
+
: (
|
|
86
|
+
await json<{ object: { sha: string } }>(
|
|
87
|
+
fetcher,
|
|
88
|
+
reference.object.url,
|
|
89
|
+
'annotated UI tag ' + ref,
|
|
90
|
+
)
|
|
91
|
+
).object.sha
|
|
92
|
+
if (!/^[0-9a-f]{40}$/u.test(commit)) {
|
|
93
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'UI ref ' + ref + ' did not resolve to a commit.')
|
|
94
|
+
}
|
|
95
|
+
return readUiReleaseSnapshot({ version, ref, commit }, fetcher)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function readUiReleaseSnapshot(
|
|
99
|
+
identity: Pick<UiRelease, 'version' | 'ref' | 'commit'>,
|
|
100
|
+
fetcher: Fetch = fetch,
|
|
101
|
+
): Promise<UiRelease> {
|
|
102
|
+
const [compatibility, registry] = await Promise.all([
|
|
103
|
+
json<UiCompatibility>(
|
|
104
|
+
fetcher,
|
|
105
|
+
RAW + '/' + identity.commit + '/tooling/compatibility.json',
|
|
106
|
+
'UI compatibility metadata',
|
|
107
|
+
),
|
|
108
|
+
readRegistry(identity.commit, fetcher),
|
|
109
|
+
])
|
|
110
|
+
if (
|
|
111
|
+
compatibility.version !== 1 ||
|
|
112
|
+
compatibility.base !== 'base' ||
|
|
113
|
+
compatibility.style !== 'nova' ||
|
|
114
|
+
!/^\d+\.\d+\.\d+$/u.test(compatibility.shadcn)
|
|
115
|
+
) {
|
|
116
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'UI compatibility metadata is invalid.')
|
|
117
|
+
}
|
|
118
|
+
return { ...identity, compatibility, registry }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function readRegistry(commit: string, fetcher: Fetch): Promise<UiRegistry> {
|
|
122
|
+
const candidate = RAW + '/' + commit + '/registry.json'
|
|
123
|
+
const root = await json<RegistrySource>(fetcher, candidate, 'UI registry')
|
|
124
|
+
const items = await resolveRegistryItems(root, candidate, commit, fetcher, new Set([candidate]))
|
|
125
|
+
const publicItems = items.filter(
|
|
126
|
+
(item) =>
|
|
127
|
+
!(item && typeof item === 'object' && (item as { type?: unknown }).type === 'registry:base'),
|
|
128
|
+
)
|
|
129
|
+
if (!publicItems.every(isInstallableItem)) {
|
|
130
|
+
throw new UiError(
|
|
131
|
+
'UI_REGISTRY_UNAVAILABLE',
|
|
132
|
+
'UI registry contains an invalid installable item.',
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
const installable = publicItems
|
|
136
|
+
if (installable.length === 0) {
|
|
137
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'UI registry has no installable items.')
|
|
138
|
+
}
|
|
139
|
+
if (
|
|
140
|
+
new Set(installable.map((item) => item.name)).size !== installable.length ||
|
|
141
|
+
new Set(installable.map((item) => item.meta.canonicalAddress)).size !== installable.length
|
|
142
|
+
) {
|
|
143
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'UI registry contains duplicate item identities.')
|
|
144
|
+
}
|
|
145
|
+
return { name: root.name ?? 'astrale-ui', homepage: root.homepage, items: installable }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function resolveRegistryItems(
|
|
149
|
+
source: RegistrySource,
|
|
150
|
+
sourceUrl: string,
|
|
151
|
+
commit: string,
|
|
152
|
+
fetcher: Fetch,
|
|
153
|
+
visited: Set<string>,
|
|
154
|
+
): Promise<unknown[]> {
|
|
155
|
+
const releaseRoot = RAW + '/' + commit + '/'
|
|
156
|
+
const sourceRelative = sourceUrl.slice(releaseRoot.length)
|
|
157
|
+
const sourceDirectory = sourceRelative.slice(0, Math.max(0, sourceRelative.lastIndexOf('/')))
|
|
158
|
+
const direct = Array.isArray(source.items)
|
|
159
|
+
? source.items.map((item) => qualifyRegistryItemPaths(item, sourceDirectory))
|
|
160
|
+
: []
|
|
161
|
+
const includes = source.include ?? []
|
|
162
|
+
if (!Array.isArray(includes)) {
|
|
163
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'UI registry include must be an array.')
|
|
164
|
+
}
|
|
165
|
+
if (visited.size + includes.length > MAX_REGISTRY_DOCUMENTS) {
|
|
166
|
+
throw new UiError(
|
|
167
|
+
'UI_REGISTRY_UNAVAILABLE',
|
|
168
|
+
'UI registry contains too many included documents.',
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
const nested = await Promise.all(
|
|
172
|
+
includes.map(async (include) => {
|
|
173
|
+
if (
|
|
174
|
+
typeof include !== 'string' ||
|
|
175
|
+
!isSafeRelative(include) ||
|
|
176
|
+
!/^[A-Za-z0-9._/-]+$/u.test(include) ||
|
|
177
|
+
!include.endsWith('registry.json') ||
|
|
178
|
+
include === 'registry.json'
|
|
179
|
+
) {
|
|
180
|
+
throw new UiError('UI_REGISTRY_UNAVAILABLE', 'UI registry contains an unsafe include.')
|
|
181
|
+
}
|
|
182
|
+
const sourceDirectoryUrl = sourceUrl.slice(0, sourceUrl.lastIndexOf('/') + 1)
|
|
183
|
+
const url = new URL(include, sourceUrl).toString()
|
|
184
|
+
if (
|
|
185
|
+
url !== sourceDirectoryUrl + include ||
|
|
186
|
+
!url.startsWith(releaseRoot) ||
|
|
187
|
+
!url.startsWith(sourceDirectoryUrl) ||
|
|
188
|
+
visited.has(url)
|
|
189
|
+
) {
|
|
190
|
+
throw new UiError(
|
|
191
|
+
'UI_REGISTRY_UNAVAILABLE',
|
|
192
|
+
'UI registry include escaped or repeated the release snapshot.',
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
visited.add(url)
|
|
196
|
+
const child = await json<RegistrySource>(fetcher, url, 'UI registry include')
|
|
197
|
+
return resolveRegistryItems(child, url, commit, fetcher, visited)
|
|
198
|
+
}),
|
|
199
|
+
)
|
|
200
|
+
return direct.concat(nested.flat())
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function qualifyRegistryItemPaths(item: unknown, sourceDirectory: string): unknown {
|
|
204
|
+
if (!item || typeof item !== 'object') return item
|
|
205
|
+
const candidate = item as { files?: unknown }
|
|
206
|
+
if (!Array.isArray(candidate.files)) return item
|
|
207
|
+
return {
|
|
208
|
+
...candidate,
|
|
209
|
+
files: candidate.files.map((file) => {
|
|
210
|
+
if (!file || typeof file !== 'object') return file
|
|
211
|
+
const candidateFile = file as { path?: unknown }
|
|
212
|
+
if (typeof candidateFile.path !== 'string') return file
|
|
213
|
+
if (
|
|
214
|
+
!isSafeRelative(candidateFile.path) ||
|
|
215
|
+
(sourceDirectory !== '' &&
|
|
216
|
+
(candidateFile.path === sourceDirectory ||
|
|
217
|
+
candidateFile.path.startsWith(sourceDirectory + '/')))
|
|
218
|
+
) {
|
|
219
|
+
throw new UiError(
|
|
220
|
+
'UI_REGISTRY_UNAVAILABLE',
|
|
221
|
+
'UI registry contains an invalid installable item path.',
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
if (sourceDirectory === '') return file
|
|
225
|
+
const qualified = sourceDirectory + '/' + candidateFile.path
|
|
226
|
+
if (!isSafeRelative(qualified)) {
|
|
227
|
+
throw new UiError(
|
|
228
|
+
'UI_REGISTRY_UNAVAILABLE',
|
|
229
|
+
'UI registry contains an invalid installable item path.',
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
return { ...candidateFile, path: qualified }
|
|
233
|
+
}),
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function isInstallableItem(item: unknown): item is UiRegistry['items'][number] {
|
|
238
|
+
if (!item || typeof item !== 'object') return false
|
|
239
|
+
const candidate = item as Partial<UiRegistry['items'][number]>
|
|
240
|
+
return (
|
|
241
|
+
typeof candidate.name === 'string' &&
|
|
242
|
+
/^(?:pattern|block)-[a-z0-9-]+$/u.test(candidate.name) &&
|
|
243
|
+
candidate.type === 'registry:block' &&
|
|
244
|
+
(candidate.dependencies === undefined ||
|
|
245
|
+
(Array.isArray(candidate.dependencies) &&
|
|
246
|
+
candidate.dependencies.every(
|
|
247
|
+
(dependency) =>
|
|
248
|
+
typeof dependency === 'string' &&
|
|
249
|
+
/^(?:@[a-z0-9-]+\/)?[a-z0-9-]+@[~^<>=0-9A-Za-z.* -]+$/u.test(dependency),
|
|
250
|
+
))) &&
|
|
251
|
+
Array.isArray(candidate.files) &&
|
|
252
|
+
candidate.files.length > 0 &&
|
|
253
|
+
candidate.files.every(
|
|
254
|
+
(file) =>
|
|
255
|
+
file &&
|
|
256
|
+
typeof file.path === 'string' &&
|
|
257
|
+
isSafeRelative(file.path) &&
|
|
258
|
+
typeof file.type === 'string' &&
|
|
259
|
+
typeof file.target === 'string' &&
|
|
260
|
+
file.target.startsWith('components/astrale/') &&
|
|
261
|
+
isSafeRelative(file.target),
|
|
262
|
+
) &&
|
|
263
|
+
typeof candidate.meta?.canonicalAddress === 'string' &&
|
|
264
|
+
/^(?:pattern|block)\/[a-z0-9-]+\/[a-z0-9-/]+$/u.test(candidate.meta.canonicalAddress)
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export async function readUiRegistryItem(
|
|
269
|
+
release: UiRelease,
|
|
270
|
+
expected: UiRegistry['items'][number],
|
|
271
|
+
fetcher: Fetch = fetch,
|
|
272
|
+
): Promise<UiRegistry['items'][number]> {
|
|
273
|
+
const item = await json<unknown>(
|
|
274
|
+
fetcher,
|
|
275
|
+
registryItemUrl(release, expected.name),
|
|
276
|
+
'UI registry item ' + expected.name,
|
|
277
|
+
)
|
|
278
|
+
if (
|
|
279
|
+
!isInstallableItem(item) ||
|
|
280
|
+
item.name !== expected.name ||
|
|
281
|
+
item.meta.canonicalAddress !== expected.meta.canonicalAddress ||
|
|
282
|
+
item.files.length !== expected.files.length ||
|
|
283
|
+
item.files.some((file, index) => {
|
|
284
|
+
const declared = expected.files[index]
|
|
285
|
+
return (
|
|
286
|
+
typeof file.content !== 'string' ||
|
|
287
|
+
file.content.length === 0 ||
|
|
288
|
+
!declared ||
|
|
289
|
+
file.path !== declared.path ||
|
|
290
|
+
file.type !== declared.type ||
|
|
291
|
+
file.target !== declared.target
|
|
292
|
+
)
|
|
293
|
+
})
|
|
294
|
+
) {
|
|
295
|
+
throw new UiError(
|
|
296
|
+
'UI_REGISTRY_UNAVAILABLE',
|
|
297
|
+
'UI registry item ' + expected.name + ' does not match the admitted release index.',
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
return item
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function isSafeRelative(value: string): boolean {
|
|
304
|
+
const segments = value.split('/')
|
|
305
|
+
return (
|
|
306
|
+
value.length > 0 &&
|
|
307
|
+
!value.startsWith('/') &&
|
|
308
|
+
!/^[A-Za-z]:[\\/]/u.test(value) &&
|
|
309
|
+
!value.includes('\\') &&
|
|
310
|
+
!/[?#%]/u.test(value) &&
|
|
311
|
+
![...value].some((character) => {
|
|
312
|
+
const code = character.codePointAt(0) ?? 0
|
|
313
|
+
return code <= 31 || code === 127
|
|
314
|
+
}) &&
|
|
315
|
+
segments.every((segment) => segment.length > 0 && segment !== '.' && segment !== '..')
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export function registryItemUrl(release: UiRelease, itemName: string): string {
|
|
320
|
+
return RAW + '/' + release.commit + '/registry/public/r/' + encodeURIComponent(itemName) + '.json'
|
|
321
|
+
}
|
package/src/ui/runner.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PackageManager } from './model'
|
|
2
|
+
|
|
3
|
+
import { run, type RunResult } from '../lib/proc'
|
|
4
|
+
|
|
5
|
+
export type UiRunner = (file: string, args: string[], cwd: string) => Promise<RunResult>
|
|
6
|
+
|
|
7
|
+
export const defaultUiRunner: UiRunner = (file, args, cwd) => run(file, args, { cwd })
|
|
8
|
+
|
|
9
|
+
export function shadcnInvocation(
|
|
10
|
+
manager: PackageManager,
|
|
11
|
+
version: string,
|
|
12
|
+
args: string[],
|
|
13
|
+
): { file: string; args: string[] } {
|
|
14
|
+
if (manager === 'pnpm') return { file: 'pnpm', args: ['dlx', 'shadcn@' + version, ...args] }
|
|
15
|
+
if (manager === 'bun') return { file: 'bunx', args: ['shadcn@' + version, ...args] }
|
|
16
|
+
if (manager === 'yarn') return { file: 'yarn', args: ['dlx', 'shadcn@' + version, ...args] }
|
|
17
|
+
return { file: 'npx', args: ['--yes', 'shadcn@' + version, ...args] }
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,t}from"./rolldown-runtime-Dd_uD5pT.js";var n=t(((t,n)=>{(function(e){if(typeof t==`object`&&n!==void 0)n.exports=e();else if(typeof define==`function`&&define.amd)define([],e);else{var r=typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:this;r.ELK=e()}})(function(){return(function(){function t(n,r,i){function a(s,c){if(!r[s]){if(!n[s]){var l=typeof e==`function`&&e;if(!c&&l)return l(s,!0);if(o)return o(s,!0);var u=Error(`Cannot find module '`+s+`'`);throw u.code=`MODULE_NOT_FOUND`,u}var d=r[s]={exports:{}};n[s][0].call(d.exports,function(e){var t=n[s][1][e];return a(t||e)},d,d.exports,t,n,r,i)}return r[s].exports}for(var o=typeof e==`function`&&e,s=0;s<i.length;s++)a(i[s]);return a}return t})()({1:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;function r(e){"@babel/helpers - typeof";return r=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},r(e)}function i(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,s(r.key),r)}}function o(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=c(e,`string`);return r(t)==`symbol`?t:t+``}function c(e,t){if(r(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var i=n.call(e,t||`default`);if(r(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}n.default=function(){function e(){var t=this,n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=n.defaultLayoutOptions,a=r===void 0?{}:r,o=n.algorithms,s=o===void 0?[`layered`,`stress`,`mrtree`,`radial`,`force`,`disco`,`sporeOverlap`,`sporeCompaction`,`rectpacking`]:o,c=n.workerFactory,u=n.workerUrl;if(i(this,e),this.defaultLayoutOptions=a,this.initialized=!1,u===void 0&&c===void 0)throw Error(`Cannot construct an ELK without both 'workerUrl' and 'workerFactory'.`);var d=c;u!==void 0&&c===void 0&&(d=function(e){return new Worker(e)});var f=d(u);if(typeof f.postMessage!=`function`)throw TypeError(`Created worker does not provide the required 'postMessage' function.`);this.worker=new l(f),this.worker.postMessage({cmd:`register`,algorithms:s}).then(function(e){return t.initialized=!0}).catch(console.err)}return o(e,[{key:`layout`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},n=t.layoutOptions,r=n===void 0?this.defaultLayoutOptions:n,i=t.logging,a=i!==void 0&&i,o=t.measureExecutionTime,s=o!==void 0&&o;return e?this.worker.postMessage({cmd:`layout`,graph:e,layoutOptions:r,options:{logging:a,measureExecutionTime:s}}):Promise.reject(Error(`Missing mandatory parameter 'graph'.`))}},{key:`knownLayoutAlgorithms`,value:function(){return this.worker.postMessage({cmd:`algorithms`})}},{key:`knownLayoutOptions`,value:function(){return this.worker.postMessage({cmd:`options`})}},{key:`knownLayoutCategories`,value:function(){return this.worker.postMessage({cmd:`categories`})}},{key:`terminateWorker`,value:function(){this.worker&&this.worker.terminate()}}])}();var l=function(){function e(t){var n=this;if(i(this,e),t===void 0)throw Error(`Missing mandatory parameter 'worker'.`);this.resolvers={},this.worker=t,this.worker.onmessage=function(e){setTimeout(function(){n.receive(n,e)},0)}}return o(e,[{key:`postMessage`,value:function(e){var t=this.id||0;this.id=t+1,e.id=t;var n=this;return new Promise(function(r,i){n.resolvers[t]=function(e,t){e?(n.convertGwtStyleError(e),i(e)):r(t)},n.worker.postMessage(e)})}},{key:`receive`,value:function(e,t){var n=t.data,r=e.resolvers[n.id];r&&(delete e.resolvers[n.id],n.error?r(n.error):r(null,n.data))}},{key:`terminate`,value:function(){this.worker&&this.worker.terminate()}},{key:`convertGwtStyleError`,value:function(e){if(e){var t=e.__java$exception;t&&(t.cause&&t.cause.backingJsObject&&(e.cause=t.cause.backingJsObject,this.convertGwtStyleError(e.cause)),delete e.__java$exception)}}}])}()},{}],2:[function(e,t,n){var r=e("./elk-api.js").default;Object.defineProperty(t.exports,"__esModule",{value:!0}),t.exports=r,r.default=r},{"./elk-api.js":1}]},{},[2])(2)})}));export default n();
|