@monosmith/plugin-sdk 0.0.0-stage → 0.1.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.
Files changed (154) hide show
  1. package/README.md +89 -2
  2. package/build-dir/build-dir.algorithm.d.ts +16 -0
  3. package/build-dir/build-dir.algorithm.js +26 -0
  4. package/build-dir/index.d.ts +1 -0
  5. package/build-dir/index.js +1 -0
  6. package/ci/ci-contribution.algorithm.d.ts +28 -0
  7. package/ci/ci-contribution.algorithm.js +19 -0
  8. package/ci/index.d.ts +2 -0
  9. package/ci/index.js +1 -0
  10. package/codec/encode-by-schema.algorithm.d.ts +12 -0
  11. package/codec/encode-by-schema.algorithm.js +105 -0
  12. package/codec/encode-error.error.d.ts +4 -0
  13. package/codec/encode-error.error.js +7 -0
  14. package/codec/encode-json-value.algorithm.d.ts +13 -0
  15. package/codec/encode-json-value.algorithm.js +51 -0
  16. package/codec/index.d.ts +6 -0
  17. package/codec/index.js +5 -0
  18. package/codec/message-parse.error.d.ts +4 -0
  19. package/codec/message-parse.error.js +7 -0
  20. package/codec/method-codec.algorithm.d.ts +8 -0
  21. package/codec/method-codec.algorithm.js +31 -0
  22. package/codec/normalize-by-schema.algorithm.d.ts +14 -0
  23. package/codec/normalize-by-schema.algorithm.js +103 -0
  24. package/codec/params-error.error.d.ts +4 -0
  25. package/codec/params-error.error.js +7 -0
  26. package/codec/schema-lookup.algorithm.d.ts +13 -0
  27. package/codec/schema-lookup.algorithm.js +56 -0
  28. package/codec/wire-message.mapper.d.ts +25 -0
  29. package/codec/wire-message.mapper.js +58 -0
  30. package/conformance/check-generation.use-case.d.ts +12 -0
  31. package/conformance/check-generation.use-case.js +91 -0
  32. package/conformance/check-plugin.use-case.d.ts +24 -0
  33. package/conformance/check-plugin.use-case.js +78 -0
  34. package/conformance/conformance-report.model.d.ts +22 -0
  35. package/conformance/conformance-report.model.js +23 -0
  36. package/conformance/find-manifests.algorithm.d.ts +7 -0
  37. package/conformance/find-manifests.algorithm.js +34 -0
  38. package/conformance/go-list.mapper.d.ts +4 -0
  39. package/conformance/go-list.mapper.js +8 -0
  40. package/conformance/index.d.ts +5 -0
  41. package/conformance/index.js +3 -0
  42. package/framing/frame-message.algorithm.d.ts +5 -0
  43. package/framing/frame-message.algorithm.js +8 -0
  44. package/framing/frame-reader.store.d.ts +15 -0
  45. package/framing/frame-reader.store.js +59 -0
  46. package/framing/framing.error.d.ts +4 -0
  47. package/framing/framing.error.js +7 -0
  48. package/framing/index.d.ts +3 -0
  49. package/framing/index.js +3 -0
  50. package/host/connect-plugin.use-case.d.ts +26 -0
  51. package/host/connect-plugin.use-case.js +44 -0
  52. package/host/host-options.contract.d.ts +28 -0
  53. package/host/host-options.contract.js +2 -0
  54. package/host/index.d.ts +7 -0
  55. package/host/index.js +4 -0
  56. package/host/plugin-client.client.d.ts +42 -0
  57. package/host/plugin-client.client.js +166 -0
  58. package/host/start-plugin.use-case.d.ts +10 -0
  59. package/host/start-plugin.use-case.js +57 -0
  60. package/index.d.ts +15 -0
  61. package/index.js +20 -0
  62. package/jsondoc/indent-raw-json.algorithm.d.ts +8 -0
  63. package/jsondoc/indent-raw-json.algorithm.js +60 -0
  64. package/jsondoc/index.d.ts +2 -0
  65. package/jsondoc/index.js +2 -0
  66. package/jsondoc/json-document.error.d.ts +4 -0
  67. package/jsondoc/json-document.error.js +7 -0
  68. package/jsondoc/json-document.model.d.ts +38 -0
  69. package/jsondoc/json-document.model.js +113 -0
  70. package/jsondoc/scan-json-object.algorithm.d.ts +17 -0
  71. package/jsondoc/scan-json-object.algorithm.js +132 -0
  72. package/package.json +34 -4
  73. package/plugin-refs/index.d.ts +1 -0
  74. package/plugin-refs/index.js +1 -0
  75. package/plugin-refs/plugin-ref.policy.d.ts +9 -0
  76. package/plugin-refs/plugin-ref.policy.js +22 -0
  77. package/plugin-roles/index.d.ts +1 -0
  78. package/plugin-roles/index.js +1 -0
  79. package/plugin-roles/plugin-role.policy.d.ts +16 -0
  80. package/plugin-roles/plugin-role.policy.js +30 -0
  81. package/projects/audit-settings.policy.d.ts +5 -0
  82. package/projects/audit-settings.policy.js +8 -0
  83. package/projects/index.d.ts +6 -0
  84. package/projects/index.js +6 -0
  85. package/projects/manifest-match.algorithm.d.ts +7 -0
  86. package/projects/manifest-match.algorithm.js +38 -0
  87. package/projects/project-kind.policy.d.ts +9 -0
  88. package/projects/project-kind.policy.js +28 -0
  89. package/projects/publishes.policy.d.ts +7 -0
  90. package/projects/publishes.policy.js +8 -0
  91. package/projects/set-toolchain.algorithm.d.ts +7 -0
  92. package/projects/set-toolchain.algorithm.js +13 -0
  93. package/projects/stack-plugins.algorithm.d.ts +3 -0
  94. package/projects/stack-plugins.algorithm.js +4 -0
  95. package/protocol/index.d.ts +4 -0
  96. package/protocol/index.js +3 -0
  97. package/protocol/protocol-schema.contract.d.ts +3 -0
  98. package/protocol/protocol-schema.contract.js +1925 -0
  99. package/protocol/protocol-types.contract.d.ts +1017 -0
  100. package/protocol/protocol-types.contract.js +36 -0
  101. package/protocol/rpc-error.error.d.ts +9 -0
  102. package/protocol/rpc-error.error.js +13 -0
  103. package/protocol/schema-document.contract.d.ts +55 -0
  104. package/protocol/schema-document.contract.js +1 -0
  105. package/scaffold/index.d.ts +3 -0
  106. package/scaffold/index.js +2 -0
  107. package/scaffold/scaffold-data.mapper.d.ts +15 -0
  108. package/scaffold/scaffold-data.mapper.js +24 -0
  109. package/scaffold/scaffold-project.use-case.d.ts +20 -0
  110. package/scaffold/scaffold-project.use-case.js +13 -0
  111. package/serve/capabilities-of.algorithm.d.ts +13 -0
  112. package/serve/capabilities-of.algorithm.js +28 -0
  113. package/serve/claim-stdout.use-case.d.ts +10 -0
  114. package/serve/claim-stdout.use-case.js +14 -0
  115. package/serve/dispatch-request.use-case.d.ts +14 -0
  116. package/serve/dispatch-request.use-case.js +56 -0
  117. package/serve/index.d.ts +4 -0
  118. package/serve/index.js +2 -0
  119. package/serve/initialize-plugin.use-case.d.ts +9 -0
  120. package/serve/initialize-plugin.use-case.js +16 -0
  121. package/serve/plugin-members.config.d.ts +16 -0
  122. package/serve/plugin-members.config.js +25 -0
  123. package/serve/plugin.contract.d.ts +65 -0
  124. package/serve/plugin.contract.js +1 -0
  125. package/serve/protocol-streams.contract.d.ts +13 -0
  126. package/serve/protocol-streams.contract.js +1 -0
  127. package/serve/request-outcome.contract.d.ts +9 -0
  128. package/serve/request-outcome.contract.js +1 -0
  129. package/serve/serve.use-case.d.ts +27 -0
  130. package/serve/serve.use-case.js +93 -0
  131. package/tasks/contribute-tasks.algorithm.d.ts +15 -0
  132. package/tasks/contribute-tasks.algorithm.js +22 -0
  133. package/tasks/index.d.ts +2 -0
  134. package/tasks/index.js +2 -0
  135. package/tasks/task.algorithm.d.ts +18 -0
  136. package/tasks/task.algorithm.js +23 -0
  137. package/templating/file-exists.error.d.ts +6 -0
  138. package/templating/file-exists.error.js +10 -0
  139. package/templating/index.d.ts +4 -0
  140. package/templating/index.js +4 -0
  141. package/templating/parse-template.algorithm.d.ts +11 -0
  142. package/templating/parse-template.algorithm.js +197 -0
  143. package/templating/render-template.algorithm.d.ts +7 -0
  144. package/templating/render-template.algorithm.js +87 -0
  145. package/templating/template-functions.algorithm.d.ts +10 -0
  146. package/templating/template-functions.algorithm.js +104 -0
  147. package/templating/template-syntax.contract.d.ts +33 -0
  148. package/templating/template-syntax.contract.js +1 -0
  149. package/templating/template.error.d.ts +4 -0
  150. package/templating/template.error.js +7 -0
  151. package/templating/tokenize-action.algorithm.d.ts +20 -0
  152. package/templating/tokenize-action.algorithm.js +57 -0
  153. package/templating/write-templates.use-case.d.ts +11 -0
  154. package/templating/write-templates.use-case.js +44 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /** A template that cannot be parsed or rendered: bad syntax, a field the data does not have, a construct outside the supported subset. */
