vim-format
Advanced tools
Comparing version 1.0.11-dev.3 to 1.0.12-a
/** | ||
* @module vim-ts | ||
*/ | ||
import { RemoteBuffer } from './remoteBuffer'; | ||
import { RemoteBuffer } from './http/remoteBuffer'; | ||
declare type NumericArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; | ||
@@ -45,4 +45,8 @@ export declare type NumericArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; | ||
private _children; | ||
constructor(source: RemoteBuffer | ArrayBuffer, offset?: number, name?: string); | ||
constructor(source: RemoteBuffer | ArrayBuffer | string, offset?: number, name?: string); | ||
/** | ||
* Aborts all downloads from the underlying RemoteBuffer | ||
*/ | ||
abort(): void; | ||
/** | ||
* @returns Bfast Header | ||
@@ -61,3 +65,3 @@ */ | ||
getBfast(name: string): Promise<BFast>; | ||
getLocalBfast(name: string): Promise<BFast | undefined>; | ||
getLocalBfast(name: string, inflate?: boolean): Promise<BFast | undefined>; | ||
/** | ||
@@ -74,2 +78,6 @@ * Returns the raw buffer associated with a name | ||
getArray(name: string): Promise<NumericArray | undefined>; | ||
getInt32Array(name: string): Promise<Int32Array | undefined>; | ||
getFloat32Array(name: string): Promise<Float32Array | undefined>; | ||
getBigInt64Array(name: string): Promise<BigInt64Array | undefined>; | ||
getUint16Array(name: string): Promise<Uint16Array | undefined>; | ||
/** | ||
@@ -76,0 +84,0 @@ * Returns a single value from given buffer name |
@@ -5,7 +5,30 @@ "use strict"; | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BFast = exports.BFastHeader = exports.typeSize = exports.parseName = exports.Range = void 0; | ||
const remoteValue_1 = require("./remoteValue"); | ||
const remoteBuffer_1 = require("./remoteBuffer"); | ||
const utils_1 = require("./utils"); | ||
const remoteValue_1 = require("./http/remoteValue"); | ||
const remoteBuffer_1 = require("./http/remoteBuffer"); | ||
const pako = __importStar(require("pako")); | ||
class Range { | ||
@@ -158,13 +181,7 @@ constructor(start, end) { | ||
constructor(source, offset = 0, name = '') { | ||
if (typeof source === 'string') { | ||
if ((0, utils_1.isLocalResource)(source)) { | ||
throw new Error(`Local resources are not supported: ${source}`); | ||
} | ||
this.source = new remoteBuffer_1.RemoteBuffer(source); | ||
} | ||
else { | ||
this.source = source; | ||
} | ||
this.source = typeof source === 'string' | ||
? new remoteBuffer_1.RemoteBuffer(source) | ||
: source; | ||
this.offset = offset; | ||
this.name = name; | ||
this.name = name ?? "root"; | ||
this._header = new remoteValue_1.RemoteValue(() => this.requestHeader(), name + '.header'); | ||
@@ -175,2 +192,13 @@ this._children = new Map(); | ||
/** | ||
* Aborts all downloads from the underlying RemoteBuffer | ||
*/ | ||
abort() { | ||
if (this.source instanceof remoteBuffer_1.RemoteBuffer) { | ||
this.source.abort(); | ||
} | ||
this._header.abort(); | ||
this._ranges.abort(); | ||
this._children.forEach(c => c.abort()); | ||
} | ||
/** | ||
* @returns Bfast Header | ||
@@ -200,6 +228,9 @@ */ | ||
} | ||
async getLocalBfast(name) { | ||
const buffer = await this.getBuffer(name); | ||
async getLocalBfast(name, inflate = false) { | ||
let buffer = await this.getBuffer(name); | ||
if (!buffer) | ||
return undefined; | ||
if (inflate) { | ||
buffer = pako.inflateRaw(buffer).buffer; | ||
} | ||
return new BFast(buffer, 0, name); | ||
@@ -233,2 +264,26 @@ } | ||
} | ||
async getInt32Array(name) { | ||
const buffer = await this.getBuffer(name); | ||
if (!buffer) | ||
return; | ||
return new Int32Array(buffer); | ||
} | ||
async getFloat32Array(name) { | ||
const buffer = await this.getBuffer(name); | ||
if (!buffer) | ||
return; | ||
return new Float32Array(buffer); | ||
} | ||
async getBigInt64Array(name) { | ||
const buffer = await this.getBuffer(name); | ||
if (!buffer) | ||
return; | ||
return new BigInt64Array(buffer); | ||
} | ||
async getUint16Array(name) { | ||
const buffer = await this.getBuffer(name); | ||
if (!buffer) | ||
return; | ||
return new Uint16Array(buffer); | ||
} | ||
/** | ||
@@ -235,0 +290,0 @@ * Returns a single value from given buffer name |
export * from './bfast'; | ||
export * from './g3d'; | ||
export * from './remoteG3d'; | ||
export * from './remoteBuffer'; | ||
export * from './requestTracker'; | ||
export * from './g3d/g3d'; | ||
export * from './remoteVimx'; | ||
export * from './g3d/g3dMaterials'; | ||
export * from './g3d/g3dMesh'; | ||
export * from './g3d/g3dChunk'; | ||
export * from './g3d/g3dScene'; | ||
export * from './http/remoteBuffer'; | ||
export * from './http/requestTracker'; | ||
export * from './http/requester'; | ||
export * from './http/remoteValue'; | ||
export * from './vimHeader'; | ||
@@ -7,0 +13,0 @@ export * from './objectModel'; |
@@ -32,6 +32,12 @@ "use strict"; | ||
__exportStar(require("./bfast"), exports); | ||
__exportStar(require("./g3d"), exports); | ||
__exportStar(require("./remoteG3d"), exports); | ||
__exportStar(require("./remoteBuffer"), exports); | ||
__exportStar(require("./requestTracker"), exports); | ||
__exportStar(require("./g3d/g3d"), exports); | ||
__exportStar(require("./remoteVimx"), exports); | ||
__exportStar(require("./g3d/g3dMaterials"), exports); | ||
__exportStar(require("./g3d/g3dMesh"), exports); | ||
__exportStar(require("./g3d/g3dChunk"), exports); | ||
__exportStar(require("./g3d/g3dScene"), exports); | ||
__exportStar(require("./http/remoteBuffer"), exports); | ||
__exportStar(require("./http/requestTracker"), exports); | ||
__exportStar(require("./http/requester"), exports); | ||
__exportStar(require("./http/remoteValue"), exports); | ||
__exportStar(require("./vimHeader"), exports); | ||
@@ -38,0 +44,0 @@ __exportStar(require("./objectModel"), exports); |
@@ -7,8 +7,2 @@ /** | ||
export declare function setRemoteBufferMaxConcurency(value: number): void; | ||
declare type RemoteBufferOptions = { | ||
url: string; | ||
headers?: Record<string, string>; | ||
verbose?: boolean; | ||
maxConcurency?: number; | ||
}; | ||
/** | ||
@@ -18,6 +12,5 @@ * Wrapper to provide tracking for all webrequests via request logger. | ||
export declare class RemoteBuffer { | ||
readonly url: string; | ||
readonly headers: Record<string, string>; | ||
url: string; | ||
maxConcurency: number; | ||
onProgress: (progress: IProgressLogs) => void; | ||
private _maxConcurency; | ||
private _tracker; | ||
@@ -28,3 +21,3 @@ private _logs; | ||
private _encoded; | ||
constructor(options: RemoteBufferOptions); | ||
constructor(url: string, verbose?: boolean); | ||
private requestEncoding; | ||
@@ -38,2 +31,1 @@ abort(): void; | ||
} | ||
export {}; |
@@ -18,8 +18,6 @@ "use strict"; | ||
// eslint-disable-next-line no-undef | ||
responseType, headers) { | ||
this.headers = {}; | ||
responseType) { | ||
this.url = url; | ||
this.range = range; | ||
this.responseType = responseType; | ||
this.headers = headers ?? {}; | ||
} | ||
@@ -34,5 +32,2 @@ abort() { | ||
xhr.responseType = this.responseType; | ||
for (const key in this.headers) { | ||
xhr.setRequestHeader(key, this.headers[key]); | ||
} | ||
if (this.range) { | ||
@@ -59,10 +54,9 @@ xhr.setRequestHeader('Range', this.range); | ||
class RemoteBuffer { | ||
constructor(options) { | ||
constructor(url, verbose = false) { | ||
this.maxConcurency = RemoteBufferMaxConcurency; | ||
this._queue = []; | ||
this._active = new Set(); | ||
this.url = options.url; | ||
this.headers = options.headers ?? {}; | ||
this._logs = options.verbose ? new logging_1.DefaultLog() : new logging_1.NoLog(); | ||
this._maxConcurency = options.maxConcurency ?? RemoteBufferMaxConcurency; | ||
this._tracker = new requestTracker_1.RequestTracker(options.url, this._logs); | ||
this.url = url; | ||
this._logs = verbose ? new logging_1.DefaultLog() : new logging_1.NoLog(); | ||
this._tracker = new requestTracker_1.RequestTracker(url, this._logs); | ||
this._tracker.onUpdate = (p) => this.onProgress?.(p); | ||
@@ -74,5 +68,2 @@ this._encoded = new remoteValue_1.RemoteValue(() => this.requestEncoding()); | ||
xhr.open('HEAD', this.url); | ||
for (const key in this.headers) { | ||
xhr.setRequestHeader(key, this.headers[key]); | ||
} | ||
xhr.send(); | ||
@@ -113,3 +104,3 @@ this._logs.log(`Requesting header for ${this.url}`); | ||
: undefined; | ||
const request = new RetryRequest(this.url, rangeStr, 'arraybuffer', this.headers); | ||
const request = new RetryRequest(this.url, rangeStr, 'arraybuffer'); | ||
request.msg = useRange | ||
@@ -141,3 +132,3 @@ ? `${label} : [${range.start}, ${range.end}] of ${this.url}` | ||
this._active.delete(xhr); | ||
this._maxConcurency = Math.max(1, this._maxConcurency - 1); | ||
this.maxConcurency = Math.max(1, this.maxConcurency - 1); | ||
setTimeout(() => this.enqueue(xhr), 2000); | ||
@@ -153,3 +144,3 @@ } | ||
} | ||
if (this._active.size >= this._maxConcurency) { | ||
if (this._active.size >= this.maxConcurency) { | ||
return; | ||
@@ -156,0 +147,0 @@ } |
/** | ||
* @module vim-ts | ||
*/ | ||
import { RemoteBuffer } from './remoteBuffer'; | ||
import { RemoteBuffer } from './http/remoteBuffer'; | ||
declare type NumericArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | BigInt64ArrayConstructor | BigUint64ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; | ||
@@ -45,4 +45,8 @@ export declare type NumericArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; | ||
private _children; | ||
constructor(source: RemoteBuffer | ArrayBuffer, offset?: number, name?: string); | ||
constructor(source: RemoteBuffer | ArrayBuffer | string, offset?: number, name?: string); | ||
/** | ||
* Aborts all downloads from the underlying RemoteBuffer | ||
*/ | ||
abort(): void; | ||
/** | ||
* @returns Bfast Header | ||
@@ -61,3 +65,3 @@ */ | ||
getBfast(name: string): Promise<BFast>; | ||
getLocalBfast(name: string): Promise<BFast | undefined>; | ||
getLocalBfast(name: string, inflate?: boolean): Promise<BFast | undefined>; | ||
/** | ||
@@ -74,2 +78,6 @@ * Returns the raw buffer associated with a name | ||
getArray(name: string): Promise<NumericArray | undefined>; | ||
getInt32Array(name: string): Promise<Int32Array | undefined>; | ||
getFloat32Array(name: string): Promise<Float32Array | undefined>; | ||
getBigInt64Array(name: string): Promise<BigInt64Array | undefined>; | ||
getUint16Array(name: string): Promise<Uint16Array | undefined>; | ||
/** | ||
@@ -76,0 +84,0 @@ * Returns a single value from given buffer name |
export * from './bfast'; | ||
export * from './g3d'; | ||
export * from './remoteG3d'; | ||
export * from './remoteBuffer'; | ||
export * from './requestTracker'; | ||
export * from './g3d/g3d'; | ||
export * from './remoteVimx'; | ||
export * from './g3d/g3dMaterials'; | ||
export * from './g3d/g3dMesh'; | ||
export * from './g3d/g3dChunk'; | ||
export * from './g3d/g3dScene'; | ||
export * from './http/remoteBuffer'; | ||
export * from './http/requestTracker'; | ||
export * from './http/requester'; | ||
export * from './http/remoteValue'; | ||
export * from './vimHeader'; | ||
@@ -7,0 +13,0 @@ export * from './objectModel'; |
@@ -7,8 +7,2 @@ /** | ||
export declare function setRemoteBufferMaxConcurency(value: number): void; | ||
declare type RemoteBufferOptions = { | ||
url: string; | ||
headers?: Record<string, string>; | ||
verbose?: boolean; | ||
maxConcurency?: number; | ||
}; | ||
/** | ||
@@ -18,6 +12,5 @@ * Wrapper to provide tracking for all webrequests via request logger. | ||
export declare class RemoteBuffer { | ||
readonly url: string; | ||
readonly headers: Record<string, string>; | ||
url: string; | ||
maxConcurency: number; | ||
onProgress: (progress: IProgressLogs) => void; | ||
private _maxConcurency; | ||
private _tracker; | ||
@@ -28,3 +21,3 @@ private _logs; | ||
private _encoded; | ||
constructor(options: RemoteBufferOptions); | ||
constructor(url: string, verbose?: boolean); | ||
private requestEncoding; | ||
@@ -38,2 +31,1 @@ abort(): void; | ||
} | ||
export {}; |
@@ -8,2 +8,3 @@ import { BFast } from "./bfast"; | ||
vim: string | undefined; | ||
vimx: string | undefined; | ||
id: string | undefined; | ||
@@ -10,0 +11,0 @@ revision: string | undefined; |
import { VimDocument } from "./objectModel"; | ||
/** | ||
* Representation of ElementParamter entity from the entity model | ||
* Representation of ElementParameter entity from the entity model | ||
* See https://github.com/vimaec/vim/blob/master/ObjectModel/object-model-schema.json | ||
@@ -5,0 +5,0 @@ */ |
@@ -6,5 +6,5 @@ /** | ||
export declare class VimLoader { | ||
static loadFromBfast(bfast: BFast, ignoreStrings: boolean): Promise<[BFast | undefined, string[] | undefined]>; | ||
static loadFromBfast(bfast: BFast, download: boolean, ignoreStrings: boolean): Promise<[BFast | undefined, string[] | undefined]>; | ||
private static requestStrings; | ||
private static requestEntities; | ||
} |
@@ -8,2 +8,3 @@ import { BFast } from "./bfast"; | ||
vim: string | undefined; | ||
vimx: string | undefined; | ||
id: string | undefined; | ||
@@ -10,0 +11,0 @@ revision: string | undefined; |
@@ -10,2 +10,3 @@ "use strict"; | ||
vim: map.get('vim'), | ||
vimx: map.get('vimx'), | ||
id: map.get('id'), | ||
@@ -12,0 +13,0 @@ revision: map.get('revision'), |
import { VimDocument } from "./objectModel"; | ||
/** | ||
* Representation of ElementParamter entity from the entity model | ||
* Representation of ElementParameter entity from the entity model | ||
* See https://github.com/vimaec/vim/blob/master/ObjectModel/object-model-schema.json | ||
@@ -5,0 +5,0 @@ */ |
@@ -46,2 +46,6 @@ "use strict"; | ||
return undefined; | ||
if (!parameterValues) | ||
return undefined; | ||
if (!getParameterDescriptorIndices) | ||
return undefined; | ||
const getParameterDisplayValue = (index) => { | ||
@@ -66,6 +70,6 @@ const value = parameterValues[index]; | ||
const name = Number.isInteger(descriptor) | ||
? parameterDescriptorNames[descriptor] | ||
? parameterDescriptorNames?.[descriptor] | ||
: undefined; | ||
const group = Number.isInteger(descriptor) | ||
? parameterDescriptorGroups[descriptor] | ||
? parameterDescriptorGroups?.[descriptor] | ||
: undefined; | ||
@@ -72,0 +76,0 @@ return { name, value, group, isInstance }; |
@@ -6,5 +6,5 @@ /** | ||
export declare class VimLoader { | ||
static loadFromBfast(bfast: BFast, ignoreStrings: boolean): Promise<[BFast | undefined, string[] | undefined]>; | ||
static loadFromBfast(bfast: BFast, download: boolean, ignoreStrings: boolean): Promise<[BFast | undefined, string[] | undefined]>; | ||
private static requestStrings; | ||
private static requestEntities; | ||
} |
@@ -8,5 +8,5 @@ "use strict"; | ||
class VimLoader { | ||
static async loadFromBfast(bfast, ignoreStrings) { | ||
static async loadFromBfast(bfast, download, ignoreStrings) { | ||
const [entity, strings] = await Promise.all([ | ||
VimLoader.requestEntities(bfast), | ||
VimLoader.requestEntities(bfast, download), | ||
ignoreStrings ? Promise.resolve(undefined) : VimLoader.requestStrings(bfast) | ||
@@ -25,4 +25,6 @@ ]); | ||
} | ||
static async requestEntities(bfast) { | ||
const entities = await bfast.getBfast('entities'); | ||
static async requestEntities(bfast, download) { | ||
const entities = download | ||
? await bfast.getLocalBfast('entities') | ||
: await bfast.getBfast('entities'); | ||
if (!entities) { | ||
@@ -29,0 +31,0 @@ console.error('Could not get String Data from VIM file. Bim features will be disabled.'); |
{ | ||
"name": "vim-format", | ||
"version": "1.0.11-dev.3", | ||
"version": "1.0.12-a", | ||
"description": "The VIM format is a modern and efficient open 3D data interchange format designed for BIM and manufacturing data optimized for efficient loading and rendering on low-power devices.", | ||
@@ -11,3 +11,3 @@ "directories": { | ||
"build": "tsc", | ||
"package": "npm run build && npm run declarations && npm publish", | ||
"package": "npm run build && npm run declarations && npm publish", | ||
"test": "jest" | ||
@@ -30,6 +30,10 @@ }, | ||
"@types/node": "^18.16.16", | ||
"@types/pako": "^2.0.0", | ||
"jest": "^29.2.2", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.8.4" | ||
}, | ||
"dependencies": { | ||
"pako": "^2.1.0" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
928956
118
21427
1
6
2
+ Addedpako@^2.1.0
+ Addedpako@2.1.0(transitive)