@thatopen/services 0.37.0 → 0.37.1

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/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "access": "public"
16
16
  },
17
17
  "private": false,
18
- "version": "0.37.0",
18
+ "version": "0.37.1",
19
19
  "main": "dist/index.cjs.js",
20
20
  "module": "dist/index.es.js",
21
21
  "types": "dist/index.d.ts",
@@ -0,0 +1,35 @@
1
+ // 🔴 web-ifc WITHOUT ITS IFC READER (Antonio 24-11: IFC files are converted by the platform when uploaded, never in the browser).
2
+ // The engine libraries import web-ifc whole (5.8 MB of the app's bundle) and use, from it, its constants (an IFC class's code,
3
+ // enums such as the log levels) and the reader, which this app never runs. `thatopen serve` and the vite build answer `web-ifc`
4
+ // with the module this writes: every constant of the installed web-ifc with its own value, read from it at build time (so it
5
+ // follows a new web-ifc by itself), and in place of everything else (the reader, the schemas' classes) a stand-in that says why
6
+ // when it is used. Not imported by the app: run at build time only.
7
+ import { createRequire } from "node:module";
8
+ import { join } from "node:path";
9
+
10
+ const isPlain = (value) => value === null || ["number", "string", "boolean"].includes(typeof value);
11
+
12
+ /** The source of the light web-ifc, from the one installed in the app at `cwd`. */
13
+ export function lightWebIfc(cwd) {
14
+ const require = createRequire(join(cwd, "package.json"));
15
+ const real = require("web-ifc");
16
+ const lines = [
17
+ `const unavailable = (what) => { throw new Error(\`\${what}: IFC files are converted by the platform when uploaded, not in this app.\`); };`,
18
+ // (Anything but a constant: made, read into and called freely; it says why only when it is asked to do something.)
19
+ `const standIn = (what) => new Proxy(function () {}, {`,
20
+ ` get: (_, key) => (key === "then" || typeof key === "symbol" ? undefined : key === "prototype" ? {} : standIn(\`\${what}.\${key}\`)),`,
21
+ ` apply: () => unavailable(what),`,
22
+ ` construct: () => new Proxy({}, { get: (_, key) => (key === "then" || typeof key === "symbol" ? undefined : (...args) => unavailable(\`\${what}.\${String(key)}\`)) }),`,
23
+ `});`,
24
+ ];
25
+ for (const name of Object.keys(real)) {
26
+ if (name === "default" || !/^[A-Za-z_$][\w$]*$/.test(name)) continue;
27
+ const value = real[name];
28
+ if (isPlain(value)) lines.push(`export const ${name} = ${JSON.stringify(value)};`);
29
+ // (An enum, as the log levels: its values as they are.)
30
+ else if (value && typeof value === "object" && !Array.isArray(value) && Object.values(value).every(isPlain))
31
+ lines.push(`export const ${name} = ${JSON.stringify(value)};`);
32
+ else lines.push(`export const ${name} = standIn(${JSON.stringify(name)});`);
33
+ }
34
+ return lines.join("\n");
35
+ }
@@ -42,7 +42,25 @@ const webgpuAliases = existsSync('src/webgpu/webgpu-lines.mjs')
42
42
  ]
43
43
  : [];
44
44
 
45
+ // web-ifc without its IFC reader, as `thatopen serve` builds it: the platform converts IFC files on upload, and this app only
46
+ // uses web-ifc's constants (`src/webgpu/web-ifc-light.mjs` writes them from the web-ifc installed).
47
+ const LIGHT_WEB_IFC = '\0web-ifc-light';
48
+ const webIfcLight = existsSync('src/webgpu/web-ifc-light.mjs')
49
+ ? [{
50
+ // (The plugin's name kept in a constant: `thatopen serve` takes the first quoted name in this file as the app's.)
51
+ name: LIGHT_WEB_IFC.slice(1),
52
+ enforce: 'pre',
53
+ resolveId: (source) => (source === 'web-ifc' ? LIGHT_WEB_IFC : null),
54
+ async load(id) {
55
+ if (id !== LIGHT_WEB_IFC) return null;
56
+ const { lightWebIfc } = await import('./src/webgpu/web-ifc-light.mjs');
57
+ return lightWebIfc(process.cwd());
58
+ },
59
+ }]
60
+ : [];
61
+
45
62
  export default defineConfig({
63
+ plugins: webIfcLight,
46
64
  resolve: {
47
65
  alias: [
48
66
  ...webgpuAliases,