@classcad/client 0.0.0-stage → 3.0.0-beta.20261119100608
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/README.md +20 -2
- package/bin/buerli-classcad.cjs +23 -0
- package/build/cjs/BuerliCadFacade.js +718 -0
- package/build/cjs/cclass/utils/assembly.js +687 -0
- package/build/cjs/cclass/utils/base.js +136 -0
- package/build/cjs/cclass/utils/index.js +99 -0
- package/build/cjs/cclass/utils/part.js +153 -0
- package/build/cjs/classcadEngine.js +33 -0
- package/build/cjs/createApi.js +71 -0
- package/build/cjs/createUnwrappedApi.js +43 -0
- package/build/cjs/facade.js +103 -0
- package/build/cjs/globals.js +157 -0
- package/build/cjs/index.js +102 -0
- package/build/cjs/io/AwvNodeClient.js +290 -0
- package/build/cjs/io/SocketIOClient.js +339 -0
- package/build/cjs/io/Transaction.js +134 -0
- package/build/cjs/io/WASMClient.js +433 -0
- package/build/cjs/io/WSClient.js +646 -0
- package/build/cjs/io/engineKey.js +202 -0
- package/build/cjs/re-export.js +35 -0
- package/build/cjs/session/host.js +479 -0
- package/build/cjs/session/identity.js +38 -0
- package/build/cjs/session/selection.js +283 -0
- package/build/cjs/session/share.js +229 -0
- package/build/cjs/session/types.js +23 -0
- package/build/cjs/test/SocketIOClient.spec.js +178 -0
- package/build/cjs/types/ComClient.js +10 -0
- package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
- package/build/cjs/utils/createRecursiveScene.js +140 -0
- package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
- package/build/cjs/utils/index.js +20 -0
- package/build/cjs/utils/polyline.js +65 -0
- package/build/cjs/utils/waitForSelect.js +29 -0
- package/build/esm/BuerliCadFacade.js +714 -0
- package/build/esm/cclass/utils/assembly.js +665 -0
- package/build/esm/cclass/utils/base.js +127 -0
- package/build/esm/cclass/utils/index.js +62 -0
- package/build/esm/cclass/utils/part.js +144 -0
- package/build/esm/classcadEngine.js +30 -0
- package/build/esm/createApi.js +66 -0
- package/build/esm/createUnwrappedApi.js +39 -0
- package/build/esm/facade.js +98 -0
- package/build/esm/globals.js +150 -0
- package/build/esm/index.js +80 -0
- package/build/esm/io/AwvNodeClient.js +286 -0
- package/build/esm/io/SocketIOClient.js +332 -0
- package/build/esm/io/Transaction.js +130 -0
- package/build/esm/io/WASMClient.js +429 -0
- package/build/esm/io/WSClient.js +642 -0
- package/build/esm/io/engineKey.js +196 -0
- package/build/esm/re-export.js +3 -0
- package/build/esm/session/host.js +474 -0
- package/build/esm/session/identity.js +34 -0
- package/build/esm/session/selection.js +277 -0
- package/build/esm/session/share.js +221 -0
- package/build/esm/session/types.js +20 -0
- package/build/esm/test/SocketIOClient.spec.js +178 -0
- package/build/esm/types/ComClient.js +7 -0
- package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
- package/build/esm/utils/createRecursiveScene.js +136 -0
- package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
- package/build/esm/utils/index.js +4 -0
- package/build/esm/utils/polyline.js +60 -0
- package/build/esm/utils/waitForSelect.js +23 -0
- package/build/types/BuerliCadFacade.d.ts +410 -0
- package/build/types/cclass/utils/assembly.d.ts +180 -0
- package/build/types/cclass/utils/base.d.ts +55 -0
- package/build/types/cclass/utils/index.d.ts +46 -0
- package/build/types/cclass/utils/part.d.ts +46 -0
- package/build/types/classcadEngine.d.ts +40 -0
- package/build/types/createApi.d.ts +65 -0
- package/build/types/createUnwrappedApi.d.ts +36 -0
- package/build/types/facade.d.ts +9 -0
- package/build/types/globals.d.ts +79 -0
- package/build/types/index.d.ts +82 -0
- package/build/types/io/AwvNodeClient.d.ts +182 -0
- package/build/types/io/SocketIOClient.d.ts +84 -0
- package/build/types/io/Transaction.d.ts +56 -0
- package/build/types/io/WASMClient.d.ts +239 -0
- package/build/types/io/WSClient.d.ts +242 -0
- package/build/types/io/engineKey.d.ts +137 -0
- package/build/types/re-export.d.ts +6 -0
- package/build/types/session/host.d.ts +108 -0
- package/build/types/session/identity.d.ts +46 -0
- package/build/types/session/selection.d.ts +164 -0
- package/build/types/session/share.d.ts +131 -0
- package/build/types/session/types.d.ts +113 -0
- package/build/types/test/SocketIOClient.spec.d.ts +0 -0
- package/build/types/types/ComClient.d.ts +307 -0
- package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
- package/build/types/utils/createRecursiveScene.d.ts +24 -0
- package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
- package/build/types/utils/index.d.ts +4 -0
- package/build/types/utils/polyline.d.ts +43 -0
- package/build/types/utils/waitForSelect.d.ts +4 -0
- package/doc/api/advanced/connection.md +488 -0
- package/doc/api/clients.md +2045 -0
- package/doc/api/engine-keys.md +230 -0
- package/doc/api/index.md +58 -0
- package/doc/api/modeling.md +682 -0
- package/doc/api/other.md +33 -0
- package/doc/api/session-sharing.md +706 -0
- package/package.json +60 -4
- package/test/classcadEngine.test.cjs +44 -0
- package/test/connect.test.cjs +81 -0
- package/test/engineKey.test.cjs +80 -0
- package/test/onClient.test.cjs +82 -0
- package/typedoc.json +8 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ServerError } from '../../types/ComClient';
|
|
2
|
+
import * as assembly from './assembly';
|
|
3
|
+
import * as base from './base';
|
|
4
|
+
import * as part from './part';
|
|
5
|
+
/**
|
|
6
|
+
* The message type (`'info'`, `'warning'`, `'error'`) for errors in the form older engines report them.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const getMessageTypeForErrors: (errors: ServerError[]) => "error" | "info" | "warning";
|
|
11
|
+
/**
|
|
12
|
+
* Helpers that look things up in a drawing's structure tree: classes, ancestors, work geometry, sketches, constraints.
|
|
13
|
+
*
|
|
14
|
+
* They read the tree in the SDK's store; none of them calls the engine.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { ccUtils, ScgClassType } from '@classcad/client'
|
|
19
|
+
*
|
|
20
|
+
* // The part a picked solid belongs to, and that part's sketches
|
|
21
|
+
* const partId = ccUtils.base.getAncestorIdByClass(facade.drawingId, solidId, ScgClassType.CCPart)
|
|
22
|
+
* if (partId !== null) {
|
|
23
|
+
* const sketches = ccUtils.part.getSketch(facade.drawingId, partId)
|
|
24
|
+
* const tree = await facade.tree()
|
|
25
|
+
* console.log(tree[partId].name, sketches.map(id => tree[id].name))
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
* @advanced
|
|
29
|
+
* @category Modeling
|
|
30
|
+
*/
|
|
31
|
+
export declare const ccUtils: {
|
|
32
|
+
/**
|
|
33
|
+
* Class checks and tree walks: `isA` (a class or one derived from it), `getChildren`, `getAncestors`,
|
|
34
|
+
* `getAncestorIdByClass`, `getDescendants`, `findObject` (by identifier or name).
|
|
35
|
+
*/
|
|
36
|
+
base: typeof base;
|
|
37
|
+
/**
|
|
38
|
+
* Assemblies: `findProduct` (of an instance), `getInstance`, `getPartTemplate`, `getAssemblyTemplate`,
|
|
39
|
+
* `getTransformation`, `getMatePath`, `getWorkGeometry`, and the constraints (`getConstraint`,
|
|
40
|
+
* `getFastenedConstraint`, `getRevoluteConstraint`, …).
|
|
41
|
+
*/
|
|
42
|
+
assembly: typeof assembly;
|
|
43
|
+
/** Parts: `getWorkGeometry`, `getSketch`, `getSketchRegion`, `getSketchlines`. */
|
|
44
|
+
part: typeof part;
|
|
45
|
+
};
|
|
46
|
+
export default ccUtils;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DrawingID, ObjectID, WorkGeomType } from '@classcad/sdkjs';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use getWorkGeometry() instead, getWorkCoordSystem() will be removed in a future release.
|
|
4
|
+
*
|
|
5
|
+
* Returns all workcoordsystems of given reference with specified name.
|
|
6
|
+
* If _wcsName_ is undefined, all workcoordsystems of given reference will be returned.
|
|
7
|
+
*
|
|
8
|
+
* @param drawingId The drawing id.
|
|
9
|
+
* @param refId The product reference to look for wcs.
|
|
10
|
+
* @param wcsName The name of wcs to look for.
|
|
11
|
+
* @returns An array of ids of all workcoordsystems found. The array is empty if nothing was found.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getWorkCoordSystem: (drawingId: DrawingID, refId: ObjectID, wcsName?: string) => ObjectID[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns all work geometry of given type and given reference with specified name.
|
|
16
|
+
* If wgName is undefined, all work geometry of given reference will be returned.
|
|
17
|
+
*
|
|
18
|
+
* @param drawingId The drawing id.
|
|
19
|
+
* @param refId The product reference to look for work geometry.
|
|
20
|
+
* @param type The type of work geometry to look for
|
|
21
|
+
* @param wgName The name of work geometry to look for.
|
|
22
|
+
* @returns An array of ids of all found work geometry. The array is empty if nothing was found.
|
|
23
|
+
*/
|
|
24
|
+
export declare const getWorkGeometry: (drawingId: DrawingID, refId: ObjectID, type: WorkGeomType, wgName?: string) => ObjectID[];
|
|
25
|
+
/**
|
|
26
|
+
* Returns all sketch regions of given reference with specified name.
|
|
27
|
+
* If sketchRegionName is undefined, all sketch regions of given reference will be returned.
|
|
28
|
+
*
|
|
29
|
+
* @param drawingId The drawing id.
|
|
30
|
+
* @param refId The product reference to look for sketch region.
|
|
31
|
+
* @param sketchRegionName The name of sketch region to look for.
|
|
32
|
+
* @returns An array of ids of all found sketch regions. The array is empty if nothing was found.
|
|
33
|
+
*/
|
|
34
|
+
export declare const getSketchRegion: (drawingId: DrawingID, refId: ObjectID, sketchRegionName?: string) => number[];
|
|
35
|
+
export declare const getSketch: (drawingId: DrawingID, refId: ObjectID, sketchName?: string) => number[];
|
|
36
|
+
/**
|
|
37
|
+
* Returns all sketch lines from a sketch or sketch regions
|
|
38
|
+
* @param sketchOrRegionIds id of the sketch or ids of the sketch regions
|
|
39
|
+
* @returns the sketchlines as array or undefined if empty
|
|
40
|
+
*/
|
|
41
|
+
export declare const getSketchlines: (drawingId: DrawingID, sketchOrRegionIds: number | number[]) => number[] | undefined;
|
|
42
|
+
export declare const calculateRollbackMovement: (oldIndex: number, newIndex: number, featureIds: ObjectID[], offset?: number) => {
|
|
43
|
+
moveTo: "end" | "before";
|
|
44
|
+
featureId: ObjectID;
|
|
45
|
+
index: number;
|
|
46
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ClassCAD engine a version of `@classcad/client` is built against: see {@link classcadEngine}.
|
|
3
|
+
*
|
|
4
|
+
* @category Clients
|
|
5
|
+
*/
|
|
6
|
+
export type ClassCadEngine = {
|
|
7
|
+
/** The ClassCAD version: `21.2.0`, or `21.2.1-alpha.169`. */
|
|
8
|
+
readonly version: string;
|
|
9
|
+
/** `release`, `alpha` (what a beta of the SDK is built against) or `dev` (a feature branch). */
|
|
10
|
+
readonly quality: string;
|
|
11
|
+
/** The bundle on awvstatic.com: the engine for every platform, the server, the API packages. */
|
|
12
|
+
readonly url: string;
|
|
13
|
+
/** The bundle's `metadata.json`: its files, with their URLs and checksums. */
|
|
14
|
+
readonly metadataUrl: string;
|
|
15
|
+
/** The WebAssembly engine {@link WASMClient} loads when it is given no `url`. */
|
|
16
|
+
readonly wasmUrl: string;
|
|
17
|
+
/** The `@classcad/api-js` package this package is built with, as a tarball. */
|
|
18
|
+
readonly apiUrl: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The ClassCAD engine this package is built against: its version, its quality, and where its bundle is.
|
|
22
|
+
*
|
|
23
|
+
* `@classcad/api-js`, the ClassCAD API this package calls, is generated by the ClassCAD engine, and carries the
|
|
24
|
+
* version and the quality of the bundle it belongs to. That bundle is the engine this version of the SDK is made
|
|
25
|
+
* for: {@link WASMClient} loads its WebAssembly from `wasmUrl`, and a host that runs the engine behind a server
|
|
26
|
+
* ({@link WSClient}, {@link SocketIOClient}) installs the same version, from `url`. A beta of the SDK is built
|
|
27
|
+
* against an `alpha` build, a stable release against a `release`.
|
|
28
|
+
*
|
|
29
|
+
* `npx @classcad/client info` prints the same (`--json` for the object).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { classcadEngine } from '@classcad/client'
|
|
34
|
+
*
|
|
35
|
+
* console.log(`Built against ClassCAD ${classcadEngine.version} (${classcadEngine.quality}): ${classcadEngine.url}`)
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @category Clients
|
|
39
|
+
*/
|
|
40
|
+
export declare const classcadEngine: ClassCadEngine;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DrawingID } from '@classcad/sdkjs';
|
|
2
|
+
import { V0T, V1T } from '@classcad/api-js';
|
|
3
|
+
export type ApiType = V1T & {
|
|
4
|
+
/** @deprecated */
|
|
5
|
+
v0: V0T;
|
|
6
|
+
v1: V1T;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The low-level facade a drawing's API calls go through: one ClassCAD function, called by its name.
|
|
10
|
+
*
|
|
11
|
+
* `callSafeApiV(version, namespace, func, args, options)` runs `<version>.<namespace>.<func>` and resolves to the
|
|
12
|
+
* engine's reply, `{ result, messages, maxLevel }`; `callSafeApi` takes the namespace with its version
|
|
13
|
+
* (`'v1.part'`). `fetchTree` loads the structure tree anew, `callUnsafeApi` sends a command as it is. Replies are
|
|
14
|
+
* handled as in {@link createApi}. Use it for a function the typed API does not have, or one picked at runtime.
|
|
15
|
+
*
|
|
16
|
+
* @param drawingId - The drawing whose client the calls go to.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { getApiFacade } from '@classcad/client'
|
|
20
|
+
*
|
|
21
|
+
* // A call named at runtime, e.g. by a script or a tool an AI agent calls
|
|
22
|
+
* async function call(name: string, args: Record<string, unknown>) {
|
|
23
|
+
* const [namespace, func] = name.split('.') // 'part.box'
|
|
24
|
+
* const { result, messages } = await getApiFacade(drawingId).callSafeApiV('v1', namespace, func, args)
|
|
25
|
+
* return { result, messages }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* const { result: part } = await call('part.create', { name: 'Part' })
|
|
29
|
+
* await call('part.box', { id: part, length: 50 })
|
|
30
|
+
* ```
|
|
31
|
+
* @advanced
|
|
32
|
+
* @category Modeling
|
|
33
|
+
*/
|
|
34
|
+
export declare const getApiFacade: (drawingId: DrawingID) => import("@classcad/api-js").IFacade & {
|
|
35
|
+
callUnsafeApi: (command: string) => Promise<import("@classcad/api-js").FacadeReturn>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The ClassCAD API of a drawing; every call resolves to the engine's reply, `{ result, messages, maxLevel }`.
|
|
39
|
+
*
|
|
40
|
+
* `v1` holds the namespaces (`part`, `sketch`, `assembly`, `solid`, `curve`, `common`, `drawing2d`); they are also
|
|
41
|
+
* on the object itself, so `createApi(id).part` is `createApi(id).v1.part`. A call rejects when the reply carries an
|
|
42
|
+
* error, with that reply, and when the drawing has no client. Warnings and errors are logged and shown as messages
|
|
43
|
+
* of the drawing. `v0`, the old API, is deprecated. {@link createUnwrappedApi} gives the results without the reply
|
|
44
|
+
* around them.
|
|
45
|
+
*
|
|
46
|
+
* @param drawingId - A drawing that is connected, for example by {@link BuerliCadFacade.connect}.
|
|
47
|
+
* @param cached - `true` (default) returns the same object for the drawing on every call, `false` makes a new one.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { BuerliCadFacade, createApi, MessageLevel } from '@classcad/client'
|
|
51
|
+
*
|
|
52
|
+
* const drawingId = await BuerliCadFacade.utils.connect('Bracket')
|
|
53
|
+
* if (drawingId) {
|
|
54
|
+
* const api = createApi(drawingId)
|
|
55
|
+
* const part = (await api.v1.part.create({ name: 'Bracket' })).result!
|
|
56
|
+
* // The reply carries the engine's messages; a warning does not reject
|
|
57
|
+
* const { messages } = await api.v1.part.box({ id: part, length: 80, width: 40, height: 5 })
|
|
58
|
+
* const warnings = messages?.filter(m => m.level === MessageLevel.warning) ?? []
|
|
59
|
+
* if (warnings.length) console.warn(warnings.map(m => m.message))
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
* @advanced
|
|
63
|
+
* @category Modeling
|
|
64
|
+
*/
|
|
65
|
+
export declare const createApi: (drawingId: DrawingID, cached?: boolean) => ApiType;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DrawingID } from '@classcad/sdkjs';
|
|
2
|
+
import { V0T, V1UnwrapT } from '@classcad/api-js';
|
|
3
|
+
export type UnwrappedApiType = V1UnwrapT & {
|
|
4
|
+
/** @deprecated */
|
|
5
|
+
v0: V0T;
|
|
6
|
+
v1: V1UnwrapT;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The ClassCAD API of a drawing, unwrapped: calls resolve to their result and reject on an engine error.
|
|
10
|
+
*
|
|
11
|
+
* The same namespaces as {@link createApi} (`v1.part`, `v1.sketch`, …, also on the object itself); this is what
|
|
12
|
+
* {@link BuerliCadFacade.api} is. A rejection carries the engine's reply (`{ result, messages, maxLevel }`).
|
|
13
|
+
* Warnings are logged and shown as messages of the drawing.
|
|
14
|
+
*
|
|
15
|
+
* @param drawingId - A drawing that is connected, for example by {@link BuerliCadFacade.connect}.
|
|
16
|
+
* @param cached - `true` (default) returns the same object for the drawing on every call, `false` makes a new one.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { BuerliCadFacade, createUnwrappedApi } from '@classcad/client'
|
|
20
|
+
*
|
|
21
|
+
* const drawingId = await BuerliCadFacade.utils.connect('Plate')
|
|
22
|
+
* if (drawingId) {
|
|
23
|
+
* const api = createUnwrappedApi(drawingId)
|
|
24
|
+
* try {
|
|
25
|
+
* const part = (await api.v1.part.create({ name: 'Plate' }))!
|
|
26
|
+
* await api.v1.part.box({ id: part, length: 200, width: 100, height: 8 })
|
|
27
|
+
* } catch (reply) {
|
|
28
|
+
* // The engine's reply, with the error in its messages
|
|
29
|
+
* console.error(reply)
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
* @advanced
|
|
34
|
+
* @category Modeling
|
|
35
|
+
*/
|
|
36
|
+
export declare const createUnwrappedApi: (drawingId: DrawingID, cached?: boolean) => UnwrappedApiType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DrawingID } from '@classcad/sdkjs';
|
|
2
|
+
import { FacadeOptions, FacadeReturn, IFacade } from '@classcad/api-js';
|
|
3
|
+
export declare const __callAPI: (drawingId: DrawingID, task: string | Array<{
|
|
4
|
+
[apiCommand: string]: any[];
|
|
5
|
+
}>, options?: FacadeOptions) => Promise<FacadeReturn>;
|
|
6
|
+
export declare const facade: (drawingId: DrawingID) => IFacade & {
|
|
7
|
+
/** Runs `command` on the engine as it is, without the typed API around it, and resolves to the engine's reply. */
|
|
8
|
+
callUnsafeApi: (command: string) => Promise<FacadeReturn>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BuerliState, DrawingID } from '@classcad/sdkjs';
|
|
2
|
+
import { AwvNodeClient } from './io/AwvNodeClient';
|
|
3
|
+
/**
|
|
4
|
+
* Makes the client for a new drawing: {@link WASMClient}, {@link WSClient}, {@link SocketIOClient} or another
|
|
5
|
+
* {@link AwvNodeClient}.
|
|
6
|
+
*
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
type ClientFactory = (drawingId: DrawingID) => AwvNodeClient;
|
|
10
|
+
export declare class Globals {
|
|
11
|
+
static factory: ClientFactory;
|
|
12
|
+
static clientCache: Record<DrawingID, AwvNodeClient>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Sets up the SDK: tells it how to reach ClassCAD, with a factory that makes the client for each drawing.
|
|
16
|
+
*
|
|
17
|
+
* Call it once, before the first drawing connects. Every drawing that connects afterwards
|
|
18
|
+
* ({@link BuerliCadFacade.connect}, `BuerliCadFacade.utils.connect`, react-cad, Buerligons) gets its client from
|
|
19
|
+
* `source`; the client connects right after it is made. Calling `init` again replaces the factory for the drawings
|
|
20
|
+
* that connect from then on. `options` go to the SDK's store (`init` of `@classcad/sdkjs`).
|
|
21
|
+
*
|
|
22
|
+
* @param source - Makes the client for a drawing: called with the new drawing's id, returns a client that is not
|
|
23
|
+
* connected yet.
|
|
24
|
+
* @param options - Options of the SDK's store: theme colors, how geometry is shown (`config.geometry`), plugins.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { init, WASMClient } from '@classcad/client'
|
|
28
|
+
*
|
|
29
|
+
* // The engine in the browser, with a public access token from classcad.ch/account
|
|
30
|
+
* init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
|
|
31
|
+
* ```
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { init, SocketIOClient, WSClient } from '@classcad/client'
|
|
35
|
+
*
|
|
36
|
+
* // A ClassCAD server (classcad-socketio)
|
|
37
|
+
* init(drawingId => new SocketIOClient('ws://localhost:9091', drawingId))
|
|
38
|
+
* // Or the native engine's own WebSocket server (classcad-cli worker)
|
|
39
|
+
* init(drawingId => new WSClient('ws://localhost:9094', drawingId))
|
|
40
|
+
* ```
|
|
41
|
+
* @category Clients
|
|
42
|
+
*/
|
|
43
|
+
export declare const init: (source: ClientFactory, options?: Partial<BuerliState["options"]>) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Called with a drawing's client and the drawing's id.
|
|
46
|
+
*
|
|
47
|
+
* @inline
|
|
48
|
+
*/
|
|
49
|
+
type ClientCallback = (client: AwvNodeClient, drawingId: DrawingID) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Calls back with every drawing's client: the ones there are, and each new one before it connects.
|
|
52
|
+
*
|
|
53
|
+
* A new client is passed as soon as the factory has made it. An app that prepares the clients a host makes
|
|
54
|
+
* (session sharing, engine settings) registers here instead of wrapping the host's factory. Returns a function
|
|
55
|
+
* that unregisters.
|
|
56
|
+
*
|
|
57
|
+
* A callback that throws is logged; the drawing connects all the same.
|
|
58
|
+
*
|
|
59
|
+
* @param callback - Called with each client and the id of its drawing.
|
|
60
|
+
* @returns A function that unregisters `callback`.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { onClient, syncSelection, WASMClient, WSClient } from '@classcad/client'
|
|
64
|
+
*
|
|
65
|
+
* // Prepares every client a host makes (react-cad, Buerligons, a facade), before it connects
|
|
66
|
+
* const unregister = onClient((client, drawingId) => {
|
|
67
|
+
* // Shares the selection where the session can be shared
|
|
68
|
+
* if (client instanceof WSClient || client instanceof WASMClient) syncSelection(client)
|
|
69
|
+
* // Hidden objects are not needed in this app
|
|
70
|
+
* client.on('connected', () => client.setEmissionConfig({ sendGraphic_Invisible: false }).catch(console.warn))
|
|
71
|
+
* client.on('conn_error', (_client, reason) => console.error(`Drawing ${drawingId} lost ClassCAD:`, reason))
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
* @category Clients
|
|
75
|
+
*/
|
|
76
|
+
export declare const onClient: (callback: ClientCallback) => () => void;
|
|
77
|
+
/** Hands a client the factory has just made to the onClient callbacks (BuerliCadFacade.utils.connect). */
|
|
78
|
+
export declare const clientMade: (client: AwvNodeClient, drawingId: DrawingID) => void;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connects an app to ClassCAD, the CAD engine, and runs the ClassCAD API on its drawings: the package every sdkjs
|
|
3
|
+
* app starts with. The engine runs in the browser as WebAssembly, or natively behind a server; a session can be
|
|
4
|
+
* shared with other apps and with AI agents.
|
|
5
|
+
*
|
|
6
|
+
* ## What it exposes
|
|
7
|
+
*
|
|
8
|
+
* - {@link init}: sets the SDK up with a factory that makes the client of each drawing.
|
|
9
|
+
* - {@link WASMClient}: runs the engine in the browser, with a public access token (`ccpk_…`).
|
|
10
|
+
* - {@link WSClient}: connects to a native engine's own WebSocket server (`classcad-cli worker`).
|
|
11
|
+
* - {@link SocketIOClient}: connects to the ClassCAD server (`classcad-socketio`).
|
|
12
|
+
* - {@link onClient}: prepares each client a host makes, before it connects.
|
|
13
|
+
* - {@link BuerliCadFacade}: connects a drawing, holds its ClassCAD API (`api.v1.*`) and makes three.js geometry of
|
|
14
|
+
* the model.
|
|
15
|
+
* - {@link resolveEngineKey}: an engine key from an access token, for engines an app starts itself.
|
|
16
|
+
* - {@link classcadEngine}: the ClassCAD engine this package is built against, and where its bundle is.
|
|
17
|
+
* - Session sharing: {@link WSClient.createInvite | createInvite} on a client, {@link buildShareUrl} and
|
|
18
|
+
* {@link getShareTokenFromUrl}, {@link getSessionShareState}, {@link syncSelection}, and the participants'
|
|
19
|
+
* {@link ClientIdentity}.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import * as THREE from 'three'
|
|
24
|
+
* import { init, BuerliCadFacade, WASMClient } from '@classcad/client'
|
|
25
|
+
*
|
|
26
|
+
* // The engine in the browser; a public access token from classcad.ch/account
|
|
27
|
+
* init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
|
|
28
|
+
*
|
|
29
|
+
* const facade = new BuerliCadFacade()
|
|
30
|
+
* await facade.connect()
|
|
31
|
+
* const part = (await facade.api.v1.part.create({ name: 'Part' }))!
|
|
32
|
+
* await facade.api.v1.part.box({ id: part, length: 100, width: 60, height: 20 })
|
|
33
|
+
* await facade.api.v1.part.cylinder({ id: part, diameter: 30, height: 50 })
|
|
34
|
+
*
|
|
35
|
+
* // The model as three.js geometry
|
|
36
|
+
* const geometries = await facade.createBufferGeometry(part)
|
|
37
|
+
* const meshes = geometries?.map(geometry => new THREE.Mesh(geometry, new THREE.MeshStandardMaterial()))
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @categoryDescription Clients
|
|
41
|
+
* Start here: `init` takes a factory that makes the client of each drawing, which connects it to ClassCAD: the engine
|
|
42
|
+
* in the page (`WASMClient`), a native engine (`WSClient`) or the ClassCAD server (`SocketIOClient`).
|
|
43
|
+
*
|
|
44
|
+
* @categoryDescription Modeling
|
|
45
|
+
* `BuerliCadFacade` connects a drawing, runs the ClassCAD API on it (`api.v1.*`) and turns the model into three.js
|
|
46
|
+
* geometry.
|
|
47
|
+
*
|
|
48
|
+
* @categoryDescription Engine Keys
|
|
49
|
+
* The key an engine starts with. A public access token on the `WASMClient` is all most apps need; the rest is for
|
|
50
|
+
* apps with a sign-in of their own, and for servers.
|
|
51
|
+
*
|
|
52
|
+
* @categoryDescription Session Sharing
|
|
53
|
+
* Shares a drawing's session with other apps and AI agents: invites and share links, who is in the session, what
|
|
54
|
+
* they publish, and what they have selected.
|
|
55
|
+
*
|
|
56
|
+
* @categoryDescription Connection
|
|
57
|
+
* The protocol between a client and its engine: requests, replies, and what the engine sends back after a command
|
|
58
|
+
* (`EmissionConfig`). For apps that talk to the engine directly.
|
|
59
|
+
*
|
|
60
|
+
* @packageDocumentation
|
|
61
|
+
*/
|
|
62
|
+
import { createApi, getApiFacade } from './createApi';
|
|
63
|
+
import { createUnwrappedApi } from './createUnwrappedApi';
|
|
64
|
+
import { init, onClient } from './globals';
|
|
65
|
+
export * from './re-export';
|
|
66
|
+
export * from './cclass/utils';
|
|
67
|
+
export * from './classcadEngine';
|
|
68
|
+
export * from './BuerliCadFacade';
|
|
69
|
+
export * from './io/AwvNodeClient';
|
|
70
|
+
export * from './io/SocketIOClient';
|
|
71
|
+
export * from './io/WASMClient';
|
|
72
|
+
export * from './io/engineKey';
|
|
73
|
+
export * from './io/WSClient';
|
|
74
|
+
export * from './session/types';
|
|
75
|
+
export * from './session/share';
|
|
76
|
+
export * from './session/identity';
|
|
77
|
+
export * from './session/selection';
|
|
78
|
+
export { SessionHost } from './session/host';
|
|
79
|
+
export type { EngineReply, SessionHostOptions } from './session/host';
|
|
80
|
+
export { createApi, createUnwrappedApi, getApiFacade, init, onClient };
|
|
81
|
+
export * from './types/ComClient';
|
|
82
|
+
export type { StreamData, StreamMap } from './types/ComClient';
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { DrawingID } from '@classcad/sdkjs';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { EmissionConfig, IComClient, RedoOptions, RequestOptions, ServerRequest, ServerResponse, StreamMap, Task, UndoOptions, UndoStackFrame } from '../types/ComClient';
|
|
4
|
+
import { PresenceMessage, SessionInvite, SessionPeer, SessionRole, ShareKind } from '../session/types';
|
|
5
|
+
import { ClientIdentity } from '../session/identity';
|
|
6
|
+
/**
|
|
7
|
+
* The base of every client: what the SDK asks of a connection to ClassCAD, and the session-sharing surface.
|
|
8
|
+
*
|
|
9
|
+
* An app makes a {@link WASMClient}, {@link WSClient} or {@link SocketIOClient} in the factory it gives {@link init};
|
|
10
|
+
* The SDK connects it and sends the drawing's API calls through it. A client that cannot share its session (the base
|
|
11
|
+
* class, {@link SocketIOClient}) has `shareKind` null and rejects `createInvite` with
|
|
12
|
+
* {@link SESSION_SHARING_UNSUPPORTED}.
|
|
13
|
+
*
|
|
14
|
+
* A client is an `EventEmitter`; every event passes the client first:
|
|
15
|
+
*
|
|
16
|
+
* - `connected` (client, true): the client has connected.
|
|
17
|
+
* - `conn_error` (client, reason): the connection failed or broke off.
|
|
18
|
+
* - `conn_timeout` (client, reason): connecting timed out ({@link SocketIOClient}).
|
|
19
|
+
* - `reconnect` (client): the connection is back, and the drawing reconnected ({@link SocketIOClient}).
|
|
20
|
+
* - `session_joined` (client, role, inviteName): the client joined a shared session with an invite ({@link WSClient}).
|
|
21
|
+
* - `peer_joined` / `peer_left` (client, {@link SessionPeer}): a guest joined or left this client's session.
|
|
22
|
+
* - `peers_changed` (client, {@link SessionPeer}[]): the guests in the session changed.
|
|
23
|
+
* - `invites_changed` (client, {@link SessionInvite}[]): an invite was made or taken back.
|
|
24
|
+
* - `identities_changed` (client, identities): a participant said who it is, or left.
|
|
25
|
+
* - `presence` (client, {@link PresenceMessage}): another participant published something.
|
|
26
|
+
* - `invite_refused` (client, {@link SessionInvite}, {@link OfferRefusal}): the share relay would not take an invite
|
|
27
|
+
* ({@link WASMClient}).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { onClient } from '@classcad/client'
|
|
32
|
+
* import type { PresenceMessage, SessionPeer } from '@classcad/client'
|
|
33
|
+
*
|
|
34
|
+
* // A status line (an element of the app's page) for every drawing's connection and session
|
|
35
|
+
* onClient(client => {
|
|
36
|
+
* client.on('connected', () => (statusLine.textContent = 'Connected'))
|
|
37
|
+
* client.on('conn_error', (_client, reason) => (statusLine.textContent = `No connection: ${reason}`))
|
|
38
|
+
* client.on('peers_changed', (_client, peers: SessionPeer[]) => (statusLine.textContent = `${peers.length} guests`))
|
|
39
|
+
* client.on('presence', (_client, msg: PresenceMessage) => {
|
|
40
|
+
* if (msg.channel === 'leave') console.log(`${client.identities[msg.peerId]?.name ?? msg.peerId} left`)
|
|
41
|
+
* })
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
* @advanced
|
|
45
|
+
* @category Clients
|
|
46
|
+
*/
|
|
47
|
+
export declare abstract class AwvNodeClient extends EventEmitter implements IComClient {
|
|
48
|
+
protected _drawingId: DrawingID;
|
|
49
|
+
/** How this client's invites are honoured; null = this client cannot share. */
|
|
50
|
+
readonly shareKind: ShareKind | null;
|
|
51
|
+
/** This connection's role within a shared session ('edit' unless a guest with a view invite). */
|
|
52
|
+
role: SessionRole;
|
|
53
|
+
/** Name of the invite this connection joined with ('' for the host or unnamed tokens). */
|
|
54
|
+
inviteName: string;
|
|
55
|
+
/** Guests currently sharing this session (host side). */
|
|
56
|
+
get peers(): SessionPeer[];
|
|
57
|
+
/** The invites this client minted (the server keeps no queryable list). */
|
|
58
|
+
protected _invites: SessionInvite[];
|
|
59
|
+
/** The invites this client minted and has not revoked. */
|
|
60
|
+
get invites(): SessionInvite[];
|
|
61
|
+
protected trackInvite(invite: SessionInvite): void;
|
|
62
|
+
protected untrackInvite(token: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Mints an invite token guests (apps, an MCP) can join with. Rejects with SESSION_SHARING_UNSUPPORTED on non-sharing transports.
|
|
65
|
+
*
|
|
66
|
+
* @param role - What guests with the invite may do: `'edit'` (default) or `'view'`.
|
|
67
|
+
* @param name - A name to show for the invite, e.g. "workgroup"; it has no effect.
|
|
68
|
+
*/
|
|
69
|
+
createInvite(role?: SessionRole, name?: string): Promise<SessionInvite>;
|
|
70
|
+
/**
|
|
71
|
+
* Revokes a token and kicks the guests using it.
|
|
72
|
+
*
|
|
73
|
+
* @param invite - The invite token.
|
|
74
|
+
* @returns The token, whether it was revoked, and how many guests were cut off.
|
|
75
|
+
*/
|
|
76
|
+
revokeInvite(invite: string): Promise<{
|
|
77
|
+
/** The token. */
|
|
78
|
+
invite: string;
|
|
79
|
+
/** Whether the token was known and is revoked now. */
|
|
80
|
+
revoked: boolean;
|
|
81
|
+
/** How many guests were cut off. */
|
|
82
|
+
kicked: number;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Fire-and-forget presence broadcast to session siblings (camera, cursor …). No-op on non-sharing transports.
|
|
86
|
+
*
|
|
87
|
+
* @param channel - The channel, e.g. `'view'` for a camera viewpoint; others get it in their `presence` event.
|
|
88
|
+
* @param data - The payload, sent as it is. A frame larger than 8 KB is dropped.
|
|
89
|
+
*/
|
|
90
|
+
sendPresence(channel: string, data: Record<string, any>): void;
|
|
91
|
+
/** What the other participants said about themselves ('client' presence, see session/identity.ts), by peer id. */
|
|
92
|
+
protected _identities: Record<string, ClientIdentity>;
|
|
93
|
+
/** What the other participants said about themselves ({@link ClientIdentity}), by peer id. */
|
|
94
|
+
get identities(): Record<string, ClientIdentity>;
|
|
95
|
+
/** Transports pass every presence frame through here: a 'client' frame says who a peer is, 'leave' that it is gone. */
|
|
96
|
+
protected noteIdentity(msg: PresenceMessage): void;
|
|
97
|
+
/** The session is gone (disconnect): so is everyone in it. */
|
|
98
|
+
protected clearIdentities(): void;
|
|
99
|
+
constructor();
|
|
100
|
+
/**
|
|
101
|
+
* Sets the drawing this client serves; the constructor does it.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
setDrawingId(drawingId: DrawingID): void;
|
|
106
|
+
/** The drawing this client serves. */
|
|
107
|
+
get drawingId(): DrawingID;
|
|
108
|
+
/**
|
|
109
|
+
* Connects to the engine. The SDK calls it when the drawing connects; it resolves once the drawing's structure tree
|
|
110
|
+
* is loaded and API calls can be made.
|
|
111
|
+
*/
|
|
112
|
+
abstract connect(): Promise<AwvNodeClient>;
|
|
113
|
+
/** Closes the connection to the engine. */
|
|
114
|
+
abstract disconnect(): Promise<AwvNodeClient>;
|
|
115
|
+
protected abstract request(command: ServerRequest): Promise<ServerResponse>;
|
|
116
|
+
/**
|
|
117
|
+
* Sends a raw request to the engine and resolves to its reply. Rejects with the reply when it carries an error.
|
|
118
|
+
*
|
|
119
|
+
* @param name - Names the request on the transport: the event of the ClassCAD server ({@link SocketIOClient}); the
|
|
120
|
+
* other clients ignore it.
|
|
121
|
+
* @param command - The request.
|
|
122
|
+
*/
|
|
123
|
+
abstract requestByName(name: string, command?: ServerRequest): Promise<ServerResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Steps back in the drawing's undo history: to `options.state` when given. The ClassCAD server
|
|
126
|
+
* ({@link SocketIOClient}) keeps that history.
|
|
127
|
+
*
|
|
128
|
+
* @param options - The state to go back to, and options for the engine.
|
|
129
|
+
*/
|
|
130
|
+
abstract undo(options?: UndoOptions): Promise<ServerResponse>;
|
|
131
|
+
/**
|
|
132
|
+
* Steps forward in the drawing's undo history: to `options.state` when given. The ClassCAD server
|
|
133
|
+
* ({@link SocketIOClient}) keeps that history.
|
|
134
|
+
*
|
|
135
|
+
* @param options - The state to go forward to, and options for the engine.
|
|
136
|
+
*/
|
|
137
|
+
abstract redo(options?: RedoOptions): Promise<ServerResponse>;
|
|
138
|
+
/**
|
|
139
|
+
* Sends a command of the server's own (a middleware command), with the fields of `data`.
|
|
140
|
+
*
|
|
141
|
+
* @param command - The command's name.
|
|
142
|
+
* @param data - Fields sent along with the command.
|
|
143
|
+
*/
|
|
144
|
+
executeMiddleware(command: string, data: any): Promise<ServerResponse>;
|
|
145
|
+
/**
|
|
146
|
+
* Runs `task` (API calls) on the engine with an `Execute` request. Rejects with the reply when it carries an error.
|
|
147
|
+
*
|
|
148
|
+
* The drawing's API ({@link createApi}) calls through here; the streams of `streamMap` are deflated and sent as
|
|
149
|
+
* base64.
|
|
150
|
+
*
|
|
151
|
+
* @param task - The API calls to run, e.g. `[{ 'v1.part.create': [{ name: 'Part' }] }]`.
|
|
152
|
+
* @param streamMap - Data the calls read, by stream key (a file to import, for example).
|
|
153
|
+
* @param options - Options of the request, such as `undoable`.
|
|
154
|
+
*/
|
|
155
|
+
executeRequest(task: Task, streamMap?: StreamMap, options?: RequestOptions): Promise<ServerResponse>;
|
|
156
|
+
/**
|
|
157
|
+
* The effective emission config of this connection ({@link EmissionConfig}): what the engine sends back after a
|
|
158
|
+
* command.
|
|
159
|
+
*
|
|
160
|
+
* Rejects with an Error named {@link EMISSION_CONFIG_UNSUPPORTED} on engines that predate the command.
|
|
161
|
+
*/
|
|
162
|
+
getEmissionConfig(): Promise<EmissionConfig>;
|
|
163
|
+
/**
|
|
164
|
+
* Merges `partial` into the emission config of this connection and resolves to the effective flags.
|
|
165
|
+
*
|
|
166
|
+
* The engine keeps the config for every command that follows, until it is changed again. Rejects with an Error
|
|
167
|
+
* named {@link EMISSION_CONFIG_UNSUPPORTED} on engines that predate the command. {@link EmissionConfig} has an
|
|
168
|
+
* example, and {@link onClient} sets flags as every client connects.
|
|
169
|
+
*
|
|
170
|
+
* @param partial - The flags to change; the others stay as they are.
|
|
171
|
+
*/
|
|
172
|
+
setEmissionConfig(partial: Partial<EmissionConfig>): Promise<EmissionConfig>;
|
|
173
|
+
/**
|
|
174
|
+
* Takes the undo history the engine reported (UndoStack frame) into the drawing's
|
|
175
|
+
* `cad.states`, in the form SocketIOClient fills from the node server's 'undo' event: the
|
|
176
|
+
* state ids, the current one, and per state its caption. The engine records a state only for
|
|
177
|
+
* an undoable command, so every state is undoable.
|
|
178
|
+
*/
|
|
179
|
+
protected applyUndoStack(frame: UndoStackFrame): void;
|
|
180
|
+
/** Loads the drawing's structure tree from the engine and sets it in the SDK's store. */
|
|
181
|
+
requestTree(): Promise<ServerResponse>;
|
|
182
|
+
}
|