@ocfl/ocfl 0.4.0 → 1.0.0-beta.2
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 +674 -0
- package/README.md +24 -9
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/digest.d.ts +58 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +204 -0
- package/dist/digest.js.map +1 -0
- package/dist/error.d.ts +5 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +9 -0
- package/dist/error.js.map +1 -0
- package/dist/extension.d.ts +82 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +169 -0
- package/dist/extension.js.map +1 -0
- package/dist/extensions/0002-flat-direct-storage-layout.d.ts +12 -0
- package/dist/extensions/0002-flat-direct-storage-layout.d.ts.map +1 -0
- package/dist/extensions/0002-flat-direct-storage-layout.js +34 -0
- package/dist/extensions/0002-flat-direct-storage-layout.js.map +1 -0
- package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.d.ts +15 -0
- package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.d.ts.map +1 -0
- package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.js +49 -0
- package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.js.map +1 -0
- package/dist/extensions/0004-hashed-n-tuple-storage-layout.d.ts +17 -0
- package/dist/extensions/0004-hashed-n-tuple-storage-layout.d.ts.map +1 -0
- package/dist/extensions/0004-hashed-n-tuple-storage-layout.js +54 -0
- package/dist/extensions/0004-hashed-n-tuple-storage-layout.js.map +1 -0
- package/dist/extensions/0006-flat-omit-prefix-storage-layout.d.ts +6 -0
- package/dist/extensions/0006-flat-omit-prefix-storage-layout.d.ts.map +1 -0
- package/dist/extensions/0006-flat-omit-prefix-storage-layout.js +8 -0
- package/dist/extensions/0006-flat-omit-prefix-storage-layout.js.map +1 -0
- package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.d.ts +6 -0
- package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.d.ts.map +1 -0
- package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.js +8 -0
- package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.js.map +1 -0
- package/dist/extensions/0009-digest-algorithms.d.ts +9 -0
- package/dist/extensions/0009-digest-algorithms.d.ts.map +1 -0
- package/dist/extensions/0009-digest-algorithms.js +11 -0
- package/dist/extensions/0009-digest-algorithms.js.map +1 -0
- package/dist/extensions/000N-path-direct-storage-layout.d.ts +16 -0
- package/dist/extensions/000N-path-direct-storage-layout.d.ts.map +1 -0
- package/dist/extensions/000N-path-direct-storage-layout.js +46 -0
- package/dist/extensions/000N-path-direct-storage-layout.js.map +1 -0
- package/dist/extensions/index.d.ts +23 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +8 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/file.d.ts +87 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/file.js +118 -0
- package/dist/file.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory.d.ts +155 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +591 -0
- package/dist/inventory.js.map +1 -0
- package/dist/object.d.ts +188 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +425 -0
- package/dist/object.js.map +1 -0
- package/dist/storage.d.ts +94 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +302 -0
- package/dist/storage.js.map +1 -0
- package/dist/store.d.ts +100 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +157 -0
- package/dist/store.js.map +1 -0
- package/dist/transaction.d.ts +155 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +394 -0
- package/dist/transaction.js.map +1 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +85 -0
- package/dist/utils.js.map +1 -0
- package/dist/validation.d.ts +32 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +31 -0
- package/dist/validation.js.map +1 -0
- package/package.json +31 -51
- package/src/constants.ts +16 -0
- package/src/digest.ts +258 -0
- package/src/error.ts +9 -0
- package/src/extension.ts +204 -0
- package/{lib/extensions/0002-flat-direct-storage-layout.js → src/extensions/0002-flat-direct-storage-layout.ts} +15 -22
- package/src/extensions/0003-hash-and-id-n-tuple-storage-layout.ts +56 -0
- package/src/extensions/0004-hashed-n-tuple-storage-layout.ts +59 -0
- package/src/extensions/0006-flat-omit-prefix-storage-layout.ts +9 -0
- package/src/extensions/0007-n-tuple-omit-prefix-storage-layout.ts +9 -0
- package/src/extensions/0009-digest-algorithms.ts +12 -0
- package/src/extensions/000N-path-direct-storage-layout.ts +51 -0
- package/src/extensions/index.ts +24 -0
- package/src/file.ts +161 -0
- package/src/index.ts +92 -0
- package/src/inventory.ts +634 -0
- package/src/object.ts +473 -0
- package/src/storage.ts +342 -0
- package/src/store.ts +199 -0
- package/src/transaction.ts +455 -0
- package/{lib/types.d.ts → src/types.ts} +28 -74
- package/src/utils.ts +94 -0
- package/src/validation.ts +46 -0
- package/index.js +0 -129
- package/index.mjs +0 -18
- package/lib/constants.js +0 -24
- package/lib/digest.js +0 -307
- package/lib/enum.js +0 -90
- package/lib/error.js +0 -19
- package/lib/extension.js +0 -194
- package/lib/extensions/0003-hash-and-id-n-tuple-storage-layout.js +0 -60
- package/lib/extensions/0004-hashed-n-tuple-storage-layout.js +0 -63
- package/lib/extensions/0005-mutable-head.js +0 -0
- package/lib/extensions/0006-flat-omit-prefix-storage-layout.js +0 -7
- package/lib/extensions/0007-n-tuple-omit-prefix-storage-layout.js +0 -7
- package/lib/extensions/0008-schema-registry.js +0 -0
- package/lib/extensions/0009-digest-algorithms.js +0 -18
- package/lib/extensions/000N-path-direct-storage-layout.js +0 -61
- package/lib/extensions/index.js +0 -13
- package/lib/file.js +0 -147
- package/lib/index.js +0 -13
- package/lib/inventory.js +0 -564
- package/lib/object.js +0 -499
- package/lib/storage.js +0 -338
- package/lib/store.js +0 -191
- package/lib/transaction.js +0 -448
- package/lib/utils.js +0 -122
- package/lib/validation.js +0 -174
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { OcflStorageLayout } from '../extension.ts';
|
|
3
|
+
|
|
4
|
+
const DefaultConfig = {
|
|
5
|
+
extensionName: '000N-path-direct-storage-layout',
|
|
6
|
+
omitScheme: false,
|
|
7
|
+
replace: [] as [string | RegExp, string][],
|
|
8
|
+
suffix: '/__object__',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type PathDirectStorageLayoutConfig = Partial<typeof DefaultConfig>;
|
|
12
|
+
|
|
13
|
+
class PathDirectStorageLayout extends OcflStorageLayout<typeof DefaultConfig> {
|
|
14
|
+
static get NAME() {
|
|
15
|
+
return DefaultConfig.extensionName;
|
|
16
|
+
}
|
|
17
|
+
static get DESCRIPTION() {
|
|
18
|
+
return 'OCFL object identifiers are used directly as the path.';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(config?: PathDirectStorageLayoutConfig) {
|
|
22
|
+
super(config, DefaultConfig);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
map(id: string): string {
|
|
26
|
+
var suffix = this.parameters.suffix;
|
|
27
|
+
if (suffix && id.endsWith(suffix)) {
|
|
28
|
+
throw new Error(`Identifier cannot end with '${suffix}'`);
|
|
29
|
+
}
|
|
30
|
+
var p = id ?? '';
|
|
31
|
+
for (const r of this.parameters.replace) {
|
|
32
|
+
p = p.replace(r[0], r[1]);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const u = new URL(p);
|
|
36
|
+
const parts = [];
|
|
37
|
+
if (!this.parameters.omitScheme && u.protocol !== 'file:') {
|
|
38
|
+
parts.push(u.protocol.replace(':', ''));
|
|
39
|
+
}
|
|
40
|
+
if (u.hostname) {
|
|
41
|
+
parts.push(u.hostname.replace(',', '_').replace(';', '/'));
|
|
42
|
+
}
|
|
43
|
+
p = path.join(parts.join('_'), u.pathname + u.search + u.hash);
|
|
44
|
+
} catch (_error) {}
|
|
45
|
+
p = p.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
46
|
+
return path.join(p, this.parameters.suffix);
|
|
47
|
+
//if (/^\w+:/.test(id)) {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { PathDirectStorageLayout };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { PathDirectStorageLayout } from './000N-path-direct-storage-layout.ts';
|
|
2
|
+
export { FlatDirectStorageLayout } from './0002-flat-direct-storage-layout.ts';
|
|
3
|
+
export { HashAndIdNTupleStorageLayout } from './0003-hash-and-id-n-tuple-storage-layout.ts';
|
|
4
|
+
export { HashedNTupleStorageLayout } from './0004-hashed-n-tuple-storage-layout.ts';
|
|
5
|
+
export { FlatOmitPrefixStorageLayout } from './0006-flat-omit-prefix-storage-layout.ts';
|
|
6
|
+
export { NTupleOmitPrefixStorageLayout } from './0007-n-tuple-omit-prefix-storage-layout.ts';
|
|
7
|
+
export { DigestAlgorithm } from './0009-digest-algorithms.ts';
|
|
8
|
+
|
|
9
|
+
import type { PathDirectStorageLayout } from './000N-path-direct-storage-layout.ts';
|
|
10
|
+
import type { FlatDirectStorageLayout } from './0002-flat-direct-storage-layout.ts';
|
|
11
|
+
import type { HashAndIdNTupleStorageLayout } from './0003-hash-and-id-n-tuple-storage-layout.ts';
|
|
12
|
+
import type { HashedNTupleStorageLayout } from './0004-hashed-n-tuple-storage-layout.ts';
|
|
13
|
+
import type { FlatOmitPrefixStorageLayout } from './0006-flat-omit-prefix-storage-layout.ts';
|
|
14
|
+
import type { NTupleOmitPrefixStorageLayout } from './0007-n-tuple-omit-prefix-storage-layout.ts';
|
|
15
|
+
|
|
16
|
+
/** Built-in storage layout classes, keyed by class name */
|
|
17
|
+
export type StorageLayout = {
|
|
18
|
+
FlatDirectStorageLayout: typeof FlatDirectStorageLayout;
|
|
19
|
+
FlatOmitPrefixStorageLayout: typeof FlatOmitPrefixStorageLayout;
|
|
20
|
+
HashAndIdNTupleStorageLayout: typeof HashAndIdNTupleStorageLayout;
|
|
21
|
+
HashedNTupleStorageLayout: typeof HashedNTupleStorageLayout;
|
|
22
|
+
NTupleOmitPrefixStorageLayout: typeof NTupleOmitPrefixStorageLayout;
|
|
23
|
+
PathDirectStorageLayout: typeof PathDirectStorageLayout;
|
|
24
|
+
};
|
package/src/file.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { OcflObject } from './object.ts';
|
|
2
|
+
|
|
3
|
+
export interface FileRef {
|
|
4
|
+
/** Actual path to the file location relative to the ocfl object root. */
|
|
5
|
+
contentPath?: string;
|
|
6
|
+
/** A path that represents a file’s location in the logical state of an object. */
|
|
7
|
+
logicalPath?: string;
|
|
8
|
+
/** An algorithmic characterization of the contents of a file conforming to a standard digest algorithm. */
|
|
9
|
+
digest?: string;
|
|
10
|
+
/** Version of the OCFL object. */
|
|
11
|
+
version?: string | undefined;
|
|
12
|
+
/** Last modified time of the file, in milliseconds since the UNIX epoch. */
|
|
13
|
+
lastModified?: number;
|
|
14
|
+
/** Size of the file in bytes. */
|
|
15
|
+
size?: number;
|
|
16
|
+
/** Fixity information of the file. */
|
|
17
|
+
fixity?: { [algorithm: string]: string };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface FileStat {
|
|
21
|
+
/** Size of the file in bytes. */
|
|
22
|
+
size?: number;
|
|
23
|
+
/** Last access time of the file. */
|
|
24
|
+
atime?: Date;
|
|
25
|
+
/** Last modified time of the file. */
|
|
26
|
+
mtime?: Date;
|
|
27
|
+
/** Creation time of the file. */
|
|
28
|
+
ctime?: Date;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const REF_KEYS = ['logicalPath', 'version', 'digest', 'contentPath'] as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Represent a file in an OCFL object
|
|
35
|
+
*/
|
|
36
|
+
class OcflObjectFile {
|
|
37
|
+
#ocflObject: OcflObject;
|
|
38
|
+
#lastModified: number | undefined;
|
|
39
|
+
#size: number | undefined;
|
|
40
|
+
logicalPath?: string;
|
|
41
|
+
contentPath?: string;
|
|
42
|
+
digest?: string;
|
|
43
|
+
version?: string;
|
|
44
|
+
fixity?: { [algorithm: string]: string };
|
|
45
|
+
|
|
46
|
+
constructor(ocflObject: OcflObject, fileRef: FileRef) {
|
|
47
|
+
this.#ocflObject = ocflObject;
|
|
48
|
+
if (fileRef.logicalPath) {
|
|
49
|
+
this.logicalPath = fileRef.logicalPath;
|
|
50
|
+
}
|
|
51
|
+
if (fileRef.contentPath) {
|
|
52
|
+
this.contentPath = fileRef.contentPath;
|
|
53
|
+
}
|
|
54
|
+
if (fileRef.digest) {
|
|
55
|
+
this.digest = fileRef.digest;
|
|
56
|
+
}
|
|
57
|
+
if (fileRef.version) {
|
|
58
|
+
this.version = fileRef.version;
|
|
59
|
+
}
|
|
60
|
+
if (fileRef.lastModified != null) {
|
|
61
|
+
this.#lastModified = fileRef.lastModified;
|
|
62
|
+
}
|
|
63
|
+
if (fileRef.size != null) {
|
|
64
|
+
this.#size = fileRef.size;
|
|
65
|
+
}
|
|
66
|
+
if (fileRef.fixity != null) {
|
|
67
|
+
this.fixity = fileRef.fixity;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resolve contentPath given either the `logicalPath` and `version`, `digest`, or `contentPath`.
|
|
73
|
+
*/
|
|
74
|
+
async #resolveContentPath(): Promise<string> {
|
|
75
|
+
let contentPath = this.contentPath;
|
|
76
|
+
if (!contentPath) {
|
|
77
|
+
const inv = await this.#ocflObject._requireInventory();
|
|
78
|
+
const version = !this.version || this.version === 'latest' ? inv.head : this.version;
|
|
79
|
+
contentPath = this.digest ? inv.getContentPath(this.digest) : this.logicalPath && inv.getFile(this.logicalPath, version)?.contentPath;
|
|
80
|
+
if (!contentPath) {
|
|
81
|
+
throw new Error(`Cannot find content "${this.toString()}" in the OCFL Object "${this.#ocflObject.id}" version "${this.version || 'latest'}"`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return contentPath;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).
|
|
89
|
+
*/
|
|
90
|
+
get lastModified() {
|
|
91
|
+
return this.#lastModified;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Returns the file size in bytes.
|
|
96
|
+
*/
|
|
97
|
+
get size() {
|
|
98
|
+
return this.#size;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
toString() {
|
|
102
|
+
const props = REF_KEYS.filter((key) => this[key]).map((key) => `${key}: '${this[key]}'`);
|
|
103
|
+
return `{ ${props.join(', ')} }`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the file content as a buffer
|
|
108
|
+
* @param options Options to be passed to underlying data store specific implementation
|
|
109
|
+
*/
|
|
110
|
+
async buffer(options?: unknown): Promise<Uint8Array> {
|
|
111
|
+
return this.#ocflObject.readFile(await this.#resolveContentPath(), options);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated Use {@link OcflObjectFile.buffer}
|
|
116
|
+
*/
|
|
117
|
+
async asBuffer(options?: unknown) {
|
|
118
|
+
return this.buffer(options);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get the file content as a string
|
|
123
|
+
* @param encoding String encoding, default to utf8
|
|
124
|
+
*/
|
|
125
|
+
async text(encoding: BufferEncoding = 'utf8'): Promise<string> {
|
|
126
|
+
return this.#ocflObject.readFile(await this.#resolveContentPath(), encoding);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @deprecated Use {@link OcflObjectFile.text}
|
|
131
|
+
*/
|
|
132
|
+
async asString(encoding: BufferEncoding = 'utf8') {
|
|
133
|
+
return this.text(encoding);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get the file content as a ReadableStream
|
|
138
|
+
* @param options Options to be passed to underlying data store specific implementation
|
|
139
|
+
* @deprecated Use {@link OcflObjectFile.stream}
|
|
140
|
+
*/
|
|
141
|
+
async asStream(options?: unknown): Promise<ReadableStream> {
|
|
142
|
+
return this.stream(options);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get the file content as a ES Streams standard ReadableStream
|
|
147
|
+
* @param options Options to be passed to underlying data store specific implementation
|
|
148
|
+
*/
|
|
149
|
+
async stream(options?: unknown): Promise<ReadableStream> {
|
|
150
|
+
return this.#ocflObject.createReadable(await this.#resolveContentPath(), options);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get the file stat info
|
|
155
|
+
*/
|
|
156
|
+
async stat(_options?: unknown): Promise<FileStat> {
|
|
157
|
+
return this.#ocflObject.stat(await this.#resolveContentPath());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { OcflObjectFile };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ocfl
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { OcflConstants } from './constants.ts';
|
|
6
|
+
import { createByName, OcflStorageLayout } from './extension.ts';
|
|
7
|
+
import * as extensions from './extensions/index.ts';
|
|
8
|
+
import { OcflObject } from './object.ts';
|
|
9
|
+
import { type OcflStorage, OcflStorageImpl } from './storage.ts';
|
|
10
|
+
import type { OcflStore } from './store.ts';
|
|
11
|
+
import type { OcflExtensionConfig, OcflObjectConfig, OcflStorageConfig } from './types.ts';
|
|
12
|
+
|
|
13
|
+
export { OcflConstants } from './constants.ts';
|
|
14
|
+
export { OcflDigest } from './digest.ts';
|
|
15
|
+
export { OcflExtension, OcflStorageLayout } from './extension.ts';
|
|
16
|
+
export type { PathDirectStorageLayoutConfig } from './extensions/000N-path-direct-storage-layout.ts';
|
|
17
|
+
export type { HashedNTupleStorageLayoutConfig } from './extensions/0004-hashed-n-tuple-storage-layout.ts';
|
|
18
|
+
export type { StorageLayout } from './extensions/index.ts';
|
|
19
|
+
export type { FileRef, FileStat, OcflObjectFile } from './file.ts';
|
|
20
|
+
export type { InventoryFile, OcflObjectInventoryMut, VersionNumber } from './inventory.ts';
|
|
21
|
+
export { OcflObjectInventory } from './inventory.ts';
|
|
22
|
+
export type { UpdateMode } from './object.ts';
|
|
23
|
+
export { OcflObject } from './object.ts';
|
|
24
|
+
export { OcflStorage, OcflStorageImpl } from './storage.ts';
|
|
25
|
+
export type { ListedFile, ListOptions, WriteFileData } from './store.ts';
|
|
26
|
+
export { OcflStore } from './store.ts';
|
|
27
|
+
export type { CommitOptions, RemoveOptions } from './transaction.ts';
|
|
28
|
+
export { OcflObjectTransaction, OcflObjectTransactionImpl } from './transaction.ts';
|
|
29
|
+
export type * from './types.ts';
|
|
30
|
+
export { extensions };
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new OCFL core API with a specific backend store.
|
|
34
|
+
* Any backend store implementation module must return the result of this method.
|
|
35
|
+
* @returns Top level OCFL API interface that provides storage and object creation.
|
|
36
|
+
*/
|
|
37
|
+
export function implementOcfl<SO extends object>(store: { getInstance(options?: SO): OcflStore }, defaultOptions?: SO) {
|
|
38
|
+
return {
|
|
39
|
+
OCFL_VERSIONS: OcflConstants.OCFL_VERSIONS,
|
|
40
|
+
|
|
41
|
+
/** Built-in storage layout classes */
|
|
42
|
+
StorageLayout: OcflStorageLayout.layout,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Instantiate a storage layout from extension name or config
|
|
46
|
+
* @param config - Layout name or config
|
|
47
|
+
*/
|
|
48
|
+
storageLayout(config: string | OcflExtensionConfig): OcflStorageLayout {
|
|
49
|
+
let name: string | undefined;
|
|
50
|
+
let c: OcflExtensionConfig | undefined;
|
|
51
|
+
if (typeof config === 'string') {
|
|
52
|
+
name = config;
|
|
53
|
+
} else {
|
|
54
|
+
name = config.extensionName;
|
|
55
|
+
c = config;
|
|
56
|
+
}
|
|
57
|
+
return createByName<OcflStorageLayout>(OcflStorageLayout, 'Layout', name, c);
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Instantiate an OCFL Object
|
|
62
|
+
*/
|
|
63
|
+
object(config: OcflObjectConfig, storeOptions: SO | undefined = defaultOptions): OcflObject {
|
|
64
|
+
return new OcflObject(config, store.getInstance(storeOptions));
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Instantiate an OCFL Storage root
|
|
69
|
+
*/
|
|
70
|
+
storage(config: OcflStorageConfig, storeOptions: SO | undefined = defaultOptions): OcflStorage {
|
|
71
|
+
return new OcflStorageImpl(config, store.getInstance(storeOptions));
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create a new OCFL Storage
|
|
76
|
+
*/
|
|
77
|
+
async createStorage(config: OcflStorageConfig, storeOptions: SO | undefined = defaultOptions): Promise<OcflStorage> {
|
|
78
|
+
return new OcflStorageImpl(config, store.getInstance(storeOptions)).create();
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Load an existing OCFL Storage
|
|
83
|
+
*/
|
|
84
|
+
async loadStorage(config: OcflStorageConfig, storeOptions: SO | undefined = defaultOptions): Promise<OcflStorage> {
|
|
85
|
+
return new OcflStorageImpl(config, store.getInstance(storeOptions)).load();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const ext of Object.values(extensions)) {
|
|
91
|
+
ext.register();
|
|
92
|
+
}
|