@concord-consortium/object-storage 1.0.0-pre.2 → 1.0.0-pre.4
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/dist/index.d.ts +1 -0
- package/dist/index.js +15 -0
- package/dist/typed-object.d.ts +73 -0
- package/dist/typed-object.js +108 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { FirebaseObjectStorage } from './firebase-object-storage';
|
|
|
3
3
|
export { createObjectStorage } from './object-storage';
|
|
4
4
|
export { ObjectStorageProvider, useObjectStorage } from './object-storage-context';
|
|
5
5
|
export { IObjectStorage, ObjectStorageConfig, DemoObjectStorageConfig, FirebaseObjectStorageConfig, ObjectMetadata, ObjectData, StoredObject, ObjectWithId, MonitorCallback, DemonitorFunction } from './types';
|
|
6
|
+
export * from './typed-object';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.useObjectStorage = exports.ObjectStorageProvider = exports.createObjectStorage = exports.FirebaseObjectStorage = exports.DemoObjectStorage = void 0;
|
|
4
18
|
var demo_object_storage_1 = require("./demo-object-storage");
|
|
@@ -10,3 +24,4 @@ Object.defineProperty(exports, "createObjectStorage", { enumerable: true, get: f
|
|
|
10
24
|
var object_storage_context_1 = require("./object-storage-context");
|
|
11
25
|
Object.defineProperty(exports, "ObjectStorageProvider", { enumerable: true, get: function () { return object_storage_context_1.ObjectStorageProvider; } });
|
|
12
26
|
Object.defineProperty(exports, "useObjectStorage", { enumerable: true, get: function () { return object_storage_context_1.useObjectStorage; } });
|
|
27
|
+
__exportStar(require("./typed-object"), exports);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { StoredObject } from "./types";
|
|
2
|
+
export type AddImageOptions = {
|
|
3
|
+
id?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
url: string;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
description?: string;
|
|
9
|
+
subType?: string;
|
|
10
|
+
};
|
|
11
|
+
export type AddDataTableOptions = {
|
|
12
|
+
id?: string;
|
|
13
|
+
name: string;
|
|
14
|
+
cols: string[];
|
|
15
|
+
rows: any[][];
|
|
16
|
+
description?: string;
|
|
17
|
+
subType?: string;
|
|
18
|
+
};
|
|
19
|
+
export type AddTypedTextOptions = {
|
|
20
|
+
id?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
text: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
subType?: string;
|
|
25
|
+
};
|
|
26
|
+
export type AddTypedObjectOptions = {
|
|
27
|
+
id?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
data: Record<string, any>;
|
|
30
|
+
description?: string;
|
|
31
|
+
subType?: string;
|
|
32
|
+
};
|
|
33
|
+
export type TypedImageMetadata = {
|
|
34
|
+
type: "image";
|
|
35
|
+
} & Omit<AddImageOptions, "id" | "url">;
|
|
36
|
+
export type TypedDataTableMetadata = {
|
|
37
|
+
type: "dataTable";
|
|
38
|
+
} & Omit<AddDataTableOptions, "id" | "rows">;
|
|
39
|
+
export type TypedTextMetadata = {
|
|
40
|
+
type: "text";
|
|
41
|
+
} & Omit<AddTypedTextOptions, "id" | "text">;
|
|
42
|
+
export type TypedObjectMetadata = {
|
|
43
|
+
type: "object";
|
|
44
|
+
keys: string[];
|
|
45
|
+
} & Omit<AddTypedObjectOptions, "id" | "data">;
|
|
46
|
+
export type TypedMetadataItem = TypedImageMetadata | TypedDataTableMetadata | TypedTextMetadata | TypedObjectMetadata;
|
|
47
|
+
export type TypedMetadataItems = Record<string, TypedMetadataItem>;
|
|
48
|
+
export type TypedMetadata = {
|
|
49
|
+
version: 1;
|
|
50
|
+
type: "typed";
|
|
51
|
+
items: TypedMetadataItems;
|
|
52
|
+
name?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
};
|
|
55
|
+
export type TypedData = Record<string, any>;
|
|
56
|
+
export type TypedObjectOptions = {
|
|
57
|
+
id?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
};
|
|
61
|
+
export declare class TypedObject implements StoredObject {
|
|
62
|
+
id: string;
|
|
63
|
+
metadata: TypedMetadata;
|
|
64
|
+
data: TypedData;
|
|
65
|
+
constructor(options?: TypedObjectOptions);
|
|
66
|
+
static IsSupportedTypedObject(storedObject: StoredObject): boolean;
|
|
67
|
+
static IsSupportedTypedObjectMetadata(storedObjectMetadata?: StoredObject["metadata"]): boolean;
|
|
68
|
+
static FromStoredObject(id: string, storedObject: StoredObject): TypedObject;
|
|
69
|
+
addImage(options: AddImageOptions): void;
|
|
70
|
+
addDataTable(options: AddDataTableOptions): void;
|
|
71
|
+
addText(options: AddTypedTextOptions): void;
|
|
72
|
+
addObject(options: AddTypedObjectOptions): void;
|
|
73
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedObject = void 0;
|
|
4
|
+
const nanoid_1 = require("nanoid");
|
|
5
|
+
class TypedObject {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.id = options?.id || (0, nanoid_1.nanoid)();
|
|
8
|
+
this.metadata = {
|
|
9
|
+
version: 1,
|
|
10
|
+
type: "typed",
|
|
11
|
+
items: {},
|
|
12
|
+
};
|
|
13
|
+
if (options?.name !== undefined) {
|
|
14
|
+
this.metadata.name = options.name;
|
|
15
|
+
}
|
|
16
|
+
if (options?.description !== undefined) {
|
|
17
|
+
this.metadata.description = options.description;
|
|
18
|
+
}
|
|
19
|
+
this.data = {};
|
|
20
|
+
}
|
|
21
|
+
static IsSupportedTypedObject(storedObject) {
|
|
22
|
+
return TypedObject.IsSupportedTypedObjectMetadata(storedObject.metadata);
|
|
23
|
+
}
|
|
24
|
+
static IsSupportedTypedObjectMetadata(storedObjectMetadata) {
|
|
25
|
+
const metadata = storedObjectMetadata;
|
|
26
|
+
return metadata !== undefined && metadata.type === "typed" && typeof metadata.version === "number" && metadata.version == 1;
|
|
27
|
+
}
|
|
28
|
+
static FromStoredObject(id, storedObject) {
|
|
29
|
+
if (!TypedObject.IsSupportedTypedObject(storedObject)) {
|
|
30
|
+
throw new Error("Invalid or unsupported TypedObject");
|
|
31
|
+
}
|
|
32
|
+
const typedObject = new TypedObject({ id });
|
|
33
|
+
typedObject.metadata = storedObject.metadata;
|
|
34
|
+
typedObject.data = storedObject.data;
|
|
35
|
+
return typedObject;
|
|
36
|
+
}
|
|
37
|
+
addImage(options) {
|
|
38
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
39
|
+
this.metadata.items[id] = {
|
|
40
|
+
type: "image",
|
|
41
|
+
name: options.name
|
|
42
|
+
};
|
|
43
|
+
if (options.subType !== undefined) {
|
|
44
|
+
this.metadata.items[id].subType = options.subType;
|
|
45
|
+
}
|
|
46
|
+
if (options.width !== undefined) {
|
|
47
|
+
this.metadata.items[id].width = options.width;
|
|
48
|
+
}
|
|
49
|
+
if (options.height !== undefined) {
|
|
50
|
+
this.metadata.items[id].height = options.height;
|
|
51
|
+
}
|
|
52
|
+
if (options.description !== undefined) {
|
|
53
|
+
this.metadata.items[id].description = options.description;
|
|
54
|
+
}
|
|
55
|
+
this.data[id] = {
|
|
56
|
+
url: options.url
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
addDataTable(options) {
|
|
60
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
61
|
+
this.metadata.items[id] = {
|
|
62
|
+
type: "dataTable",
|
|
63
|
+
name: options.name,
|
|
64
|
+
cols: options.cols,
|
|
65
|
+
};
|
|
66
|
+
if (options.subType !== undefined) {
|
|
67
|
+
this.metadata.items[id].subType = options.subType;
|
|
68
|
+
}
|
|
69
|
+
if (options.description !== undefined) {
|
|
70
|
+
this.metadata.items[id].description = options.description;
|
|
71
|
+
}
|
|
72
|
+
this.data[id] = {
|
|
73
|
+
rows: options.rows
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
addText(options) {
|
|
77
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
78
|
+
this.metadata.items[id] = {
|
|
79
|
+
type: "text",
|
|
80
|
+
name: options.name,
|
|
81
|
+
};
|
|
82
|
+
if (options.subType !== undefined) {
|
|
83
|
+
this.metadata.items[id].subType = options.subType;
|
|
84
|
+
}
|
|
85
|
+
if (options.description !== undefined) {
|
|
86
|
+
this.metadata.items[id].description = options.description;
|
|
87
|
+
}
|
|
88
|
+
this.data[id] = {
|
|
89
|
+
text: options.text
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
addObject(options) {
|
|
93
|
+
const id = options.id || (0, nanoid_1.nanoid)();
|
|
94
|
+
this.metadata.items[id] = {
|
|
95
|
+
type: "object",
|
|
96
|
+
name: options.name,
|
|
97
|
+
keys: Object.keys(options.data),
|
|
98
|
+
};
|
|
99
|
+
if (options.subType !== undefined) {
|
|
100
|
+
this.metadata.items[id].subType = options.subType;
|
|
101
|
+
}
|
|
102
|
+
if (options.description !== undefined) {
|
|
103
|
+
this.metadata.items[id].description = options.description;
|
|
104
|
+
}
|
|
105
|
+
this.data[id] = options.data;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.TypedObject = TypedObject;
|