@geastack/geatsc-plugin-gea 0.1.6

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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +37 -0
  3. package/dist/analyze.d.ts +4 -0
  4. package/dist/analyze.js +195 -0
  5. package/dist/cpp-canvas-colors.d.ts +4 -0
  6. package/dist/cpp-canvas-colors.js +226 -0
  7. package/dist/cpp-field-access.d.ts +49 -0
  8. package/dist/cpp-field-access.js +144 -0
  9. package/dist/cpp-ir-dom-style.d.ts +1 -0
  10. package/dist/cpp-ir-dom-style.js +49 -0
  11. package/dist/cpp-ir.d.ts +30 -0
  12. package/dist/cpp-ir.js +2426 -0
  13. package/dist/cpp-keyed-component-diagnostics.d.ts +8 -0
  14. package/dist/cpp-keyed-component-diagnostics.js +74 -0
  15. package/dist/cpp-keyed-list-diagnostics.d.ts +17 -0
  16. package/dist/cpp-keyed-list-diagnostics.js +84 -0
  17. package/dist/cpp-mounted-lowering.d.ts +81 -0
  18. package/dist/cpp-mounted-lowering.js +2235 -0
  19. package/dist/cpp-mounted.d.ts +25 -0
  20. package/dist/cpp-mounted.js +1376 -0
  21. package/dist/cpp-reactive-component-diagnostics.d.ts +2 -0
  22. package/dist/cpp-reactive-component-diagnostics.js +76 -0
  23. package/dist/cpp-reactive-component.d.ts +14 -0
  24. package/dist/cpp-reactive-component.js +349 -0
  25. package/dist/cpp-replacements.d.ts +14 -0
  26. package/dist/cpp-replacements.js +787 -0
  27. package/dist/cpp-source-replacements.d.ts +11 -0
  28. package/dist/cpp-source-replacements.js +257 -0
  29. package/dist/cpp-store-hub.d.ts +7 -0
  30. package/dist/cpp-store-hub.js +160 -0
  31. package/dist/cpp-store-method-body-parser.d.ts +2 -0
  32. package/dist/cpp-store-method-body-parser.js +392 -0
  33. package/dist/cpp-store-method-context.d.ts +48 -0
  34. package/dist/cpp-store-method-context.js +114 -0
  35. package/dist/cpp-store-method-expressions.d.ts +12 -0
  36. package/dist/cpp-store-method-expressions.js +1263 -0
  37. package/dist/cpp-store-method-replacements.d.ts +5 -0
  38. package/dist/cpp-store-method-replacements.js +1521 -0
  39. package/dist/cpp-store-method-targets.d.ts +19 -0
  40. package/dist/cpp-store-method-targets.js +296 -0
  41. package/dist/cpp-store-typed-arrays.d.ts +2 -0
  42. package/dist/cpp-store-typed-arrays.js +655 -0
  43. package/dist/cpp-stores.d.ts +73 -0
  44. package/dist/cpp-stores.js +1739 -0
  45. package/dist/cpp-template-renderer.d.ts +23 -0
  46. package/dist/cpp-template-renderer.js +3530 -0
  47. package/dist/css-style-declaration-shims.d.ts +3 -0
  48. package/dist/css-style-declaration-shims.js +47 -0
  49. package/dist/host-declarations.d.ts +11 -0
  50. package/dist/host-declarations.js +320 -0
  51. package/dist/host-shims.d.ts +3 -0
  52. package/dist/host-shims.js +3217 -0
  53. package/dist/index.d.ts +3 -0
  54. package/dist/index.js +1239 -0
  55. package/dist/load-ir.d.ts +7 -0
  56. package/dist/load-ir.js +40 -0
  57. package/dist/types.d.ts +604 -0
  58. package/dist/types.js +1 -0
  59. package/dist/utils.d.ts +26 -0
  60. package/dist/utils.js +723 -0
  61. package/dist/validate.d.ts +3 -0
  62. package/dist/validate.js +226 -0
  63. package/package.json +57 -0
