@ocfl/ocfl 0.1.1 → 0.1.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/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # ocfl-js - Common modules
2
2
  This is JavaScript/Node.js library to create and interact with Oxford Common File Layout (OCFL) storage and objects within it.
3
3
  This package contains abstract classes definition. Do not use this package directly. To work with an actual OCFL storage and object, use the following concrete implementation:
4
- * ocfl-fs - File system storage backend
4
+
5
+ * ocfl-fs - File system backend
5
6
 
6
7
  ## Extensions
7
8
  This library by default includes all the community extensions defined in the [OCFL Community Extensions page](https://github.com/OCFL/extensions). The implementation is organised in the ocfl-extensions package.
@@ -14,3 +15,7 @@ To implement a local extension in this library, first follow the description in
14
15
 
15
16
  }
16
17
 
18
+
19
+ ## Implementation
20
+
21
+ A new data store backend can be implemented by creating a new package with a store class that extends the `OcflStore` class and implements its methods. Please see the source code of ocfl-fs as an example implementation
package/index.js CHANGED
@@ -73,7 +73,7 @@ class Ocfl {
73
73
  get StorageLayout() { return OcflStorageLayout.layout }
74
74
 
75
75
  /**
76
- * Create a storage layout from extension name or config
76
+ * Instantiate a storage layout from extension name or config
77
77
  * @param {string|OcflExtensionConfig} config - Layout name or config
78
78
  */
79
79
  storageLayout(config) {
@@ -90,7 +90,7 @@ class Ocfl {
90
90
  }
91
91
 
92
92
  /**
93
- * Create an OCFL Object
93
+ * Instantiate an OCFL Object object
94
94
  * @param {OcflObjectConfig} config
95
95
  * @param {SO} [storeOptions]
96
96
  * @return {OcflObject}
@@ -100,7 +100,7 @@ class Ocfl {
100
100
  }
101
101
 
102
102
  /**
103
- * Create an OCFL Storage
103
+ * Instantiate an OCFL Storage object
104
104
  * @param {OcflStorageConfig} config
105
105
  * @param {SO} [storeOptions]
106
106
  * @return {OcflStorage}
@@ -109,16 +109,27 @@ class Ocfl {
109
109
  return new OcflStorageImpl(config, this.#store.getInstance(storeOptions));
110
110
  }
111
111
 
112
- }
113
-
114
- class Storage {
115
- async create(config) {
116
-
112
+ /**
113
+ * Create a new OCFL Storage
114
+ * @param {OcflStorageConfig} config
115
+ * @param {SO} [storeOptions]
116
+ * @return {Promise<OcflStorage>}
117
+ */
118
+ async createStorage(config, storeOptions = this.#defaultOptions) {
119
+ return (new OcflStorageImpl(config, this.#store.getInstance(storeOptions))).create();
117
120
  }
118
- async load(config) {
119
121
 
122
+ /**
123
+ * Load an existing OCFL Storage
124
+ * @param {OcflStorageConfig} config
125
+ * @param {SO} [storeOptions]
126
+ * @return {Promise<OcflStorage>}
127
+ */
128
+ async loadStorage(config, storeOptions = this.#defaultOptions) {
129
+ return (new OcflStorageImpl(config, this.#store.getInstance(storeOptions))).load();
120
130
  }
121
- }
131
+ }
132
+
122
133
 
123
134
 
124
135
  module.exports = {
package/lib/object.js CHANGED
@@ -150,7 +150,7 @@ class OcflObject {
150
150
  * @param {ObjectUpdateMode} [mode=UPDATE_MODE.MERGE]
151
151
  * @return {Promise<?OcflObjectTransaction>}
152
152
  */
153
- async update(updater, mode = UPDATE_MODE.MERGE) { throw new NotImplementedError() }
153
+ async update(updater, mode) { throw new NotImplementedError() }
154
154
 
155
155
  /**
156
156
  * Import one or more content files or directories to the object
@@ -199,7 +199,8 @@ class OcflObject {
199
199
 
200
200
  /**
201
201
  * Iterate through the content files contained in the specified version.
202
- * Returns an array of FileRef which consists of logical path, content path, and digest, in no particular order
202
+ * Returns an Iterator that contains FileRef which consists of logical path, content path, and digest, in no particular order.
203
+ * The iterator is implemented as a generator.
203
204
  * @param {string} [version]
204
205
  * @return {Promise<Generator<OcflObjectFile, void, unknown>>}
205
206
  */
@@ -502,7 +503,6 @@ class OcflObjectImpl extends OcflObject {
502
503
  }
503
504
 
504
505
  async isObject(aPath) { }
505
- async importDir(id, sourceDir) { }
506
506
  getVersionString(i) { }
507
507
  async determineVersion() { }
508
508
  nameVersion(version) {
package/lib/storage.js CHANGED
@@ -7,8 +7,8 @@ const { OcflStorageLayout } = require("./extension");
7
7
  const { HashedNTupleStorageLayout } = require("./extensions/0004-hashed-n-tuple-storage-layout");
8
8
  const { OcflObject, OcflObjectImpl } = require("./object");
9
9
  const { isDirEmpty, findNamasteVersion } = require("./utils.js");
10
- const { OCFL_VERSION, OCFL_VERSIONS, OCFL_LAYOUT,
11
- EXTENSIONS_DIR, EXTENSION_CONFIG,
10
+ const { OCFL_VERSION, OCFL_VERSIONS, OCFL_LAYOUT,
11
+ EXTENSIONS_DIR, EXTENSION_CONFIG,
12
12
  NAMASTE_PREFIX_STORAGE, NAMASTE_PREFIX_OBJECT, NAMASTE_T } = require('./constants').OcflConstants;
13
13
  const DIGEST = require('./digest').OcflDigest.CONTENT;
14
14
 
@@ -66,42 +66,44 @@ class OcflStorage {
66
66
  * Create the storage root in the underlying storage backend
67
67
  * @param {Object} [options] - Additional options for creating storage root
68
68
  * @param {boolean} [options.ocflSpecText=false] - If true, create a copy of the OCFL specification text in the storage root
69
+ * @return {Promise<OcflStorage>}
69
70
  */
70
71
  async create(options) { throw new NotImplementedError(); }
71
72
 
72
- /**
73
- * Check if the storage root path points to an existing file or non-empty directory in the underlying backend store.
74
- * The existing directory may or may not be a valid OCFL Storage.
75
- * @return {Promise<boolean>}
76
- */
77
- async exists() { throw new NotImplementedError(); }
78
-
79
73
  /**
80
74
  * Check namaste, retrieve storage layout extension, and read its config file.
81
- * @return {Promise<boolean>}
75
+ * @return {Promise<OcflStorage>}
82
76
  */
83
77
  async load() { throw new NotImplementedError(); }
84
78
 
79
+ /**
80
+ * Check if the storage root path points to an existing file or non-empty directory in the underlying backend store.
81
+ * The existing directory may or may not be a valid OCFL Storage.
82
+ * @return {Promise<boolean>}
83
+ */
84
+ async exists() { throw new NotImplementedError(); }
85
+
85
86
  /**
86
87
  *
87
- * @return {AsyncIterator<OcflObject>}
88
+ * @return {AsyncIterableIterator<OcflObject>}
88
89
  */
89
90
  [Symbol.asyncIterator]() { throw new NotImplementedError(); }
90
91
 
91
92
  /**
92
- * Return all OCFL objects under this storage as array
93
- * @return {Promise<OcflObject[]>}
93
+ * Return a new AsyncIterator that contains all the OCFL objects in this Storage.
94
+ * @return {AsyncIterableIterator<OcflObject>}
94
95
  */
95
- async objects() {
96
- const objects = [];
97
- for await(const o of this) objects.push(o);
98
- return objects;
96
+ objects() {
97
+ return this[Symbol.asyncIterator]();
98
+ // const objects = [];
99
+ // for await (const o of this) objects.push(o);
100
+ // return objects;
99
101
  }
100
102
 
101
103
  async delete(id) {
102
104
  return this.remove(id);
103
105
  }
104
-
106
+
105
107
  async purge(id) {
106
108
  return this.remove(id);
107
109
  }
@@ -188,7 +190,7 @@ class OcflStorageImpl extends OcflStorage {
188
190
  object(opt) {
189
191
  let id, root;
190
192
  if (typeof opt === 'string') id = opt;
191
- else ({id, root} = opt);
193
+ else ({ id, root } = opt);
192
194
  let relObjectRoot = root || this.objectRoot(id);
193
195
  return new OcflObjectImpl({
194
196
  id,
@@ -230,7 +232,7 @@ class OcflStorageImpl extends OcflStorage {
230
232
 
231
233
  //@todo: load storage level extensions
232
234
 
233
- return true;
235
+ return this;
234
236
  }
235
237
 
236
238
  /**
@@ -264,11 +266,9 @@ class OcflStorageImpl extends OcflStorage {
264
266
  if (options?.ocflSpecText) {
265
267
 
266
268
  }
269
+ return this;
267
270
  }
268
271
 
269
- /**
270
- * @return {AsyncIterator<OcflObject, OcflObject>}
271
- */
272
272
  [Symbol.asyncIterator]() {
273
273
  let store = this.#store;
274
274
  let workspace = this.#workspace;
@@ -276,6 +276,7 @@ class OcflStorageImpl extends OcflStorage {
276
276
  let root = this.root;
277
277
  let stack = [this.#store.opendir(this.root)];
278
278
  return {
279
+ [Symbol.asyncIterator]() { return this; },
279
280
  async next() {
280
281
  let dirp;
281
282
  while ((dirp = stack.pop())) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocfl/ocfl",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Oxford Common File Layout (OCFL) JS library",
5
5
  "main": "index.js",
6
6
  "exports": {