nicot 1.2.10 → 1.2.11
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.cjs +114 -48
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +95 -29
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1478,7 +1478,6 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
|
|
|
1478
1478
|
|
|
1479
1479
|
// src/crud-base.ts
|
|
1480
1480
|
var import_p_queue = __toESM(require("p-queue"));
|
|
1481
|
-
var import_nfkit = require("nfkit");
|
|
1482
1481
|
var Relation = (name, options = {}) => {
|
|
1483
1482
|
return { name, inner: false, ...options };
|
|
1484
1483
|
};
|
|
@@ -2107,52 +2106,119 @@ var CrudBase = class {
|
|
|
2107
2106
|
if (!await this.repo.exists({ where })) {
|
|
2108
2107
|
throw404();
|
|
2109
2108
|
}
|
|
2109
|
+
const isPlainObject = (v) => {
|
|
2110
|
+
if (!v || typeof v !== "object") return false;
|
|
2111
|
+
const proto = Object.getPrototypeOf(v);
|
|
2112
|
+
return proto === Object.prototype || proto === null;
|
|
2113
|
+
};
|
|
2114
|
+
const cloneAtomicOrJson = (v) => {
|
|
2115
|
+
if (v == null) return v;
|
|
2116
|
+
if (typeof v !== "object") return v;
|
|
2117
|
+
if (v instanceof Date) return new Date(v.getTime());
|
|
2118
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(v)) {
|
|
2119
|
+
return Buffer.from(v);
|
|
2120
|
+
}
|
|
2121
|
+
if (ArrayBuffer.isView(v)) {
|
|
2122
|
+
const ctor = v.constructor;
|
|
2123
|
+
return new ctor(v.slice?.() ?? v);
|
|
2124
|
+
}
|
|
2125
|
+
if (v instanceof ArrayBuffer) return v.slice(0);
|
|
2126
|
+
if (Array.isArray(v) || isPlainObject(v)) {
|
|
2127
|
+
const sc = globalThis.structuredClone;
|
|
2128
|
+
if (typeof sc === "function") return sc(v);
|
|
2129
|
+
return JSON.parse(JSON.stringify(v));
|
|
2130
|
+
}
|
|
2131
|
+
return v;
|
|
2132
|
+
};
|
|
2133
|
+
const deepEqual = (a, b) => {
|
|
2134
|
+
if (a === b) return true;
|
|
2135
|
+
if (a == null || b == null) return a === b;
|
|
2136
|
+
if (a instanceof Date && b instanceof Date)
|
|
2137
|
+
return a.getTime() === b.getTime();
|
|
2138
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(a) && Buffer.isBuffer(b)) {
|
|
2139
|
+
return a.equals(b);
|
|
2140
|
+
}
|
|
2141
|
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
2142
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
2143
|
+
const ua = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
|
|
2144
|
+
const ub = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
2145
|
+
for (let i = 0; i < ua.length; i++) if (ua[i] !== ub[i]) return false;
|
|
2146
|
+
return true;
|
|
2147
|
+
}
|
|
2148
|
+
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) {
|
|
2149
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
2150
|
+
const ua = new Uint8Array(a);
|
|
2151
|
+
const ub = new Uint8Array(b);
|
|
2152
|
+
for (let i = 0; i < ua.length; i++) if (ua[i] !== ub[i]) return false;
|
|
2153
|
+
return true;
|
|
2154
|
+
}
|
|
2155
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2156
|
+
if (!Array.isArray(a) || !Array.isArray(b)) return false;
|
|
2157
|
+
if (a.length !== b.length) return false;
|
|
2158
|
+
for (let i = 0; i < a.length; i++)
|
|
2159
|
+
if (!deepEqual(a[i], b[i])) return false;
|
|
2160
|
+
return true;
|
|
2161
|
+
}
|
|
2162
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
2163
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
2164
|
+
for (const k of keys) {
|
|
2165
|
+
if (!deepEqual(a[k], b[k])) return false;
|
|
2166
|
+
}
|
|
2167
|
+
return true;
|
|
2168
|
+
}
|
|
2169
|
+
return false;
|
|
2170
|
+
};
|
|
2110
2171
|
const op = async (repo) => {
|
|
2111
2172
|
const ent = await repo.findOne({
|
|
2112
2173
|
lock: { mode: "pessimistic_write", tables: [repo.metadata.tableName] },
|
|
2113
2174
|
...options.find || {},
|
|
2114
2175
|
where
|
|
2115
2176
|
});
|
|
2116
|
-
if (!ent)
|
|
2117
|
-
|
|
2177
|
+
if (!ent) throw404();
|
|
2178
|
+
const columns = repo.metadata.columns.map(
|
|
2179
|
+
(c) => c.propertyName
|
|
2180
|
+
);
|
|
2181
|
+
const snapshot = {};
|
|
2182
|
+
const snapshotHasKey = {};
|
|
2183
|
+
for (const key of columns) {
|
|
2184
|
+
snapshotHasKey[key] = Object.prototype.hasOwnProperty.call(
|
|
2185
|
+
ent,
|
|
2186
|
+
key
|
|
2187
|
+
);
|
|
2188
|
+
snapshot[key] = cloneAtomicOrJson(ent[key]);
|
|
2118
2189
|
}
|
|
2119
|
-
const
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
if (
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2190
|
+
const flush = async () => {
|
|
2191
|
+
const patch = {};
|
|
2192
|
+
for (const key of columns) {
|
|
2193
|
+
const hasNow = Object.prototype.hasOwnProperty.call(ent, key);
|
|
2194
|
+
if (!hasNow) {
|
|
2195
|
+
if (snapshotHasKey[key]) {
|
|
2196
|
+
patch[key] = null;
|
|
2197
|
+
snapshotHasKey[key] = true;
|
|
2198
|
+
snapshot[key] = null;
|
|
2199
|
+
}
|
|
2200
|
+
continue;
|
|
2127
2201
|
}
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2202
|
+
const current = ent[key];
|
|
2203
|
+
const before = snapshot[key];
|
|
2204
|
+
if (!deepEqual(before, current)) {
|
|
2205
|
+
patch[key] = current;
|
|
2206
|
+
snapshotHasKey[key] = true;
|
|
2207
|
+
snapshot[key] = cloneAtomicOrJson(current);
|
|
2133
2208
|
}
|
|
2134
2209
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
if (Object.keys(changes).length) {
|
|
2138
|
-
const currentChanges = { ...changes };
|
|
2139
|
-
Object.assign(initial, changes);
|
|
2140
|
-
changes = {};
|
|
2141
|
-
await repo.update({ id }, currentChanges);
|
|
2210
|
+
if (Object.keys(patch).length) {
|
|
2211
|
+
await repo.update({ id }, patch);
|
|
2142
2212
|
}
|
|
2143
2213
|
};
|
|
2144
|
-
const result = await cb(
|
|
2214
|
+
const result = await cb(ent, { repo, flush });
|
|
2145
2215
|
await flush();
|
|
2146
2216
|
return result;
|
|
2147
2217
|
};
|
|
2148
2218
|
const res = await (options.repo ? op(options.repo) : this.repo.manager.transaction(
|
|
2149
2219
|
(tdb) => op(tdb.getRepository(this.entityClass))
|
|
2150
2220
|
));
|
|
2151
|
-
|
|
2152
|
-
return new import_nesties8.BlankReturnMessageDto(200, "success");
|
|
2153
|
-
} else {
|
|
2154
|
-
return new import_nesties8.GenericReturnMessageDto(200, "success", res);
|
|
2155
|
-
}
|
|
2221
|
+
return res == null ? new import_nesties8.BlankReturnMessageDto(200, "success") : new import_nesties8.GenericReturnMessageDto(200, "success", res);
|
|
2156
2222
|
}
|
|
2157
2223
|
async _loadFullTextIndex() {
|
|
2158
2224
|
const fields = reflector.getArray(
|
|
@@ -2349,7 +2415,7 @@ var MutatorPipe = class {
|
|
|
2349
2415
|
};
|
|
2350
2416
|
|
|
2351
2417
|
// src/restful.ts
|
|
2352
|
-
var
|
|
2418
|
+
var import_nfkit = require("nfkit");
|
|
2353
2419
|
var getCurrentLevelRelations = (relations) => relations.filter((r) => !r.includes("."));
|
|
2354
2420
|
var getNextLevelRelations = (relations, enteringField) => relations.filter((r) => r.includes(".") && r.startsWith(`${enteringField}.`)).map((r) => r.split(".").slice(1).join("."));
|
|
2355
2421
|
var _RestfulFactory = class _RestfulFactory {
|
|
@@ -2966,58 +3032,58 @@ var _RestfulFactory = class _RestfulFactory {
|
|
|
2966
3032
|
}
|
|
2967
3033
|
};
|
|
2968
3034
|
__decorateClass([
|
|
2969
|
-
(0,
|
|
3035
|
+
(0, import_nfkit.Memorize)()
|
|
2970
3036
|
], _RestfulFactory.prototype, "fieldsToOmit", 1);
|
|
2971
3037
|
__decorateClass([
|
|
2972
|
-
(0,
|
|
3038
|
+
(0, import_nfkit.Memorize)()
|
|
2973
3039
|
], _RestfulFactory.prototype, "fieldsInCreateToOmit", 1);
|
|
2974
3040
|
__decorateClass([
|
|
2975
|
-
(0,
|
|
3041
|
+
(0, import_nfkit.Memorize)()
|
|
2976
3042
|
], _RestfulFactory.prototype, "createDto", 1);
|
|
2977
3043
|
__decorateClass([
|
|
2978
|
-
(0,
|
|
3044
|
+
(0, import_nfkit.Memorize)()
|
|
2979
3045
|
], _RestfulFactory.prototype, "fieldsInUpdateToOmit", 1);
|
|
2980
3046
|
__decorateClass([
|
|
2981
|
-
(0,
|
|
3047
|
+
(0, import_nfkit.Memorize)()
|
|
2982
3048
|
], _RestfulFactory.prototype, "updateDto", 1);
|
|
2983
3049
|
__decorateClass([
|
|
2984
|
-
(0,
|
|
3050
|
+
(0, import_nfkit.Memorize)()
|
|
2985
3051
|
], _RestfulFactory.prototype, "importDto", 1);
|
|
2986
3052
|
__decorateClass([
|
|
2987
|
-
(0,
|
|
3053
|
+
(0, import_nfkit.Memorize)()
|
|
2988
3054
|
], _RestfulFactory.prototype, "fieldsInGetToOmit", 1);
|
|
2989
3055
|
__decorateClass([
|
|
2990
|
-
(0,
|
|
3056
|
+
(0, import_nfkit.Memorize)()
|
|
2991
3057
|
], _RestfulFactory.prototype, "queryableFields", 1);
|
|
2992
3058
|
__decorateClass([
|
|
2993
|
-
(0,
|
|
3059
|
+
(0, import_nfkit.Memorize)()
|
|
2994
3060
|
], _RestfulFactory.prototype, "findAllDto", 1);
|
|
2995
3061
|
__decorateClass([
|
|
2996
|
-
(0,
|
|
3062
|
+
(0, import_nfkit.Memorize)()
|
|
2997
3063
|
], _RestfulFactory.prototype, "findAllCursorPaginatedDto", 1);
|
|
2998
3064
|
__decorateClass([
|
|
2999
|
-
(0,
|
|
3065
|
+
(0, import_nfkit.Memorize)()
|
|
3000
3066
|
], _RestfulFactory.prototype, "entityResultDto", 1);
|
|
3001
3067
|
__decorateClass([
|
|
3002
|
-
(0,
|
|
3068
|
+
(0, import_nfkit.Memorize)()
|
|
3003
3069
|
], _RestfulFactory.prototype, "entityCreateResultDto", 1);
|
|
3004
3070
|
__decorateClass([
|
|
3005
|
-
(0,
|
|
3071
|
+
(0, import_nfkit.Memorize)()
|
|
3006
3072
|
], _RestfulFactory.prototype, "entityReturnMessageDto", 1);
|
|
3007
3073
|
__decorateClass([
|
|
3008
|
-
(0,
|
|
3074
|
+
(0, import_nfkit.Memorize)()
|
|
3009
3075
|
], _RestfulFactory.prototype, "entityCreateReturnMessageDto", 1);
|
|
3010
3076
|
__decorateClass([
|
|
3011
|
-
(0,
|
|
3077
|
+
(0, import_nfkit.Memorize)()
|
|
3012
3078
|
], _RestfulFactory.prototype, "entityArrayReturnMessageDto", 1);
|
|
3013
3079
|
__decorateClass([
|
|
3014
|
-
(0,
|
|
3080
|
+
(0, import_nfkit.Memorize)()
|
|
3015
3081
|
], _RestfulFactory.prototype, "entityCursorPaginationReturnMessageDto", 1);
|
|
3016
3082
|
__decorateClass([
|
|
3017
|
-
(0,
|
|
3083
|
+
(0, import_nfkit.Memorize)()
|
|
3018
3084
|
], _RestfulFactory.prototype, "importReturnMessageDto", 1);
|
|
3019
3085
|
__decorateClass([
|
|
3020
|
-
(0,
|
|
3086
|
+
(0, import_nfkit.Memorize)()
|
|
3021
3087
|
], _RestfulFactory.prototype, "idType", 1);
|
|
3022
3088
|
var RestfulFactory = _RestfulFactory;
|
|
3023
3089
|
|