@@ -0,0 +1,3 @@
1
+ import type { GeaIrBundleV1, GeaIrSourceSpan, PluginDiagnostic } from './types.js';
2
+ export declare function validateIr(ir: GeaIrBundleV1, file: string): PluginDiagnostic[];
3
+ export declare function sourceDiagnostic(file: string, span: GeaIrSourceSpan | undefined, message: string): PluginDiagnostic;
@@ -0,0 +1,226 @@
1
+ import fs from 'node:fs';
2
+ import { isRecord } from './utils.js';
3
+ const supportedSlotKinds = new Set([
4
+ 'text',
5
+ 'attr',
6
+ 'bool',
7
+ 'class',
8
+ 'style',
9
+ 'value',
10
+ 'event',
11
+ 'ref',
12
+ 'mount',
13
+ 'direct-fn',
14
+ 'conditional',
15
+ 'keyed-list',
16
+ 'html',
17
+ ]);
18
+ const supportedRuntimeBases = new Set(['static', 'static-element', 'compiled', 'tiny-reactive', 'lean-reactive', 'reactive']);
19
+ export function validateIr(ir, file) {
20
+ const diagnostics = [];
21
+ if (typeof ir.entry !== 'string')
22
+ diagnostics.push(baseDiagnostic(file, 'entry must be a string'));
23
+ for (const module of ir.modules)
24
+ validateModule(module, file, diagnostics);
25
+ for (const component of ir.components)
26
+ validateComponent(component, file, diagnostics);
27
+ for (const store of ir.stores)
28
+ validateStore(store, file, diagnostics);
29
+ for (const capability of ir.hostCapabilities) {
30
+ if (typeof capability !== 'string')
31
+ diagnostics.push(baseDiagnostic(file, 'hostCapabilities entries must be strings'));
32
+ }
33
+ return diagnostics;
34
+ }
35
+ function validateModule(module, file, diagnostics) {
36
+ if (!isRecord(module)) {
37
+ diagnostics.push(baseDiagnostic(file, 'module entries must be objects'));
38
+ return;
39
+ }
40
+ if (typeof module.id !== 'string')
41
+ diagnostics.push(baseDiagnostic(file, 'module.id must be a string'));
42
+ if (typeof module.file !== 'string')
43
+ diagnostics.push(baseDiagnostic(file, 'module.file must be a string'));
44
+ if (!Array.isArray(module.components))
45
+ diagnostics.push(baseDiagnostic(file, 'module.components must be an array'));
46
+ if (!Array.isArray(module.stores))
47
+ diagnostics.push(baseDiagnostic(file, 'module.stores must be an array'));
48
+ }
49
+ function validateComponent(component, file, diagnostics) {
50
+ if (!isRecord(component)) {
51
+ diagnostics.push(baseDiagnostic(file, 'component entries must be objects'));
52
+ return;
53
+ }
54
+ const componentFile = typeof component.module === 'string' ? component.module : file;
55
+ if (typeof component.id !== 'string')
56
+ diagnostics.push(componentDiagnostic(componentFile, component, 'component.id must be a string'));
57
+ if (typeof component.module !== 'string')
58
+ diagnostics.push(componentDiagnostic(componentFile, component, 'component.module must be a string'));
59
+ if (typeof component.exportName !== 'string') {
60
+ diagnostics.push(componentDiagnostic(componentFile, component, 'component.exportName must be a string'));
61
+ }
62
+ if (typeof component.runtimeBase !== 'string' || !supportedRuntimeBases.has(component.runtimeBase)) {
63
+ diagnostics.push(componentDiagnostic(componentFile, component, `unsupported component runtime base: ${String(component.runtimeBase)}`));
64
+ }
65
+ if (!isRecord(component.template)) {
66
+ diagnostics.push(componentDiagnostic(componentFile, component, 'component.template must be an object'));
67
+ return;
68
+ }
69
+ if (typeof component.template.html !== 'string')
70
+ diagnostics.push(componentDiagnostic(componentFile, component, 'template.html must be a string'));
71
+ if (!Array.isArray(component.template.slots)) {
72
+ diagnostics.push(componentDiagnostic(componentFile, component, 'template.slots must be an array'));
73
+ return;
74
+ }
75
+ for (const slot of component.template.slots)
76
+ validateSlot(slot, componentFile, component, diagnostics);
77
+ }
78
+ function validateSlot(slot, file, component, diagnostics) {
79
+ if (!isRecord(slot)) {
80
+ diagnostics.push(componentDiagnostic(file, component, 'slot entries must be objects'));
81
+ return;
82
+ }
83
+ if (typeof slot.index !== 'number')
84
+ diagnostics.push(componentDiagnostic(file, component, 'slot.index must be a number'));
85
+ if (typeof slot.kind !== 'string' || !supportedSlotKinds.has(slot.kind)) {
86
+ diagnostics.push(componentDiagnostic(file, component, `unsupported slot kind: ${String(slot.kind)}`));
87
+ }
88
+ if (!Array.isArray(slot.walk) || !slot.walk.every((part) => typeof part === 'number')) {
89
+ diagnostics.push(componentDiagnostic(file, component, 'slot.walk must be a number array'));
90
+ }
91
+ if (slot.exprPath !== undefined && (!Array.isArray(slot.exprPath) || !slot.exprPath.every((part) => typeof part === 'string'))) {
92
+ diagnostics.push(componentDiagnostic(file, component, 'slot.exprPath must be a string array'));
93
+ }
94
+ if (slot.exprObjectFields !== undefined)
95
+ validateExpressionObjectFields(slot.exprObjectFields, file, component, diagnostics);
96
+ if (slot.kind === 'keyed-list' && isRecord(slot.payload) && slot.payload.rowTemplate !== undefined) {
97
+ validateKeyedListRowTemplate(slot.payload.rowTemplate, file, component, diagnostics);
98
+ }
99
+ }
100
+ function validateStore(store, file, diagnostics) {
101
+ if (!isRecord(store)) {
102
+ diagnostics.push(baseDiagnostic(file, 'store entries must be objects'));
103
+ return;
104
+ }
105
+ const storeFile = typeof store.module === 'string' ? store.module : file;
106
+ if (typeof store.id !== 'string')
107
+ diagnostics.push(storeDiagnostic(storeFile, store, 'store.id must be a string'));
108
+ if (typeof store.module !== 'string')
109
+ diagnostics.push(storeDiagnostic(storeFile, store, 'store.module must be a string'));
110
+ if (typeof store.className !== 'string')
111
+ diagnostics.push(storeDiagnostic(storeFile, store, 'store.className must be a string'));
112
+ if (store.runtimeBase !== 'compiled' && store.runtimeBase !== 'lean') {
113
+ diagnostics.push(storeDiagnostic(storeFile, store, `unsupported store runtime base: ${String(store.runtimeBase)}`));
114
+ }
115
+ if (!Array.isArray(store.fields)) {
116
+ diagnostics.push(storeDiagnostic(storeFile, store, 'store.fields must be an array'));
117
+ return;
118
+ }
119
+ const names = new Set();
120
+ for (const field of store.fields) {
121
+ if (!isRecord(field) || typeof field.name !== 'string') {
122
+ diagnostics.push(storeDiagnostic(storeFile, store, 'store fields must have string names'));
123
+ continue;
124
+ }
125
+ if (names.has(field.name))
126
+ diagnostics.push(storeDiagnostic(storeFile, store, `duplicate store field: ${field.name}`));
127
+ names.add(field.name);
128
+ if (field.shape)
129
+ validateStoreShape(field.shape, storeFile, store, diagnostics);
130
+ }
131
+ }
132
+ function validateStoreShape(shape, file, store, diagnostics) {
133
+ if (!isRecord(shape) || typeof shape.kind !== 'string') {
134
+ diagnostics.push(storeDiagnostic(file, store, 'store field shape must be an object with a kind'));
135
+ return;
136
+ }
137
+ const shapeKind = shape.kind;
138
+ if (shapeKind === 'array') {
139
+ if (shape.element)
140
+ validateStoreShape(shape.element, file, store, diagnostics);
141
+ return;
142
+ }
143
+ if (shapeKind === 'object') {
144
+ if (!Array.isArray(shape.fields)) {
145
+ diagnostics.push(storeDiagnostic(file, store, 'object store shape fields must be an array'));
146
+ return;
147
+ }
148
+ for (const field of shape.fields) {
149
+ if (!isRecord(field) || typeof field.name !== 'string') {
150
+ diagnostics.push(storeDiagnostic(file, store, 'object store shape fields must have string names'));
151
+ continue;
152
+ }
153
+ if (field.shape)
154
+ validateStoreShape(field.shape, file, store, diagnostics);
155
+ }
156
+ return;
157
+ }
158
+ if (shapeKind === 'literal') {
159
+ if (!['string', 'number', 'boolean', 'null'].includes(String(shape.valueType))) {
160
+ diagnostics.push(storeDiagnostic(file, store, `unsupported literal store shape: ${String(shape.valueType)}`));
161
+ }
162
+ return;
163
+ }
164
+ diagnostics.push(storeDiagnostic(file, store, `unsupported store shape kind: ${shapeKind}`));
165
+ }
166
+ function validateExpressionObjectFields(fields, file, component, diagnostics) {
167
+ if (!Array.isArray(fields)) {
168
+ diagnostics.push(componentDiagnostic(file, component, 'slot.exprObjectFields must be an array'));
169
+ return;
170
+ }
171
+ for (const field of fields) {
172
+ if (!isRecord(field) || typeof field.name !== 'string' || typeof field.expr !== 'string') {
173
+ diagnostics.push(componentDiagnostic(file, component, 'slot.exprObjectFields entries must have string name and expr'));
174
+ continue;
175
+ }
176
+ if (field.exprPath !== undefined && (!Array.isArray(field.exprPath) || !field.exprPath.every((part) => typeof part === 'string'))) {
177
+ diagnostics.push(componentDiagnostic(file, component, 'slot.exprObjectFields.exprPath must be a string array'));
178
+ }
179
+ }
180
+ }
181
+ function validateKeyedListRowTemplate(rowTemplate, file, component, diagnostics) {
182
+ if (!isRecord(rowTemplate)) {
183
+ diagnostics.push(componentDiagnostic(file, component, 'keyed-list payload.rowTemplate must be an object'));
184
+ return;
185
+ }
186
+ if (typeof rowTemplate.html !== 'string')
187
+ diagnostics.push(componentDiagnostic(file, component, 'keyed-list rowTemplate.html must be a string'));
188
+ if (!Array.isArray(rowTemplate.slots)) {
189
+ diagnostics.push(componentDiagnostic(file, component, 'keyed-list rowTemplate.slots must be an array'));
190
+ return;
191
+ }
192
+ for (const rowSlot of rowTemplate.slots)
193
+ validateSlot(rowSlot, file, component, diagnostics);
194
+ }
195
+ function baseDiagnostic(file, message) {
196
+ return { kind: 'unsupported', code: 'gea-ir', file, message };
197
+ }
198
+ function componentDiagnostic(file, component, message) {
199
+ return sourceDiagnostic(file, component.sourceSpan, message);
200
+ }
201
+ function storeDiagnostic(file, store, message) {
202
+ return sourceDiagnostic(file, store.sourceSpan, message);
203
+ }
204
+ export function sourceDiagnostic(file, span, message) {
205
+ const diagnostic = { kind: 'unsupported', code: 'gea-ir', file, message };
206
+ if (span?.start === undefined || !fs.existsSync(file))
207
+ return diagnostic;
208
+ const location = offsetLocation(fs.readFileSync(file, 'utf8'), span.start);
209
+ diagnostic.line = location.line;
210
+ diagnostic.column = location.column;
211
+ return diagnostic;
212
+ }
213
+ function offsetLocation(text, offset) {
214
+ let line = 1;
215
+ let column = 1;
216
+ for (let i = 0; i < Math.min(offset, text.length); i++) {
217
+ if (text.charCodeAt(i) === 10) {
218
+ line++;
219
+ column = 1;
220
+ }
221
+ else {
222
+ column++;
223
+ }
224
+ }
225
+ return { line, column };
226
+ }
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@geastack/geatsc-plugin-gea",
3
+ "version": "0.1.6",
4
+ "description": "Gea IR backend plugin for geatsc.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/geastack/core.git",
9
+ "directory": "packages/geatsc-plugin-gea"
10
+ },
11
+ "engines": {
12
+ "node": ">=20.19"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./host-shims": {
24
+ "types": "./dist/host-shims.d.ts",
25
+ "import": "./dist/host-shims.js",
26
+ "default": "./dist/host-shims.js"
27
+ },
28
+ "./cpp-ir": {
29
+ "types": "./dist/cpp-ir.d.ts",
30
+ "import": "./dist/cpp-ir.js",
31
+ "default": "./dist/cpp-ir.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "architecture": "node scripts/architecture/ratchet-gea-rendered-cpp-source.mjs",
43
+ "prebuild": "npm run architecture",
44
+ "prepublishOnly": "npm run build",
45
+ "build": "tsc -p tsconfig.json",
46
+ "test": "npm run build && node --test test/*.test.mjs",
47
+ "pretypecheck": "npm run architecture",
48
+ "typecheck": "tsc -p tsconfig.json --noEmit"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.15.3",
52
+ "typescript": "^5.9.3"
53
+ },
54
+ "peerDependencies": {
55
+ "typescript": ">=5.9.3"
56
+ }
57
+ }