@concord-consortium/object-storage 1.0.0-pre.1 → 1.0.0-pre.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.
@@ -1,4 +1,4 @@
1
- import { DemoObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
1
+ import { DemoObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction, AddOptions } from './types';
2
2
  export declare class DemoObjectStorage implements IObjectStorage {
3
3
  private config;
4
4
  private objects;
@@ -36,9 +36,9 @@ export declare class DemoObjectStorage implements IObjectStorage {
36
36
  monitor(questionIds: string[], callback: MonitorCallback): DemonitorFunction;
37
37
  /**
38
38
  * Adds both metadata and data documents for a new object
39
- * Returns the generated object ID (nanoid)
39
+ * Returns the generated object ID (nanoid) or the provided ID if specified in options
40
40
  */
41
- add(object: StoredObject): Promise<string>;
41
+ add(object: StoredObject, options?: AddOptions): Promise<string>;
42
42
  /**
43
43
  * Reads both metadata and data documents for an object
44
44
  * Returns undefined if the object is not found
@@ -54,6 +54,10 @@ export declare class DemoObjectStorage implements IObjectStorage {
54
54
  * Returns undefined if the object is not found
55
55
  */
56
56
  readData(objectId: string): Promise<ObjectData | undefined>;
57
+ /**
58
+ * Generates a new unique ID using nanoid
59
+ */
60
+ genId(): string;
57
61
  /**
58
62
  * Notifies all active monitors of changes
59
63
  */
@@ -91,10 +91,10 @@ class DemoObjectStorage {
91
91
  }
92
92
  /**
93
93
  * Adds both metadata and data documents for a new object
94
- * Returns the generated object ID (nanoid)
94
+ * Returns the generated object ID (nanoid) or the provided ID if specified in options
95
95
  */
96
- async add(object) {
97
- const id = (0, nanoid_1.nanoid)();
96
+ async add(object, options) {
97
+ const id = options?.id ?? (0, nanoid_1.nanoid)();
98
98
  const objectWithId = {
99
99
  id,
100
100
  metadata: object.metadata,
@@ -141,6 +141,12 @@ class DemoObjectStorage {
141
141
  }
142
142
  return obj.data;
143
143
  }
144
+ /**
145
+ * Generates a new unique ID using nanoid
146
+ */
147
+ genId() {
148
+ return (0, nanoid_1.nanoid)();
149
+ }
144
150
  /**
145
151
  * Notifies all active monitors of changes
146
152
  */
@@ -1,4 +1,4 @@
1
- import { FirebaseObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
1
+ import { FirebaseObjectStorageConfig, IObjectStorage, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction, AddOptions } from './types';
2
2
  export declare class FirebaseObjectStorage implements IObjectStorage {
3
3
  private config;
4
4
  constructor(config: FirebaseObjectStorageConfig);
@@ -34,9 +34,9 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
34
34
  monitor(questionIds: string[], callback: MonitorCallback): DemonitorFunction;
35
35
  /**
36
36
  * Adds both metadata and data documents for a new object
37
- * Returns the generated object ID (nanoid)
37
+ * Returns the generated object ID (nanoid) or the provided ID if specified in options
38
38
  */
39
- add(object: StoredObject): Promise<string>;
39
+ add(object: StoredObject, options?: AddOptions): Promise<string>;
40
40
  /**
41
41
  * Reads both metadata and data documents for an object
42
42
  */
@@ -49,4 +49,8 @@ export declare class FirebaseObjectStorage implements IObjectStorage {
49
49
  * Reads only the data document for an object
50
50
  */
51
51
  readData(objectId: string): Promise<ObjectData | undefined>;
52
+ /**
53
+ * Generates a new unique ID using nanoid
54
+ */
55
+ genId(): string;
52
56
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FirebaseObjectStorage = void 0;
4
+ const nanoid_1 = require("nanoid");
4
5
  class FirebaseObjectStorage {
5
6
  constructor(config) {
6
7
  if (config.version !== 1) {
@@ -67,13 +68,13 @@ class FirebaseObjectStorage {
67
68
  }
68
69
  /**
69
70
  * Adds both metadata and data documents for a new object
70
- * Returns the generated object ID (nanoid)
71
+ * Returns the generated object ID (nanoid) or the provided ID if specified in options
71
72
  */
72
- async add(object) {
73
- // TODO: Generate nanoid
73
+ async add(object, options) {
74
+ // TODO: Generate nanoid if not provided in options
74
75
  // TODO: Add metadata document to Firebase
75
76
  // TODO: Add data document to Firebase
76
- const newObjectId = 'placeholder-id';
77
+ const newObjectId = options?.id ?? 'placeholder-id';
77
78
  return newObjectId;
78
79
  }
79
80
  /**
@@ -101,5 +102,11 @@ class FirebaseObjectStorage {
101
102
  // TODO: Read data document from Firebase
102
103
  return {};
103
104
  }
105
+ /**
106
+ * Generates a new unique ID using nanoid
107
+ */
108
+ genId() {
109
+ return (0, nanoid_1.nanoid)();
110
+ }
104
111
  }
105
112
  exports.FirebaseObjectStorage = FirebaseObjectStorage;
package/dist/types.d.ts CHANGED
@@ -7,6 +7,9 @@ export interface FirebaseObjectStorageConfig {
7
7
  version: 1;
8
8
  }
9
9
  export type ObjectStorageConfig = DemoObjectStorageConfig | FirebaseObjectStorageConfig;
10
+ export interface AddOptions {
11
+ id?: string;
12
+ }
10
13
  export interface IObjectStorage {
11
14
  listMine(): Promise<ObjectWithId[]>;
12
15
  listLinked(): Promise<ObjectWithId[]>;
@@ -14,10 +17,11 @@ export interface IObjectStorage {
14
17
  monitorMine(callback: MonitorCallback): DemonitorFunction;
15
18
  monitorLinked(callback: MonitorCallback): DemonitorFunction;
16
19
  monitor(questionIds: string[], callback: MonitorCallback): DemonitorFunction;
17
- add(object: StoredObject): Promise<string>;
20
+ add(object: StoredObject, options?: AddOptions): Promise<string>;
18
21
  read(objectId: string): Promise<StoredObject | undefined>;
19
22
  readMetadata(objectId: string): Promise<ObjectMetadata | undefined>;
20
23
  readData(objectId: string): Promise<ObjectData | undefined>;
24
+ genId(): string;
21
25
  }
22
26
  export interface ObjectMetadata {
23
27
  [key: string]: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concord-consortium/object-storage",
3
- "version": "1.0.0-pre.1",
3
+ "version": "1.0.0-pre.2",
4
4
  "description": "A TypeScript library for object storage",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",