@gramlot/gramlot 0.2.11 → 0.2.12
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/gramlot.js +146 -137
- package/dist/gramlot.min.js +42 -0
- package/package.json +5 -5
- package/src/binding/inline.js +1 -1
- package/src/bootstrap.d.ts +2 -2
- package/src/bootstrap.js +1 -1
- package/src/gramlot.d.ts +2 -2
- package/src/handlers/rpc-handler.d.ts +2 -2
- package/src/handlers/rpc-handler.js +2 -2
- package/src/handlers/source-handler.d.ts +1 -1
- package/src/handlers/source-handler.js +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/server/assets.d.ts +12 -0
- package/src/server/assets.js +30 -0
- package/src/server/conformance.d.ts +9 -0
- package/src/server/conformance.js +138 -0
- package/src/{adapters/file-host.d.ts → server/gramlot-file-server.d.ts} +15 -7
- package/src/{adapters/file-host.js → server/gramlot-file-server.js} +26 -13
- package/src/{adapters/host.d.ts → server/gramlot-server.d.ts} +24 -13
- package/src/{adapters/host.js → server/gramlot-server.js} +18 -13
- package/src/server/index.d.ts +16 -0
- package/src/server/index.js +15 -0
- package/src/{adapters → server}/page.d.ts +12 -12
- package/src/server/page.js +47 -0
- package/src/{adapters → server}/resources.d.ts +3 -1
- package/src/{adapters → server}/resources.js +2 -2
- package/src/transport.d.ts +2 -2
- package/src/transport.js +1 -1
- package/src/adapters/index.d.ts +0 -13
- package/src/adapters/index.js +0 -13
- package/src/adapters/page.js +0 -43
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server entry point of Gramlot: the server-side `Page` and `GramlotServer` classes, the file-based
|
|
3
|
+
* reference server and the resource name helpers. It is not part of the browser entry point.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export {Page} from './page.js';
|
|
8
|
+
export {GramlotServer, PageExpired, PageNotFound, SourceNotFound, ServerCapacity} from './gramlot-server.js';
|
|
9
|
+
export type {GramlotServerOptions, OpenedPage, RegisteredPage} from './gramlot-server.js';
|
|
10
|
+
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
11
|
+
export {GramlotFileServer} from './gramlot-file-server.js';
|
|
12
|
+
export type {GramlotFileServerOptions} from './gramlot-file-server.js';
|
|
13
|
+
export {gramlotDev, runtimeAsset} from './assets.js';
|
|
14
|
+
export {checkProtocol} from './conformance.js';
|
|
15
|
+
export {InvalidResourceName, parseRequires} from './resources.js';
|
|
16
|
+
export type {Resources} from './resources.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* @ts-self-types="./index.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* The server entry point of Gramlot: the server-side `Page` and `GramlotServer` classes, the file-based
|
|
4
|
+
* reference server and the resource name helpers. It is not part of the browser entry point.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
// Server entry point: deliberately not re-exported by the browser entry point.
|
|
9
|
+
export {Page} from './page.js';
|
|
10
|
+
export {GramlotServer, PageExpired, PageNotFound, SourceNotFound, ServerCapacity} from './gramlot-server.js';
|
|
11
|
+
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
12
|
+
export {GramlotFileServer} from './gramlot-file-server.js';
|
|
13
|
+
export {gramlotDev, runtimeAsset} from './assets.js';
|
|
14
|
+
export {checkProtocol} from './conformance.js';
|
|
15
|
+
export {InvalidResourceName, parseRequires} from './resources.js';
|
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Server-side page base class and the `registerSource` marker.
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import type {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Explicit registration of a remote Source method, equivalent to the Python `@source`.
|
|
10
|
-
* A Source method populates its `root` argument and returns nothing.
|
|
11
|
-
*
|
|
12
|
-
* Source methods (`@source`, `source(...)`, `remoteSource`) are not yet part of the page-writing API:
|
|
13
|
-
* they arrive together with the `remote` grammar attribute and `@endpoint`.
|
|
14
|
-
*/
|
|
15
|
-
export function source<T extends Function>(method: T): T;
|
|
16
|
-
|
|
17
8
|
/** The registered Source method `name` of `page`, or null. */
|
|
18
9
|
export function sourceMethod(page: Page, name: string): Function | null;
|
|
19
10
|
|
|
20
|
-
/**
|
|
11
|
+
/** Server-side page base; unrelated to browser view components. */
|
|
21
12
|
export class Page {
|
|
22
13
|
/** The title of the page document. */
|
|
23
14
|
static title: string;
|
|
@@ -29,8 +20,17 @@ export class Page {
|
|
|
29
20
|
static js_requires: string;
|
|
30
21
|
/** The builder class that authors the Source of the page. */
|
|
31
22
|
static sourceBuilder: typeof GramlotBuilder;
|
|
32
|
-
/** The id of the page, set by the
|
|
23
|
+
/** The id of the page, set by the server. */
|
|
33
24
|
pageId?: string;
|
|
34
25
|
/** Populate the `main` Source in `root`; subclasses must implement it. */
|
|
35
26
|
main(root: unknown): void | Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Mark the own method `methodName` of this page class as a remote Source method,
|
|
29
|
+
* equivalent to the Python `@source`; call it after the class. A Source method populates
|
|
30
|
+
* its `root` argument and returns nothing.
|
|
31
|
+
*
|
|
32
|
+
* Source methods (`@source`, `registerSource`, `remoteSource`) are not yet part of the page-writing API:
|
|
33
|
+
* they arrive together with the `remote` grammar attribute and `@endpoint`.
|
|
34
|
+
*/
|
|
35
|
+
static registerSource(methodName: string): void;
|
|
36
36
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* @ts-self-types="./page.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* Server-side page base class and the `registerSource` marker.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
8
|
+
|
|
9
|
+
const SOURCE_METHOD = Symbol('gramlot.source');
|
|
10
|
+
|
|
11
|
+
export function sourceMethod(page, name) {
|
|
12
|
+
if (typeof name !== 'string' || !/^[A-Za-z][\w]*$/.test(name)) return null;
|
|
13
|
+
for (let proto = Object.getPrototypeOf(page); proto; proto = Object.getPrototypeOf(proto)) {
|
|
14
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
15
|
+
if (descriptor) return descriptor.value?.[SOURCE_METHOD] ? descriptor.value : null;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Server-side page base; unrelated to browser view components. */
|
|
21
|
+
export class Page {
|
|
22
|
+
static title = 'Gramlot';
|
|
23
|
+
static css = [];
|
|
24
|
+
static css_requires = '';
|
|
25
|
+
static js_requires = '';
|
|
26
|
+
static sourceBuilder = GramlotBuilder;
|
|
27
|
+
|
|
28
|
+
main(root) {
|
|
29
|
+
throw new Error('Page.main(root) must be implemented');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Mark the own method `methodName` of this page class as a remote Source method,
|
|
34
|
+
* equivalent to Python `@source`; call it after the class.
|
|
35
|
+
*
|
|
36
|
+
* Source methods (`@source`, `registerSource`, `remoteSource`) are not yet part of the page-writing API:
|
|
37
|
+
* they arrive together with the `remote` grammar attribute and `@endpoint`.
|
|
38
|
+
*/
|
|
39
|
+
static registerSource(methodName) {
|
|
40
|
+
const method = Object.getOwnPropertyDescriptor(this.prototype, methodName)?.value;
|
|
41
|
+
if (typeof method !== 'function') {
|
|
42
|
+
throw new TypeError(`registerSource requires an own method of ${this.name}: ${String(methodName)}`);
|
|
43
|
+
}
|
|
44
|
+
if (method[SOURCE_METHOD]) throw new TypeError(`Source method already registered: ${methodName}`);
|
|
45
|
+
method[SOURCE_METHOD] = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -11,7 +11,9 @@ export const SEGMENT: RegExp;
|
|
|
11
11
|
export const SPACES: string;
|
|
12
12
|
|
|
13
13
|
/** A page declares its resources in an invalid way. */
|
|
14
|
-
export class InvalidResourceName extends Error {
|
|
14
|
+
export class InvalidResourceName extends Error {
|
|
15
|
+
name: 'InvalidResourceName';
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
/** Parse `css_requires` or `js_requires`: comma-separated resource names, without duplicates. */
|
|
17
19
|
export function parseRequires(text: string): string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* @ts-self-types="./resources.d.ts" */
|
|
2
2
|
/** Resource names and bootstrap load order; no file lookup and no HTTP engine.
|
|
3
3
|
* The Python counterpart is src/gramlot/server/resources.py; both apply the same
|
|
4
|
-
* rules. css_requires/js_requires names are interpreted by a
|
|
4
|
+
* rules. css_requires/js_requires names are interpreted by a GramlotServer with a resource
|
|
5
5
|
* system, not by the core.
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
@@ -15,7 +15,7 @@ export const SPACES = '\u0009\u000a\u000b\u000c\u000d \u0085 ' +
|
|
|
15
15
|
'
';
|
|
16
16
|
|
|
17
17
|
/** A page declares its resources in an invalid way. */
|
|
18
|
-
export class InvalidResourceName extends Error {}
|
|
18
|
+
export class InvalidResourceName extends Error { name = 'InvalidResourceName'; }
|
|
19
19
|
|
|
20
20
|
function checkName(name) {
|
|
21
21
|
if (name.includes(':')) throw new InvalidResourceName(`Resource name "${name}": 'name:media' is not supported`);
|
package/src/transport.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type {BeaconNavigator} from './dom.d.ts';
|
|
|
8
8
|
/** The fetch function used by the transport. */
|
|
9
9
|
export type Fetcher = (input: string, init?: RequestInit) => Promise<Response>;
|
|
10
10
|
|
|
11
|
-
/** The page-to-
|
|
11
|
+
/** The page-to-server transport: loads `main` and remote Sources and closes the server page. */
|
|
12
12
|
export class MainTransport {
|
|
13
13
|
/** The URL of the `main` endpoint. */
|
|
14
14
|
url: string;
|
|
@@ -29,6 +29,6 @@ export class MainTransport {
|
|
|
29
29
|
source(pageId: string, method: string, params: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
|
|
30
30
|
/** POST a JSON payload to `url`; resolves with the response text, rejects on a non-2xx status. */
|
|
31
31
|
request(operation: string, url: string, payload: unknown, signal?: AbortSignal): Promise<string>;
|
|
32
|
-
/** Ask the
|
|
32
|
+
/** Ask the server to close the page, with a beacon or a best-effort fetch; delivery failure is ignored. */
|
|
33
33
|
close(pageId: string, options?: {beacon?: boolean}): void;
|
|
34
34
|
}
|
package/src/transport.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
/** The page-to-
|
|
7
|
+
/** The page-to-server transport: loads `main` and remote Sources and closes the server page. */
|
|
8
8
|
export class MainTransport {
|
|
9
9
|
constructor(url, fetcher = globalThis.fetch?.bind(globalThis), sourceUrl = '/gramlot/source',
|
|
10
10
|
closeUrl = '/gramlot/close', navigator = globalThis.navigator) {
|
package/src/adapters/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The server entry point of Gramlot: the host-side `Page` and `Host` classes, the file-based
|
|
3
|
-
* reference host and the resource name helpers. It is not part of the browser entry point.
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
export {Page, source} from './page.js';
|
|
8
|
-
export {Host, PageExpired, PageNotFound, SourceNotFound, HostCapacity} from './host.js';
|
|
9
|
-
export type {HostOptions, OpenedPage, RegisteredPage} from './host.js';
|
|
10
|
-
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
11
|
-
export {FileHost} from './file-host.js';
|
|
12
|
-
export {InvalidResourceName, parseRequires} from './resources.js';
|
|
13
|
-
export type {Resources} from './resources.js';
|
package/src/adapters/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./index.d.ts" */
|
|
2
|
-
/**
|
|
3
|
-
* The server entry point of Gramlot: the host-side `Page` and `Host` classes, the file-based
|
|
4
|
-
* reference host and the resource name helpers. It is not part of the browser entry point.
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
// Server entry point: deliberately not re-exported by the browser entry point.
|
|
9
|
-
export {Page, source} from './page.js';
|
|
10
|
-
export {Host, PageExpired, PageNotFound, SourceNotFound, HostCapacity} from './host.js';
|
|
11
|
-
export {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
12
|
-
export {FileHost} from './file-host.js';
|
|
13
|
-
export {InvalidResourceName, parseRequires} from './resources.js';
|
package/src/adapters/page.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./page.d.ts" */
|
|
2
|
-
/**
|
|
3
|
-
* Host-side page base class and the `source` registration.
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
import {GramlotBuilder} from '../builder/gramlot-builder.js';
|
|
8
|
-
|
|
9
|
-
const SOURCE_METHOD = Symbol('gramlot.source');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Explicit method registration, equivalent to Python @source without syntax transforms.
|
|
13
|
-
*
|
|
14
|
-
* Source methods (`@source`, `source(...)`, `remoteSource`) are not yet part of the page-writing API:
|
|
15
|
-
* they arrive together with the `remote` grammar attribute and `@endpoint`.
|
|
16
|
-
*/
|
|
17
|
-
export function source(method) {
|
|
18
|
-
if (typeof method !== 'function') throw new TypeError('source requires a method');
|
|
19
|
-
method[SOURCE_METHOD] = true;
|
|
20
|
-
return method;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function sourceMethod(page, name) {
|
|
24
|
-
if (typeof name !== 'string' || !/^[A-Za-z][\w]*$/.test(name)) return null;
|
|
25
|
-
for (let proto = Object.getPrototypeOf(page); proto; proto = Object.getPrototypeOf(proto)) {
|
|
26
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
|
27
|
-
if (descriptor) return descriptor.value?.[SOURCE_METHOD] ? descriptor.value : null;
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Host-side page base; unrelated to browser view components. */
|
|
33
|
-
export class Page {
|
|
34
|
-
static title = 'Gramlot';
|
|
35
|
-
static css = [];
|
|
36
|
-
static css_requires = '';
|
|
37
|
-
static js_requires = '';
|
|
38
|
-
static sourceBuilder = GramlotBuilder;
|
|
39
|
-
|
|
40
|
-
main(root) {
|
|
41
|
-
throw new Error('Page.main(root) must be implemented');
|
|
42
|
-
}
|
|
43
|
-
}
|