@ocfl/ocfl 0.3.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +24 -9
  3. package/dist/constants.d.ts +15 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/constants.js +14 -0
  6. package/dist/constants.js.map +1 -0
  7. package/dist/digest.d.ts +58 -0
  8. package/dist/digest.d.ts.map +1 -0
  9. package/dist/digest.js +204 -0
  10. package/dist/digest.js.map +1 -0
  11. package/dist/error.d.ts +5 -0
  12. package/dist/error.d.ts.map +1 -0
  13. package/dist/error.js +9 -0
  14. package/dist/error.js.map +1 -0
  15. package/dist/extension.d.ts +83 -0
  16. package/dist/extension.d.ts.map +1 -0
  17. package/dist/extension.js +170 -0
  18. package/dist/extension.js.map +1 -0
  19. package/dist/extensions/0002-flat-direct-storage-layout.d.ts +12 -0
  20. package/dist/extensions/0002-flat-direct-storage-layout.d.ts.map +1 -0
  21. package/dist/extensions/0002-flat-direct-storage-layout.js +34 -0
  22. package/dist/extensions/0002-flat-direct-storage-layout.js.map +1 -0
  23. package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.d.ts +15 -0
  24. package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.d.ts.map +1 -0
  25. package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.js +49 -0
  26. package/dist/extensions/0003-hash-and-id-n-tuple-storage-layout.js.map +1 -0
  27. package/dist/extensions/0004-hashed-n-tuple-storage-layout.d.ts +17 -0
  28. package/dist/extensions/0004-hashed-n-tuple-storage-layout.d.ts.map +1 -0
  29. package/dist/extensions/0004-hashed-n-tuple-storage-layout.js +54 -0
  30. package/dist/extensions/0004-hashed-n-tuple-storage-layout.js.map +1 -0
  31. package/dist/extensions/0006-flat-omit-prefix-storage-layout.d.ts +6 -0
  32. package/dist/extensions/0006-flat-omit-prefix-storage-layout.d.ts.map +1 -0
  33. package/dist/extensions/0006-flat-omit-prefix-storage-layout.js +8 -0
  34. package/dist/extensions/0006-flat-omit-prefix-storage-layout.js.map +1 -0
  35. package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.d.ts +6 -0
  36. package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.d.ts.map +1 -0
  37. package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.js +8 -0
  38. package/dist/extensions/0007-n-tuple-omit-prefix-storage-layout.js.map +1 -0
  39. package/dist/extensions/0009-digest-algorithms.d.ts +9 -0
  40. package/dist/extensions/0009-digest-algorithms.d.ts.map +1 -0
  41. package/dist/extensions/0009-digest-algorithms.js +11 -0
  42. package/dist/extensions/0009-digest-algorithms.js.map +1 -0
  43. package/dist/extensions/000N-path-direct-storage-layout.d.ts +16 -0
  44. package/dist/extensions/000N-path-direct-storage-layout.d.ts.map +1 -0
  45. package/dist/extensions/000N-path-direct-storage-layout.js +46 -0
  46. package/dist/extensions/000N-path-direct-storage-layout.js.map +1 -0
  47. package/dist/extensions/index.d.ts +23 -0
  48. package/dist/extensions/index.d.ts.map +1 -0
  49. package/dist/extensions/index.js +8 -0
  50. package/dist/extensions/index.js.map +1 -0
  51. package/dist/file.d.ts +87 -0
  52. package/dist/file.d.ts.map +1 -0
  53. package/dist/file.js +118 -0
  54. package/dist/file.js.map +1 -0
  55. package/dist/index.d.ts +61 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +73 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/inventory.d.ts +155 -0
  60. package/dist/inventory.d.ts.map +1 -0
  61. package/dist/inventory.js +591 -0
  62. package/dist/inventory.js.map +1 -0
  63. package/dist/object.d.ts +188 -0
  64. package/dist/object.d.ts.map +1 -0
  65. package/dist/object.js +425 -0
  66. package/dist/object.js.map +1 -0
  67. package/dist/storage.d.ts +94 -0
  68. package/dist/storage.d.ts.map +1 -0
  69. package/dist/storage.js +302 -0
  70. package/dist/storage.js.map +1 -0
  71. package/dist/store.d.ts +100 -0
  72. package/dist/store.d.ts.map +1 -0
  73. package/dist/store.js +157 -0
  74. package/dist/store.js.map +1 -0
  75. package/dist/transaction.d.ts +155 -0
  76. package/dist/transaction.d.ts.map +1 -0
  77. package/dist/transaction.js +395 -0
  78. package/dist/transaction.js.map +1 -0
  79. package/dist/types.d.ts +107 -0
  80. package/dist/types.d.ts.map +1 -0
  81. package/dist/types.js +2 -0
  82. package/dist/types.js.map +1 -0
  83. package/dist/utils.d.ts +24 -0
  84. package/dist/utils.d.ts.map +1 -0
  85. package/dist/utils.js +85 -0
  86. package/dist/utils.js.map +1 -0
  87. package/dist/validation.d.ts +32 -0
  88. package/dist/validation.d.ts.map +1 -0
  89. package/dist/validation.js +31 -0
  90. package/dist/validation.js.map +1 -0
  91. package/package.json +31 -50
  92. package/src/constants.ts +16 -0
  93. package/src/digest.ts +258 -0
  94. package/src/error.ts +9 -0
  95. package/src/extension.ts +206 -0
  96. package/{lib/extensions/0002-flat-direct-storage-layout.js → src/extensions/0002-flat-direct-storage-layout.ts} +15 -22
  97. package/src/extensions/0003-hash-and-id-n-tuple-storage-layout.ts +56 -0
  98. package/src/extensions/0004-hashed-n-tuple-storage-layout.ts +59 -0
  99. package/src/extensions/0006-flat-omit-prefix-storage-layout.ts +9 -0
  100. package/src/extensions/0007-n-tuple-omit-prefix-storage-layout.ts +9 -0
  101. package/src/extensions/0009-digest-algorithms.ts +12 -0
  102. package/src/extensions/000N-path-direct-storage-layout.ts +51 -0
  103. package/src/extensions/index.ts +24 -0
  104. package/src/file.ts +161 -0
  105. package/src/index.ts +92 -0
  106. package/src/inventory.ts +634 -0
  107. package/src/object.ts +473 -0
  108. package/src/storage.ts +342 -0
  109. package/src/store.ts +199 -0
  110. package/src/transaction.ts +456 -0
  111. package/{lib/types.d.ts → src/types.ts} +28 -74
  112. package/src/utils.ts +94 -0
  113. package/src/validation.ts +46 -0
  114. package/index.js +0 -129
  115. package/index.mjs +0 -18
  116. package/lib/constants.js +0 -24
  117. package/lib/digest.js +0 -307
  118. package/lib/enum.js +0 -90
  119. package/lib/error.js +0 -19
  120. package/lib/extension.js +0 -194
  121. package/lib/extensions/0003-hash-and-id-n-tuple-storage-layout.js +0 -60
  122. package/lib/extensions/0004-hashed-n-tuple-storage-layout.js +0 -63
  123. package/lib/extensions/0005-mutable-head.js +0 -0
  124. package/lib/extensions/0006-flat-omit-prefix-storage-layout.js +0 -7
  125. package/lib/extensions/0007-n-tuple-omit-prefix-storage-layout.js +0 -7
  126. package/lib/extensions/0008-schema-registry.js +0 -0
  127. package/lib/extensions/0009-digest-algorithms.js +0 -18
  128. package/lib/extensions/000N-path-direct-storage-layout.js +0 -61
  129. package/lib/extensions/index.js +0 -13
  130. package/lib/file.js +0 -129
  131. package/lib/index.js +0 -13
  132. package/lib/inventory.js +0 -564
  133. package/lib/object.js +0 -451
  134. package/lib/storage.js +0 -338
  135. package/lib/store.js +0 -191
  136. package/lib/transaction.js +0 -448
  137. package/lib/utils.js +0 -123
  138. package/lib/validation.js +0 -174
