@vertesia/memory 0.43.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/LICENSE +201 -0
- package/README.md +421 -0
- package/lib/cjs/Builder.js +186 -0
- package/lib/cjs/Builder.js.map +1 -0
- package/lib/cjs/ContentObject.js +114 -0
- package/lib/cjs/ContentObject.js.map +1 -0
- package/lib/cjs/ContentSource.js +82 -0
- package/lib/cjs/ContentSource.js.map +1 -0
- package/lib/cjs/MemoryPack.js +228 -0
- package/lib/cjs/MemoryPack.js.map +1 -0
- package/lib/cjs/MemoryPackBuilder.js +47 -0
- package/lib/cjs/MemoryPackBuilder.js.map +1 -0
- package/lib/cjs/commands/copy.js +53 -0
- package/lib/cjs/commands/copy.js.map +1 -0
- package/lib/cjs/commands/exec.js +82 -0
- package/lib/cjs/commands/exec.js.map +1 -0
- package/lib/cjs/index.js +28 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/utils/cmdline.js +90 -0
- package/lib/cjs/utils/cmdline.js.map +1 -0
- package/lib/cjs/utils/rewrite.js +166 -0
- package/lib/cjs/utils/rewrite.js.map +1 -0
- package/lib/cjs/utils/stream.js +27 -0
- package/lib/cjs/utils/stream.js.map +1 -0
- package/lib/cjs/utils/tar.js +185 -0
- package/lib/cjs/utils/tar.js.map +1 -0
- package/lib/esm/Builder.js +178 -0
- package/lib/esm/Builder.js.map +1 -0
- package/lib/esm/ContentObject.js +103 -0
- package/lib/esm/ContentObject.js.map +1 -0
- package/lib/esm/ContentSource.js +75 -0
- package/lib/esm/ContentSource.js.map +1 -0
- package/lib/esm/MemoryPack.js +218 -0
- package/lib/esm/MemoryPack.js.map +1 -0
- package/lib/esm/MemoryPackBuilder.js +43 -0
- package/lib/esm/MemoryPackBuilder.js.map +1 -0
- package/lib/esm/commands/copy.js +50 -0
- package/lib/esm/commands/copy.js.map +1 -0
- package/lib/esm/commands/exec.js +75 -0
- package/lib/esm/commands/exec.js.map +1 -0
- package/lib/esm/index.js +7 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/utils/cmdline.js +86 -0
- package/lib/esm/utils/cmdline.js.map +1 -0
- package/lib/esm/utils/rewrite.js +161 -0
- package/lib/esm/utils/rewrite.js.map +1 -0
- package/lib/esm/utils/stream.js +23 -0
- package/lib/esm/utils/stream.js.map +1 -0
- package/lib/esm/utils/tar.js +175 -0
- package/lib/esm/utils/tar.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/Builder.d.ts +72 -0
- package/lib/types/Builder.d.ts.map +1 -0
- package/lib/types/ContentObject.d.ts +43 -0
- package/lib/types/ContentObject.d.ts.map +1 -0
- package/lib/types/ContentSource.d.ts +32 -0
- package/lib/types/ContentSource.d.ts.map +1 -0
- package/lib/types/MemoryPack.d.ts +46 -0
- package/lib/types/MemoryPack.d.ts.map +1 -0
- package/lib/types/MemoryPackBuilder.d.ts +18 -0
- package/lib/types/MemoryPackBuilder.d.ts.map +1 -0
- package/lib/types/commands/copy.d.ts +8 -0
- package/lib/types/commands/copy.d.ts.map +1 -0
- package/lib/types/commands/exec.d.ts +7 -0
- package/lib/types/commands/exec.d.ts.map +1 -0
- package/lib/types/index.d.ts +14 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/utils/cmdline.d.ts +10 -0
- package/lib/types/utils/cmdline.d.ts.map +1 -0
- package/lib/types/utils/rewrite.d.ts +38 -0
- package/lib/types/utils/rewrite.d.ts.map +1 -0
- package/lib/types/utils/stream.d.ts +9 -0
- package/lib/types/utils/stream.d.ts.map +1 -0
- package/lib/types/utils/tar.d.ts +40 -0
- package/lib/types/utils/tar.d.ts.map +1 -0
- package/package.json +40 -0
- package/src/Builder.ts +239 -0
- package/src/ContentObject.ts +114 -0
- package/src/ContentSource.ts +88 -0
- package/src/MemoryPack.ts +233 -0
- package/src/MemoryPackBuilder.ts +55 -0
- package/src/builder.test.ts +214 -0
- package/src/commands/copy.ts +53 -0
- package/src/commands/exec.test.ts +22 -0
- package/src/commands/exec.ts +83 -0
- package/src/index.ts +14 -0
- package/src/utils/cmdline.test.ts +32 -0
- package/src/utils/cmdline.ts +92 -0
- package/src/utils/rewrite.test.ts +65 -0
- package/src/utils/rewrite.ts +167 -0
- package/src/utils/stream.test.ts +13 -0
- package/src/utils/stream.ts +27 -0
- package/src/utils/tar.test.ts +48 -0
- package/src/utils/tar.ts +203 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentObject.d.ts","sourceRoot":"","sources":["../../src/ContentObject.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,aAAc,YAAW,aAAa;IAC5B,OAAO,EAAE,OAAO;IAAS,MAAM,EAAE,aAAa;IAAS,QAAQ,EAAE,cAAc;gBAA/E,OAAO,EAAE,OAAO,EAAS,MAAM,EAAE,aAAa,EAAS,QAAQ,GAAE,cAAwB;IAE5G,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAI3C,MAAM,CAAC,KAAK,EAAE,MAAM;IAId,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC;IAmBvD;;OAEG;IACG,OAAO,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAKzD,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;CAG/B;AAED,qBAAa,UAAW,SAAQ,aAAa;IACnC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;CAGrC;AAED,MAAM,WAAW,YAAY;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC3B;AACD,qBAAa,WAAY,SAAQ,aAAa;IACkB,OAAO,EAAE,YAAY;gBAArE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAS,OAAO,GAAE,YAAiB;IAIhF,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAM3C,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAItC;AAGD,qBAAa,SAAU,SAAQ,aAAa;gBAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa;IAG7C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAG3C,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAG7B,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAGnC;AAGD,qBAAa,UAAW,SAAQ,aAAa;gBAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa;IAG7C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAG5B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAK3C,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;CAInC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface ContentSource {
|
|
2
|
+
getContent(): Promise<Buffer>;
|
|
3
|
+
getStream(): Promise<NodeJS.ReadableStream>;
|
|
4
|
+
}
|
|
5
|
+
export type SourceSpec = string | ContentSource;
|
|
6
|
+
export declare abstract class AbstractContentSource implements ContentSource {
|
|
7
|
+
abstract getContent(): Promise<Buffer>;
|
|
8
|
+
getStream(): Promise<NodeJS.ReadableStream>;
|
|
9
|
+
static resolve(source: SourceSpec): ContentSource | ContentSource[];
|
|
10
|
+
}
|
|
11
|
+
export declare class BufferSource extends AbstractContentSource {
|
|
12
|
+
buffer: Buffer;
|
|
13
|
+
constructor(buffer: Buffer);
|
|
14
|
+
getContent(): Promise<Buffer>;
|
|
15
|
+
}
|
|
16
|
+
export declare class TextSource extends AbstractContentSource {
|
|
17
|
+
value: string;
|
|
18
|
+
encoding: BufferEncoding;
|
|
19
|
+
constructor(value: string, encoding?: BufferEncoding);
|
|
20
|
+
getContent(): Promise<Buffer>;
|
|
21
|
+
}
|
|
22
|
+
export declare class FileSource extends AbstractContentSource {
|
|
23
|
+
file: string;
|
|
24
|
+
constructor(file: string, resolvePath?: boolean);
|
|
25
|
+
get path(): string;
|
|
26
|
+
get name(): string;
|
|
27
|
+
get extname(): string;
|
|
28
|
+
get nameWithoutExt(): string;
|
|
29
|
+
getContent(): Promise<Buffer>;
|
|
30
|
+
getStream(): Promise<NodeJS.ReadableStream>;
|
|
31
|
+
static resolve(location: string): FileSource | FileSource[];
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSource.d.ts","sourceRoot":"","sources":["../../src/ContentSource.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,aAAa;IAC1B,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,aAAa,CAAC;AAChD,8BAAsB,qBAAsB,YAAW,aAAa;IAChE,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAEhC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAIjD,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,GAAG,aAAa,EAAE;CAQtE;AAED,qBAAa,YAAa,SAAQ,qBAAqB;IAChC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;IAGjC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAGhC;AAED,qBAAa,UAAW,SAAQ,qBAAqB;IAC9B,KAAK,EAAE,MAAM;IAAS,QAAQ,EAAE,cAAc;gBAA9C,KAAK,EAAE,MAAM,EAAS,QAAQ,GAAE,cAAwB;IAI3E,UAAU;CAGb;AAED,qBAAa,UAAW,SAAQ,qBAAqB;IACjD,IAAI,EAAE,MAAM,CAAC;gBACD,IAAI,EAAE,MAAM,EAAE,WAAW,UAAO;IAK5C,IAAI,IAAI,WAEP;IAED,IAAI,IAAI,WAEP;IAED,IAAI,OAAO,WAEV;IAED,IAAI,cAAc,WAEjB;IAED,UAAU;IAIJ,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAIjD,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE;CAQ9D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AbstractContentSource } from "./ContentSource.js";
|
|
2
|
+
import { TarIndex } from "./utils/tar.js";
|
|
3
|
+
export declare const MEMORY_METADATA_ENTRY = "metadata.json";
|
|
4
|
+
/**
|
|
5
|
+
* Projection cannot contains both include and exclude keys
|
|
6
|
+
*/
|
|
7
|
+
export interface ProjectionProperties {
|
|
8
|
+
[key: string]: boolean | 0 | 1;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class MemoryPack {
|
|
11
|
+
abstract readonly file: string;
|
|
12
|
+
abstract getMetadata(projection?: ProjectionProperties): Promise<Record<string, any>>;
|
|
13
|
+
abstract getEntry(path: string): MemoryEntry | null;
|
|
14
|
+
abstract getEntryContent(path: string): Promise<Buffer | null>;
|
|
15
|
+
abstract getEntryText(path: string, encoding?: BufferEncoding): Promise<string | null>;
|
|
16
|
+
abstract getPaths(filters?: string[]): string[];
|
|
17
|
+
abstract getEntries(filters?: string[]): MemoryEntry[];
|
|
18
|
+
abstract getEntriesContent(filters?: string[]): Promise<Buffer[]>;
|
|
19
|
+
abstract getEntriesText(filters?: string[], encoding?: BufferEncoding): Promise<string[]>;
|
|
20
|
+
exportObject(mapping: Record<string, any>): Promise<Record<string, any>>;
|
|
21
|
+
}
|
|
22
|
+
export declare class MemoryEntry extends AbstractContentSource {
|
|
23
|
+
index: TarIndex;
|
|
24
|
+
name: string;
|
|
25
|
+
offset: number;
|
|
26
|
+
size: number;
|
|
27
|
+
constructor(index: TarIndex, name: string, offset: number, size: number);
|
|
28
|
+
getContent(): Promise<Buffer>;
|
|
29
|
+
getText(encoding?: BufferEncoding): Promise<string>;
|
|
30
|
+
}
|
|
31
|
+
export declare class TarMemoryPack extends MemoryPack {
|
|
32
|
+
file: string;
|
|
33
|
+
index: TarIndex;
|
|
34
|
+
constructor(file: string, index: TarIndex);
|
|
35
|
+
getMetadata(projection?: ProjectionProperties): Promise<Record<string, any>>;
|
|
36
|
+
getPaths(filters?: string[]): string[];
|
|
37
|
+
getEntries(filters?: string[]): MemoryEntry[];
|
|
38
|
+
private _getEntries;
|
|
39
|
+
getEntriesContent(filters?: string[]): Promise<Buffer[]>;
|
|
40
|
+
getEntriesText(filters?: string[], encoding?: BufferEncoding): Promise<string[]>;
|
|
41
|
+
getEntry(path: string): MemoryEntry | null;
|
|
42
|
+
getEntryContent(path: string): Promise<Buffer | null>;
|
|
43
|
+
getEntryText(path: string, encoding?: BufferEncoding): Promise<string | null>;
|
|
44
|
+
static loadFile(file: string): Promise<TarMemoryPack>;
|
|
45
|
+
}
|
|
46
|
+
export declare function loadMemoryPack(location: string): Promise<MemoryPack>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryPack.d.ts","sourceRoot":"","sources":["../../src/MemoryPack.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAA+B,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEvE,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAOrD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;CAClC;AA2BD,8BAAsB,UAAU;IAC5B,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrF,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IACnD,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAC9D,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IACtF,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAC/C,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE;IACtD,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACjE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEnF,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAgDjF;AAGD,qBAAa,WAAY,SAAQ,qBAAqB;IAC/B,KAAK,EAAE,QAAQ;IAAS,IAAI,EAAE,MAAM;IAAS,MAAM,EAAE,MAAM;IAAS,IAAI,EAAE,MAAM;gBAAhF,KAAK,EAAE,QAAQ,EAAS,IAAI,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM;IAGnG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAG7B,OAAO,CAAC,QAAQ,GAAE,cAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;CAG/D;AAED,qBAAa,aAAc,SAAQ,UAAU;IACtB,IAAI,EAAE,MAAM;IAAS,KAAK,EAAE,QAAQ;gBAApC,IAAI,EAAE,MAAM,EAAS,KAAK,EAAE,QAAQ;IAMjD,WAAW,CAAC,UAAU,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAalF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE;IAQ3B,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE;IAI7B,OAAO,CAAC,WAAW;IAUnB,iBAAiB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE;IASpC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,cAAc;IAS5D,QAAQ,CAAC,IAAI,EAAE,MAAM;IAKrB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASrD,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;WAIhE,QAAQ,CAAC,IAAI,EAAE,MAAM;CAQrC;AAGD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAGpE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Builder } from "./Builder.js";
|
|
2
|
+
import { ContentSource } from "./ContentSource.js";
|
|
3
|
+
import { MemoryPack, ProjectionProperties } from "./MemoryPack.js";
|
|
4
|
+
export interface FromOptions {
|
|
5
|
+
files?: string[];
|
|
6
|
+
projection?: ProjectionProperties;
|
|
7
|
+
}
|
|
8
|
+
export declare class MemoryPackBuilder {
|
|
9
|
+
builder: Builder;
|
|
10
|
+
baseMetadata: Record<string, any>;
|
|
11
|
+
entries: {
|
|
12
|
+
[path: string]: ContentSource;
|
|
13
|
+
};
|
|
14
|
+
constructor(builder: Builder);
|
|
15
|
+
load(memory: MemoryPack, options?: FromOptions): Promise<void>;
|
|
16
|
+
add(path: string, content: ContentSource): void;
|
|
17
|
+
build(file: string, metadata: object): Promise<string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryPackBuilder.d.ts","sourceRoot":"","sources":["../../src/MemoryPackBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAyB,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG1F,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACrC;AAED,qBAAa,iBAAiB;IAIP,OAAO,EAAE,OAAO;IAHnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IACvC,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAA;KAAE,CAAM;gBAE7B,OAAO,EAAE,OAAO;IAG7B,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,WAAgB;IAWxD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa;IAKlC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAqB7C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Builder } from "../Builder.js";
|
|
2
|
+
import { MediaOptions } from "../ContentObject.js";
|
|
3
|
+
import { SourceSpec } from "../ContentSource.js";
|
|
4
|
+
export interface CopyOptions {
|
|
5
|
+
media?: MediaOptions;
|
|
6
|
+
extractText?: boolean | string;
|
|
7
|
+
}
|
|
8
|
+
export declare function copy(builder: Builder, source: SourceSpec, toPath: string, options?: CopyOptions): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../../src/commands/copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAA2B,YAAY,EAAa,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAoD,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQnG,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAClC;AACD,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,QAWnG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
import { Command } from '../utils/cmdline.js';
|
|
3
|
+
export interface ExecOptions {
|
|
4
|
+
quiet?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function exec(commandLine: string, options?: ExecOptions): Promise<string | undefined>;
|
|
7
|
+
export declare function executePipe(commands: Command[], finalOutput: Writable | undefined, verbose?: boolean): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/commands/exec.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAqB,MAAM,qBAAqB,CAAC;AAGjE,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwCtG;AAGD,wBAAgB,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,QAAQ,GAAG,SAAS,EAAE,OAAO,GAAE,OAAe,oBA6B3G"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { Builder, buildMemoryPack } from "./Builder.js";
|
|
2
|
+
export type { BuildOptions, Commands } from "./Builder.js";
|
|
3
|
+
export type { CopyOptions } from "./commands/copy.js";
|
|
4
|
+
export type { ExecOptions } from "./commands/exec.js";
|
|
5
|
+
export { ContentObject, DocxObject, JsonObject, MediaObject, PdfObject } from "./ContentObject.js";
|
|
6
|
+
export type { MediaOptions } from "./ContentObject.js";
|
|
7
|
+
export { AbstractContentSource, BufferSource, FileSource, TextSource } from "./ContentSource.js";
|
|
8
|
+
export type { ContentSource, SourceSpec } from "./ContentSource.js";
|
|
9
|
+
export { MemoryEntry, TarMemoryPack, loadMemoryPack } from "./MemoryPack.js";
|
|
10
|
+
export type { MemoryPack, ProjectionProperties } from "./MemoryPack.js";
|
|
11
|
+
export { MemoryPackBuilder } from "./MemoryPackBuilder.js";
|
|
12
|
+
export type { FromOptions } from "./MemoryPackBuilder.js";
|
|
13
|
+
export { TarBuilder, TarIndex, loadTarIndex } from './utils/tar.js';
|
|
14
|
+
export type { TarEntry, TarEntryIndex } from './utils/tar.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACvD,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAClG,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAChG,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC5E,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACnE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function splitCommandLine(text: string): string[];
|
|
2
|
+
export interface Command {
|
|
3
|
+
name: string;
|
|
4
|
+
args: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface CommandPipe {
|
|
7
|
+
commands: Command[];
|
|
8
|
+
out?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function splitPipeCommands(text: string): CommandPipe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmdline.d.ts","sourceRoot":"","sources":["../../../src/utils/cmdline.ts"],"names":[],"mappings":"AA6BA,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,YAkB5C;AAED,MAAM,WAAW,OAAO;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;CAClB;AACD,MAAM,WAAW,WAAW;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AACD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAkC3D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The path argumentmay is the empty string when mapping streams or buffers not related to a file system file.
|
|
3
|
+
*/
|
|
4
|
+
export type PathMapperFn = ((path: string, index: number) => string);
|
|
5
|
+
export declare function createPathRewrite(path: string): PathMapperFn;
|
|
6
|
+
export declare class Path {
|
|
7
|
+
_name?: string;
|
|
8
|
+
_extname?: string;
|
|
9
|
+
_dirname?: string;
|
|
10
|
+
_basename?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The complete path value
|
|
13
|
+
*/
|
|
14
|
+
value: string;
|
|
15
|
+
/**
|
|
16
|
+
* The file name (the last portion of the path). Includes the extension if present.
|
|
17
|
+
*/
|
|
18
|
+
get name(): string;
|
|
19
|
+
/**
|
|
20
|
+
* The extension of the file including the leading '.'.
|
|
21
|
+
* An empty string if the file has no extension.
|
|
22
|
+
*/
|
|
23
|
+
get extname(): string;
|
|
24
|
+
/**
|
|
25
|
+
* The directory portion of the path. Doesn'r include the trailing slash.
|
|
26
|
+
* If no directory is present, returns an empty string.
|
|
27
|
+
*/
|
|
28
|
+
get dirname(): string;
|
|
29
|
+
/**
|
|
30
|
+
* The path without the extension
|
|
31
|
+
*/
|
|
32
|
+
get basename(): string;
|
|
33
|
+
constructor(value: string);
|
|
34
|
+
/**
|
|
35
|
+
* Return the complete path value (same as `value`)
|
|
36
|
+
*/
|
|
37
|
+
toString(): string;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../../src/utils/rewrite.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;AAErE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CA+B5D;AAgED,qBAAa,IAAI;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAKjB;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAKpB;IACD;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAQpB;IACD;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAKrB;gBAEW,KAAK,EAAE,MAAM;IAIzB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAGrB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Writable } from "stream";
|
|
2
|
+
export declare class BufferWritableStream extends Writable {
|
|
3
|
+
chunks: Buffer[];
|
|
4
|
+
buffer: Buffer | undefined;
|
|
5
|
+
_write(chunk: Buffer, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
6
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
7
|
+
getBuffer(): Buffer | undefined;
|
|
8
|
+
getText(encoding?: BufferEncoding): string | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,qBAAa,oBAAqB,SAAQ,QAAQ;IAC9C,MAAM,EAAE,MAAM,EAAE,CAAK;IACrB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAG3B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI;IAMzF,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI;IAM/C,SAAS;IAIT,OAAO,CAAC,QAAQ,GAAE,cAAwB;CAG7C"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { FileHandle } from "fs/promises";
|
|
3
|
+
import tar from "tar-stream";
|
|
4
|
+
export interface TarEntry {
|
|
5
|
+
name: string;
|
|
6
|
+
getContent(): Promise<Buffer>;
|
|
7
|
+
}
|
|
8
|
+
export declare class TarBuilder {
|
|
9
|
+
pack: tar.Pack;
|
|
10
|
+
indexData: string[];
|
|
11
|
+
currentOffset: number;
|
|
12
|
+
tarPromise: Promise<unknown>;
|
|
13
|
+
constructor(file: string);
|
|
14
|
+
add(name: string, content?: Buffer): Promise<void>;
|
|
15
|
+
build(): Promise<void>;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function loadTarIndex(tarFile: string): Promise<TarIndex | null>;
|
|
19
|
+
export interface TarEntryIndex {
|
|
20
|
+
offset: number;
|
|
21
|
+
size: number;
|
|
22
|
+
}
|
|
23
|
+
export declare class TarIndex {
|
|
24
|
+
fd: FileHandle;
|
|
25
|
+
entries: Record<string, TarEntryIndex>;
|
|
26
|
+
headerBuffer: Buffer;
|
|
27
|
+
/**
|
|
28
|
+
* @param fd the tar file descriptor
|
|
29
|
+
* @param content the index content
|
|
30
|
+
*/
|
|
31
|
+
constructor(fd: FileHandle, content: string);
|
|
32
|
+
getPaths(): string[];
|
|
33
|
+
getSortedPaths(): string[];
|
|
34
|
+
get(name: string): TarEntryIndex;
|
|
35
|
+
getContentAt(offset: number, size: number): Promise<Buffer>;
|
|
36
|
+
getContent(name: string): Promise<Buffer | null>;
|
|
37
|
+
getReadStream(name: string, encoding?: BufferEncoding): fs.ReadStream | null;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export declare function normalizePath(path: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tar.d.ts","sourceRoot":"","sources":["../../../src/utils/tar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAQ,MAAM,aAAa,CAAC;AAE/C,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,qBAAa,UAAU;IACnB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,SAAS,EAAE,MAAM,EAAE,CAAM;IACzB,aAAa,SAAK;IAClB,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;gBAEjB,IAAI,EAAE,MAAM;IAalB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAwBlC,KAAK;IAcX,OAAO;CAIV;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,4BAQjD;AAoCD,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAA;CACf;AACD,qBAAa,QAAQ;IAOE,EAAE,EAAE,UAAU;IANjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAM;IAC5C,YAAY,SAAqB;IACjC;;;OAGG;gBACgB,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;IAalD,QAAQ;IAIR,cAAc;IAId,GAAG,CAAC,IAAI,EAAE,MAAM;IAIV,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAKzC,UAAU,CAAC,IAAI,EAAE,MAAM;IAS7B,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,cAAc;IAc/C,KAAK;CAId;AAQD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,UAQzC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vertesia/memory",
|
|
3
|
+
"description": "Manipulate memory images for LLMs",
|
|
4
|
+
"version": "0.43.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./lib/types/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/micromatch": "^4.0.9",
|
|
14
|
+
"@types/node": "^22.5.1",
|
|
15
|
+
"@types/tar-stream": "^3.1.3",
|
|
16
|
+
"ts-dual-module": "^0.6.3",
|
|
17
|
+
"vitest": "^1.4.0"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@vertesia/converters": "^0.42.2",
|
|
21
|
+
"@vertesia/json": "^0.42.2",
|
|
22
|
+
"glob": "^11.0.0",
|
|
23
|
+
"micromatch": "^4.0.8",
|
|
24
|
+
"tar-stream": "^3.1.7"
|
|
25
|
+
},
|
|
26
|
+
"ts_dual_module": {
|
|
27
|
+
"outDir": "lib"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
"types": "./lib/types/index.d.ts",
|
|
31
|
+
"import": "./lib/esm/index.js",
|
|
32
|
+
"require": "./lib/cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"eslint": "eslint './src/**/*.{jsx,js,tsx,ts}'",
|
|
36
|
+
"build": "pnpm exec tsmod build",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/Builder.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { AsyncObjectWalker } from "@vertesia/json";
|
|
2
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import { join, resolve } from "path";
|
|
5
|
+
import { copy, CopyOptions } from "./commands/copy.js";
|
|
6
|
+
import { exec, ExecOptions } from "./commands/exec.js";
|
|
7
|
+
import { ContentObject, DocxObject, JsonObject, MediaObject, MediaOptions, PdfObject } from "./ContentObject.js";
|
|
8
|
+
import { AbstractContentSource, ContentSource, SourceSpec, TextSource } from "./ContentSource.js";
|
|
9
|
+
import { loadMemoryPack } from "./MemoryPack.js";
|
|
10
|
+
import { FromOptions, MemoryPackBuilder } from "./MemoryPackBuilder.js";
|
|
11
|
+
|
|
12
|
+
export interface BuildOptions {
|
|
13
|
+
indent?: number;
|
|
14
|
+
/**
|
|
15
|
+
* the path to save the output. Defaults to 'memory.tar'.
|
|
16
|
+
* If no .tar extension is present it will be added
|
|
17
|
+
*/
|
|
18
|
+
out?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* If set, suppress logs. Defaults to false.
|
|
22
|
+
*/
|
|
23
|
+
quiet?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* If true, compress the output (tar or json) with gzip. Defaults to false.
|
|
27
|
+
*/
|
|
28
|
+
gzip?: boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Vars to be injected into the script context as the vars object
|
|
32
|
+
*/
|
|
33
|
+
vars?: Record<string, any>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Optional publish action
|
|
37
|
+
* @param file
|
|
38
|
+
* @returns the URI of the published memory
|
|
39
|
+
*/
|
|
40
|
+
publish?: (file: string, name: string) => Promise<string>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The directory where to transpile the recipe ts file
|
|
44
|
+
*/
|
|
45
|
+
transpileDir?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Commands {
|
|
49
|
+
vars: () => Record<string, any>;
|
|
50
|
+
tmpdir: () => string;
|
|
51
|
+
exec: (cmd: string, options?: ExecOptions) => Promise<void | string>;
|
|
52
|
+
from: (location: string, options?: FromOptions) => Promise<void>;
|
|
53
|
+
content: (location: string, encoding?: BufferEncoding) => ContentObject | ContentObject[];
|
|
54
|
+
json: (location: string) => ContentObject | ContentObject[];
|
|
55
|
+
pdf: (location: string) => PdfObject | PdfObject[];
|
|
56
|
+
docx: (location: string) => DocxObject | DocxObject[];
|
|
57
|
+
media: (location: string, options?: MediaOptions) => MediaObject | MediaObject[];
|
|
58
|
+
copy: (location: SourceSpec, path: string, options?: CopyOptions) => void;
|
|
59
|
+
copyText: (text: string, path: string) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class Builder implements Commands {
|
|
63
|
+
static instance?: Builder;
|
|
64
|
+
|
|
65
|
+
static getInstance() {
|
|
66
|
+
if (!Builder.instance) {
|
|
67
|
+
throw new Error("No builder instance found");
|
|
68
|
+
}
|
|
69
|
+
return Builder.instance;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_vars: Record<string, any>;
|
|
73
|
+
_tmpdir?: string;
|
|
74
|
+
memory: MemoryPackBuilder;
|
|
75
|
+
|
|
76
|
+
constructor(public options: BuildOptions = {}) {
|
|
77
|
+
this.memory = new MemoryPackBuilder(this);
|
|
78
|
+
this._vars = options.vars || {};
|
|
79
|
+
Builder.instance = this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
vars(): Record<string, any> {
|
|
83
|
+
return this._vars;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
tmpdir() {
|
|
87
|
+
if (!this._tmpdir) {
|
|
88
|
+
this._tmpdir = mkdtempSync(join(os.tmpdir(), 'becomposable-memo-'));
|
|
89
|
+
}
|
|
90
|
+
return this._tmpdir;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
from(location: string, options?: FromOptions) {
|
|
94
|
+
return loadMemoryPack(location).then((memory) => {
|
|
95
|
+
return this.memory.load(memory, options);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
addEntry(path: string, source: ContentSource) {
|
|
100
|
+
this.memory.add(path, source);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
copy(location: SourceSpec, path: string, options: CopyOptions = {}) {
|
|
104
|
+
copy(this, location, path, options);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
copyText(text: string, path: string) {
|
|
108
|
+
copy(this, new TextSource(text), path);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exec(cmd: string, options?: ExecOptions) {
|
|
112
|
+
return exec(cmd, options);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
content(location: string, encoding?: BufferEncoding) {
|
|
116
|
+
const source = AbstractContentSource.resolve(location);
|
|
117
|
+
if (Array.isArray(source)) {
|
|
118
|
+
return source.map(s => new ContentObject(this, s, encoding));
|
|
119
|
+
} else {
|
|
120
|
+
return new ContentObject(this, source, encoding);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
json(location: string) {
|
|
125
|
+
const source = AbstractContentSource.resolve(location);
|
|
126
|
+
if (Array.isArray(source)) {
|
|
127
|
+
return source.map(s => new JsonObject(this, s));
|
|
128
|
+
} else {
|
|
129
|
+
return new JsonObject(this, source);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pdf(location: string) {
|
|
134
|
+
const source = AbstractContentSource.resolve(location);
|
|
135
|
+
if (Array.isArray(source)) {
|
|
136
|
+
return source.map(s => new PdfObject(this, s));
|
|
137
|
+
} else {
|
|
138
|
+
return new PdfObject(this, source);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
docx(location: string) {
|
|
143
|
+
const source = AbstractContentSource.resolve(location);
|
|
144
|
+
if (Array.isArray(source)) {
|
|
145
|
+
return source.map(s => new DocxObject(this, s));
|
|
146
|
+
} else {
|
|
147
|
+
return new DocxObject(this, source);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
media(location: string, options?: MediaOptions) {
|
|
152
|
+
const source = AbstractContentSource.resolve(location);
|
|
153
|
+
if (Array.isArray(source)) {
|
|
154
|
+
return source.map(s => new MediaObject(this, s, options));
|
|
155
|
+
} else {
|
|
156
|
+
return new MediaObject(this, source, options);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async build(object: Record<string, any>) {
|
|
161
|
+
try {
|
|
162
|
+
let { fileName, publishName } = this._getOutputNames();
|
|
163
|
+
// resolve all content objects values from the conext object
|
|
164
|
+
object = await resolveContextObject(object);
|
|
165
|
+
// write the memory to a file
|
|
166
|
+
fileName = await this.memory.build(fileName, object);
|
|
167
|
+
let target: string = fileName;
|
|
168
|
+
if (publishName) {
|
|
169
|
+
try {
|
|
170
|
+
target = await this.options.publish!(fileName, publishName);
|
|
171
|
+
} finally {
|
|
172
|
+
rmSync(fileName);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
this.options.quiet || console.log(`Memory saved to ${target}`);
|
|
176
|
+
return target;
|
|
177
|
+
} finally {
|
|
178
|
+
if (this._tmpdir) {
|
|
179
|
+
rmSync(this._tmpdir, { recursive: true });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private _getOutputNames(): { fileName: string, publishName: string | undefined } {
|
|
185
|
+
const options = this.options;
|
|
186
|
+
if (!options.out) {
|
|
187
|
+
options.out = "memory.tar";
|
|
188
|
+
}
|
|
189
|
+
let fileName: string;
|
|
190
|
+
let publishName: string | undefined;
|
|
191
|
+
const out = options.out;
|
|
192
|
+
if (out.startsWith("memory:")) {
|
|
193
|
+
if (!options.publish) {
|
|
194
|
+
throw new Error(`The publish option is required for "${out}" output`);
|
|
195
|
+
}
|
|
196
|
+
// force gzip when publishing
|
|
197
|
+
options.gzip = true;
|
|
198
|
+
// create a temporary path for the output
|
|
199
|
+
fileName = createTmpBaseName(this.tmpdir());
|
|
200
|
+
publishName = out.substring("memory:".length);
|
|
201
|
+
} else {
|
|
202
|
+
fileName = resolve(out);
|
|
203
|
+
}
|
|
204
|
+
return { fileName, publishName };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function resolveContextObject(object: Record<string, any>): Promise<Record<string, any>> {
|
|
210
|
+
return new AsyncObjectWalker().map(object, async (_key, value) => {
|
|
211
|
+
if (value instanceof ContentObject) {
|
|
212
|
+
return await value.getText();
|
|
213
|
+
} else {
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function createTmpBaseName(tmpdir: string) {
|
|
220
|
+
return join(tmpdir, `.composable-memory-${Date.now()}.tar`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
export function buildMemoryPack(recipeFn: (commands: Commands) => Promise<Record<string, any>>, options: BuildOptions): Promise<string> {
|
|
225
|
+
const builder = new Builder(options);
|
|
226
|
+
return recipeFn({
|
|
227
|
+
vars: builder.vars.bind(builder),
|
|
228
|
+
tmpdir: builder.tmpdir.bind(builder),
|
|
229
|
+
exec: builder.exec.bind(builder),
|
|
230
|
+
from: builder.from.bind(builder),
|
|
231
|
+
content: builder.content.bind(builder),
|
|
232
|
+
json: builder.json.bind(builder),
|
|
233
|
+
pdf: builder.pdf.bind(builder),
|
|
234
|
+
docx: builder.docx.bind(builder),
|
|
235
|
+
media: builder.media.bind(builder),
|
|
236
|
+
copy: builder.copy.bind(builder),
|
|
237
|
+
copyText: builder.copyText.bind(builder),
|
|
238
|
+
}).then(metadata => builder.build(metadata));
|
|
239
|
+
}
|