@concord-consortium/object-storage 1.0.0-pre.2 → 1.0.0-pre.3

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 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,70 @@
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
+ addImage(options: AddImageOptions): void;
67
+ addDataTable(options: AddDataTableOptions): void;
68
+ addText(options: AddTypedTextOptions): void;
69
+ addObject(options: AddTypedObjectOptions): void;
70
+ }
@@ -0,0 +1,92 @@
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
+ addImage(options) {
22
+ const id = options.id || (0, nanoid_1.nanoid)();
23
+ this.metadata.items[id] = {
24
+ type: "image",
25
+ name: options.name
26
+ };
27
+ if (options.subType !== undefined) {
28
+ this.metadata.items[id].subType = options.subType;
29
+ }
30
+ if (options.width !== undefined) {
31
+ this.metadata.items[id].width = options.width;
32
+ }
33
+ if (options.height !== undefined) {
34
+ this.metadata.items[id].height = options.height;
35
+ }
36
+ if (options.description !== undefined) {
37
+ this.metadata.items[id].description = options.description;
38
+ }
39
+ this.data[id] = {
40
+ url: options.url
41
+ };
42
+ }
43
+ addDataTable(options) {
44
+ const id = options.id || (0, nanoid_1.nanoid)();
45
+ this.metadata.items[id] = {
46
+ type: "dataTable",
47
+ name: options.name,
48
+ cols: options.cols,
49
+ };
50
+ if (options.subType !== undefined) {
51
+ this.metadata.items[id].subType = options.subType;
52
+ }
53
+ if (options.description !== undefined) {
54
+ this.metadata.items[id].description = options.description;
55
+ }
56
+ this.data[id] = {
57
+ rows: options.rows
58
+ };
59
+ }
60
+ addText(options) {
61
+ const id = options.id || (0, nanoid_1.nanoid)();
62
+ this.metadata.items[id] = {
63
+ type: "text",
64
+ name: options.name,
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
+ text: options.text
74
+ };
75
+ }
76
+ addObject(options) {
77
+ const id = options.id || (0, nanoid_1.nanoid)();
78
+ this.metadata.items[id] = {
79
+ type: "object",
80
+ name: options.name,
81
+ keys: Object.keys(options.data),
82
+ };
83
+ if (options.subType !== undefined) {
84
+ this.metadata.items[id].subType = options.subType;
85
+ }
86
+ if (options.description !== undefined) {
87
+ this.metadata.items[id].description = options.description;
88
+ }
89
+ this.data[id] = options.data;
90
+ }
91
+ }
92
+ exports.TypedObject = TypedObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concord-consortium/object-storage",
3
- "version": "1.0.0-pre.2",
3
+ "version": "1.0.0-pre.3",
4
4
  "description": "A TypeScript library for object storage",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",