@toolproof-npm/shared 0.1.41 → 0.1.43

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,7 +1,5 @@
1
1
  import type { ResourceTypeIdJson } from '@toolproof-npm/schema';
2
- import type { FilterConst, ResourceShapeConst, ResourceRoleConst, StepConst, WorkflowConst, ShapesMeta, ShapesData, ShapesMetaMap, ShapesDataMap, ResourceRawMetaMap, ResourceDataMap, ResourceConst } from './types.d.ts';
2
+ import type { ResourceShapeConst, ResourceRoleConst, StepConst, WorkflowConst, ResourceMap, ResourceConst } from './types.d.ts';
3
3
  export declare function getNewId(identifiable: ResourceShapeConst | ResourceRoleConst | ResourceConst | StepConst | WorkflowConst): string;
4
- export declare function listResourceShapesMeta<T extends ShapesMeta>(groupKey: ResourceShapeConst, filterConfig: Record<FilterConst, boolean>): Promise<ShapesMetaMap<T>>;
5
- export declare function listResourcesRawMeta(resourceTypeIds: ResourceTypeIdJson[]): Promise<ResourceRawMetaMap>;
6
- export declare function listResourceShapesData<T extends ShapesData>(groupKey: ResourceShapeConst, filterConfig: Record<FilterConst, boolean>): Promise<ShapesDataMap<T>>;
7
- export declare function listResourcesData(resourceTypeIds: ResourceTypeIdJson[]): Promise<ResourceDataMap>;
4
+ export declare function listResources(// ATTENTION: must clean up
5
+ resourceTypeIds: ResourceTypeIdJson[]): Promise<ResourceMap>;
@@ -7,70 +7,8 @@ export function getNewId(identifiable) {
7
7
  const docRef = dbAdmin.collection(CONSTANTS.STORAGE.COLLECTIONS.shapes).doc(identifiable).collection(CONSTANTS.STORAGE.FILTER.members).doc();
8
8
  return prefix + docRef.id;
9
9
  }
