@kumwe/studio-core 0.1.0-alpha.7 → 0.1.0-beta.2
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 +87 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/dist/authentication-lifetime.d.ts +16 -0
- package/dist/authentication-lifetime.d.ts.map +1 -0
- package/dist/authentication-lifetime.js +1 -0
- package/dist/binding-projection.d.ts +47 -0
- package/dist/binding-projection.d.ts.map +1 -0
- package/dist/binding-projection.js +1 -0
- package/dist/canonical.js +1 -100
- package/dist/clone.js +1 -4
- package/dist/commands.d.ts +1 -1
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +1 -799
- package/dist/contextual-session.d.ts +112 -0
- package/dist/contextual-session.d.ts.map +1 -0
- package/dist/contextual-session.js +1 -0
- package/dist/contributions.d.ts +63 -2
- package/dist/contributions.d.ts.map +1 -1
- package/dist/contributions.js +1 -302
- package/dist/deployment-validation.d.ts +10 -0
- package/dist/deployment-validation.d.ts.map +1 -0
- package/dist/deployment-validation.js +1 -0
- package/dist/entry-commands.js +1 -36
- package/dist/extension-sdk.d.ts +12 -6
- package/dist/extension-sdk.d.ts.map +1 -1
- package/dist/extension-sdk.js +1 -188
- package/dist/history.d.ts +12 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +1 -63
- package/dist/host-session.d.ts +93 -0
- package/dist/host-session.d.ts.map +1 -0
- package/dist/host-session.js +1 -0
- package/dist/http-authoring-contract.d.ts +29 -0
- package/dist/http-authoring-contract.d.ts.map +1 -0
- package/dist/http-authoring-contract.js +1 -0
- package/dist/http-host-adapter.d.ts +173 -0
- package/dist/http-host-adapter.d.ts.map +1 -0
- package/dist/http-host-adapter.js +1 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -18
- package/dist/layout.d.ts +66 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +1 -0
- package/dist/migrations.js +1 -83
- package/dist/model-commands.js +1 -21
- package/dist/modes.js +1 -280
- package/dist/negotiation.js +1 -65
- package/dist/production-values.d.ts +12 -0
- package/dist/production-values.d.ts.map +1 -0
- package/dist/production-values.js +1 -0
- package/dist/production.d.ts +86 -0
- package/dist/production.d.ts.map +1 -0
- package/dist/production.js +1 -0
- package/dist/profile-validator.d.ts +2 -2
- package/dist/profile-validator.d.ts.map +1 -1
- package/dist/profile-validator.js +1 -783
- package/dist/recipes.js +1 -34
- package/dist/registry.js +1 -56
- package/dist/schema-profile.d.ts +23 -5
- package/dist/schema-profile.d.ts.map +1 -1
- package/dist/schema-profile.js +1 -390
- package/dist/semver.js +1 -128
- package/dist/session-policy.d.ts +23 -0
- package/dist/session-policy.d.ts.map +1 -0
- package/dist/session-policy.js +1 -0
- package/dist/session.d.ts +14 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +1 -178
- package/dist/strict-json.d.ts +7 -0
- package/dist/strict-json.d.ts.map +1 -0
- package/dist/strict-json.js +2 -0
- package/dist/url-policy.js +1 -248
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +1 -398
- package/package.json +5 -3
- package/dist/canonical.js.map +0 -1
- package/dist/clone.js.map +0 -1
- package/dist/commands.js.map +0 -1
- package/dist/contributions.js.map +0 -1
- package/dist/entry-commands.js.map +0 -1
- package/dist/extension-sdk.js.map +0 -1
- package/dist/history.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/migrations.js.map +0 -1
- package/dist/model-commands.js.map +0 -1
- package/dist/modes.js.map +0 -1
- package/dist/negotiation.js.map +0 -1
- package/dist/profile-validator.js.map +0 -1
- package/dist/recipes.js.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/schema-profile.js.map +0 -1
- package/dist/semver.js.map +0 -1
- package/dist/session.js.map +0 -1
- package/dist/url-policy.js.map +0 -1
- package/dist/validation.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# `@kumwe/studio-core`
|
|
2
2
|
|
|
3
|
-
Status: pre-Gate-A
|
|
3
|
+
Status: governed beta development, still pre-Gate-A and not production-supported. The exact coordinated
|
|
4
|
+
version is in the workspace `studio-release.json`; the implemented kernel does not claim product or
|
|
5
|
+
host-integration completeness.
|
|
4
6
|
|
|
5
7
|
The framework-neutral state engine for Studio. It registers versioned blocks, validates blueprint
|
|
6
8
|
documents, applies typed commands without mutating caller-owned data, and maintains bounded
|
|
@@ -15,13 +17,94 @@ The implemented surface covers:
|
|
|
15
17
|
- `applyEntryCommand` — the locale-guarded `set-field-value` reducer for entries;
|
|
16
18
|
- `StudioSession` — bounded history behind fail-closed session guards (read-only state, session
|
|
17
19
|
generation, expected revision), dirty tracking, and a validated selection model;
|
|
18
|
-
- `
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
- `openStudioSession` — capability-negotiated Blueprint loading and a headless host-session handle for
|
|
21
|
+
serialized optimistic saves, raw optional recovery-port access, read-only model `list`/`get`, bounded
|
|
22
|
+
resource search, stale-generation invalidation, and local idempotent disposal;
|
|
23
|
+
- `openContextualStudioSession` — the additive resource-bound coordinator for exact target resolution and
|
|
24
|
+
blank/from-type/existing starts, separate Model/Blueprint/Entry draft state, presentation state, save
|
|
25
|
+
planning, all three explicit save outcomes, revision reconciliation, and authoritative failure handling;
|
|
26
|
+
- `preflightContextualStudioSession` — the same coordinator split at its in-context create boundary: resolve
|
|
27
|
+
target authority, optionally page through authorized exact reusable types, then transfer into one exact
|
|
28
|
+
session without another route vocabulary or local fallback;
|
|
29
|
+
- `projectBlueprintFieldBindings` — an immutable exact-model projection of compatible block-port field
|
|
30
|
+
candidates, declared authoring controls and stable invalid-binding diagnostics;
|
|
31
|
+
- `ContributionRuntime` — owner-aware, transactional, schema-validated activation of block,
|
|
32
|
+
pattern, design-vocabulary, migration, inspector, and field-adapter payloads into kind-scoped
|
|
33
|
+
immutable generations, with disable, reactivate, trust-revocation, stale-generation refusal, and
|
|
34
|
+
inspectable unresolved contributions;
|
|
21
35
|
- `validateBlueprint` and `BlockRegistry` — schema, limit, lock, and registry validation with
|
|
22
36
|
stable diagnostics;
|
|
23
37
|
- `canonicalStringify` / `canonicalUtf8Bytes` — the canonical cross-language serialization form
|
|
24
38
|
used for checksums.
|
|
39
|
+
- `createCoreLayoutBlockDefinitions` / `resolveCoreLayoutIntent` — first-party section, stack, grid,
|
|
40
|
+
and columns definitions plus theme-validated responsive intent resolution, with no DOM or stored
|
|
41
|
+
CSS;
|
|
42
|
+
- `createCoreProductionBlockDefinitions` / `createCoreProductionPatterns` — the standalone 45-block
|
|
43
|
+
production catalog and ten portable starter compositions, including media, rich content,
|
|
44
|
+
progressive composites including dialogs, popovers, and notices, data display, and
|
|
45
|
+
host-authoritative resource/query projections;
|
|
46
|
+
- `coreProductionInitialProperties` — schema-valid defaults used by the Studio insertion path for
|
|
47
|
+
every first-party type;
|
|
48
|
+
- `parseStudioPresentationIntent` — the closed, CSS-free visual capability contract shared by all
|
|
49
|
+
first-party inspector surfaces and renderers;
|
|
50
|
+
- `compileStudioPropertySchema` / `assertStudioPropertySchema` — eval-free admission and validation
|
|
51
|
+
for the closed, local-only `studio.profile/schema-property` surface, with stable
|
|
52
|
+
`StudioSchemaProfileError` codes and schema pointers.
|
|
53
|
+
- `validateStudioDeploymentConfiguration` / `assertStudioDeploymentConfiguration` — canonical deployment
|
|
54
|
+
validation plus hosted launch/session resource-context and route/capability agreement before transport use.
|
|
25
55
|
|
|
26
56
|
The package has no DOM dependency. Web Components, Flutter clients, command-line tools, and server
|
|
27
57
|
adapters can therefore share the same command and validation semantics through the protocol.
|
|
58
|
+
|
|
59
|
+
## Advanced HTTP HostAdapter
|
|
60
|
+
|
|
61
|
+
Normal browser integrations pass a canonical `StudioDeploymentConfiguration` to `mountStudio()`; the mounted
|
|
62
|
+
runtime constructs this adapter automatically. `createHttpHostAdapter(httpTransportConfiguration, options)` is
|
|
63
|
+
the lower-level DOM- and Node-free client for applications that intentionally own composition. The caller
|
|
64
|
+
supplies exact per-operation URLs or one exact dispatcher URL, a closed authentication profile, a fetch-like
|
|
65
|
+
transport, and optional deadline/credential-refresh factories. The adapter never derives or probes a URL.
|
|
66
|
+
|
|
67
|
+
It supplies canonical envelopes, bounded response reading, schema-validation hooks, safe status
|
|
68
|
+
classification, and canonical `HostPortFailure` rejections. Contextual authoring uses the operation-specific
|
|
69
|
+
`authoring-http.schema.json` definitions. Conventional base-path expansion is available only from testkit
|
|
70
|
+
fixtures and must not define a host integration. This is client code after compilation, not a server runtime;
|
|
71
|
+
PHP hosts implement the documented JSON endpoints and own every authoritative effect.
|
|
72
|
+
|
|
73
|
+
## Blueprint host-session composition
|
|
74
|
+
|
|
75
|
+
`openStudioSession(hostAdapter, options)` consumes a complete, host-resolved `StudioConfiguration` from
|
|
76
|
+
`OpenStudioSessionOptions`. Its injected `StudioHostSessionIdentifierFactories` provide deterministic
|
|
77
|
+
`requestId(operationId)` and `idempotencyKey(operationId)` values. Opening requires
|
|
78
|
+
`mode: blueprint`, `composite: single`, either session state, and the configured Blueprint reference;
|
|
79
|
+
it passes the resolved Blueprint/read-only mode, session generation, resource context, locale,
|
|
80
|
+
protocol, and history limit through the headless lifecycle. It does not perform the host handshake,
|
|
81
|
+
automatically load model/theme dependencies or fabricate an artifact for model/content/hybrid configuration.
|
|
82
|
+
Callers may inject any conforming `HostAdapter`, including the separately exported HTTP adapter.
|
|
83
|
+
|
|
84
|
+
The returned handle serializes saves against the latest accepted host revision and coalesces matching
|
|
85
|
+
concurrent intents. An exact retry after failure retains its idempotency key. If the document changes
|
|
86
|
+
while a snapshot is saving, the success advances the accepted revision but the newer state remains
|
|
87
|
+
dirty. Every current, undo, and redo snapshot carries that accepted revision without a local state-version
|
|
88
|
+
change, so later history and exact preview staging use one coherent base. Conflicts and other refusals
|
|
89
|
+
preserve the document, history, selection, and saved baseline.
|
|
90
|
+
|
|
91
|
+
`StudioHostSessionHandle.recovery` is a `StudioHostSessionRecovery` with direct `store`, `load`, and
|
|
92
|
+
`discard` calls when the optional port is present, and is `undefined` otherwise. The core does not
|
|
93
|
+
synthesize or reconcile recovery envelopes. A
|
|
94
|
+
`studio.host/stale-session-generation` diagnostic invalidates the complete handle. `dispose()` is
|
|
95
|
+
local and idempotent and does not imply host teardown or preview cleanup. See
|
|
96
|
+
[ADR 0020](../../docs/decisions/0020-blueprint-host-session-composition.md) for the deliberate scope.
|
|
97
|
+
|
|
98
|
+
`StudioHostSessionHandle.models` is present only when the negotiated model port and adapter both implement
|
|
99
|
+
`list` and `get`. Results are canonical-schema validated, exact-coordinate checked and detached before they
|
|
100
|
+
leave the boundary; stale generation invalidates the whole handle. The surface is deliberately read-only.
|
|
101
|
+
Pass an authorized active model to `projectBlueprintFieldBindings(blueprint, model, definitions)` to derive
|
|
102
|
+
portable candidates and diagnostics without changing any input. See
|
|
103
|
+
[ADR 0024](../../docs/decisions/0024-read-only-model-binding-projection.md).
|
|
104
|
+
|
|
105
|
+
`StudioHostSessionHandle.resources` is present only when the negotiated resource port advertises
|
|
106
|
+
`studio.operation/resource.search` and the adapter implements it. `search` validates and clones bounded
|
|
107
|
+
queries before allocating a request, then accepts only detached pages whose stable, unique hit IDs and
|
|
108
|
+
qualified message references match the requested resource type. Malformed adapter output becomes a safe
|
|
109
|
+
`studio.host/unexpected-resource-result` failure. This is a read-only discovery surface: hosts still own
|
|
110
|
+
authorization and resolution, and first-party dynamic resource/query bindings remain read-only in Studio.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
<!-- Generated by scripts/generate-third-party-notices.mjs. Do not edit by hand. -->
|
|
4
|
+
|
|
5
|
+
Package: `@kumwe/studio-core`
|
|
6
|
+
|
|
7
|
+
Production closure SHA-256: `4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945`
|
|
8
|
+
|
|
9
|
+
This package has no third-party runtime dependencies.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Maximum serialized bearer/custom-header credential lifetime: fifteen minutes. */
|
|
2
|
+
export declare const STUDIO_TOKEN_MAXIMUM_LIFETIME_MILLISECONDS: number;
|
|
3
|
+
export interface StudioTokenLifetime {
|
|
4
|
+
readonly expiresAt: unknown;
|
|
5
|
+
readonly issuedAt: unknown;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Validate one browser-visible token's closed lifetime interval. The exact
|
|
9
|
+
* clock rule is `issuedAt <= now < expiresAt`; no implicit grace period turns
|
|
10
|
+
* a future or expired serialized credential into a usable one.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isStudioTokenLifetimeValid(lifetime: StudioTokenLifetime, currentTimeMilliseconds: number): boolean;
|
|
13
|
+
/** Assert metadata and duration, optionally including current usability. */
|
|
14
|
+
export declare function assertStudioTokenLifetime(lifetime: StudioTokenLifetime, currentTimeMilliseconds?: number): void;
|
|
15
|
+
export declare function isAuthenticationLifetimeFailure(reason: unknown): boolean;
|
|
16
|
+
//# sourceMappingURL=authentication-lifetime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-lifetime.d.ts","sourceRoot":"","sources":["../src/authentication-lifetime.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,eAAO,MAAM,0CAA0C,EAAE,MAAuB,CAAC;AAYjF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,mBAAmB,EAC7B,uBAAuB,EAAE,MAAM,GAC9B,OAAO,CAaT;AAED,4EAA4E;AAC5E,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,mBAAmB,EAC7B,uBAAuB,CAAC,EAAE,MAAM,GAC/B,IAAI,CAqBN;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAOxE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STUDIO_TOKEN_MAXIMUM_LIFETIME_MILLISECONDS=9e5;const t=/^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.(\d{1,9}))?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/u;export function isStudioTokenLifetimeValid(e,t){if(!Number.isFinite(t))return!1;let n=a(e.issuedAt),r=a(e.expiresAt);return n!==void 0&&r!==void 0&&o(n,t)<=0&&o(r,t)>0&&s(n,r)}export function assertStudioTokenLifetime(e,t){let n=a(e.issuedAt),r=a(e.expiresAt);if(n===void 0||r===void 0)throw TypeError(`issuedAt and expiresAt must be RFC 3339 date-times.`);if(!s(n,r))throw l();if(t!==void 0){if(!Number.isFinite(t))throw TypeError(`The configured transport clock returned an invalid time.`);if(o(n,t)>0||o(r,t)<=0)throw l()}}export function isAuthenticationLifetimeFailure(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`AuthenticationLifetimeError`}function a(e){if(typeof e!=`string`||e.length>40)return;let n=t.exec(e);if(n===null)return;let r=Number(n[1]),i=Number(n[2]);if(Number(n[3])>c(r,i))return;let a=Date.parse(e);return Number.isFinite(a)?{milliseconds:a,nanosecondRemainder:Number((n[4]??``).padEnd(9,`0`))%1e6}:void 0}function o(e,t){return e.milliseconds===t?Math.sign(e.nanosecondRemainder):Math.sign(e.milliseconds-t)}function s(t,n){let r=n.milliseconds-t.milliseconds,i=n.nanosecondRemainder-t.nanosecondRemainder;return(r>0||r===0&&i>0)&&(r<STUDIO_TOKEN_MAXIMUM_LIFETIME_MILLISECONDS||r===STUDIO_TOKEN_MAXIMUM_LIFETIME_MILLISECONDS&&i<=0)}function c(e,t){return t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:t===4||t===6||t===9||t===11?30:31}function l(){let e=Error(`The configured HTTP authentication lifetime is not currently valid.`);return e.name=`AuthenticationLifetimeError`,e}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BlockDefinition, BlueprintDocument, ContentFieldKind, ContentModelDocument, FieldBinding, FieldDefinition, LocalName, LockedArtifactReference, MessageReference, QualifiedName, StudioDiagnostic } from '@kumwe/studio-protocol';
|
|
2
|
+
/** The stable outcomes a binding port can expose to any authoring shell. */
|
|
3
|
+
export type FieldBindingProjectionStatus = 'invalid' | 'non-field-source' | 'resolved' | 'unbound';
|
|
4
|
+
/** One model field that can be bound to one exact block port. */
|
|
5
|
+
export interface FieldBindingCandidate {
|
|
6
|
+
readonly cardinality: FieldDefinition['cardinality'];
|
|
7
|
+
readonly control?: QualifiedName;
|
|
8
|
+
readonly fieldPath: readonly LocalName[];
|
|
9
|
+
readonly itemKind?: Exclude<ContentFieldKind, 'collection'>;
|
|
10
|
+
readonly kind: ContentFieldKind;
|
|
11
|
+
readonly label: MessageReference;
|
|
12
|
+
}
|
|
13
|
+
/** Deterministic projection of one declared or preserved node binding port. */
|
|
14
|
+
export interface FieldBindingPortProjection {
|
|
15
|
+
readonly binding?: FieldBinding;
|
|
16
|
+
readonly boundFieldPath?: readonly LocalName[];
|
|
17
|
+
readonly candidates: readonly FieldBindingCandidate[];
|
|
18
|
+
readonly multiple?: boolean;
|
|
19
|
+
readonly port: LocalName;
|
|
20
|
+
readonly required?: boolean;
|
|
21
|
+
readonly status: FieldBindingProjectionStatus;
|
|
22
|
+
readonly valueType?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Deterministic projection of all binding affordances on one Blueprint node. */
|
|
25
|
+
export interface NodeFieldBindingProjection {
|
|
26
|
+
readonly nodeId: string;
|
|
27
|
+
readonly ports: readonly FieldBindingPortProjection[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read-only, language-neutral view of a Blueprint's bindings against one exact
|
|
31
|
+
* host-projected model revision.
|
|
32
|
+
*/
|
|
33
|
+
export interface BlueprintFieldBindingProjection {
|
|
34
|
+
readonly diagnostics: readonly StudioDiagnostic[];
|
|
35
|
+
readonly model: LockedArtifactReference;
|
|
36
|
+
readonly nodes: readonly NodeFieldBindingProjection[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Projects the active model into field-binding affordances and diagnostics.
|
|
40
|
+
*
|
|
41
|
+
* The function never changes a model, Blueprint, block definition, workflow,
|
|
42
|
+
* translation, or permission value. It accepts only already-authorized model
|
|
43
|
+
* projections and returns detached JSON-compatible snapshots. Field IDs, not
|
|
44
|
+
* labels or storage names, are the only binding coordinates.
|
|
45
|
+
*/
|
|
46
|
+
export declare function projectBlueprintFieldBindings(blueprint: BlueprintDocument, model: ContentModelDocument, definitions: readonly BlockDefinition[]): BlueprintFieldBindingProjection;
|
|
47
|
+
//# sourceMappingURL=binding-projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding-projection.d.ts","sourceRoot":"","sources":["../src/binding-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEf,iBAAiB,EAEjB,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,eAAe,EAEf,SAAS,EACT,uBAAuB,EACvB,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAGhC,4EAA4E;AAC5E,MAAM,MAAM,4BAA4B,GAAG,SAAS,GAAG,kBAAkB,GAAG,UAAU,GAAG,SAAS,CAAC;AAEnG,iEAAiE;AACjE,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;IACrD,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,SAAS,EAAE,CAAC;IACzC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAC5D,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;CAClC;AAED,+EAA+E;AAC/E,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC/C,QAAQ,CAAC,UAAU,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACtD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,4BAA4B,CAAC;IAC9C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,iFAAiF;AACjF,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,0BAA0B,EAAE,CAAC;CACvD;AAED;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAClD,QAAQ,CAAC,KAAK,EAAE,uBAAuB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,SAAS,0BAA0B,EAAE,CAAC;CACvD;AAgBD;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,oBAAoB,EAC3B,WAAW,EAAE,SAAS,eAAe,EAAE,GACtC,+BAA+B,CA6BjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cloneContractValue as e}from"./clone.js";export function projectBlueprintFieldBindings(t,i,a){let o=e(t),s=e(i),l=e(a),u=[],d=e(o.model),f=n(o,s,u),p=new Map;for(let e of l)p.set(g(e.type,e.version),e);let h={blueprintId:o.id,definitions:p,diagnostics:u,fields:f?c(s.fields):[],modelCompatible:f,modelReference:d},_=[];return m(o.roots,e=>{_.push(r(e,h))}),e({diagnostics:u,model:d,nodes:_})}function n(e,t,n){let r=!0;for(let i of[{actual:t.id,code:`studio.binding/model-id-mismatch`,expected:e.model.id,member:`id`},{actual:t.version,code:`studio.binding/model-version-mismatch`,expected:e.model.version,member:`version`},{actual:t.revision,code:`studio.binding/model-revision-mismatch`,expected:e.model.revision,member:`revision`}])i.actual!==i.expected&&(r=!1,n.push(h(i.code,`The projected model ${i.member} {actual} does not match the Blueprint lock {expected}.`,`error`,{actual:i.actual,expected:i.expected,member:i.member},{artifactId:e.id})));return r}function r(e,t){let n=t.definitions.get(g(e.type,e.version))?.ports??[],r=new Set(n.map(e=>e.id)),o=Object.keys(e.bindings).filter(e=>!r.has(e)).sort(v),s=[...n.map(n=>i(e,n,t)),...o.map(n=>a(e,n,t))];return{nodeId:e.id,ports:s}}function i(t,n,r){let i=r.modelCompatible?r.fields.filter(e=>e.field.authoring?.hidden!==!0&&u(e.field,n)).map(({field:e,fieldPath:t})=>s(e,t)):[],a=t.bindings[n.id];if(a===void 0)return n.required&&r.diagnostics.push(h(`studio.binding/required-port-unbound`,`Required block port {port} is not bound to a source.`,`warning`,{port:n.id},{artifactId:r.blueprintId,nodeId:t.id})),{candidates:i,multiple:n.multiple,port:n.id,required:n.required,status:`unbound`,valueType:n.valueType};if(a.source.kind!==`entry-field`)return{binding:e(a),candidates:i,multiple:n.multiple,port:n.id,required:n.required,status:`non-field-source`,valueType:n.valueType};let c=[...a.source.fieldPath];if(!r.modelCompatible)return o(n,a,c,i);let m=l(r.fields,c);return m===void 0?(r.diagnostics.push(h(`studio.binding/field-missing`,`Binding port {port} addresses field path {fieldPath}, which the locked model no longer declares.`,`error`,{fieldPath:c.join(`.`),port:n.id},{artifactId:r.blueprintId,fieldPath:c,nodeId:t.id})),o(n,a,c,i)):d(m.field)===n.multiple?f(m.field,n.valueType)?{binding:e(a),boundFieldPath:c,candidates:i,multiple:n.multiple,port:n.id,required:n.required,status:`resolved`,valueType:n.valueType}:(r.diagnostics.push(h(`studio.binding/field-kind-incompatible`,`Binding port {port} expects {valueType}, but field {fieldPath} now projects as {fieldKind}.`,`error`,{fieldKind:p(m.field),fieldPath:c.join(`.`),port:n.id,valueType:n.valueType},{artifactId:r.blueprintId,fieldPath:c,nodeId:t.id})),o(n,a,c,i)):(r.diagnostics.push(h(`studio.binding/field-cardinality-incompatible`,`Binding port {port} and field {fieldPath} no longer have compatible cardinality.`,`error`,{fieldPath:c.join(`.`),port:n.id},{artifactId:r.blueprintId,fieldPath:c,nodeId:t.id})),o(n,a,c,i))}function a(t,n,r){let i=t.bindings[n];return i===void 0?{candidates:[],port:n,status:`invalid`}:(r.diagnostics.push(h(`studio.binding/port-missing`,`Binding port {port} is not declared by the locked block definition.`,`error`,{port:n},{artifactId:r.blueprintId,nodeId:t.id})),{binding:e(i),...i.source.kind===`entry-field`?{boundFieldPath:[...i.source.fieldPath]}:{},candidates:[],port:n,status:`invalid`})}function o(t,n,r,i){return{binding:e(n),boundFieldPath:[...r],candidates:i,multiple:t.multiple,port:t.id,required:t.required,status:`invalid`,valueType:t.valueType}}function s(t,n){return{cardinality:t.cardinality,...t.authoring?.control===void 0?{}:{control:t.authoring.control},fieldPath:[...n],...t.itemKind===void 0?{}:{itemKind:t.itemKind},kind:t.kind,label:e(t.label)}}function c(e){let t=[],n=(e,r)=>{let i=e.map((e,t)=>({field:e,index:t})).sort((e,t)=>(e.field.authoring?.order??2**53-1)-(t.field.authoring?.order??2**53-1)||e.index-t.index);for(let{field:e}of i){let i=[...r,e.id];t.push({field:e,fieldPath:i}),e.kind===`object`&&e.cardinality===`one`&&e.fields!==void 0&&n(e.fields,i)}};return n(e,[]),t}function l(e,t){return e.find(e=>_(e.fieldPath,t))}function u(e,t){return d(e)===t.multiple&&f(e,t.valueType)}function d(e){return e.cardinality===`many`}function f(e,t){let n=p(e);return n===t?!0:t===`text`?n===`string`||n===`enum`:t===`number`?n===`decimal`||n===`integer`:!1}function p(e){return e.kind===`collection`?e.itemKind??`object`:e.kind}function m(e,t){for(let n of e){t(n);for(let e of Object.keys(n.slots).sort(v))m(n.slots[e]??[],t)}}function h(e,t,n,r,i){return{code:e,...i===void 0?{}:{location:i},message:{defaultMessage:t,key:e},...r===void 0?{}:{parameters:r},severity:n}}function g(e,t){return`${e}@${t}`}function _(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function v(e,t){return e<t?-1:+(e>t)}
|
package/dist/canonical.js
CHANGED
|
@@ -1,100 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Serialize a bounded JSON value into the canonical cross-language form the
|
|
4
|
-
* portability contract defines for checksums: UTF-8 JSON, object members
|
|
5
|
-
* sorted by Unicode code unit, arrays in semantic order, minimal ECMA-404
|
|
6
|
-
* string escaping, and finite numbers only. Every conforming runtime MUST
|
|
7
|
-
* produce byte-identical output for the same value.
|
|
8
|
-
*/
|
|
9
|
-
export function canonicalStringify(value, options = {}) {
|
|
10
|
-
const maximumDepth = options.maximumDepth ?? DEFAULT_MAXIMUM_DEPTH;
|
|
11
|
-
if (!Number.isInteger(maximumDepth) || maximumDepth < 1) {
|
|
12
|
-
throw new RangeError('Canonical serialization depth must be a positive integer.');
|
|
13
|
-
}
|
|
14
|
-
return serialize(value, maximumDepth, 0);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* The canonical UTF-8 bytes of a value; checksums in Studio contracts are
|
|
18
|
-
* computed over exactly these bytes with the algorithm the referencing
|
|
19
|
-
* contract names (SRI-style sha256 unless stated otherwise). Encoding is
|
|
20
|
-
* implemented locally so the core stays free of DOM and platform globals.
|
|
21
|
-
*/
|
|
22
|
-
export function canonicalUtf8Bytes(value, options = {}) {
|
|
23
|
-
const text = canonicalStringify(value, options);
|
|
24
|
-
const bytes = [];
|
|
25
|
-
for (const character of text) {
|
|
26
|
-
const codePoint = character.codePointAt(0);
|
|
27
|
-
if (codePoint === undefined) {
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
if (codePoint <= 0x7f) {
|
|
31
|
-
bytes.push(codePoint);
|
|
32
|
-
}
|
|
33
|
-
else if (codePoint <= 0x7ff) {
|
|
34
|
-
bytes.push(0xc0 | (codePoint >> 6), 0x80 | (codePoint & 0x3f));
|
|
35
|
-
}
|
|
36
|
-
else if (codePoint <= 0xffff) {
|
|
37
|
-
bytes.push(0xe0 | (codePoint >> 12), 0x80 | ((codePoint >> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
bytes.push(0xf0 | (codePoint >> 18), 0x80 | ((codePoint >> 12) & 0x3f), 0x80 | ((codePoint >> 6) & 0x3f), 0x80 | (codePoint & 0x3f));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return Uint8Array.from(bytes);
|
|
44
|
-
}
|
|
45
|
-
function serialize(value, maximumDepth, depth) {
|
|
46
|
-
if (value === null) {
|
|
47
|
-
return 'null';
|
|
48
|
-
}
|
|
49
|
-
switch (typeof value) {
|
|
50
|
-
case 'boolean':
|
|
51
|
-
return value ? 'true' : 'false';
|
|
52
|
-
case 'number': {
|
|
53
|
-
if (!Number.isFinite(value)) {
|
|
54
|
-
throw new TypeError('Canonical JSON cannot represent a non-finite number.');
|
|
55
|
-
}
|
|
56
|
-
// JSON.stringify implements the deterministic ECMAScript number
|
|
57
|
-
// grammar; Object.is separates -0, which canonicalizes to 0.
|
|
58
|
-
return JSON.stringify(Object.is(value, -0) ? 0 : value);
|
|
59
|
-
}
|
|
60
|
-
case 'string':
|
|
61
|
-
return JSON.stringify(value);
|
|
62
|
-
case 'object':
|
|
63
|
-
break;
|
|
64
|
-
default:
|
|
65
|
-
throw new TypeError(`Canonical JSON cannot represent a ${typeof value} value.`);
|
|
66
|
-
}
|
|
67
|
-
if (depth >= maximumDepth) {
|
|
68
|
-
throw new RangeError(`Canonical serialization exceeds the depth limit of ${maximumDepth}.`);
|
|
69
|
-
}
|
|
70
|
-
if (Array.isArray(value)) {
|
|
71
|
-
const items = value.map((item) => {
|
|
72
|
-
if (item === undefined) {
|
|
73
|
-
throw new TypeError('Canonical JSON arrays cannot contain undefined entries.');
|
|
74
|
-
}
|
|
75
|
-
return serialize(item, maximumDepth, depth + 1);
|
|
76
|
-
});
|
|
77
|
-
return `[${items.join(',')}]`;
|
|
78
|
-
}
|
|
79
|
-
const prototype = Object.getPrototypeOf(value);
|
|
80
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
81
|
-
throw new TypeError('Canonical JSON only serializes plain objects and arrays.');
|
|
82
|
-
}
|
|
83
|
-
const members = Object.keys(value).sort(compareCodeUnits);
|
|
84
|
-
const parts = [];
|
|
85
|
-
for (const member of members) {
|
|
86
|
-
if (member === '__proto__' || member === 'prototype' || member === 'constructor') {
|
|
87
|
-
throw new TypeError(`Canonical JSON forbids the object member name ${member}.`);
|
|
88
|
-
}
|
|
89
|
-
const memberValue = value[member];
|
|
90
|
-
if (memberValue === undefined) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
parts.push(`${JSON.stringify(member)}:${serialize(memberValue, maximumDepth, depth + 1)}`);
|
|
94
|
-
}
|
|
95
|
-
return `{${parts.join(',')}}`;
|
|
96
|
-
}
|
|
97
|
-
function compareCodeUnits(left, right) {
|
|
98
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=canonical.js.map
|
|
1
|
+
export function canonicalStringify(e,t={}){let r=t.maximumDepth??64;if(!Number.isInteger(r)||r<1)throw RangeError(`Canonical serialization depth must be a positive integer.`);return n(e,r,0)}export function canonicalUtf8Bytes(t,n={}){let r=canonicalStringify(t,n),i=[];for(let e of r){let t=e.codePointAt(0);if(t===void 0)break;t<=127?i.push(t):t<=2047?i.push(192|t>>6,128|t&63):t<=65535?i.push(224|t>>12,128|t>>6&63,128|t&63):i.push(240|t>>18,128|t>>12&63,128|t>>6&63,128|t&63)}return Uint8Array.from(i)}function n(e,t,i){if(e===null)return`null`;switch(typeof e){case`boolean`:return e?`true`:`false`;case`number`:if(!Number.isFinite(e))throw TypeError(`Canonical JSON cannot represent a non-finite number.`);return JSON.stringify(Object.is(e,-0)?0:e);case`string`:return JSON.stringify(e);case`object`:break;default:throw TypeError(`Canonical JSON cannot represent a ${typeof e} value.`)}if(i>=t)throw RangeError(`Canonical serialization exceeds the depth limit of ${t}.`);if(Array.isArray(e))return`[${e.map(e=>{if(e===void 0)throw TypeError(`Canonical JSON arrays cannot contain undefined entries.`);return n(e,t,i+1)}).join(`,`)}]`;let a=Object.getPrototypeOf(e);if(a!==Object.prototype&&a!==null)throw TypeError(`Canonical JSON only serializes plain objects and arrays.`);let o=Object.keys(e).sort(r),s=[];for(let r of o){if(r===`__proto__`||r===`prototype`||r===`constructor`)throw TypeError(`Canonical JSON forbids the object member name ${r}.`);let a=e[r];a!==void 0&&s.push(`${JSON.stringify(r)}:${n(a,t,i+1)}`)}return`{${s.join(`,`)}}`}function r(e,t){return e<t?-1:+(e>t)}
|
package/dist/clone.js
CHANGED
package/dist/commands.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BlueprintBatchOperation, BlueprintCommand, BlueprintDocument, StableId } from '@kumwe/studio-protocol';
|
|
2
|
-
export type StudioCommandErrorCode = 'artifact-not-draft' | 'binding-not-found' | 'duplicate-field' | 'duplicate-node' | 'illegal-move' | 'invalid-batch' | 'invalid-id-map' | 'invalid-index' | 'invalid-order' | 'locale-mismatch' | 'mode-forbidden' | 'node-not-found' | 'parent-not-found' | 'property-not-found' | 'read-only-session' | 'stale-generation' | 'stale-state' | 'unsupported-command';
|
|
2
|
+
export type StudioCommandErrorCode = 'artifact-not-draft' | 'binding-not-found' | 'duplicate-field' | 'duplicate-node' | 'illegal-move' | 'invalid-batch' | 'invalid-id-map' | 'invalid-index' | 'invalid-order' | 'locale-mismatch' | 'mode-forbidden' | 'node-not-found' | 'parent-not-found' | 'permission-forbidden' | 'property-not-found' | 'read-only-session' | 'resource-limit' | 'stale-generation' | 'stale-state' | 'unsupported-command';
|
|
3
3
|
export declare class StudioCommandError extends Error {
|
|
4
4
|
readonly code: StudioCommandErrorCode;
|
|
5
5
|
constructor(code: StudioCommandErrorCode, message: string);
|
package/dist/commands.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EASjB,QAAQ,EAET,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,sBAAsB,GAC9B,oBAAoB,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,eAAe,GACf,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,oBAAoB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,aAAa,GACb,qBAAqB,CAAC;AAE1B,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAgB,IAAI,EAAE,sBAAsB,CAAC;gBAE1B,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAKjE;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,QAAQ,CAAC;CACd;AAUD,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,iBAAiB,CAqBnB;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GACvC,gBAAgB,CA4DlB;AA2BD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,iBAAiB,EAC3B,SAAS,EAAE,uBAAuB,GACjC,IAAI,CAgPN"}
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EASjB,QAAQ,EAET,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,sBAAsB,GAC9B,oBAAoB,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,gBAAgB,GAChB,eAAe,GACf,eAAe,GACf,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,kBAAkB,GAClB,sBAAsB,GACtB,oBAAoB,GACpB,mBAAmB,GACnB,gBAAgB,GAChB,kBAAkB,GAClB,aAAa,GACb,qBAAqB,CAAC;AAE1B,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAgB,IAAI,EAAE,sBAAsB,CAAC;gBAE1B,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAKjE;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,QAAQ,CAAC;CACd;AAUD,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,gBAAgB,GACxB,iBAAiB,CAqBnB;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GACvC,gBAAgB,CA4DlB;AA2BD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,iBAAiB,EAC3B,SAAS,EAAE,uBAAuB,GACjC,IAAI,CAgPN"}
|