@did-space/core 0.5.71 → 0.5.72

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.
@@ -31,7 +31,7 @@ export declare abstract class BaseDriver implements DriverProtocol {
31
31
  getHash(options: GetHashOptions): Promise<string>;
32
32
  exists(options: ReadOptions): Promise<boolean>;
33
33
  lists(options: ListsOptions): Promise<Object[]>;
34
- list(options: ListOptions): Promise<Object>;
34
+ list(options: ListOptions): Promise<Object | null>;
35
35
  writeAsOwner(key: string, data: Data, options?: WriteAsOwnerOptions): Promise<void>;
36
36
  deleteAsOwner(key: string, options?: ReadAsOwnerOptions): Promise<void>;
37
37
  readAsOwner(key: string, options?: ReadAsOwnerOptions): Promise<Stream>;
@@ -1,4 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { Readable } from 'stream';
4
- export type Data = Readable | ReadableStream | string | Buffer | ReadableStream<any>;
4
+ export type Data = Readable | ReadableStream | string | Buffer | ReadableStream<any> | null;
@@ -46,7 +46,7 @@ export interface Object {
46
46
  * @type {string}
47
47
  * @memberof Object
48
48
  */
49
- mimeType: string;
49
+ mimeType: string | null;
50
50
  /**
51
51
  * @description
52
52
  * @type {string}
@@ -1,5 +1,6 @@
1
- export * from './app-disconnected';
2
1
  export * from './app-backup';
3
2
  export * from './app-connected';
3
+ export * from './app-disconnected';
4
4
  export * from './app-restore';
5
5
  export * from './app';
6
+ export * from './preview';
@@ -14,8 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./app-disconnected"), exports);
18
17
  __exportStar(require("./app-backup"), exports);
19
18
  __exportStar(require("./app-connected"), exports);
19
+ __exportStar(require("./app-disconnected"), exports);
20
20
  __exportStar(require("./app-restore"), exports);
21
21
  __exportStar(require("./app"), exports);
22
+ __exportStar(require("./preview"), exports);
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const DidSchema: z.ZodEffects<z.ZodString, string, string>;
3
+ export declare const BasePreviewTemplateSchema: z.ZodObject<{
4
+ template: z.ZodString;
5
+ did: z.ZodEffects<z.ZodString, string, string>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ template: string;
8
+ did: string;
9
+ }, {
10
+ template: string;
11
+ did: string;
12
+ }>;
13
+ export type BasePreviewTemplate = z.infer<typeof BasePreviewTemplateSchema>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasePreviewTemplateSchema = exports.DidSchema = void 0;
4
+ const did_1 = require("@arcblock/did");
5
+ const zod_1 = require("zod");
6
+ exports.DidSchema = zod_1.z.string().refine((value) => (0, did_1.isValid)(value), (value) => {
7
+ return {
8
+ code: zod_1.z.ZodIssueCode.custom,
9
+ message: `${value} is not a valid DID`,
10
+ };
11
+ });
12
+ exports.BasePreviewTemplateSchema = zod_1.z.object({
13
+ template: zod_1.z.string().min(1),
14
+ did: exports.DidSchema,
15
+ });
@@ -0,0 +1,75 @@
1
+ import z from 'zod';
2
+ export declare const PreviewTemplateSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
3
+ template: z.ZodString;
4
+ did: z.ZodEffects<z.ZodString, string, string>;
5
+ }, {
6
+ template: z.ZodLiteral<"nft">;
7
+ name: z.ZodString;
8
+ image: z.ZodString;
9
+ chainHost: z.ZodString;
10
+ }>, "strip", z.ZodTypeAny, {
11
+ template: "nft";
12
+ did: string;
13
+ name: string;
14
+ image: string;
15
+ chainHost: string;
16
+ }, {
17
+ template: "nft";
18
+ did: string;
19
+ name: string;
20
+ image: string;
21
+ chainHost: string;
22
+ }>, z.ZodObject<z.objectUtil.extendShape<{
23
+ template: z.ZodString;
24
+ did: z.ZodEffects<z.ZodString, string, string>;
25
+ }, {
26
+ template: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"profile">>>;
27
+ avatar: z.ZodString;
28
+ fullname: z.ZodString;
29
+ email: z.ZodString;
30
+ }>, "strip", z.ZodTypeAny, {
31
+ template: "profile";
32
+ did: string;
33
+ avatar: string;
34
+ fullname: string;
35
+ email: string;
36
+ }, {
37
+ did: string;
38
+ avatar: string;
39
+ fullname: string;
40
+ email: string;
41
+ template?: "profile" | undefined;
42
+ }>, z.ZodObject<z.objectUtil.extendShape<{
43
+ template: z.ZodString;
44
+ did: z.ZodEffects<z.ZodString, string, string>;
45
+ }, {
46
+ template: z.ZodLiteral<"passport">;
47
+ image: z.ZodString;
48
+ type: z.ZodArray<z.ZodString, "many">;
49
+ issuerDid: z.ZodEffects<z.ZodString, string, string>;
50
+ issuerName: z.ZodString;
51
+ issuedAt: z.ZodString;
52
+ issuedTo: z.ZodString;
53
+ verified: z.ZodBoolean;
54
+ }>, "strip", z.ZodTypeAny, {
55
+ type: string[];
56
+ template: "passport";
57
+ did: string;
58
+ image: string;
59
+ issuerDid: string;
60
+ issuerName: string;
61
+ issuedAt: string;
62
+ issuedTo: string;
63
+ verified: boolean;
64
+ }, {
65
+ type: string[];
66
+ template: "passport";
67
+ did: string;
68
+ image: string;
69
+ issuerDid: string;
70
+ issuerName: string;
71
+ issuedAt: string;
72
+ issuedTo: string;
73
+ verified: boolean;
74
+ }>]>;
75
+ export type PreviewTemplate = z.infer<typeof PreviewTemplateSchema>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PreviewTemplateSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const nft_1 = require("./nft");
9
+ const profile_1 = require("./profile");
10
+ const passport_1 = require("./passport");
11
+ exports.PreviewTemplateSchema = zod_1.default.union([
12
+ nft_1.NftPreviewTemplateSchema,
13
+ profile_1.ProfilePreviewTemplateSchema,
14
+ passport_1.PassportPreviewTemplateSchema,
15
+ ]);
@@ -0,0 +1,5 @@
1
+ export * from './base';
2
+ export * from './default';
3
+ export * from './nft';
4
+ export * from './passport';
5
+ export * from './profile';
@@ -0,0 +1,21 @@
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
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base"), exports);
18
+ __exportStar(require("./default"), exports);
19
+ __exportStar(require("./nft"), exports);
20
+ __exportStar(require("./passport"), exports);
21
+ __exportStar(require("./profile"), exports);
@@ -0,0 +1,23 @@
1
+ import z from 'zod';
2
+ export declare const NftPreviewTemplateSchema: z.ZodObject<z.objectUtil.extendShape<{
3
+ template: z.ZodString;
4
+ did: z.ZodEffects<z.ZodString, string, string>;
5
+ }, {
6
+ template: z.ZodLiteral<"nft">;
7
+ name: z.ZodString;
8
+ image: z.ZodString;
9
+ chainHost: z.ZodString;
10
+ }>, "strip", z.ZodTypeAny, {
11
+ template: "nft";
12
+ did: string;
13
+ name: string;
14
+ image: string;
15
+ chainHost: string;
16
+ }, {
17
+ template: "nft";
18
+ did: string;
19
+ name: string;
20
+ image: string;
21
+ chainHost: string;
22
+ }>;
23
+ export type NftPreviewTemplate = z.infer<typeof NftPreviewTemplateSchema>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NftPreviewTemplateSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const base_1 = require("./base");
9
+ exports.NftPreviewTemplateSchema = base_1.BasePreviewTemplateSchema.extend({
10
+ template: zod_1.default.literal('nft'),
11
+ name: zod_1.default.string().min(1),
12
+ image: zod_1.default.string().min(1),
13
+ chainHost: zod_1.default.string().min(1).startsWith('http').url(),
14
+ });
@@ -0,0 +1,35 @@
1
+ import z from 'zod';
2
+ export declare const PassportPreviewTemplateSchema: z.ZodObject<z.objectUtil.extendShape<{
3
+ template: z.ZodString;
4
+ did: z.ZodEffects<z.ZodString, string, string>;
5
+ }, {
6
+ template: z.ZodLiteral<"passport">;
7
+ image: z.ZodString;
8
+ type: z.ZodArray<z.ZodString, "many">;
9
+ issuerDid: z.ZodEffects<z.ZodString, string, string>;
10
+ issuerName: z.ZodString;
11
+ issuedAt: z.ZodString;
12
+ issuedTo: z.ZodString;
13
+ verified: z.ZodBoolean;
14
+ }>, "strip", z.ZodTypeAny, {
15
+ type: string[];
16
+ template: "passport";
17
+ did: string;
18
+ image: string;
19
+ issuerDid: string;
20
+ issuerName: string;
21
+ issuedAt: string;
22
+ issuedTo: string;
23
+ verified: boolean;
24
+ }, {
25
+ type: string[];
26
+ template: "passport";
27
+ did: string;
28
+ image: string;
29
+ issuerDid: string;
30
+ issuerName: string;
31
+ issuedAt: string;
32
+ issuedTo: string;
33
+ verified: boolean;
34
+ }>;
35
+ export type PassportPreviewTemplate = z.infer<typeof PassportPreviewTemplateSchema>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PassportPreviewTemplateSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const base_1 = require("./base");
9
+ exports.PassportPreviewTemplateSchema = base_1.BasePreviewTemplateSchema.extend({
10
+ template: zod_1.default.literal('passport'),
11
+ // 通常是一个 svg 图片
12
+ image: zod_1.default.string().min(1),
13
+ // 类型
14
+ type: zod_1.default.array(zod_1.default.string()).min(1),
15
+ // 颁发者 DID
16
+ issuerDid: base_1.DidSchema,
17
+ // 颁发者
18
+ issuerName: zod_1.default.string().min(1),
19
+ // 颁发时间
20
+ issuedAt: zod_1.default.string().min(1),
21
+ // 颁发给了谁
22
+ issuedTo: zod_1.default.string().min(1),
23
+ // 验证状态
24
+ verified: zod_1.default.boolean(),
25
+ });
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ export declare const ProfilePreviewTemplateSchema: z.ZodObject<z.objectUtil.extendShape<{
3
+ template: z.ZodString;
4
+ did: z.ZodEffects<z.ZodString, string, string>;
5
+ }, {
6
+ template: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"profile">>>;
7
+ avatar: z.ZodString;
8
+ fullname: z.ZodString;
9
+ email: z.ZodString;
10
+ }>, "strip", z.ZodTypeAny, {
11
+ template: "profile";
12
+ did: string;
13
+ avatar: string;
14
+ fullname: string;
15
+ email: string;
16
+ }, {
17
+ did: string;
18
+ avatar: string;
19
+ fullname: string;
20
+ email: string;
21
+ template?: "profile" | undefined;
22
+ }>;
23
+ export type ProfilePreviewTemplate = z.TypeOf<typeof ProfilePreviewTemplateSchema>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProfilePreviewTemplateSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const base_1 = require("./base");
6
+ exports.ProfilePreviewTemplateSchema = base_1.BasePreviewTemplateSchema.extend({
7
+ template: zod_1.z.literal('profile').optional().default('profile'),
8
+ avatar: zod_1.z.string().min(1),
9
+ fullname: zod_1.z.string().min(1),
10
+ email: zod_1.z.string().min(1),
11
+ });
@@ -1,4 +1,4 @@
1
- import { Model } from 'sequelize';
1
+ import { Model, CreationOptional } from 'sequelize';
2
2
  /**
3
3
  * @description 存储的是对象的信息,不保存结构,创建之初就确定了,只能增加,删除
4
4
  * @export
@@ -33,7 +33,7 @@ export interface ObjectModel {
33
33
  * @column {DataTypes.DATE}
34
34
  * @memberof ObjectModel
35
35
  */
36
- createdAt: string;
36
+ createdAt?: CreationOptional<string>;
37
37
  }
38
38
  export interface ObjectModelMeta {
39
39
  /**
@@ -42,7 +42,7 @@ export interface ObjectModelMeta {
42
42
  * @type {string}
43
43
  * @memberof ObjectModelMeta
44
44
  */
45
- mimeType: string;
45
+ mimeType: string | null;
46
46
  /**
47
47
  * @description 保存这个对象第一次出现的文件名
48
48
  * @type {string}
@@ -54,6 +54,6 @@ export declare class ObjectRepositoryClass extends Model<ObjectModel> implements
54
54
  id: string;
55
55
  size: number;
56
56
  meta: ObjectModelMeta;
57
- createdAt: string;
57
+ createdAt?: CreationOptional<string>;
58
58
  }
59
59
  export type ObjectRepository = typeof ObjectRepositoryClass;
@@ -20,7 +20,7 @@ export type KeyStatus = {
20
20
  };
21
21
  export type ObjectMetadata = Record<string, any>;
22
22
  export type WriteAsOwnerOptions = {
23
- hash: string;
23
+ hash: string | null;
24
24
  size: number;
25
25
  useGlobal?: false | true;
26
26
  metadata?: ObjectMetadata;
@@ -25,6 +25,7 @@ const schemas_1 = require("../schemas");
25
25
  const debug = (0, debug_1.default)('@did-space/core:GlobalSpace');
26
26
  class GlobalSpace {
27
27
  constructor(options) {
28
+ var _a, _b;
28
29
  debug('GlobalSpace.constructor', JSON.stringify({ options: (0, lodash_1.pick)(options, 'gcMaxCount', 'gcMaxConcurrency') }));
29
30
  const { error, value } = global_space_1.GlobalSpaceOptionsSchema.validate(options);
30
31
  if (error) {
@@ -34,8 +35,8 @@ class GlobalSpace {
34
35
  this.treeRepository = value.treeRepository;
35
36
  this.objectRepository = value.objectRepository;
36
37
  this.objectCollectionRepository = value.objectCollectionRepository;
37
- this.gcMaxCount = value.gcMaxCount;
38
- this.gcMaxConcurrency = value.gcMaxConcurrency;
38
+ this.gcMaxCount = (_a = value.gcMaxCount) !== null && _a !== void 0 ? _a : 100;
39
+ this.gcMaxConcurrency = (_b = value.gcMaxConcurrency) !== null && _b !== void 0 ? _b : 8;
39
40
  debug('GlobalSpace.constructor', JSON.stringify({ gcMaxCount: value.gcMaxCount, gcMaxConcurrency: value.gcMaxConcurrency }));
40
41
  }
41
42
  /**
@@ -70,7 +70,7 @@ export declare class ObjectSpace extends EventEmitter implements SpaceProtocol {
70
70
  * @return {*} {Promise<Object>}
71
71
  * @memberof ObjectSpace
72
72
  */
73
- list(options: ListOptions): Promise<Object>;
73
+ list(options: ListOptions): Promise<Object | null>;
74
74
  /**
75
75
  * @refactor: @jianchao 后续让 write 的接口参数保持一致,即 key, data 都在 options 里面,目前改动收益比较小
76
76
  * @description
@@ -183,6 +183,9 @@ class ObjectSpace extends events_1.default {
183
183
  attributes: ['objectId'],
184
184
  raw: true,
185
185
  });
186
+ if (!tree) {
187
+ throw new Error(`Object(${key}) not exists`);
188
+ }
186
189
  return tree.objectId;
187
190
  });
188
191
  }
@@ -205,6 +208,9 @@ class ObjectSpace extends events_1.default {
205
208
  attributes: ['id'],
206
209
  raw: true,
207
210
  });
211
+ if (!parentTree) {
212
+ return [];
213
+ }
208
214
  debug('listsOneLevel.$parentTree', JSON.stringify(parentTree, null, 2));
209
215
  const trees = yield this.options.treeRepository.findAll({
210
216
  where: {
@@ -318,6 +324,9 @@ class ObjectSpace extends events_1.default {
318
324
  where,
319
325
  include: this.options.objectRepository,
320
326
  });
327
+ if (!tree) {
328
+ return null;
329
+ }
321
330
  return {
322
331
  key: tree.key,
323
332
  name: (0, path_1.basename)(tree.key),
@@ -403,6 +412,9 @@ class ObjectSpace extends events_1.default {
403
412
  where,
404
413
  include: this.options.objectRepository,
405
414
  });
415
+ if (!oldTree) {
416
+ return;
417
+ }
406
418
  const listObject = yield this.driver.list({
407
419
  key: (0, utils_1.getHashPath)(options.hash),
408
420
  useGlobal: true,
@@ -484,6 +496,9 @@ class ObjectSpace extends events_1.default {
484
496
  attributes: ['id', 'meta'],
485
497
  });
486
498
  debug('updateMetadata.$oldTree', JSON.stringify(oldTree));
499
+ if (!oldTree) {
500
+ return;
501
+ }
487
502
  if (!(0, isEmpty_1.default)(options.metadata)) {
488
503
  yield oldTree.update({
489
504
  meta: Object.assign(Object.assign({}, oldTree.meta), options.metadata),
@@ -535,6 +550,9 @@ class ObjectSpace extends events_1.default {
535
550
  attributes: ['objectId'],
536
551
  raw: true,
537
552
  });
553
+ if (!tree) {
554
+ return;
555
+ }
538
556
  yield this.options.treeRepository.destroy({
539
557
  where,
540
558
  });
@@ -651,7 +669,7 @@ class ObjectSpace extends events_1.default {
651
669
  yield this.createConfig(data);
652
670
  });
653
671
  }
654
- get(key, defaultValue = undefined) {
672
+ get(key, defaultValue = {}) {
655
673
  var _a;
656
674
  return __awaiter(this, void 0, void 0, function* () {
657
675
  debug('get.before', JSON.stringify({ key }));
@@ -37,7 +37,7 @@ export declare class Space extends EventEmitter implements SpaceProtocol {
37
37
  getHash(options: GetHashOptions): Promise<string>;
38
38
  exists(options: ReadOptions): Promise<boolean>;
39
39
  lists(options: ListsOptions): Promise<Object[]>;
40
- list(options: ListOptions): Promise<Object>;
40
+ list(options: ListOptions): Promise<Object | null>;
41
41
  writeAsOwner(key: string, data: Data): Promise<void>;
42
42
  deleteAsOwner(key: string): Promise<void>;
43
43
  readAsOwner(key: string, options?: ReadAsOwnerOptions): Promise<Stream>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-space/core",
3
- "version": "0.5.71",
3
+ "version": "0.5.72",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -27,8 +27,9 @@
27
27
  "watch": "npm run build -- -w"
28
28
  },
29
29
  "dependencies": {
30
+ "@arcblock/did": "^1.18.150",
30
31
  "@arcblock/ipfs-only-hash": "^0.0.2",
31
- "@arcblock/validator": "^1.18.147",
32
+ "@arcblock/validator": "^1.18.150",
32
33
  "dayjs": "^1.11.13",
33
34
  "debug": "^4.3.7",
34
35
  "hasha": "^5.2.2",
@@ -39,7 +40,8 @@
39
40
  "multiformats": "9",
40
41
  "p-all": "3.0.0",
41
42
  "sequelize": "^6.37.5",
42
- "xbytes": "^1.9.1"
43
+ "xbytes": "^1.9.1",
44
+ "zod": "^3.23.8"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@arcblock/eslint-config-ts": "^0.3.3",
@@ -54,5 +56,5 @@
54
56
  "vite": "^5.4.11",
55
57
  "vitest": "^2.1.5"
56
58
  },
57
- "gitHead": "7e29ad79c4997c0f3029ab75fb0193f9a3cd05b7"
59
+ "gitHead": "b3f61b466a81b6bf9de2b82f17d95b0c3da11038"
58
60
  }