@mapples/types 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +93 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +11 -0
- package/dist/api.js.map +1 -0
- package/dist/apiValidator.d.ts +27 -0
- package/dist/apiValidator.d.ts.map +1 -0
- package/dist/apiValidator.js +71 -0
- package/dist/apiValidator.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/navigation.d.ts +20 -0
- package/dist/navigation.d.ts.map +1 -1
- package/dist/variables.d.ts +51 -0
- package/dist/variables.d.ts.map +1 -0
- package/dist/variables.js +23 -0
- package/dist/variables.js.map +1 -0
- package/dist/variablesValidator.d.ts +31 -0
- package/dist/variablesValidator.d.ts.map +1 -0
- package/dist/variablesValidator.js +79 -0
- package/dist/variablesValidator.js.map +1 -0
- package/package.json +1 -1
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The project API document: a catalog of HTTP request
|
|
3
|
+
* definitions and environments, editable in the Creator and executed by the
|
|
4
|
+
* `mapples:request` action runtime.
|
|
5
|
+
*
|
|
6
|
+
* Persisted as one opaque row per project (mirroring the navigation
|
|
7
|
+
* document); validated client-side by `validateApiDocument`.
|
|
8
|
+
*/
|
|
9
|
+
/** Where a request parameter/body value comes from at execution time. */
|
|
10
|
+
export type ApiValueSource =
|
|
11
|
+
/** A literal string. */
|
|
12
|
+
{
|
|
13
|
+
kind: 'static';
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
/** A state binding resolved via `@mapples/state` (dot path). */
|
|
17
|
+
| {
|
|
18
|
+
kind: 'state';
|
|
19
|
+
dataProp: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A value from the triggering action's event payload (e.g. form values,
|
|
23
|
+
* input text). `path` narrows into the payload; omitted = whole payload.
|
|
24
|
+
*/
|
|
25
|
+
| {
|
|
26
|
+
kind: 'event';
|
|
27
|
+
path?: string;
|
|
28
|
+
};
|
|
29
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
30
|
+
export interface ApiEnvironment {
|
|
31
|
+
id: string;
|
|
32
|
+
/** e.g. `Development`, `Production`. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Base URL prepended to relative request paths. */
|
|
35
|
+
baseUrl: string;
|
|
36
|
+
/** Headers merged into every request of this environment. */
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
/** Interpolated into url/header templates as `{{variable}}`. */
|
|
39
|
+
variables?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
export interface ApiRequestAuth {
|
|
42
|
+
kind: 'none' | 'bearer' | 'header';
|
|
43
|
+
/** Header name for `kind: 'header'` (defaults to `Authorization`). */
|
|
44
|
+
header?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Name of a project API key (or exported-app env variable) holding the
|
|
47
|
+
* secret. Literal secrets are never stored in the document.
|
|
48
|
+
*/
|
|
49
|
+
secretRef?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ApiRequest {
|
|
52
|
+
id: string;
|
|
53
|
+
/** Unique per document; doubles as the default state key suffix. */
|
|
54
|
+
name: string;
|
|
55
|
+
method: HttpMethod;
|
|
56
|
+
/**
|
|
57
|
+
* Request path — `/users/{id}` (tokens bound via {@link params}) — or an
|
|
58
|
+
* absolute URL, which bypasses the environment's `baseUrl`.
|
|
59
|
+
*/
|
|
60
|
+
path: string;
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* Values for `{token}` path segments and (for non-token keys) the query
|
|
64
|
+
* string.
|
|
65
|
+
*/
|
|
66
|
+
params?: Record<string, ApiValueSource>;
|
|
67
|
+
/** JSON body template; leaf values may be {@link ApiValueSource}s. */
|
|
68
|
+
body?: {
|
|
69
|
+
kind: 'json';
|
|
70
|
+
template: unknown;
|
|
71
|
+
};
|
|
72
|
+
auth?: ApiRequestAuth;
|
|
73
|
+
/**
|
|
74
|
+
* A sample response powering design-time binding pickers and sample-mode
|
|
75
|
+
* execution in the editor preview.
|
|
76
|
+
*/
|
|
77
|
+
responseSample?: unknown;
|
|
78
|
+
/**
|
|
79
|
+
* State path the response lands under (`api.<name>` by default). Bindings
|
|
80
|
+
* read `<stateKey>.data`, `<stateKey>.loading`, `<stateKey>.error`.
|
|
81
|
+
*/
|
|
82
|
+
stateKey?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface ApiDocument {
|
|
85
|
+
version: 1;
|
|
86
|
+
/** The environment used by the editor preview. */
|
|
87
|
+
activeEnvironmentId?: string;
|
|
88
|
+
environments: Record<string, ApiEnvironment>;
|
|
89
|
+
requests: Record<string, ApiRequest>;
|
|
90
|
+
}
|
|
91
|
+
/** The default state key a request's responses are stored under. */
|
|
92
|
+
export declare const apiRequestStateKey: (request: ApiRequest) => string;
|
|
93
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yEAAyE;AACzE,MAAM,MAAM,cAAc;AACxB,wBAAwB;AACtB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AACnC,gEAAgE;GAC9D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AACrC;;;GAGG;GACD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,WAAW,c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,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACtC;AAED,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,GAAI,SAAS,UAAU,KAAG,MACd,CAAC"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The project API document: a catalog of HTTP request
|
|
3
|
+
* definitions and environments, editable in the Creator and executed by the
|
|
4
|
+
* `mapples:request` action runtime.
|
|
5
|
+
*
|
|
6
|
+
* Persisted as one opaque row per project (mirroring the navigation
|
|
7
|
+
* document); validated client-side by `validateApiDocument`.
|
|
8
|
+
*/
|
|
9
|
+
/** The default state key a request's responses are stored under. */
|
|
10
|
+
export const apiRequestStateKey = (request) => request.stateKey || `api.${request.name}`;
|
|
11
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA8EH,oEAAoE;AACpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAmB,EAAU,EAAE,CAChE,OAAO,CAAC,QAAQ,IAAI,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ApiDocument } from './api';
|
|
2
|
+
/**
|
|
3
|
+
* Codes for the invariants enforced by {@link validateApiDocument}.
|
|
4
|
+
*
|
|
5
|
+
* - `REQUEST_NAME_DUPLICATE` — two requests share a name.
|
|
6
|
+
* - `ENVIRONMENT_MISSING` — `activeEnvironmentId` has no matching environment.
|
|
7
|
+
* - `PATH_PARAM_UNBOUND` — a `{token}` in a request path has no params entry.
|
|
8
|
+
* - `BODY_ON_GET` — a GET request declares a body.
|
|
9
|
+
* - `STATE_KEY_COLLISION` — two requests resolve to the same state key.
|
|
10
|
+
* - `SECRET_REF_EMPTY` — auth requires a secret but `secretRef` is empty.
|
|
11
|
+
*/
|
|
12
|
+
export type ApiValidationCode = 'REQUEST_NAME_DUPLICATE' | 'ENVIRONMENT_MISSING' | 'PATH_PARAM_UNBOUND' | 'BODY_ON_GET' | 'STATE_KEY_COLLISION' | 'SECRET_REF_EMPTY';
|
|
13
|
+
export interface ApiValidationError {
|
|
14
|
+
code: ApiValidationCode;
|
|
15
|
+
message: string;
|
|
16
|
+
requestId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ApiValidationResult {
|
|
19
|
+
valid: boolean;
|
|
20
|
+
errors: ApiValidationError[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Validate the structural invariants of an {@link ApiDocument}. Collects
|
|
24
|
+
* every violation (same shape as `validateNavigationDocument`).
|
|
25
|
+
*/
|
|
26
|
+
export declare const validateApiDocument: (document: ApiDocument) => ApiValidationResult;
|
|
27
|
+
//# sourceMappingURL=apiValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiValidator.d.ts","sourceRoot":"","sources":["../src/apiValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,MAAM,OAAO,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GACzB,wBAAwB,GACxB,qBAAqB,GACrB,oBAAoB,GACpB,aAAa,GACb,qBAAqB,GACrB,kBAAkB,CAAC;AAEvB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAID;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,WAAW,KACpB,mBAyEF,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { apiRequestStateKey } from './api';
|
|
2
|
+
const PATH_TOKEN_PATTERN = /\{([^}]+)\}/g;
|
|
3
|
+
/**
|
|
4
|
+
* Validate the structural invariants of an {@link ApiDocument}. Collects
|
|
5
|
+
* every violation (same shape as `validateNavigationDocument`).
|
|
6
|
+
*/
|
|
7
|
+
export const validateApiDocument = (document) => {
|
|
8
|
+
const errors = [];
|
|
9
|
+
if (document.activeEnvironmentId &&
|
|
10
|
+
!document.environments[document.activeEnvironmentId]) {
|
|
11
|
+
errors.push({
|
|
12
|
+
code: 'ENVIRONMENT_MISSING',
|
|
13
|
+
message: `activeEnvironmentId "${document.activeEnvironmentId}" does not resolve to an environment`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const namesSeen = new Map();
|
|
17
|
+
const stateKeysSeen = new Map();
|
|
18
|
+
for (const request of Object.values(document.requests)) {
|
|
19
|
+
const existingName = namesSeen.get(request.name);
|
|
20
|
+
if (existingName) {
|
|
21
|
+
errors.push({
|
|
22
|
+
code: 'REQUEST_NAME_DUPLICATE',
|
|
23
|
+
message: `Request name "${request.name}" is used by more than one request`,
|
|
24
|
+
requestId: request.id,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
namesSeen.set(request.name, request.id);
|
|
29
|
+
}
|
|
30
|
+
const stateKey = apiRequestStateKey(request);
|
|
31
|
+
const existingStateKey = stateKeysSeen.get(stateKey);
|
|
32
|
+
if (existingStateKey) {
|
|
33
|
+
errors.push({
|
|
34
|
+
code: 'STATE_KEY_COLLISION',
|
|
35
|
+
message: `State key "${stateKey}" is produced by more than one request`,
|
|
36
|
+
requestId: request.id,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
stateKeysSeen.set(stateKey, request.id);
|
|
41
|
+
}
|
|
42
|
+
for (const match of request.path.matchAll(PATH_TOKEN_PATTERN)) {
|
|
43
|
+
const token = match[1];
|
|
44
|
+
if (!request.params?.[token]) {
|
|
45
|
+
errors.push({
|
|
46
|
+
code: 'PATH_PARAM_UNBOUND',
|
|
47
|
+
message: `Path token "{${token}}" in "${request.path}" has no params entry`,
|
|
48
|
+
requestId: request.id,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (request.method === 'GET' && request.body) {
|
|
53
|
+
errors.push({
|
|
54
|
+
code: 'BODY_ON_GET',
|
|
55
|
+
message: `GET request "${request.name}" must not declare a body`,
|
|
56
|
+
requestId: request.id,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (request.auth &&
|
|
60
|
+
request.auth.kind !== 'none' &&
|
|
61
|
+
!request.auth.secretRef) {
|
|
62
|
+
errors.push({
|
|
63
|
+
code: 'SECRET_REF_EMPTY',
|
|
64
|
+
message: `Request "${request.name}" auth requires a secretRef`,
|
|
65
|
+
requestId: request.id,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { valid: errors.length === 0, errors };
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=apiValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiValidator.js","sourceRoot":"","sources":["../src/apiValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,kBAAkB,EAAE,MAAM,OAAO,CAAC;AA+BxD,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAE1C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,QAAqB,EACA,EAAE;IACvB,MAAM,MAAM,GAAyB,EAAE,CAAC;IAExC,IACE,QAAQ,CAAC,mBAAmB;QAC5B,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EACpD,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,wBAAwB,QAAQ,CAAC,mBAAmB,sCAAsC;SACpG,CAAC,CAAC;IACL,CAAC;IAED,MAAM,SAAS,GAAG,I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,CAAC;oBACV,IAAI,EAAE,oBAAoB;oBAC1B,OAAO,EAAE,gBAAgB,KAAK,UAAU,OAAO,CAAC,IAAI,uBAAuB;oBAC3E,SAAS,EAAE,OAAO,CAAC,EAAE;iBACtB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,gBAAgB,OAAO,CAAC,IAAI,2BAA2B;gBAChE,SAAS,EAAE,OAAO,CAAC,EAAE;aACtB,CAAC,CAAC;QACL,CAAC;QAED,IACE,OAAO,CAAC,IAAI;YACZ,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM;YAC5B,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EACvB,CAAC;YACD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,YAAY,OAAO,CAAC,IAAI,6BAA6B;gBAC9D,SAAS,EAAE,OAAO,CAAC,EAAE;aACtB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export * from './action';
|
|
|
4
4
|
export * from './mapplet';
|
|
5
5
|
export * from './navigation';
|
|
6
6
|
export * from './navigationValidator';
|
|
7
|
+
export * from './api';
|
|
8
|
+
export * from './apiValidator';
|
|
9
|
+
export * from './variables';
|
|
10
|
+
export * from './variablesValidator';
|
|
7
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,8 @@ export * from './action';
|
|
|
4
4
|
export * from './mapplet';
|
|
5
5
|
export * from './navigation';
|
|
6
6
|
export * from './navigationValidator';
|
|
7
|
+
export * from './api';
|
|
8
|
+
export * from './apiValidator';
|
|
9
|
+
export * from './variables';
|
|
10
|
+
export * from './variablesValidator';
|
|
7
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC"}
|
package/dist/navigation.d.ts
CHANGED
|
@@ -33,6 +33,24 @@ export interface NavigationDocument {
|
|
|
33
33
|
/** Flat map of every navigator in the document, keyed by {@link NavigatorNode.id}. */
|
|
34
34
|
navigators: Record<string, NavigatorNode>;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Editor-only world-space rectangle of a navigator's section on the Creator
|
|
38
|
+
* canvas. The runtime ignores it entirely — it exists so the canvas can
|
|
39
|
+
* persist where the section is drawn, the same way pages persist their frame
|
|
40
|
+
* placement in `_canvasProps`.
|
|
41
|
+
*
|
|
42
|
+
* @interface NavigatorCanvasRect
|
|
43
|
+
*/
|
|
44
|
+
export interface NavigatorCanvasRect {
|
|
45
|
+
/** World-space left edge. */
|
|
46
|
+
x: number;
|
|
47
|
+
/** World-space top edge. */
|
|
48
|
+
y: number;
|
|
49
|
+
/** Width in world units. */
|
|
50
|
+
width: number;
|
|
51
|
+
/** Height in world units. */
|
|
52
|
+
height: number;
|
|
53
|
+
}
|
|
36
54
|
/**
|
|
37
55
|
* A single navigator (stack, tabs, or drawer) and its ordered child routes.
|
|
38
56
|
*
|
|
@@ -51,6 +69,8 @@ export interface NavigatorNode {
|
|
|
51
69
|
routes: RouteNode[];
|
|
52
70
|
/** Presentation/styling options scoped to this navigator. */
|
|
53
71
|
options?: NavigatorOptions;
|
|
72
|
+
/** Editor-only canvas placement. Ignored by the runtime. */
|
|
73
|
+
canvas?: NavigatorCanvasRect;
|
|
54
74
|
}
|
|
55
75
|
/**
|
|
56
76
|
* A single route within a navigator — either a page leaf or a nested navigator.
|
package/dist/navigation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;GAMG;AACH,M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;;;;;;GAOG;AACH,MAAM,WAAW,aAAc,SAAQ,OAAO,CAAC,aAAa,CAAC;IAC3D,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The project variables document: typed, writable app/page
|
|
3
|
+
* state declarations, editable in the Creator and seeded into the writable
|
|
4
|
+
* state store (`@mapples/state`) at runtime.
|
|
5
|
+
*
|
|
6
|
+
* Persisted as one opaque row per project (mirroring the api document);
|
|
7
|
+
* validated client-side by `validateVariablesDocument`. Values are exposed
|
|
8
|
+
* to bindings under the `vars.` namespace regardless of scope — scope
|
|
9
|
+
* governs lifecycle (when a value resets), not addressing, so promoting a
|
|
10
|
+
* page variable to app scope never breaks a binding.
|
|
11
|
+
*/
|
|
12
|
+
/** Runtime type of a declared variable's value. */
|
|
13
|
+
export type VariableValueType = 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
14
|
+
/** Where a variable lives and when it resets. */
|
|
15
|
+
export type VariableScope =
|
|
16
|
+
/** Lives for the app session (optionally persisted). */
|
|
17
|
+
{
|
|
18
|
+
kind: 'app';
|
|
19
|
+
}
|
|
20
|
+
/** Reset to `initialValue` whenever the page unmounts. */
|
|
21
|
+
| {
|
|
22
|
+
kind: 'page';
|
|
23
|
+
pageUuid: string;
|
|
24
|
+
};
|
|
25
|
+
/** A variable's `name` must match this to compose into binding dot-paths. */
|
|
26
|
+
export declare const VARIABLE_NAME_PATTERN: RegExp;
|
|
27
|
+
/** The namespace prefix variables resolve under in bindings/conditions. */
|
|
28
|
+
export declare const VARIABLES_NAMESPACE = "vars";
|
|
29
|
+
export interface VariableDefinition {
|
|
30
|
+
/** Stable uuid — survives renames. */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Binding segment under `vars.`; must match {@link VARIABLE_NAME_PATTERN}. */
|
|
33
|
+
name: string;
|
|
34
|
+
type: VariableValueType;
|
|
35
|
+
scope: VariableScope;
|
|
36
|
+
/** Seed value; must conform to `type` (validator-enforced). */
|
|
37
|
+
initialValue: string | number | boolean | object | unknown[] | null;
|
|
38
|
+
description?: string;
|
|
39
|
+
/** App-scope only: persist across sessions via the host storage adapter. */
|
|
40
|
+
persist?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface VariablesDocument {
|
|
43
|
+
version: 1;
|
|
44
|
+
/** Keyed by {@link VariableDefinition.id}. */
|
|
45
|
+
variables: Record<string, VariableDefinition>;
|
|
46
|
+
}
|
|
47
|
+
/** An empty document, used before a project has saved any variables. */
|
|
48
|
+
export declare const emptyVariablesDocument: () => VariablesDocument;
|
|
49
|
+
/** The state path a variable's value is bound at, e.g. `vars.count`. */
|
|
50
|
+
export declare const variableStatePath: (variable: VariableDefinition) => string;
|
|
51
|
+
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,mDAAmD;AACnD,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,OAAO,CAAC;AAEZ,iDAAiD;AACjD,MAAM,MAAM,aAAa;AACvB,wDAAwD;AACtD;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE;AACjB,0DAA0D;GACxD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,QAA6B,CAAC;AAEhE,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,aAAa,CAAC;IACrB,+DAA+D;IAC/D,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC;IACpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,CAAC,CAAC;IACX,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAC/C;AAED,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,QAAO,iBAGxC,CAAC;AAEH,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,GAAI,UAAU,kBAAkB,KAAG,MACtB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The project variables document: typed, writable app/page
|
|
3
|
+
* state declarations, editable in the Creator and seeded into the writable
|
|
4
|
+
* state store (`@mapples/state`) at runtime.
|
|
5
|
+
*
|
|
6
|
+
* Persisted as one opaque row per project (mirroring the api document);
|
|
7
|
+
* validated client-side by `validateVariablesDocument`. Values are exposed
|
|
8
|
+
* to bindings under the `vars.` namespace regardless of scope — scope
|
|
9
|
+
* governs lifecycle (when a value resets), not addressing, so promoting a
|
|
10
|
+
* page variable to app scope never breaks a binding.
|
|
11
|
+
*/
|
|
12
|
+
/** A variable's `name` must match this to compose into binding dot-paths. */
|
|
13
|
+
export const VARIABLE_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
14
|
+
/** The namespace prefix variables resolve under in bindings/conditions. */
|
|
15
|
+
export const VARIABLES_NAMESPACE = 'vars';
|
|
16
|
+
/** An empty document, used before a project has saved any variables. */
|
|
17
|
+
export const emptyVariablesDocument = () => ({
|
|
18
|
+
version: 1,
|
|
19
|
+
variables: {},
|
|
20
|
+
});
|
|
21
|
+
/** The state path a variable's value is bound at, e.g. `vars.count`. */
|
|
22
|
+
export const variableStatePath = (variable) => `${VARIABLES_NAMESPACE}.${variable.name}`;
|
|
23
|
+
//# sourceMappingURL=variables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAiBH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAEhE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAsB1C,wEAAwE;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAsB,EAAE,CAAC,CAAC;IAC9D,OAAO,EAAE,CAAC;IACV,SAAS,EAAE,EAAE;CACd,CAAC,CAAC;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,QAA4B,EAAU,EAAE,CACxE,GAAG,mBAAmB,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { VariablesDocument } from './variables';
|
|
2
|
+
/**
|
|
3
|
+
* Codes for the invariants enforced by {@link validateVariablesDocument}.
|
|
4
|
+
*
|
|
5
|
+
* - `NAME_INVALID` — a name does not match {@link VARIABLE_NAME_PATTERN}.
|
|
6
|
+
* - `NAME_DUPLICATE` — an app-scoped name is reused anywhere, or a
|
|
7
|
+
* page-scoped name is reused within the same page.
|
|
8
|
+
* - `INITIAL_VALUE_MISMATCH` — `initialValue` does not conform to `type`.
|
|
9
|
+
* - `PERSIST_ON_PAGE_SCOPE` — `persist` is set on a page-scoped variable.
|
|
10
|
+
*/
|
|
11
|
+
export type VariablesValidationCode = 'NAME_INVALID' | 'NAME_DUPLICATE' | 'INITIAL_VALUE_MISMATCH' | 'PERSIST_ON_PAGE_SCOPE';
|
|
12
|
+
export interface VariablesValidationError {
|
|
13
|
+
code: VariablesValidationCode;
|
|
14
|
+
message: string;
|
|
15
|
+
variableId?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface VariablesValidationResult {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
errors: VariablesValidationError[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate the structural invariants of a {@link VariablesDocument}. Collects
|
|
23
|
+
* every violation (same shape as `validateApiDocument`).
|
|
24
|
+
*
|
|
25
|
+
* Name uniqueness: app-scoped names are unique project-wide (across both
|
|
26
|
+
* scopes — a page variable may not shadow an app variable, since both
|
|
27
|
+
* resolve under the flat `vars.` namespace); page-scoped names are unique
|
|
28
|
+
* within their page.
|
|
29
|
+
*/
|
|
30
|
+
export declare const validateVariablesDocument: (document: VariablesDocument) => VariablesValidationResult;
|
|
31
|
+
//# sourceMappingURL=variablesValidator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variablesValidator.d.ts","sourceRoot":"","sources":["../src/variablesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAErB;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAC/B,cAAc,GACd,gBAAgB,GAChB,wBAAwB,GACxB,uBAAuB,CAAC;AAE5B,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,wBAAwB,EAAE,CAAC;CACpC;AAmBD;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAU,iBAAiB,KAC1B,yBAyDF,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { VARIABLE_NAME_PATTERN, } from './variables';
|
|
2
|
+
const conformsToType = (variable) => {
|
|
3
|
+
const { type, initialValue } = variable;
|
|
4
|
+
if (initialValue === null)
|
|
5
|
+
return true;
|
|
6
|
+
switch (type) {
|
|
7
|
+
case 'string':
|
|
8
|
+
return typeof initialValue === 'string';
|
|
9
|
+
case 'number':
|
|
10
|
+
return typeof initialValue === 'number' && !Number.isNaN(initialValue);
|
|
11
|
+
case 'boolean':
|
|
12
|
+
return typeof initialValue === 'boolean';
|
|
13
|
+
case 'array':
|
|
14
|
+
return Array.isArray(initialValue);
|
|
15
|
+
case 'object':
|
|
16
|
+
return typeof initialValue === 'object' && !Array.isArray(initialValue);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validate the structural invariants of a {@link VariablesDocument}. Collects
|
|
21
|
+
* every violation (same shape as `validateApiDocument`).
|
|
22
|
+
*
|
|
23
|
+
* Name uniqueness: app-scoped names are unique project-wide (across both
|
|
24
|
+
* scopes — a page variable may not shadow an app variable, since both
|
|
25
|
+
* resolve under the flat `vars.` namespace); page-scoped names are unique
|
|
26
|
+
* within their page.
|
|
27
|
+
*/
|
|
28
|
+
export const validateVariablesDocument = (document) => {
|
|
29
|
+
const errors = [];
|
|
30
|
+
const variables = Object.values(document.variables);
|
|
31
|
+
const appNames = new Set();
|
|
32
|
+
for (const variable of variables) {
|
|
33
|
+
if (variable.scope.kind === 'app')
|
|
34
|
+
appNames.add(variable.name);
|
|
35
|
+
}
|
|
36
|
+
/** `<name>` for app clashes, `<pageUuid>/<name>` for page clashes. */
|
|
37
|
+
const namesSeen = new Set();
|
|
38
|
+
for (const variable of variables) {
|
|
39
|
+
if (!VARIABLE_NAME_PATTERN.test(variable.name)) {
|
|
40
|
+
errors.push({
|
|
41
|
+
code: 'NAME_INVALID',
|
|
42
|
+
message: `Variable name "${variable.name}" must match ${VARIABLE_NAME_PATTERN}`,
|
|
43
|
+
variableId: variable.id,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const scopedKey = variable.scope.kind === 'page'
|
|
47
|
+
? `${variable.scope.pageUuid}/${variable.name}`
|
|
48
|
+
: variable.name;
|
|
49
|
+
const shadowsApp = variable.scope.kind === 'page' && appNames.has(variable.name);
|
|
50
|
+
if (namesSeen.has(scopedKey) || shadowsApp) {
|
|
51
|
+
errors.push({
|
|
52
|
+
code: 'NAME_DUPLICATE',
|
|
53
|
+
message: shadowsApp
|
|
54
|
+
? `Page variable "${variable.name}" collides with an app variable of the same name`
|
|
55
|
+
: `Variable name "${variable.name}" is used more than once in its scope`,
|
|
56
|
+
variableId: variable.id,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
namesSeen.add(scopedKey);
|
|
61
|
+
}
|
|
62
|
+
if (!conformsToType(variable)) {
|
|
63
|
+
errors.push({
|
|
64
|
+
code: 'INITIAL_VALUE_MISMATCH',
|
|
65
|
+
message: `Variable "${variable.name}" initialValue does not conform to type "${variable.type}"`,
|
|
66
|
+
variableId: variable.id,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (variable.persist && variable.scope.kind === 'page') {
|
|
70
|
+
errors.push({
|
|
71
|
+
code: 'PERSIST_ON_PAGE_SCOPE',
|
|
72
|
+
message: `Variable "${variable.name}" is page-scoped and cannot be persisted`,
|
|
73
|
+
variableId: variable.id,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { valid: errors.length === 0, errors };
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=variablesValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variablesValidator.js","sourceRoot":"","sources":["../src/variablesValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,GAGtB,MAAM,aAAa,CAAC;AA4BrB,MAAM,cAAc,GAAG,CAAC,Q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