@toolproof-npm/shared 0.1.41 → 0.1.42

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,4 @@
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(resourceTypeIds: ResourceTypeIdJson[]): Promise<ResourceMap>;
@@ -7,70 +7,7 @@ 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(resourceTypeIds) {
74
11
  const bucket = storageAdmin.bucket(CONSTANTS.STORAGE.BUCKETS.tp_resources);
75
12
  async function fetchFilesUnder(resourceTypeId) {
76
13
  const prefix = `${resourceTypeId}/`;
@@ -166,8 +103,8 @@ export async function listResourcesData(resourceTypeIds) {
166
103
  ['resourceRoleId', resourceRoleId],
167
104
  ['executionId', executionId],
168
105
  ['kind', kind],
169
- ['path', path],
170
106
  ['timestamp', timestamp],
107
+ ['path', path],
171
108
  ].filter(([_, v]) => typeof v !== 'string' || v.length === 0);
172
109
  if (missing.length) {
173
110
  const keys = missing.map(([k]) => k).join(', ');
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,12 +11,8 @@ 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[]>;
15
+ export type ResourceMap = Record<ResourceTypeIdJson, ResourceJson[]>;
20
16
  export type ExternallyProvidedResourceMeta = {
21
17
  id: ResourceIdJson;
22
18
  resourceTypeId: ResourceTypeIdJson;
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.42",
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.35",
56
56
  "firebase-admin": "^13.6.0"
57
57
  },
58
58
  "scripts": {