10
- export async function listResourceShapesMeta(groupKey, filterConfig) {
11
- const baseRef = dbAdmin
12
- .collection(CONSTANTS.STORAGE.COLLECTIONS.shapes)
13
- .doc(groupKey);
14
- const entries = await Promise.all([
15
- filterConfig.members
16
- ? baseRef.collection(CONSTANTS.STORAGE.FILTER.members).get().then(snap => snap.docs.map(d => {
17
- const data = d.data();
18
- return { ...data, id: d.id };
19
- }))
20
- : Promise.resolve([]),
21
- filterConfig.specials
22
- ? baseRef.collection(CONSTANTS.STORAGE.FILTER.specials).get().then(snap => snap.docs.map(d => {
23
- const data = d.data();
24
- return { ...data, id: d.id };
25
- }))
26
- : Promise.resolve([]),
27
- ]);
28
- const [members, specials] = entries;
29
- return { members, specials };
30
- }
31
- export async function listResourcesRawMeta(resourceTypeIds) {
32
- const collectionName = CONSTANTS.STORAGE.COLLECTIONS.resources;
33
- const entries = await Promise.all(resourceTypeIds.map(async (resourceTypeId) => {
34
- const snap = await dbAdmin
35
- .collection(collectionName)
36
- .doc(resourceTypeId)
37
- .collection(CONSTANTS.STORAGE.FILTER.members)
38
- .get();
39
- const items = snap.docs.map(d => {
40
- const data = d.data();
41
- // Ensure id field is present (doc id is the resourceId)
42
- return { ...data, id: d.id };
43
- });
44
- return [resourceTypeId, items];
45
- }));
46
- return Object.fromEntries(entries);
47
- }
48
- export async function listResourceShapesData(groupKey, filterConfig) {
49
- const bucket = storageAdmin.bucket(CONSTANTS.STORAGE.BUCKETS.tp_shapes);
50
- const prefix = `${groupKey}/`;
51
- const [files] = await bucket.getFiles({ prefix });
52
- const result = {
53
- members: [],
54
- specials: [],
55
- };
56
- const tasks = files
57
- .filter(f => !(f.name.endsWith('/') || f.name.split('/').pop() === ''))
58
- .map(async (file) => {
59
- const meta = file.metadata || (await file.getMetadata())[0];
60
- const subNameRaw = meta?.metadata?.filter;
61
- const subName = (subNameRaw === CONSTANTS.STORAGE.FILTER.specials
62
- ? CONSTANTS.STORAGE.FILTER.specials
63
- : CONSTANTS.STORAGE.FILTER.members);
64
- if (!filterConfig[subName])
65
- return;
66
- const [buf] = await file.download();
67
- const json = JSON.parse(buf.toString('utf8'));
68
- result[subName].push(json);
69
- });
70
- await Promise.all(tasks);
71
- return result;
72
- }
73
- export async function listResourcesData(resourceTypeIds) {
10
+ export async function listResources(// ATTENTION: must clean up
11
+ resourceTypeIds) {
74
12
  const bucket = storageAdmin.bucket(CONSTANTS.STORAGE.BUCKETS.tp_resources);
75
13
  async function fetchFilesUnder(resourceTypeId) {
76
14
  const prefix = `${resourceTypeId}/`;
@@ -152,7 +90,7 @@ export async function listResourcesData(resourceTypeIds) {
152
90
  }
153
91
  }
154
92
  }
155
- const idMeta = root.id;
93
+ const identity = root.identity;
156
94
  const resourceTypeIdMeta = root.resourceTypeId;
157
95
  // creationContext may be flattened as creationContext.resourceRoleId or direct resourceRoleId
158
96
  const resourceRoleId = (root.creationContext?.resourceRoleId ?? root.resourceRoleId);
@@ -161,24 +99,24 @@ export async function listResourcesData(resourceTypeIds) {
161
99
  const path = root.path;
162
100
  const timestamp = root.timestamp;
163
101
  const missing = [
164
- ['id', idMeta],
102
+ ['identity', identity],
165
103
  ['resourceTypeId', resourceTypeIdMeta],
166
104
  ['resourceRoleId', resourceRoleId],
167
105
  ['executionId', executionId],
168
106
  ['kind', kind],
169
- ['path', path],
170
107
  ['timestamp', timestamp],
108
+ ['path', path],
171
109
  ].filter(([_, v]) => typeof v !== 'string' || v.length === 0);
172
110
  if (missing.length) {
173
111
  const keys = missing.map(([k]) => k).join(', ');
174
112
  throw new Error(`Missing required metadata keys [${keys}] for resource file: ${name}`);
175
113
  }
176
114
  return {
177
- id: idMeta,
178
- resourceTypeId: resourceTypeIdMeta,
115
+ identity,
116
+ resourceTypeId,
179
117
  creationContext: {
180
- resourceRoleId: resourceRoleId,
181
- executionId: executionId,
118
+ resourceRoleId,
119
+ executionId,
182
120
  },
183
121
  kind: kind,
184
122
  path: path,
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ResourceIdJson, ExecutionIdJson, ResourceRoleIdJson, ResourceRoleValueJson, ResourceTypeIdJson, ResourceFormatMetaJson, ResourceFormatDataJson, ResourceTypeMetaJson, ResourceTypeDataJson, ResourceRawMetaJson, ResourceDataJson } from '@toolproof-npm/schema';
1
+ import type { ResourceIdJson, ExecutionIdJson, ResourceRoleIdJson, ResourceRoleValueJson, ResourceTypeIdJson, ResourceRawMetaJson, ResourceJson } from '@toolproof-npm/schema';
2
2
  import { CONSTANTS } from './constants.js';
3
3
  export type BucketConst = typeof CONSTANTS.STORAGE.BUCKETS.tp_shapes | typeof CONSTANTS.STORAGE.BUCKETS.tp_resources;
4
4
  export type CollectionConst = typeof CONSTANTS.STORAGE.COLLECTIONS.shapes | typeof CONSTANTS.STORAGE.COLLECTIONS.resources;
@@ -11,14 +11,10 @@ export type WorkflowConst = typeof CONSTANTS.WORKFLOW.workflow | typeof CONSTANT
11
11
  export type Role = {
12
12
  id: ResourceRoleIdJson;
13
13
  } & ResourceRoleValueJson;
14
- export type ShapesData = ResourceFormatDataJson | ResourceTypeDataJson;
15
- export type ShapesMeta = ResourceFormatMetaJson | ResourceTypeMetaJson;
16
- export type ShapesDataMap<T extends ShapesData> = Record<FilterConst, T[]>;
17
- export type ShapesMetaMap<T extends ShapesMeta> = Record<FilterConst, T[]>;
18
14
  export type ResourceRawMetaMap = Record<ResourceTypeIdJson, ResourceRawMetaJson[]>;
19
- export type ResourceDataMap = Record<ResourceTypeIdJson, ResourceDataJson[]>;
20
- export type ExternallyProvidedResourceMeta = {
21
- id: ResourceIdJson;
15
+ export type ResourceMap = Record<ResourceTypeIdJson, ResourceJson[]>;
16
+ export type PartialResourceMeta = {
17
+ identity: ResourceIdJson;
22
18
  resourceTypeId: ResourceTypeIdJson;
23
19
  creationContext: {
24
20
  resourceRoleId: ResourceRoleIdJson;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolproof-npm/shared",
3
- "version": "0.1.41",
3
+ "version": "0.1.43",
4
4
  "description": "Core library utilities for ToolProof",
5
5
  "keywords": [
6
6
  "toolproof",
@@ -52,7 +52,7 @@
52
52
  "typescript": "^5.9.3"
53
53
  },
54
54
  "dependencies": {
55
- "@toolproof-npm/schema": "^0.1.34",
55
+ "@toolproof-npm/schema": "^0.1.36",
56
56
  "firebase-admin": "^13.6.0"
57
57
  },
58
58
  "scripts": {