2
+ export declare class TemplateError extends Error {
3
+ constructor(name: string, message: string);
4
+ }
@@ -0,0 +1,7 @@
1
+ /** A template that cannot be parsed or rendered: bad syntax, a field the data does not have, a construct outside the supported subset. */
2
+ export class TemplateError extends Error {
3
+ constructor(name, message) {
4
+ super(`template ${name}: ${message}`);
5
+ this.name = 'TemplateError';
6
+ }
7
+ }
@@ -0,0 +1,20 @@
1
+ export type Token = {
2
+ t: 'open' | 'close' | 'pipe';
3
+ } | {
4
+ t: 'field';
5
+ root: boolean;
6
+ path: string[];
7
+ } | {
8
+ t: 'string';
9
+ value: string;
10
+ } | {
11
+ t: 'number';
12
+ value: number;
13
+ } | {
14
+ t: 'word';
15
+ value: string;
16
+ };
17
+ /**
18
+ * Splits the text of an action into tokens. `fail` reports what cannot be a token.
19
+ */
20
+ export declare function tokenizeAction(body: string, fail: (message: string) => never): Token[];
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The elements of an action, in the order the alternatives are tried: space,
3
+ * brackets and pipe, a quoted or raw string, a number, a field (`.A.B`, `$`,
4
+ * `$.A`, or a lone `.`), a word, and `:=`/`=`, which are variables. Anything else
5
+ * is the last alternative, so every character belongs to some match.
6
+ */
7
+ const ELEMENT = new RegExp([
8
+ String.raw `\s+`,
9
+ String.raw `(?<open>\()`,
10
+ String.raw `(?<close>\))`,
11
+ String.raw `(?<pipe>\|)`,
12
+ String.raw `(?<string>"(?:[^"\\]|\\.)*")`,
13
+ '(?<raw>`[^`]*`)',
14
+ String.raw `(?<number>-?\d+(?:\.\d+)?(?![\w.]))`,
15
+ String.raw `(?<field>\$(?:\.[A-Z_]\w*)*|(?:\.[A-Z_]\w*)+|\.)`,
16
+ String.raw `(?<word>[A-Z_]\w*)`,
17
+ '(?<variable>:?=)',
18
+ '(?<other>.)',
19
+ ].join('|'), 'gis');
20
+ /**
21
+ * Splits the text of an action into tokens. `fail` reports what cannot be a token.
22
+ */
23
+ export function tokenizeAction(body, fail) {
24
+ const tokens = [];
25
+ for (const match of body.matchAll(ELEMENT)) {
26
+ const found = match.groups ?? {};
27
+ if (found.open !== undefined)
28
+ tokens.push({ t: 'open' });
29
+ else if (found.close !== undefined)
30
+ tokens.push({ t: 'close' });
31
+ else if (found.pipe !== undefined)
32
+ tokens.push({ t: 'pipe' });
33
+ else if (found.string !== undefined)
34
+ tokens.push({ t: 'string', value: unquote(found.string, fail) });
35
+ else if (found.raw !== undefined)
36
+ tokens.push({ t: 'string', value: found.raw.slice(1, -1) });
37
+ else if (found.number !== undefined)
38
+ tokens.push({ t: 'number', value: Number(found.number) });
39
+ else if (found.field !== undefined)
40
+ tokens.push({ t: 'field', root: found.field.startsWith('$'), path: found.field.split('.').filter(part => part !== '' && part !== '$') });
41
+ else if (found.word !== undefined)
42
+ tokens.push({ t: 'word', value: found.word });
43
+ else if (found.variable !== undefined)
44
+ fail('variables are not supported by the SDK\'s templates');
45
+ else if (found.other !== undefined)
46
+ fail(`unexpected character "${found.other}" in action`);
47
+ }
48
+ return tokens;
49
+ }
50
+ function unquote(literal, fail) {
51
+ try {
52
+ return JSON.parse(literal);
53
+ }
54
+ catch {
55
+ return fail(`invalid string ${literal}`);
56
+ }
57
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Renders every template in `files` (target path to template text) under
3
+ * `root` with `data`, creating directories as needed. A target path may itself
4
+ * contain template actions (`[[.Dir]]/main.ts`). Returns the written paths,
5
+ * forward-slashed and relative to `root`, in the order of the sorted templates.
6
+ *
7
+ * Nothing is written if any template fails to render or any target exists
8
+ * ({@link FileExistsError}): it never overwrites a file. A target that would
9
+ * land outside `root` is refused.
10
+ */
11
+ export declare function writeTemplates(root: string, files: Record<string, string>, data?: unknown): Promise<string[]>;
@@ -0,0 +1,44 @@
1
+ import { access, mkdir, writeFile } from 'node:fs/promises';
2
+ import { dirname, isAbsolute, join, posix, resolve, sep } from 'node:path';
3
+ import { FileExistsError } from './file-exists.error.js';
4
+ import { renderTemplate } from './render-template.algorithm.js';
5
+ import { byKey } from './template-functions.algorithm.js';
6
+ import { TemplateError } from './template.error.js';
7
+ /**
8
+ * Renders every template in `files` (target path to template text) under
9
+ * `root` with `data`, creating directories as needed. A target path may itself
10
+ * contain template actions (`[[.Dir]]/main.ts`). Returns the written paths,
11
+ * forward-slashed and relative to `root`, in the order of the sorted templates.
12
+ *
13
+ * Nothing is written if any template fails to render or any target exists
14
+ * ({@link FileExistsError}): it never overwrites a file. A target that would
15
+ * land outside `root` is refused.
16
+ */
17
+ export async function writeTemplates(root, files, data) {
18
+ const rendered = [];
19
+ for (const target of Object.keys(files).sort(byKey)) {
20
+ const path = posix.normalize(renderTemplate(target, data, 'path'));
21
+ const full = resolve(root, ...path.split('/'));
22
+ if (path === '..' || path.startsWith('../') || isAbsolute(path) || !full.startsWith(resolve(root) + sep)) {
23
+ throw new TemplateError(path, 'the target is outside the project root');
24
+ }
25
+ if (await exists(full))
26
+ throw new FileExistsError(path);
27
+ rendered.push({ path, content: renderTemplate(files[target], data, path) });
28
+ }
29
+ for (const file of rendered) {
30
+ const full = join(root, ...file.path.split('/'));
31
+ await mkdir(dirname(full), { recursive: true, mode: 0o755 });
32
+ await writeFile(full, file.content, { mode: 0o644 });
33
+ }
34
+ return rendered.map(file => file.path);
35
+ }
36
+ async function exists(path) {
37
+ try {
38
+ await access(path);
39
+ return true;
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }