New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ag-repo

Package Overview
Dependencies
Maintainers
1
Versions
212
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ag-repo - npm Package Compare versions

Comparing version

to
1.0.2

AgRemaker.d.ts

70

AgActivityBase.d.ts
import { Db, Filter } from "mongodb";
import { Ided, OrderingOptions, PagingOptions } from "./AgDataTypes";
import { NoFunc, Input, Output } from 'ag-utilities/AgTypes';
export type Active<T> = T & {

@@ -7,2 +8,5 @@ _from: Date;

};
export type ActiveNoFunc<T> = T & {
_from: Date;
};
export type History<T> = T & {

@@ -16,5 +20,54 @@ _from: Date;

};
export type ActivityApi<T> = {
type ActivityFilterFunc<TOpt, T extends Ided> = (opt: TOpt, paging: PagingOptions, order: OrderingOptions) => {
data: ActiveNoFunc<T>[];
total: number;
};
type ActivityQueryFunc<TOpt, T extends Ided> = (opt: TOpt, paging: PagingOptions, order: OrderingOptions) => Promise<{
data: Activity<T>[];
total: number;
}>;
type ApiMaker<T extends Ided, TApi> = {
ok(): TApi;
exclude<K extends keyof TApi>(...keys: K[]): ApiMaker<T, Exclude<TApi, K>>;
before<K extends keyof TApi>(key: K, fn: (v: {
args: Input<TApi[K]>;
}) => void): ApiMaker<T, TApi>;
after<K extends keyof TApi>(key: K, fn: (v: {
res: Output<TApi[K]>;
}) => void): ApiMaker<T, TApi>;
before_all(fn: () => void): ApiMaker<T, TApi>;
after_all(fn: () => void): ApiMaker<T, TApi>;
make_query<TKey extends string, TOpt>(key: TKey, fn: (opt: TOpt) => Filter<Activity<T>>): ApiMaker<T, TApi & {
[k in TKey]: ActivityQueryFunc<TOpt, T>;
}>;
make_filter<TKey extends string, TOpt>(key: TKey, fn: (opt: TOpt) => () => boolean): ApiMaker<T, TApi & {
[k in TKey]: ActivityFilterFunc<TOpt, T>;
}>;
};
declare function clientapi<T extends Ided>(api: ActivityApi<T>): {
add(obj: T): NoFunc<Active<T>>;
keys(): string[];
map(): {
[x: string]: import("ag-utilities/AgTypes").ExcludePropsDeep<Active<T>, import("ag-utilities/AgTypes").Func<any[], any>>;
};
list(): NoFunc<Active<T>>[];
map_key<K extends keyof T>(key: K): {
[x: string]: T[K];
};
upsert(obj: T): Promise<string>;
update(obj: T): Promise<void>;
del(id: string): Promise<void>;
};
type ClientApi<T extends Ided> = ReturnType<typeof clientapi<T>>;
export type ActivityApi<T extends Ided> = {
add(obj: T): Active<T>;
getStamp(): number;
stamp(): number;
keys(): string[];
map(): {
[k in string]: Active<T>;
};
map_key<K extends keyof T>(key: K): {
[k in string]: T[K];
};
list(): Active<T>[];
query(filter: Filter<Activity<T>>, paging: PagingOptions, orderby: OrderingOptions): Promise<{

@@ -25,12 +78,13 @@ data: Activity<T>[];

filter(filter: (obj: Active<T>) => boolean, paging: PagingOptions, orderby: OrderingOptions): {
data: T[];
data: ActiveNoFunc<T>[];
total: number;
};
keys(): string[];
values(): Active<T>[];
remap<TNew>(fn: (value: Active<T>) => TNew): Record<string, TNew>;
upsert(obj: T): string;
update(obj: T): void;
del(id: string): void;
makeapi(): ApiMaker<T, ClientApi<T>>;
};
export type Activities<T> = Readonly<Record<string, Active<T>>> & ActivityApi<T>;
export declare const AgActivityBase: {
create<T extends Record<string, Ided>>(_db: Db): Promise<{ [k in keyof T]: Activities<T[k]>; }>;
create<T extends Record<string, Ided>>(_db: Db): Promise<{ [k in keyof T]: ActivityApi<T[k]>; }>;
};
export {};

@@ -55,2 +55,87 @@ "use strict";

var AgDataSync_1 = require("./AgDataSync");
var AgRemaker_1 = require("./AgRemaker");
var apimaker = {
make: function (api, full) {
var inner = AgRemaker_1.AgRemaker.make(api);
var ret = {
ok: function () {
return inner.ok();
},
exclude: function () {
var keys = [];
for (var _i = 0; _i < arguments.length; _i++) {
keys[_i] = arguments[_i];
}
return apimaker.make(inner.exclude.apply(inner, keys).ok(), full);
},
before: function (key, fn) {
return apimaker.make(inner.before(key, fn).ok(), full);
},
after: function (key, fn) {
return apimaker.make(inner.after(key, fn).ok(), full);
},
before_all: function (fn) {
return apimaker.make(inner.before_all(fn).ok(), full);
},
after_all: function (fn) {
return apimaker.make(inner.after_all(fn).ok(), full);
},
make_query: function (key, fn) {
var query_fn = function (opt, paging, order) {
return full.query(fn(opt), paging, order);
};
return apimaker.make(inner.append(key, query_fn).ok(), full);
},
make_filter: function (key, fn) {
var filter_fn = function (opt, paging, order) {
return full.filter(fn(opt), paging, order);
};
return apimaker.make(inner.append(key, filter_fn).ok(), full);
}
};
return ret;
}
};
function clientapi(api) {
return {
add: function (obj) {
return api.add(obj);
},
keys: function () {
return api.keys();
},
map: function () {
return api.map();
},
list: function () {
return api.list();
},
map_key: function (key) {
return api.map_key(key);
},
upsert: function (obj) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, api.upsert(obj)];
});
});
},
update: function (obj) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
api.update(obj);
return [2 /*return*/];
});
});
},
del: function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
api.del(id);
return [2 /*return*/];
});
});
}
};
}
exports.AgActivityBase = {

@@ -131,3 +216,2 @@ create: function (_db) {

var api = {
getStamp: function () { return dbStamp.value; },
add: function (obj) {

@@ -175,13 +259,43 @@ var active = obj;

},
stamp: function () { return dbStamp.value; },
keys: function () {
return Object.keys(map);
},
values: function () {
list: function () {
return Object.values(map);
},
map: function () {
return map;
},
remap: function (fn) {
return AgHelper_1.AgHelper.remap(map, function (id, value) { return fn(value); });
map_key: function (key) {
return AgHelper_1.AgHelper.remap(map, function (id, obj) { return obj[key]; });
},
upsert: function (obj) {
if (!obj._id)
obj._id = AgHelper_1.AgHelper.uuid();
var old = api.map()[obj._id];
if (old)
AgHelper_1.AgHelper.update(obj, old);
else
api.add(obj);
return obj._id;
},
update: function (obj) {
var old = api.map()[obj._id];
if (!old)
throw "item not found";
AgHelper_1.AgHelper.update(obj, old);
return obj._id;
},
del: function (id) {
var old = api.map()[id];
if (!old)
throw "item not found";
old.archive();
},
makeapi: function () {
return apimaker.make(clientapi(api), api);
}
};
return Object.assign(map, api);
return api;
})];

@@ -188,0 +302,0 @@ }

