@pwfabric/compiler 0.0.0-stage → 1.0.0-rc.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/screen.js ADDED
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Source screening — what a block or capability source may CONTAIN.
3
+ *
4
+ * ── THIS IS A HYGIENE CHECK, NOT A SECURITY BOUNDARY. ──
5
+ * It is a regex denylist over comment- and literal-masked text. Aliasing a global through a binding (`const g = globalThis;
6
+ * g['fe' + 'tch']`), `Reflect.get`, `top[...]` and similar spellings walk past
7
+ * it — the tests pin several as known gaps. Running untrusted block code safely
8
+ * is the HOST's job: an isolated origin or sandboxed iframe/worker for block
9
+ * bundles, plus a Content Security Policy. Do not treat a passing screen as
10
+ * permission to run a module with the host's privileges.
11
+ *
12
+ * Authorisation ("may this caller add a block") is the host's business. This
13
+ * answers the different question: once a source string reaches the compiler,
14
+ * may the module it becomes reach the ambient browser capabilities that turn
15
+ * "renders a component" into "reads your session and ships it somewhere"?
16
+ *
17
+ * A source that arrives as content — written by a model steered by text an
18
+ * attacker can influence, or posted directly by a caller — is compiled and then
19
+ * executed by every renderer that loads it, on the host's own origin, inside an
20
+ * authenticated session. So the module is constrained: it may render from its
21
+ * props; it may not reach network egress, credential stores or code
22
+ * construction.
23
+ *
24
+ * This narrows the blast radius. It does NOT stop prompt injection — see
25
+ * {@link screenSource}'s KNOWN GAPS for exactly what still gets through.
26
+ *
27
+ * The compiler does not call this for you: `compileAtom` compiles what it is
28
+ * given. A host that compiles untrusted source screens it first, and screens
29
+ * every companion the source reaches — `collectCompanions` does both.
30
+ *
31
+ * @module @pwfabric/compiler/screen
32
+ */
33
+ import { blockBundleExternals } from '@pwfabric/core';
34
+ /**
35
+ * Module specifiers a screened source may import at VALUE level.
36
+ *
37
+ * DERIVED from the host import list (`blockBundleExternals()` over
38
+ * `BLOCK_HOST_IMPORTS` in `@pwfabric/core`), so the screen and
39
+ * the bundler can never disagree. A narrower hand-written list would refuse
40
+ * real packs, which import the runtime for the event bus, surface id and
41
+ * connection contexts. A specifier the bundler
42
+ * leaves external and every host maps for compiled blocks is a specifier the
43
+ * screen admits; one list says both.
44
+ *
45
+ * What still keeps a screened module from network egress, credential stores
46
+ * and code construction is layer 2 (the forbidden-capability scan) and the
47
+ * host's sandbox — not the narrowness of this list.
48
+ */
49
+ export const SCREEN_IMPORT_ALLOWLIST = Object.freeze([...blockBundleExternals()]);
50
+ /**
51
+ * Browser capabilities a screened source may not reach.
52
+ *
53
+ * Every entry was checked against a large set of real block components before
54
+ * being added: it appears in none of them, so none is the price of a
55
+ * legitimate block. The list is the "turns rendering into exfiltration or
56
+ * execution" set, not a general-purpose JS denylist:
57
+ *
58
+ * - arbitrary code construction (`eval`, `Function`, `.constructor(...)`)
59
+ * - network egress (`fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource`,
60
+ * `sendBeacon`, `importScripts`, `Worker`, `RTCPeerConnection`)
61
+ * - cross-context messaging (`postMessage`)
62
+ * - credential/state reads (`document.cookie`, `localStorage`,
63
+ * `sessionStorage`, `indexedDB`, `caches`, `process.env`)
64
+ * - document rewriting (`document.write`/`writeln`/`domain`,
65
+ * `createElement('script')`)
66
+ * - the obvious spellings-around: computed member access on a global
67
+ * (`window[...]`, `globalThis[...]`, `self[...]`, `document[...]`) and
68
+ * module loading at run time (`import()`, `require()`).
69
+ *
70
+ * Patterns whose evidence lives INSIDE a string literal (the `createElement`
71
+ * pair) run against the comment-masked-but-literals-intact source instead. They
72
+ * are weak by construction — `createElement(tag)` with a computed `tag` walks
73
+ * straight past — but the literal spelling is the one a model actually emits.
74
+ */
75
+ const FORBIDDEN_SOURCE_PATTERNS = [
76
+ [/\beval\s*\(/, 'eval()'],
77
+ [/\bnew\s+Function\b/, 'new Function()'],
78
+ [/\bFunction\s*\(/, 'Function() as a constructor/call'],
79
+ [/\.\s*constructor\s*[[(]/, '.constructor access (Function-constructor escape)'],
80
+ [/\bfetch\s*\(/, 'fetch()'],
81
+ [/\bXMLHttpRequest\b/, 'XMLHttpRequest'],
82
+ [/\bWebSocket\b/, 'WebSocket'],
83
+ [/\bEventSource\b/, 'EventSource'],
84
+ [/\bsendBeacon\b/, 'navigator.sendBeacon()'],
85
+ [/\bimportScripts\s*\(/, 'importScripts()'],
86
+ [/\b(?:Shared)?Worker\s*\(/, 'Worker()'],
87
+ [/\bRTCPeerConnection\b/, 'RTCPeerConnection'],
88
+ [/\bpostMessage\s*\(/, 'postMessage()'],
89
+ [/\bdocument\s*\.\s*cookie\b/, 'document.cookie'],
90
+ [/\bdocument\s*\.\s*(?:write|writeln|domain)\b/, 'document.write / writeln / domain'],
91
+ [/\blocalStorage\b/, 'localStorage'],
92
+ [/\bsessionStorage\b/, 'sessionStorage'],
93
+ [/\bindexedDB\b/, 'indexedDB'],
94
+ [/\bcaches\s*\./, 'caches (CacheStorage)'],
95
+ [/\bprocess\s*\.\s*env\b/, 'process.env'],
96
+ [/\b(?:window|globalThis|self|document)\s*\[/, 'computed member access on a global object'],
97
+ [/\bimport\s*\(/, 'dynamic import()'],
98
+ [/\brequire\s*\(/, 'require()'],
99
+ ];
100
+ const FORBIDDEN_LITERAL_PATTERNS = [
101
+ [/\bcreateElement\s*\(\s*['"`]script['"`]/, "createElement('script')"],
102
+ [/\bcreateElement\s*\(\s*['"`]iframe['"`]/, "createElement('iframe')"],
103
+ ];
104
+ /**
105
+ * Blank out comments and (optionally) string/template/regex literal CONTENT,
106
+ * preserving byte offsets and newlines so reported line numbers stay true.
107
+ *
108
+ * Why this exists rather than a raw `source.includes('fetch(')`: a shipped
109
+ * first-party block's JSDoc says `same-origin fetch('/api/orders')`. A scan that
110
+ * did not strip comments would refuse a block for describing itself. Template
111
+ * SUBSTITUTIONS (`${...}`) are deliberately kept live — that is real code.
112
+ *
113
+ * The literal scanner must run even when `blankLiterals` is false, because a
114
+ * `//` or a `/` inside a string would otherwise be misread as a comment or a
115
+ * regex and swallow the rest of the file.
116
+ */
117
+ export function maskSource(src, blankLiterals) {
118
+ let out = '';
119
+ let i = 0;
120
+ let prev = '\n';
121
+ const blank = (ch) => (ch === '\n' ? '\n' : ' ');
122
+ const emit = (ch) => {
123
+ out += blankLiterals ? blank(ch) : ch;
124
+ };
125
+ while (i < src.length) {
126
+ const two = src.slice(i, i + 2);
127
+ if (two === '//') {
128
+ while (i < src.length && src[i] !== '\n') {
129
+ out += ' ';
130
+ i++;
131
+ }
132
+ continue;
133
+ }
134
+ if (two === '/*') {
135
+ while (i < src.length && src.slice(i, i + 2) !== '*/') {
136
+ out += blank(src[i]);
137
+ i++;
138
+ }
139
+ out += ' ';
140
+ i += 2;
141
+ continue;
142
+ }
143
+ const c = src[i];
144
+ if (c === "'" || c === '"') {
145
+ emit(c);
146
+ i++;
147
+ while (i < src.length && src[i] !== c) {
148
+ if (src[i] === '\\') {
149
+ emit(src[i]);
150
+ i++;
151
+ if (i >= src.length)
152
+ break;
153
+ }
154
+ emit(src[i]);
155
+ i++;
156
+ }
157
+ if (i < src.length) {
158
+ emit(src[i]);
159
+ i++;
160
+ }
161
+ prev = c;
162
+ continue;
163
+ }
164
+ if (c === '`') {
165
+ emit(c);
166
+ i++;
167
+ while (i < src.length) {
168
+ if (src[i] === '\\') {
169
+ emit(src[i]);
170
+ i++;
171
+ if (i >= src.length)
172
+ break;
173
+ emit(src[i]);
174
+ i++;
175
+ continue;
176
+ }
177
+ if (src[i] === '`') {
178
+ emit(src[i]);
179
+ i++;
180
+ break;
181
+ }
182
+ if (src.slice(i, i + 2) === '${') {
183
+ // Live code — copy verbatim, tracking brace depth back to the `}`.
184
+ out += '${';
185
+ i += 2;
186
+ let depth = 1;
187
+ while (i < src.length && depth > 0) {
188
+ const s = src[i];
189
+ if (s === '{')
190
+ depth++;
191
+ else if (s === '}')
192
+ depth--;
193
+ out += s;
194
+ i++;
195
+ }
196
+ continue;
197
+ }
198
+ emit(src[i]);
199
+ i++;
200
+ }
201
+ prev = '`';
202
+ continue;
203
+ }
204
+ // Regex literal: a `/` in a position where a value may start.
205
+ if (c === '/' && /[(,=:[!&|?{};+\-*%~^<>\n]/.test(prev)) {
206
+ emit(c);
207
+ i++;
208
+ while (i < src.length && src[i] !== '/' && src[i] !== '\n') {
209
+ if (src[i] === '\\') {
210
+ emit(src[i]);
211
+ i++;
212
+ if (i >= src.length)
213
+ break;
214
+ }
215
+ emit(src[i]);
216
+ i++;
217
+ }
218
+ if (i < src.length && src[i] === '/') {
219
+ emit(src[i]);
220
+ i++;
221
+ }
222
+ while (i < src.length && /[dgimsuy]/.test(src[i])) {
223
+ emit(src[i]);
224
+ i++;
225
+ }
226
+ prev = '/';
227
+ continue;
228
+ }
229
+ out += c;
230
+ if (!/\s/.test(c))
231
+ prev = c;
232
+ i++;
233
+ }
234
+ return out;
235
+ }
236
+ const IMPORT_FROM_RE = /(?:^|[\n;])[ \t]*(import|export)\b([ \t]+type\b)?([^;]*?)\bfrom[ \t]*['"]([^'"]+)['"]/g;
237
+ const BARE_IMPORT_RE = /(?:^|[\n;])[ \t]*import[ \t]*['"]([^'"]+)['"]/g;
238
+ function lineOf(src, index) {
239
+ return src.slice(0, index).split('\n').length;
240
+ }
241
+ /**
242
+ * Where the statement itself starts inside an import match. The import
243
+ * patterns open on the newline or `;` that precedes a statement, so the match
244
+ * index can sit one line early — or, at the very start of the file, not early
245
+ * at all. Skipping the separators gives the statement's own line either way.
246
+ */
247
+ function statementIndex(src, matchIndex) {
248
+ let i = matchIndex;
249
+ while (i < src.length && /[\n; \t]/.test(src[i]))
250
+ i++;
251
+ return i;
252
+ }
253
+ /**
254
+ * Screen one source before it is allowed anywhere near the compiler. Returns
255
+ * every violation found (not just the first) so a repair loop gets a complete,
256
+ * actionable message.
257
+ *
258
+ * TWO LAYERS:
259
+ * 1. IMPORT ALLOWLIST — every value-level `import`/`export ... from` and bare
260
+ * `import '...'` specifier must be in {@link SCREEN_IMPORT_ALLOWLIST}.
261
+ * Relative specifiers are rejected at value level unless
262
+ * {@link ScreenOptions.allowRelativeImport} admits them, but permitted on
263
+ * `import type` / `export type` statements, which the compiler erases.
264
+ * 2. ESCAPE SCAN — the forbidden-capability patterns over the
265
+ * comment-and-literal-masked source.
266
+ *
267
+ * ── KNOWN GAPS. Read these before believing this closes anything. ──
268
+ *
269
+ * This is a DENYLIST over source text, not a sandbox, and it is deliberately
270
+ * incomplete. It does not stop:
271
+ *
272
+ * - **Prompt injection itself.** Attacker-controlled text still steers the
273
+ * model. All this changes is what the resulting module is allowed to do.
274
+ * - **`dangerouslySetInnerHTML` / `innerHTML`.** 30 of the 100 first-party
275
+ * blocks use `dangerouslySetInnerHTML` for inline SVG icon paths, so it is
276
+ * allowed — a screened block CAN inject arbitrary markup.
277
+ * - **Navigation-based exfiltration.** `window.location.href = ...` is used by
278
+ * first-party blocks for link handling, so it is allowed; a block can
279
+ * navigate the tab to an attacker URL with data in the query.
280
+ * - **Rendering hostile content into props/children**, phishing UI, and any
281
+ * purely-visual deception.
282
+ * - **Sufficiently indirect spellings.** The scan is textual: identifiers
283
+ * assembled at run time, property names built from arrays, aliasing a global
284
+ * through a permitted binding, or `top`/`parent` (excluded from the
285
+ * computed-access rule because they are common local names) can still reach
286
+ * a banned capability. Closing that class needs an execution sandbox (CSP +
287
+ * an isolated origin/worker for block bundles), not a string scan.
288
+ */
289
+ export function screenSource(source, opts) {
290
+ const violations = [];
291
+ // Layer 2 runs over fully-masked source (comments + literal content gone).
292
+ const code = maskSource(source, true);
293
+ for (const [pattern, label] of FORBIDDEN_SOURCE_PATTERNS) {
294
+ const m = pattern.exec(code);
295
+ if (m) {
296
+ violations.push(`line ${lineOf(code, m.index)}: ${label} is not permitted in a block component`);
297
+ }
298
+ }
299
+ // Layer 1 runs over comment-masked-but-literals-intact source: the
300
+ // specifier itself lives inside quotes, but a commented-out import must not
301
+ // count. The literal-evidence patterns share that view.
302
+ const withStrings = maskSource(source, false);
303
+ for (const [pattern, label] of FORBIDDEN_LITERAL_PATTERNS) {
304
+ const lm = pattern.exec(withStrings);
305
+ if (lm) {
306
+ violations.push(`line ${lineOf(withStrings, lm.index)}: ${label} is not permitted in a block component`);
307
+ }
308
+ }
309
+ const specs = [];
310
+ IMPORT_FROM_RE.lastIndex = 0;
311
+ let m;
312
+ while ((m = IMPORT_FROM_RE.exec(withStrings)) !== null) {
313
+ specs.push({ typeOnly: m[2] !== undefined, spec: m[4], index: m.index });
314
+ }
315
+ BARE_IMPORT_RE.lastIndex = 0;
316
+ while ((m = BARE_IMPORT_RE.exec(withStrings)) !== null) {
317
+ specs.push({ typeOnly: false, spec: m[1], index: m.index });
318
+ }
319
+ for (const s of specs) {
320
+ if (s.typeOnly)
321
+ continue;
322
+ const line = lineOf(withStrings, statementIndex(withStrings, s.index));
323
+ if (s.spec.startsWith('.') && opts?.allowRelativeImport?.(s.spec))
324
+ continue;
325
+ if (s.spec.startsWith('.') || s.spec.startsWith('/')) {
326
+ violations.push(`line ${line}: relative import '${s.spec}' — a generated block is bundled as a single self-contained file; only \`import type\` may reference a sibling module`);
327
+ }
328
+ else if (!SCREEN_IMPORT_ALLOWLIST.includes(s.spec)) {
329
+ violations.push(`line ${line}: import '${s.spec}' is outside the block import allowlist (${SCREEN_IMPORT_ALLOWLIST.join(', ')})`);
330
+ }
331
+ }
332
+ return violations.length === 0 ? { ok: true } : { ok: false, violations };
333
+ }
334
+ /** Alternative name for `screenSource`. */
335
+ export const screenBlockSource = screenSource;
336
+ /** Alternative name for `SCREEN_IMPORT_ALLOWLIST`. */
337
+ export const BLOCK_SOURCE_IMPORT_ALLOWLIST = SCREEN_IMPORT_ALLOWLIST;
338
+ //# sourceMappingURL=screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.js","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM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AC,IAAI,CAAC,GAAG,CACjH,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA;AAC3E,CAAC;AAED,2CAA2C;AAC3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAA;AAC7C,sDAAsD;AACtD,MAAM,CAAC,MAAM,6BAA6B,GAAG,uBAAuB,CAAA"}
@@ -0,0 +1,5 @@
1
+ /** This package's version — `dist/` and `src/` both sit one level below `package.json`. */
2
+ export declare const COMPILER_VERSION: string;
3
+ /** The esbuild version that produced the bytes. */
4
+ export declare const ESBUILD_VERSION: string;
5
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAYA,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,EAAE,MAAoE,CAAA;AAEnG,mDAAmD;AACnD,eAAO,MAAM,eAAe,EAAE,MAAuB,CAAA"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Versions a caller records next to a compiled bundle.
3
+ *
4
+ * Same input + same compiler version + same esbuild version → identical bytes.
5
+ * Both versions are read at run time (not copied into a constant) so a release
6
+ * that bumps `package.json` cannot leave a stale number behind.
7
+ */
8
+ import { createRequire } from 'node:module';
9
+ import { version as esbuildVersion } from 'esbuild';
10
+ const require = createRequire(import.meta.url);
11
+ /** This package's version — `dist/` and `src/` both sit one level below `package.json`. */
12
+ export const COMPILER_VERSION = require('../package.json').version;
13
+ /** The esbuild version that produced the bytes. */
14
+ export const ESBUILD_VERSION = esbuildVersion;
15
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,SAAS,CAAA;AAEnD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C,2FAA2F;AAC3F,MAAM,CAAC,MAAM,gBAAgB,GAAY,OAAO,CAAC,iBAAiB,CAAyB,CAAC,OAAO,CAAA;AAEnG,mDAAmD;AACnD,MAAM,CAAC,MAAM,eAAe,GAAW,cAAc,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Entry wrappers — the thin module the compiler actually bundles.
3
+ *
4
+ * Which template applies is decided by the kind's `entry` metadata in
5
+ * `@pwfabric/contracts` (`atomKindMeta(kind).entry`), not by
6
+ * ad-hoc "block vs capability vs connector" branches:
7
+ *
8
+ * - block (identity) → re-export the component and the definition under
9
+ * the stable names `Component` + `definition`, so the
10
+ * runtime's block module loader reads two fixed keys
11
+ * whatever the author named them.
12
+ * - capability (identity) → opaque `export *` (the handler contract is not
13
+ * normalised).
14
+ * - connector (sibling) → loader-contract adapter: `createConnector` that
15
+ * delegates to an explicit export, wraps an engine
16
+ * class (`prototype.query`), or calls/constructs the
17
+ * default export of the sibling `./<Name>`.
18
+ * - provider (sibling) → per-facet entry over the SHARED vendor motor
19
+ * (`../index`): binds the domain's entity map from
20
+ * `./<domain>` into the vendor engine class, or falls
21
+ * back to a vendor `create*` factory.
22
+ *
23
+ * @module @pwfabric/compiler/wrappers
24
+ */
25
+ import { type AtomKind } from '@pwfabric/contracts';
26
+ /**
27
+ * Context passed to the wrapper registry. `identity` kinds supply `sourceBase`
28
+ * (basename of the atom's own source, no extension); `sibling-generated` kinds
29
+ * supply `engineName` (connector `<Name>` / provider `<domain>`).
30
+ */
31
+ export interface WrapperContext {
32
+ readonly sourceBase?: string;
33
+ readonly engineName?: string;
34
+ }
35
+ /** Connector `<Name>` / provider `<domain>`: letters, digits, `_`, `-`. */
36
+ export declare function isValidEngineName(name: string): boolean;
37
+ /** Entry basename without extension: letters, digits, `_`, `-`, `.` — never `..`. */
38
+ export declare function isValidSourceBase(base: string): boolean;
39
+ /**
40
+ * The single wrapper registry, keyed off the kind's contract metadata.
41
+ * Throws on a name that fails {@link isValidEngineName} / {@link isValidSourceBase}.
42
+ */
43
+ export declare function buildWrapperSource(kind: AtomKind, ctx: WrapperContext): string;
44
+ //# sourceMappingURL=wrappers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrappers.d.ts","sourceRoot":"","sources":["../src/wrappers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAEjE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B;AAcD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,cAAc,GAAG,MAAM,CAuC9E"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Entry wrappers — the thin module the compiler actually bundles.
3
+ *
4
+ * Which template applies is decided by the kind's `entry` metadata in
5
+ * `@pwfabric/contracts` (`atomKindMeta(kind).entry`), not by
6
+ * ad-hoc "block vs capability vs connector" branches:
7
+ *
8
+ * - block (identity) → re-export the component and the definition under
9
+ * the stable names `Component` + `definition`, so the
10
+ * runtime's block module loader reads two fixed keys
11
+ * whatever the author named them.
12
+ * - capability (identity) → opaque `export *` (the handler contract is not
13
+ * normalised).
14
+ * - connector (sibling) → loader-contract adapter: `createConnector` that
15
+ * delegates to an explicit export, wraps an engine
16
+ * class (`prototype.query`), or calls/constructs the
17
+ * default export of the sibling `./<Name>`.
18
+ * - provider (sibling) → per-facet entry over the SHARED vendor motor
19
+ * (`../index`): binds the domain's entity map from
20
+ * `./<domain>` into the vendor engine class, or falls
21
+ * back to a vendor `create*` factory.
22
+ *
23
+ * @module @pwfabric/compiler/wrappers
24
+ */
25
+ import { atomKindMeta } from '@pwfabric/contracts';
26
+ /**
27
+ * NAMES ARE UNTRUSTED. `engineName` and `sourceBase` come from pack folder and
28
+ * file names, and they are written into generated SOURCE — a name carrying a
29
+ * quote, a newline or `'; …; //` would be code that no screen ever looked at.
30
+ * Two defences, both always on: the name must match a strict pattern (checked
31
+ * here and, as a diagnostic, by `compileAtom` before it gets this far), and
32
+ * every specifier, property key and message built from a name is emitted
33
+ * through `JSON.stringify`, never spliced between hand-written quotes.
34
+ */
35
+ const ENGINE_NAME_RE = /^[A-Za-z0-9_-]+$/;
36
+ const SOURCE_BASE_RE = /^[A-Za-z0-9_.-]+$/;
37
+ /** Connector `<Name>` / provider `<domain>`: letters, digits, `_`, `-`. */
38
+ export function isValidEngineName(name) {
39
+ return ENGINE_NAME_RE.test(name);
40
+ }
41
+ /** Entry basename without extension: letters, digits, `_`, `-`, `.` — never `..`. */
42
+ export function isValidSourceBase(base) {
43
+ return SOURCE_BASE_RE.test(base) && !base.includes('..') && base !== '.';
44
+ }
45
+ /**
46
+ * The single wrapper registry, keyed off the kind's contract metadata.
47
+ * Throws on a name that fails {@link isValidEngineName} / {@link isValidSourceBase}.
48
+ */
49
+ export function buildWrapperSource(kind, ctx) {
50
+ const meta = atomKindMeta(kind);
51
+ if (meta.entry === 'sibling-generated') {
52
+ const name = ctx.engineName ?? '';
53
+ if (!isValidEngineName(name))
54
+ throw new Error(`invalid engine name ${JSON.stringify(name)}`);
55
+ return kind === 'provider' ? providerEntrySource(name) : connectorEntrySource(name);
56
+ }
57
+ // identity
58
+ const sourceBase = ctx.sourceBase ?? '';
59
+ if (!isValidSourceBase(sourceBase))
60
+ throw new Error(`invalid entry basename ${JSON.stringify(sourceBase)}`);
61
+ if (kind === 'block') {
62
+ return `import * as _atom from ${JSON.stringify(`./${sourceBase}.js`)}
63
+
64
+ const _isDef = (v) =>
65
+ v != null && typeof v === 'object' && 'type' in v && 'schema' in v
66
+
67
+ const _resolveDefinition = (m) => {
68
+ for (const k of Object.keys(m)) {
69
+ const v = m[k]
70
+ if (_isDef(v)) return v
71
+ }
72
+ return null
73
+ }
74
+
75
+ const _resolveComponent = (m) => {
76
+ if (typeof m.default === 'function') return m.default
77
+ for (const k of Object.keys(m)) {
78
+ const v = m[k]
79
+ if (typeof v === 'function') return v
80
+ }
81
+ return null
82
+ }
83
+
84
+ export const definition = _resolveDefinition(_atom)
85
+ export const Component = _resolveComponent(_atom)
86
+ `;
87
+ }
88
+ // capability + any other identity kind
89
+ return `export * from ${JSON.stringify(`./${sourceBase}.js`)}\n`;
90
+ }
91
+ // ── sibling-generated engine adapters ──
92
+ const SHARED_ENGINE_HELPERS = `
93
+ const _isEngineClass = (v: unknown): boolean =>
94
+ typeof v === 'function' &&
95
+ !!(v as { prototype?: { query?: unknown } }).prototype &&
96
+ typeof (v as { prototype: { query?: unknown } }).prototype.query === 'function'
97
+ `;
98
+ /**
99
+ * Wrapper for kind='connector' — adapts `connectors/<Name>.ts` to the loader
100
+ * contract. Priority: explicit `createConnector` export → engine class
101
+ * (`prototype.query`) → default export (called or constructed).
102
+ */
103
+ function connectorEntrySource(name) {
104
+ return `// AUTO-GENERATED (pwfabric-compiler) — loader-contract adapter.
105
+ import * as _mod from ${JSON.stringify(`./${name}`)}
106
+ ${SHARED_ENGINE_HELPERS}
107
+ export function createConnector(
108
+ getAccessToken: () => Promise<string | null>,
109
+ config: Record<string, unknown>
110
+ ): unknown {
111
+ const m = _mod as Record<string, unknown>
112
+ const direct = m['createConnector']
113
+ if (typeof direct === 'function' && !_isEngineClass(direct)) {
114
+ return (direct as (t: unknown, c: unknown) => unknown)(getAccessToken, config)
115
+ }
116
+ for (const k of Object.keys(m)) {
117
+ const v = m[k]
118
+ if (_isEngineClass(v)) {
119
+ return new (v as new (t: unknown, c: unknown) => unknown)(getAccessToken, config)
120
+ }
121
+ }
122
+ const d = m['default']
123
+ if (typeof d === 'function') {
124
+ return _isEngineClass(d)
125
+ ? new (d as new (t: unknown, c: unknown) => unknown)(getAccessToken, config)
126
+ : (d as (t: unknown, c: unknown) => unknown)(getAccessToken, config)
127
+ }
128
+ throw new Error(
129
+ ${JSON.stringify(`connector module "${name}" exports no engine (createConnector / class with query() / default)`)}
130
+ )
131
+ }
132
+ export default createConnector
133
+ `;
134
+ }
135
+ /**
136
+ * Wrapper for kind='provider' — thin per-facet entry over the SHARED vendor
137
+ * motor. Binds the domain: the entity module's EntityMap + the vendor index's
138
+ * engine class (`new Engine(getAccessToken, domainMap)`). Falls back to a
139
+ * vendor-level `create*` factory (all-domain engine) when no engine class is
140
+ * exported.
141
+ */
142
+ function providerEntrySource(domain) {
143
+ return `// AUTO-GENERATED (pwfabric-compiler) — per-facet engine entry.
144
+ import * as _vendor from '../index'
145
+ import * as _domain from ${JSON.stringify(`./${domain}`)}
146
+ ${SHARED_ENGINE_HELPERS}
147
+ const _isEntityMap = (v: unknown): boolean => {
148
+ if (!v || typeof v !== 'object' || Array.isArray(v)) return false
149
+ const vals = Object.values(v as Record<string, unknown>)
150
+ return vals.length > 0 && vals.every((x) => !!x && typeof x === 'object')
151
+ }
152
+
153
+ const _domainMap = (() => {
154
+ const m = _domain as Record<string, unknown>
155
+ if (_isEntityMap(m[${JSON.stringify(domain)}])) return m[${JSON.stringify(domain)}]
156
+ if (_isEntityMap(m['default'])) return m['default']
157
+ for (const k of Object.keys(m)) if (_isEntityMap(m[k])) return m[k]
158
+ return null
159
+ })()
160
+
161
+ export function createConnector(
162
+ getAccessToken: () => Promise<string | null>,
163
+ config: Record<string, unknown>
164
+ ): unknown {
165
+ const vendor = _vendor as Record<string, unknown>
166
+ if (_domainMap) {
167
+ for (const k of Object.keys(vendor)) {
168
+ const v = vendor[k]
169
+ if (_isEngineClass(v)) {
170
+ return new (v as new (t: unknown, m: unknown) => unknown)(getAccessToken, _domainMap)
171
+ }
172
+ }
173
+ }
174
+ for (const k of Object.keys(vendor)) {
175
+ const v = vendor[k]
176
+ if (typeof v === 'function' && !_isEngineClass(v) && k.startsWith('create')) {
177
+ return (v as (t: unknown, c: unknown) => unknown)(getAccessToken, config)
178
+ }
179
+ }
180
+ throw new Error(
181
+ ${JSON.stringify(`provider module "${domain}" — vendor index exposes no engine class or create* factory`)}
182
+ )
183
+ }
184
+ export default createConnector
185
+ `;
186
+ }
187
+ //# sourceMappingURL=wrappers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrappers.js","sourceRoot":"","sources":["../src/wrappers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,YAAY,EAAiB,MAAM,qBAAqB,CAAA;AAYjE;;;;;;;;GAQG;AACH,MAAM,cAAc,GAAG,kBAAkB,CAAA;AACzC,MAAM,cAAc,GAAG,mBAAmB,CAAA;AAE1C,2EAA2E;AAC3E,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAClC,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,CAAA;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAc,EAAE,GAAmB;IACpE,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,IAAI,CAAC,KAAK,KAAK,mBAAmB,E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