package/lib/enum.js DELETED
@@ -1,90 +0,0 @@
1
- /**
2
- * Enumeration tool for working with a set of options
3
- * @module enumeration
4
- */
5
-
6
- // const COLOR = (c => {
7
- // let r = /** @type {{[key in (typeof c)[number]]: string}} */({});
8
- // return r;
9
- // })(/** @type {const} */(['red', 'green', 'blue']));
10
- // COLOR.blue
11
- const constantsSymbol = Symbol('constants');
12
-
13
- /**
14
- * Create enumeration type by passing the list of constants as arguments of string
15
- * @template {readonly string[]} const T
16
- * @param {T} constants
17
- */
18
-
19
- function enumeration(constants) {
20
- class Enum {
21
- /** @type {string} */
22
- #name;
23
- /** @type {number} */
24
- #ordinal;
25
- constructor(name, ordinal) {
26
- this.#name = name;
27
- this.#ordinal = ordinal;
28
- //Object.defineProperty(this, 'name', { writable: false, enumerable: true, value: name });
29
- //Object.defineProperty(this, 'ordinal', { writable: false, enumerable: true, value: ordinal });
30
- }
31
- get name() { return this.#name }
32
- get ordinal() { return this.#ordinal }
33
- toString() {
34
- return this.name;
35
- }
36
- /** @returns {Iterator<string>} */
37
- static [Symbol.iterator]() {
38
- return this[constantsSymbol][Symbol.iterator]();
39
- }
40
- }
41
- /** @typedef { typeof Enum & {[key in T[number]]: Enum} } EnumType */
42
- let count = 0;
43
- for (let c of constants) {
44
- Object.defineProperty(Enum, c, {
45
- value: Object.freeze(new Enum(c, count++)),
46
- writable: false,
47
- enumerable: true
48
- });
49
- }
50
- Object.defineProperty(Enum, constantsSymbol, {
51
- value: constants,
52
- writable: false,
53
- enumerable: false
54
- });
55
- return /** @type {EnumType} */(Object.freeze(Enum));
56
- }
57
-
58
- /**
59
- * Return an existing constant that represents the specified value
60
- * @type {{<T extends abstract new() => any>(type: T, value: any): InstanceType<T>}}
61
- */
62
- enumeration.of = function (type, value) {
63
- if (value instanceof type && type[value.name]) return value;
64
- else if (typeof value === 'string') {
65
- return type[/**@type {string}*/(value)] || (() => {
66
- for (let name in type) {
67
- if (name.toUpperCase() === value.toUpperCase()) return type[name];
68
- }
69
- })();
70
- }
71
- }
72
-
73
- /**
74
- * Return an existing constant based on the index
75
- * @template T
76
- * @param {new() => T} type
77
- * @param {number} index
78
- * @return {T}
79
- */
80
- enumeration.at = function (type, index) {
81
- return type[type[constantsSymbol][index]];
82
- }
83
-
84
- enumeration.size = function (type) {
85
- return type[constantsSymbol].length;
86
- }
87
-
88
- exports.enumeration = enumeration;
89
- exports.default = { ...enumeration };
90
- //export default { ...enumeration };
package/lib/error.js DELETED
@@ -1,19 +0,0 @@
1
- class ValidationError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = 'ValidationError';
5
- }
6
- }
7
-
8
- class NotImplementedError extends Error {
9
- constructor(methodName) {
10
- let msg = methodName ? 'Method ' + methodName + ' has not been implemented' : '';
11
- super(msg);
12
- this.name = 'NotImplementedError';
13
- }
14
- }
15
-
16
- module.exports = {
17
- ValidationError,
18
- NotImplementedError
19
- };
package/lib/extension.js DELETED
@@ -1,194 +0,0 @@
1
- const { NotImplementedError } = require("./error");
2
-
3
- /** Index by Registered extension name */
4
- const extensionByName = {};
5
- /** Index by extension class name */
6
- const extensionByClassName = {};
7
-
8
- const storageLayout = {};
9
-
10
- // class OcflExtensionConfig {
11
- // /** User defined config */
12
- // definedConfig;
13
- // constructor(config) {
14
- // this.definedConfig = config;
15
- // }
16
-
17
- // }
18
- /** @typedef {import('../index.js').StorageLayout} StorageLayout */
19
-
20
- /**
21
- * @template {{}} C
22
- */
23
- class OcflExtension {
24
- static #object = {};
25
- static #storage = {};
26
-
27
- /**
28
- * Get an object-level extension
29
- * @param {string} name - A registered extension name
30
- */
31
- static object(name) {
32
- return this.#object[name];
33
- }
34
- /**
35
- * Get an storage-level extension
36
- * @param {string} name - A registered extension name
37
- */
38
- static storage(name) {
39
- return this.#storage[name];
40
- }
41
-
42
- /** List all registered extension classes */
43
- static get classes() {
44
- return Object.values(extensionByName);
45
- }
46
-
47
- /**
48
- * Find a registered extension with the specified name
49
- * @param {string} name - extension class name or registered extension name
50
- * @return {typeof OcflExtension} - the extension class
51
- */
52
- static class(name) {
53
- return extensionByName[name] || extensionByClassName[name];
54
- }
55
-
56
- /**
57
- * Register an extension
58
- * @param {typeof OcflExtension} extensionClass
59
- */
60
- static register(extensionClass = this) {
61
- let name = extensionClass.NAME;
62
- extensionByName[name] = extensionClass;
63
- extensionByClassName[extensionClass.name] = extensionClass;
64
- // if (extensionClass.forObject) {
65
- // if (this.#object[name]) throw new Error(`Extension ${name} already registered.`);
66
- // this.#object[name] = extensionClass;
67
- // }
68
- // if (extensionClass.forStorage) {
69
- // if (this.#storage[name]) throw new Error(`Extension ${name} already registered.`);
70
- // this.#storage[name] = extensionClass;
71
- // }
72
- extensionClass.setup(require('./index.js'));
73
- }
74
-
75
- /**
76
- * Create an instance of the extension
77
- * @type {<T extends typeof OcflExtension>(this: T, config?: OcflExtensionConfig) => InstanceType<T>}
78
- */
79
- static create = function (config) {
80
- // @ts-ignore
81
- if (!config?.extensionName || this.NAME === config.extensionName) return new this(config);
82
- // @ts-ignore
83
- return OcflExtension.class(config.extensionName).create(config);
84
- }
85
-
86
- static get forObject() { return false; }
87
- static get forStorage() { return false; }
88
- static get NAME() { return '0000-example-extension' }
89
- static get DESCRIPTION() { return 'Example extension' }
90
- static async setup(ocfl) { };
91
-
92
- /**
93
- *
94
- * @param {OcflExtensionConfig} [config]
95
- * @param {C} [defaultConfig]
96
- */
97
- constructor(config, defaultConfig) {
98
- /** @type {C} */
99
- this.parameters = typeof defaultConfig === 'object' ? Object.create(/**@type{object}*/(defaultConfig)) : {};
100
- if (typeof config === 'object') {
101
- for (let k in config) {
102
- if (k in defaultConfig) this.parameters[k] = config[k];
103
- }
104
- }
105
- }
106
-
107
- /** Return all the parameters in which the value has been set to non-default value */
108
- get config() {
109
- let paramNames = Object.keys(this.parameters);
110
- if (paramNames.length > 0) {
111
- return paramNames.reduce( (params, name) => (params[name] = this.parameters[name], params), {extensionName: this.name});
112
- }
113
- }
114
-
115
- get p() { return this.parameters; }
116
-
117
- /** Extension registered name */
118
- get name() { return /** @type {typeof OcflExtension}*/(this.constructor).NAME }
119
- get description() { return /** @type {typeof OcflExtension}*/(this.constructor).DESCRIPTION }
120
- get minOcflVersion() { return "1.0" }
121
- get version() { return "1.0" }
122
-
123
- /**
124
- * Get the specified parameter value
125
- * @param {string} param - The extension parameter name
126
- * @return {*}
127
- */
128
- get(param) { return this.parameters[param]; }
129
-
130
- /**
131
- * Set the specified parameter value
132
- * @param {string} param - The extension parameter name
133
- * @param {*} value - The extension parameter value
134
- */
135
- set(param, value) { if (param in this.parameters) this.parameters[param] = value; }
136
- }
137
-
138
-
139
- /**
140
- * @template {{}} C
141
- * @extends {OcflExtension<C>}
142
- */
143
- class OcflStorageLayout extends OcflExtension {
144
-
145
- static get layout() {
146
- return /** @type StorageLayout */(storageLayout);
147
- }
148
-
149
- /**
150
- *
151
- * @param {string} name
152
- * @return {typeof OcflStorageLayout}
153
- */
154
- static class(name) {
155
- let c = super.class(name);
156
- if (c && c.prototype instanceof OcflStorageLayout) return /** @type {typeof OcflStorageLayout} */(c);
157
- }
158
-
159
- static get classes() {
160
- return Object.values(storageLayout);
161
- }
162
-
163
- /**
164
- * Register a storage layout extension
165
- * @param {typeof OcflStorageLayout} extensionClass
166
- */
167
- static register(extensionClass = this) {
168
- super.register(extensionClass);
169
- storageLayout[extensionClass.name] = extensionClass;
170
- }
171
-
172
- static get forStorage() { return true; }
173
-
174
- /**
175
- *
176
- * @param {OcflExtensionConfig} [config]
177
- * @param {C} [defaultConfig]
178
- */
179
- constructor(config, defaultConfig) { super(config, defaultConfig); }
180
-
181
- async validate() {}
182
-
183
- /**
184
- * Map an object identifier to a path
185
- * @param {string} id - The identifier of the OCFL Object
186
- * @return {string}
187
- */
188
- map(id) { throw new NotImplementedError(); }
189
- }
190
-
191
- module.exports = {
192
- OcflExtension,
193
- OcflStorageLayout
194
- };
@@ -1,60 +0,0 @@
1
- const { OcflStorageLayout } = require("../extension");
2
- const { OcflDigest } = require("../digest");
3
- const { enumeration } = require("../enum");
4
- const path = require("path");
5
-
6
- function encodeIdentifier(id) {
7
- return encodeURIComponent(id).toLowerCase().replace(/\./g, '%2e');
8
- }
9
-
10
- const DefaultConfig = {
11
- extensionName: '0003-hash-and-id-n-tuple-storage-layout',
12
- digestAlgorithm: 'sha256',
13
- tupleSize: 3,
14
- numberOfTuples: 3,
15
- };
16
-
17
- /**
18
- * @extends {OcflStorageLayout<typeof DefaultConfig>}
19
- */
20
- class HashAndIdNTupleStorageLayout extends OcflStorageLayout {
21
- static get NAME() { return DefaultConfig.extensionName }
22
- static get DESCRIPTION() {
23
- return "OCFL object identifiers are hashed and encoded as lowercase hex strings." +
24
- " These digests are then divided into N n-tuple segments," +
25
- " which are used to create nested paths under the OCFL storage root." +
26
- " Finally, the OCFL object identifier is percent-encoded to create a directory name for the OCFL object root.";
27
- }
28
-
29
- /**
30
- * @param {Partial<typeof DefaultConfig>} [config]
31
- */
32
- constructor(config) {
33
- super(config, DefaultConfig);
34
- let c = this.parameters;
35
- const algo = enumeration.of(OcflDigest.FIXITY, c.digestAlgorithm)?.name;
36
- if (!algo) throw new Error('Invalid digestAlgorithm');
37
- let digestLength = OcflDigest.getHexDigestLength(algo);
38
- let p = c.numberOfTuples * c.tupleSize
39
- if (p > digestLength) throw new Error('Product of numberOfTuples and tupleSize is greater than the number of characters in the hex encoded digest.');
40
- }
41
-
42
- /**
43
- * @param {string} id
44
- * @return {string}
45
- */
46
- map(id) {
47
- let digest = OcflDigest.digestSync(this.parameters.digestAlgorithm, id);
48
- let segments = [];
49
- let s = this.parameters.tupleSize;
50
- let n = this.parameters.numberOfTuples;
51
- let i;
52
- for (i = 0; i < n; ++i) {
53
- segments.push(digest.slice(s * i, s * i + s));
54
- }
55
- segments.push(encodeIdentifier(id));
56
- return segments.join(path.sep);
57
- }
58
- }
59
-
60
- module.exports = { HashAndIdNTupleStorageLayout };
@@ -1,63 +0,0 @@
1
- const { OcflStorageLayout } = require("../extension");
2
- const { OcflDigest } = require("../digest");
3
- const path = require("path");
4
- const { enumeration } = require("../enum");
5
-
6
- const DefaultConfig = {
7
- extensionName: '0004-hashed-n-tuple-storage-layout',
8
- digestAlgorithm: 'sha256',
9
- tupleSize: 3,
10
- numberOfTuples: 3,
11
- shortObjectRoot: false
12
- };
13
- /** @typedef {Partial<typeof DefaultConfig>} HashedNTupleStorageLayoutConfig */
14
- /**
15
- * @extends {OcflStorageLayout<typeof DefaultConfig>}
16
- */
17
- class HashedNTupleStorageLayout extends OcflStorageLayout {
18
- static get NAME() { return DefaultConfig.extensionName; }
19
- static get DESCRIPTION() {
20
- return "OCFL object identifiers are hashed and encoded as lowercase hex strings." +
21
- " These digests are then divided into N n-tuple segments," +
22
- " which are used to create nested paths under the OCFL storage root.";
23
- }
24
-
25
- /**
26
- *
27
- * @param {HashedNTupleStorageLayoutConfig} [config]
28
- */
29
- constructor(config) {
30
- super(config, DefaultConfig);
31
- let c = this.parameters;
32
- const algo = enumeration.of(OcflDigest.FIXITY, c.digestAlgorithm)?.name;
33
- if (!algo) throw new Error('Invalid digestAlgorithm');
34
- let digestLength = OcflDigest.getHexDigestLength(algo);
35
- let p = c.numberOfTuples * c.tupleSize
36
- if (p > digestLength) throw new Error('Product of numberOfTuples and tupleSize is greater than the number of characters in the hex encoded digest.');
37
- else if (p === digestLength && c.shortObjectRoot) throw new Error('shortObjectRoot cannot be set to true');
38
- }
39
-
40
- /**
41
- * @param {string} id
42
- * @return {string}
43
- */
44
- map(id) {
45
- let digest = OcflDigest.digestSync(this.parameters.digestAlgorithm, id);
46
- let segments = [];
47
- let s = this.parameters.tupleSize;
48
- let n = this.parameters.numberOfTuples;
49
- let i;
50
- for (i = 0; i < n; ++i) {
51
- segments.push(digest.slice(s * i, s * i + s));
52
- }
53
- if (this.parameters.shortObjectRoot) {
54
- segments.push(digest.slice(s * i));
55
- } else {
56
- segments.push(digest);
57
- }
58
- return segments.join(path.sep);
59
- }
60
-
61
- }
62
-
63
- module.exports = { HashedNTupleStorageLayout };
File without changes
@@ -1,7 +0,0 @@
1
- const {OcflStorageLayout} = require("../extension");
2
-
3
- class FlatOmitPrefixStorageLayout extends OcflStorageLayout {
4
- static get NAME() { return '0006-flat-omit-prefix-storage-layout' }
5
- }
6
-
7
- module.exports = { FlatOmitPrefixStorageLayout };
@@ -1,7 +0,0 @@
1
- const {OcflStorageLayout} = require("../extension");
2
-
3
- class NTupleOmitPrefixStorageLayout extends OcflStorageLayout {
4
- static get NAME() { return '0007-n-tuple-omit-prefix-storage-layout' }
5
- }
6
-
7
- module.exports = { NTupleOmitPrefixStorageLayout };
File without changes
@@ -1,18 +0,0 @@
1
- //@ts-check
2
-
3
- const {OcflExtension} = require("../extension");
4
-
5
- /**
6
- * Notes: this implementation does nothing because the 0009 extension is implemented directly in the OcflDigest class.
7
- */
8
- class DigestAlgorithm extends OcflExtension {
9
- static get NAME() { return '0009-digest-algorithms' }
10
-
11
- /**
12
- *
13
- * @param {import('ocfl')} ocfl
14
- */
15
- static async setup(ocfl) {}
16
- }
17
-
18
- module.exports = { DigestAlgorithm };
@@ -1,61 +0,0 @@
1
- const { OcflStorageLayout } = require("../extension");
2
- const { OcflDigest } = require("../digest");
3
- const path = require("path");
4
-
5
- const DefaultConfig = {
6
- extensionName: '000N-path-direct-storage-layout',
7
- omitScheme: false,
8
- /** @type {any} */
9
- replace: [],
10
- suffix: '/__object__'
11
- };
12
-
13
- /** @typedef {Partial<typeof DefaultConfig>} PathDirectStorageLayoutConfig */
14
- /**
15
- * @extends {OcflStorageLayout<typeof DefaultConfig>}
16
- */
17
- class PathDirectStorageLayout extends OcflStorageLayout {
18
- static get NAME() { return DefaultConfig.extensionName; }
19
- static get DESCRIPTION() {
20
- return "OCFL object identifiers are used directly as the path.";
21
- }
22
-
23
- /**
24
- *
25
- * @param {PathDirectStorageLayoutConfig} [config]
26
- */
27
- constructor(config) {
28
- super(config, DefaultConfig);
29
- }
30
-
31
- /**
32
- * @param {string} id
33
- * @return {string}
34
- */
35
- map(id) {
36
- var suffix = this.parameters.suffix;
37
- if (suffix && id.endsWith(suffix)) throw new Error(`Identifier cannot end with '${suffix}'`);
38
- var p = id ?? '';
39
- for (const r of this.parameters.replace) {
40
- p = p.replace(r[0], r[1]);
41
- }
42
- try {
43
- let u = new URL(p);
44
- let parts = [];
45
- if (!this.parameters.omitScheme && u.protocol !== 'file:') {
46
- parts.push(u.protocol.replace(':', ''));
47
- }
48
- if (u.hostname) {
49
- parts.push(u.hostname.replace(',', '_').replace(';', '/'));
50
- }
51
- p = path.join(parts.join('_'), u.pathname + u.search + u.hash);
52
- } catch (error) {
53
- }
54
- p = p.replace(/^\/+/, '').replace(/\/+$/, '');
55
- return path.join(p, this.parameters.suffix);
56
- //if (/^\w+:/.test(id)) {
57
- }
58
-
59
- }
60
-
61
- module.exports = { PathDirectStorageLayout };
@@ -1,13 +0,0 @@
1
-
2
- module.exports = {
3
- ...require('./0009-digest-algorithms'),
4
- ...require('./0002-flat-direct-storage-layout'),
5
- ...require('./0003-hash-and-id-n-tuple-storage-layout'),
6
- ...require('./0004-hashed-n-tuple-storage-layout'),
7
- // ...require('./0005-mutable-head'),
8
- ...require('./0006-flat-omit-prefix-storage-layout'),
9
- ...require('./0007-n-tuple-omit-prefix-storage-layout'),
10
- ...require('./000N-path-direct-storage-layout')
11
- //...require('./0008-schema-registry')
12
- };
13
- //const { DigestAlgorithm } = require('./0001-digest-algorithms.js');
package/lib/file.js DELETED
@@ -1,129 +0,0 @@
1
- /**
2
- * @typedef {Object} FileRef
3
- * @property {string} [contentPath] - Actual path to the file location relative to the ocfl object root.
4
- * @property {string} [logicalPath] - A path that represents a file’s location in the logical state of an object.
5
- * @property {string} [digest] - An algorithmic characterization of the contents of a file conforming to a standard digest algorithm.
6
- * @property {string} [version] - Version of the OCFL object.
7
- * @property {string} [lastModified] - Last modified date of the file.
8
- * @property {string} [size] - Size of the file in bytes.
9
- * @property {Object.<string, string>} [fixity] - Fixity information of the file.
10
- */
11
-
12
- /**
13
- * Represent a file in an OCFL object
14
- */
15
- class OcflObjectFile {
16
- #ocflObject;
17
- #lastModified;
18
- #size;
19
-
20
- /**
21
- *
22
- * @param {import('./object').OcflObject} ocflObject
23
- * @param {FileRef} fileRef
24
- */
25
- constructor(ocflObject, fileRef) {
26
- this.#ocflObject = ocflObject;
27
- // for (const key in ['logicalPath', 'version', 'digest', 'contentPath']) {
28
- // if (fileRef[key]) this[key] = fileRef[key];
29
- // }
30
- if (fileRef.logicalPath) this.logicalPath = fileRef.logicalPath;
31
- if (fileRef.contentPath) this.contentPath = fileRef.contentPath;
32
- if (fileRef.digest) this.digest = fileRef.digest;
33
- if (fileRef.version) this.version = fileRef.version;
34
- if (fileRef.lastModified != null) this.#lastModified = fileRef.lastModified;
35
- if (fileRef.size != null) this.#size = fileRef.size;
36
- if (fileRef.fixity != null) this.fixity = fileRef.fixity;
37
- }
38
-
39
- /**
40
- * Resolve contentPath given either the `logicalPath` and `version`, `digest`, or `contentPath`.
41
- */
42
- async #resolveContentPath() {
43
- let contentPath = this.contentPath;
44
- if (!contentPath) {
45
- let inv = await this.#ocflObject.getInventory();
46
- if (!inv) throw new Error(`OCFL Object "${this.#ocflObject.id}" does not exist`);
47
- let version = !this.version || this.version === 'latest' ? inv.head : this.version;
48
- let digest = this.digest || inv.getDigest(this.logicalPath, version);
49
- contentPath = inv.getContentPath(digest);
50
- if (!contentPath) throw new Error(`Cannot find content "${this.toString()}" in the OCFL Object "${this.#ocflObject.id}" version "${this.version || 'latest'}"`);
51
- }
52
- return contentPath;
53
- }
54
-
55
- /**
56
- * Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).
57
- */
58
- get lastModified() { return this.#lastModified }
59
-
60
- /**
61
- * Returns the file size in bytes.
62
- */
63
- get size() { return this.#size }
64
-
65
- toString() {
66
- let props = [];
67
- for (const key in ['logicalPath', 'version', 'digest', 'contentPath']) {
68
- if (this[key]) props.push(key + ": '" + this[key] + "'");
69
- }
70
- return `{ ${props.join(', ')} }`;
71
- }
72
-
73
- /**
74
- * Get the file content as a buffer
75
- * @param {*} [options] Options to be passed to underlying data store specific implementation
76
-
77
- * @return {Promise<Buffer>}
78
- */
79
- async buffer(options) {
80
- return this.#ocflObject.readFile(await this.#resolveContentPath(), options);
81
- }
82
-
83
- /**
84
- * @deprecated Use {@link buffer()}
85
- */
86
- async asBuffer(options) {
87
- return this.buffer(options);
88
- }
89
-
90
- /**
91
- * Get the file content as a string
92
- * @param {BufferEncoding} [encoding='utf8'] String encoding, default to utf8
93
- * @return {Promise<string>}
94
- */
95
- async text(encoding = 'utf8') {
96
- // @ts-ignore
97
- return this.buffer(encoding);
98
- }
99
- /**
100
- * @deprecated Use {@link text()}
101
- */
102
- async asString(encoding = 'utf8') {
103
- // @ts-ignore
104
- return this.text(encoding);
105
- }
106
-
107
- /**
108
- * Get the file content as a NodeJS stream
109
- * @param {*} [options] Options to be passed to underlying data store specific implementation
110
- * @return {Promise<ReadableStream>}
111
- * @deprecated Use {@link stream()}
112
- */
113
- async asStream(options) {
114
- return this.#ocflObject.createReadable(await this.#resolveContentPath(), options);
115
- }
116
-
117
- /**
118
- * Get the file content as a ES Streams standard ReadableStream
119
- * @param {*} [options] Options to be passed to underlying data store specific implementation
120
- * @return {Promise<ReadableStream>}
121
- */
122
- async stream(options) {
123
- return this.#ocflObject.createReadable(await this.#resolveContentPath(), options);
124
- }
125
- }
126
-
127
- module.exports = {
128
- OcflObjectFile
129
- };
package/lib/index.js DELETED
@@ -1,13 +0,0 @@
1
- // this is an internal index.js to avoid circular dependencies problem
2
- module.exports = {
3
- ...require('./constants.js'),
4
- ...require('./digest.js'),
5
- ...require('./transaction.js'),
6
- ...require('./extension.js'),
7
- ...require('./store.js'),
8
- ...require('./object.js'),
9
- ...require('./storage.js'),
10
- extensions: {
11
- ...require('./extensions/index.js')
12
- }
13
- };