11

AgObjectBase.d.ts
import { Ided } from "./AgDataTypes";
import { Activities } from "./AgActivityBase";
import { ActivityApi } from "./AgActivityBase";
export type Object<T> = T & {
value(): T;
update(obj: T): void;
restore(): void;
};
export declare const AgObjectBase: {
create<T extends {}>(object_collection: Activities<Ided & {
create<T extends {}>(object_collection: ActivityApi<Ided & {
value: any;
}>, defaultValue: T): Readonly<T>;
}>, defaultValue: T): Readonly<{ [k in keyof T]: Object<T[k]>; }>;
};

@@ -9,9 +9,12 @@ "use strict";

return AgHelper_1.AgHelper.remap(defaultValue, function (id, def) {
if (id in object_collection)
return object_collection[id].value;
else {
return object_collection.add({ _id: id, value: (0, lodash_1.cloneDeep)(def) }).value;
}
var obj = (id in object_collection) ? object_collection.map()[id] : object_collection.add({ _id: id, value: (0, lodash_1.cloneDeep)(def) });
var proto = {
value: function () { return obj.value; },
update: function (v) { AgHelper_1.AgHelper.update(v, obj.value); },
restore: function () { obj.value = AgHelper_1.AgHelper.update((0, lodash_1.cloneDeep)(def), obj.value); }
};
Object.setPrototypeOf(obj.value, proto);
return obj.value;
});
}
};
{
"name": "ag-repo",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -12,5 +12,6 @@ "author": "",

"dependencies": {
"ag-utilities": "^1.1.67"
"ag-utilities": "^1.1.70",
"mongodb": "^6.3.0"
},
"bin": {}
}