@websolutespa/bom-mixer-store 1.1.0 → 1.2.0
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +107 -107
- package/dist/index.js +7 -7
- package/dist/index.mjs +7 -7
- package/package.json +4 -4
- package/src/fs/fs.service.ts +12 -10
- package/src/store/store.handler.ts +6 -3
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,145 +2,145 @@ import { FetchRequestOptions, IEntity, JsonService, IStore, QueryParams, IPageRe
|
|
|
2
2
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
3
3
|
import { NextRequest } from 'next/server';
|
|
4
4
|
|
|
5
|
-
type ApiRequestOptions = FetchRequestOptions;
|
|
6
|
-
declare const defaultApiRequestOptions: ApiRequestOptions;
|
|
5
|
+
type ApiRequestOptions = FetchRequestOptions;
|
|
6
|
+
declare const defaultApiRequestOptions: ApiRequestOptions;
|
|
7
7
|
declare function getDefaultApiRequestOptions(): ApiRequestOptions;
|
|
8
8
|
|
|
9
|
-
type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
|
|
10
|
-
type IHandler = (request: NextApiRequest, response: NextApiResponse) => Promise<any>;
|
|
11
|
-
type IApiHandler = Record<ICrudMethod, IHandler>;
|
|
12
|
-
declare function apiHandler(handler: IApiHandler): any;
|
|
9
|
+
type ICrudMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | string;
|
|
10
|
+
type IHandler = (request: NextApiRequest, response: NextApiResponse) => Promise<any>;
|
|
11
|
+
type IApiHandler = Record<ICrudMethod, IHandler>;
|
|
12
|
+
declare function apiHandler(handler: IApiHandler): any;
|
|
13
13
|
declare function errorHandler(error: any, response: NextApiResponse): Promise<any> | void;
|
|
14
14
|
|
|
15
15
|
declare function fromCache<T = unknown>(callback: () => Promise<T>, key?: string): Promise<T>;
|
|
16
16
|
|
|
17
|
-
declare function getLocalApiUrl(pathname: string): string;
|
|
18
|
-
declare function localApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
19
|
-
locale: string;
|
|
20
|
-
market: string;
|
|
21
|
-
}): Promise<T>;
|
|
22
|
-
declare function localApiGet<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
23
|
-
locale: string;
|
|
24
|
-
market: string;
|
|
25
|
-
}): Promise<T>;
|
|
26
|
-
declare function localApiPost<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
|
|
27
|
-
locale: string;
|
|
28
|
-
market: string;
|
|
29
|
-
}): Promise<T>;
|
|
30
|
-
declare function localApiPut<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
|
|
31
|
-
locale: string;
|
|
32
|
-
market: string;
|
|
33
|
-
}): Promise<T>;
|
|
34
|
-
declare function localApiPatch<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
|
|
35
|
-
locale: string;
|
|
36
|
-
market: string;
|
|
37
|
-
}): Promise<T>;
|
|
38
|
-
declare function localApiDelete<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
39
|
-
locale: string;
|
|
40
|
-
market: string;
|
|
17
|
+
declare function getLocalApiUrl(pathname: string): string;
|
|
18
|
+
declare function localApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
19
|
+
locale: string;
|
|
20
|
+
market: string;
|
|
21
|
+
}): Promise<T>;
|
|
22
|
+
declare function localApiGet<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
23
|
+
locale: string;
|
|
24
|
+
market: string;
|
|
25
|
+
}): Promise<T>;
|
|
26
|
+
declare function localApiPost<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
|
|
27
|
+
locale: string;
|
|
28
|
+
market: string;
|
|
29
|
+
}): Promise<T>;
|
|
30
|
+
declare function localApiPut<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
|
|
31
|
+
locale: string;
|
|
32
|
+
market: string;
|
|
33
|
+
}): Promise<T>;
|
|
34
|
+
declare function localApiPatch<T = unknown>(url: string, payload?: unknown, options?: ApiRequestOptions, serviceOptions?: {
|
|
35
|
+
locale: string;
|
|
36
|
+
market: string;
|
|
37
|
+
}): Promise<T>;
|
|
38
|
+
declare function localApiDelete<T = unknown>(url: string, options?: ApiRequestOptions, serviceOptions?: {
|
|
39
|
+
locale: string;
|
|
40
|
+
market: string;
|
|
41
41
|
}): Promise<T>;
|
|
42
42
|
|
|
43
|
-
declare function isStaticRequest(request: NextRequest): boolean;
|
|
44
|
-
declare function isNextRequest(request: NextRequest): boolean;
|
|
43
|
+
declare function isStaticRequest(request: NextRequest): boolean;
|
|
44
|
+
declare function isNextRequest(request: NextRequest): boolean;
|
|
45
45
|
declare function isApiRequest(request: NextRequest): boolean;
|
|
46
46
|
|
|
47
|
-
declare function mockApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
|
|
48
|
-
declare function mockApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
49
|
-
declare function mockApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
50
|
-
declare function mockApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
51
|
-
declare function mockApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
47
|
+
declare function mockApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
|
|
48
|
+
declare function mockApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
49
|
+
declare function mockApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
50
|
+
declare function mockApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
51
|
+
declare function mockApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
52
52
|
declare function mockApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
53
53
|
|
|
54
54
|
declare function mockHandler(): any;
|
|
55
55
|
|
|
56
|
-
declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
57
|
-
store: IStore;
|
|
58
|
-
constructor(items: T[], store: IStore);
|
|
59
|
-
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
60
|
-
}
|
|
61
|
-
declare function isObject(item: unknown): item is Record<string, unknown>;
|
|
56
|
+
declare class MockService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
57
|
+
store: IStore;
|
|
58
|
+
constructor(items: T[], store: IStore);
|
|
59
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
60
|
+
}
|
|
61
|
+
declare function isObject(item: unknown): item is Record<string, unknown>;
|
|
62
62
|
declare function isRelation(item: unknown): item is IPageRelation;
|
|
63
63
|
|
|
64
64
|
declare function getMockStore<T extends IStore = IStore>(): Promise<T>;
|
|
65
65
|
|
|
66
|
-
declare function remoteApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
|
|
67
|
-
declare function remoteApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
68
|
-
declare function remoteApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
69
|
-
declare function remoteApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
70
|
-
declare function remoteApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
66
|
+
declare function remoteApiFetch<T = unknown>(pathname: string, options?: ApiRequestOptions): Promise<T>;
|
|
67
|
+
declare function remoteApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
68
|
+
declare function remoteApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
69
|
+
declare function remoteApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
70
|
+
declare function remoteApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
71
71
|
declare function remoteApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
* This service handle call to remote api (bowl or over)
|
|
75
|
-
*/
|
|
76
|
-
declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
77
|
-
key: string;
|
|
78
|
-
constructor(key: string);
|
|
79
|
-
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
80
|
-
findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
81
|
-
findPaged<B extends T = T>(params?: QueryParams): Promise<{
|
|
82
|
-
docs: B[];
|
|
83
|
-
} & Pagination>;
|
|
84
|
-
create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
|
|
85
|
-
update<B extends T = T>(payload: Partial<B>): Promise<B>;
|
|
86
|
-
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
87
|
-
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
73
|
+
/**
|
|
74
|
+
* This service handle call to remote api (bowl or over)
|
|
75
|
+
*/
|
|
76
|
+
declare class RemoteService<T extends IEntity = IEntity> implements IQuerable<T> {
|
|
77
|
+
key: string;
|
|
78
|
+
constructor(key: string);
|
|
79
|
+
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
80
|
+
findMany<B extends T = T>(params?: QueryParams): Promise<B[]>;
|
|
81
|
+
findPaged<B extends T = T>(params?: QueryParams): Promise<{
|
|
82
|
+
docs: B[];
|
|
83
|
+
} & Pagination>;
|
|
84
|
+
create<B extends T = T>(payload: Omit<B, 'id'>): Promise<B>;
|
|
85
|
+
update<B extends T = T>(payload: Partial<B>): Promise<B>;
|
|
86
|
+
delete<B extends T = T>(id: IEquatable): Promise<B | undefined>;
|
|
87
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
declare function getRemoteStore<T extends IStore>(): Promise<T>;
|
|
91
91
|
|
|
92
|
-
type IField = {
|
|
93
|
-
name: string;
|
|
94
|
-
type: 'text' | 'number' | 'relationship';
|
|
95
|
-
localized?: boolean;
|
|
96
|
-
relationTo?: string;
|
|
97
|
-
hasMany?: boolean;
|
|
98
|
-
required?: boolean;
|
|
99
|
-
};
|
|
100
|
-
type MapTo = Record<string, string>;
|
|
101
|
-
type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
|
|
102
|
-
type StaticServiceConfig<T extends IEntity = IEntity> = {
|
|
103
|
-
src: StaticServiceSrc<T>;
|
|
104
|
-
slug: string;
|
|
105
|
-
fields: IField[];
|
|
106
|
-
map?: MapTo;
|
|
107
|
-
};
|
|
92
|
+
type IField = {
|
|
93
|
+
name: string;
|
|
94
|
+
type: 'text' | 'number' | 'relationship';
|
|
95
|
+
localized?: boolean;
|
|
96
|
+
relationTo?: string;
|
|
97
|
+
hasMany?: boolean;
|
|
98
|
+
required?: boolean;
|
|
99
|
+
};
|
|
100
|
+
type MapTo = Record<string, string>;
|
|
101
|
+
type StaticServiceSrc<T extends IEntity = IEntity> = string | T[] | ((config: StaticServiceConfig<T>) => T[]) | ((config: StaticServiceConfig<T>) => Promise<T[]>);
|
|
102
|
+
type StaticServiceConfig<T extends IEntity = IEntity> = {
|
|
103
|
+
src: StaticServiceSrc<T>;
|
|
104
|
+
slug: string;
|
|
105
|
+
fields: IField[];
|
|
106
|
+
map?: MapTo;
|
|
107
|
+
};
|
|
108
108
|
declare const staticCollections: StaticServiceConfig[];
|
|
109
109
|
|
|
110
|
-
declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
111
|
-
loaded: boolean;
|
|
112
|
-
config: StaticServiceConfig<T>;
|
|
113
|
-
store: IStore;
|
|
114
|
-
constructor(config: StaticServiceConfig<T>, store: IStore);
|
|
115
|
-
getItems<B extends T = T>(): Promise<B[]>;
|
|
116
|
-
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
117
|
-
protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
|
|
118
|
-
protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
|
|
119
|
-
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
110
|
+
declare class StaticService<T extends IEntity = IEntity> extends JsonService<T> {
|
|
111
|
+
loaded: boolean;
|
|
112
|
+
config: StaticServiceConfig<T>;
|
|
113
|
+
store: IStore;
|
|
114
|
+
constructor(config: StaticServiceConfig<T>, store: IStore);
|
|
115
|
+
getItems<B extends T = T>(): Promise<B[]>;
|
|
116
|
+
findOne<B extends T = T>(id: IEquatable, params?: QueryParams): Promise<B | undefined>;
|
|
117
|
+
protected mapItems_<B extends T = T>(items: B[], map?: MapTo): B[];
|
|
118
|
+
protected relatedItems_<B extends T = T>(item: B, fields: IField[], locale?: string): Promise<B>;
|
|
119
|
+
protected decorator_<B extends T = T>(item: B, params?: QueryParams): B;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
declare enum StoreStrategy {
|
|
123
|
-
Api = "api",
|
|
124
|
-
Data = "data",
|
|
125
|
-
Mock = "mock"
|
|
126
|
-
}
|
|
127
|
-
declare const storeStrategy: StoreStrategy;
|
|
128
|
-
declare const MOCK_COLLECTIONS: string[];
|
|
129
|
-
declare const STATIC_COLLECTIONS: string[];
|
|
130
|
-
declare const KNOWN_COLLECTIONS: string[];
|
|
122
|
+
declare enum StoreStrategy {
|
|
123
|
+
Api = "api",
|
|
124
|
+
Data = "data",
|
|
125
|
+
Mock = "mock"
|
|
126
|
+
}
|
|
127
|
+
declare const storeStrategy: StoreStrategy;
|
|
128
|
+
declare const MOCK_COLLECTIONS: string[];
|
|
129
|
+
declare const STATIC_COLLECTIONS: string[];
|
|
130
|
+
declare const KNOWN_COLLECTIONS: string[];
|
|
131
131
|
declare const COLLECTIONS: string[];
|
|
132
132
|
|
|
133
|
-
declare function storeApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
134
|
-
declare function storeApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
135
|
-
declare function storeApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
136
|
-
declare function storeApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
133
|
+
declare function storeApiGet<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
134
|
+
declare function storeApiPost<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
135
|
+
declare function storeApiPut<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
136
|
+
declare function storeApiPatch<T = unknown>(url: string, payload: unknown, options?: ApiRequestOptions): Promise<T>;
|
|
137
137
|
declare function storeApiDelete<T = unknown>(url: string, options?: ApiRequestOptions): Promise<T>;
|
|
138
138
|
|
|
139
|
-
declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
|
|
140
|
-
declare function collectionGet<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
141
|
-
declare function collectionPost<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
142
|
-
declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
143
|
-
declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
139
|
+
declare function storeHandler<T extends IStore>(storePromise?: () => Promise<T>): any;
|
|
140
|
+
declare function collectionGet<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
141
|
+
declare function collectionPost<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
142
|
+
declare function collectionPatch<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
143
|
+
declare function collectionDelete<T extends IStore>(storePromise: () => Promise<T>): (request: NextApiRequest, response: NextApiResponse) => Promise<void>;
|
|
144
144
|
declare function routePost(store: IStore, request: NextApiRequest, response: NextApiResponse): Promise<void>;
|
|
145
145
|
|
|
146
146
|
declare function getStore<T extends IStore>(): Promise<T>;
|
package/dist/index.js
CHANGED
|
@@ -271,8 +271,7 @@ var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
|
|
|
271
271
|
var import_bom_core7 = require("@websolutespa/bom-core");
|
|
272
272
|
|
|
273
273
|
// src/fs/fs.service.ts
|
|
274
|
-
var
|
|
275
|
-
var fs = require("fs");
|
|
274
|
+
var fs = __toESM(require("fs"));
|
|
276
275
|
async function fsRead(pathname, option) {
|
|
277
276
|
try {
|
|
278
277
|
const data = await fs.promises.readFile(pathname, option?.encoding || "utf8");
|
|
@@ -971,8 +970,8 @@ function getMockStoreFromData_(data) {
|
|
|
971
970
|
}
|
|
972
971
|
async function getStoreData_() {
|
|
973
972
|
if (import_bom_core7.isDevelopment) {
|
|
974
|
-
const
|
|
975
|
-
const pathname =
|
|
973
|
+
const path = require("path");
|
|
974
|
+
const pathname = path.join(process.cwd(), ".mixer", "store.json");
|
|
976
975
|
return await fsReadJson(pathname) || {};
|
|
977
976
|
} else {
|
|
978
977
|
const store = process.env.STORE_ || {};
|
|
@@ -1350,9 +1349,10 @@ async function routePost(store, request, response) {
|
|
|
1350
1349
|
}
|
|
1351
1350
|
};
|
|
1352
1351
|
redirects.forEach((x) => {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1352
|
+
let expression = x.from;
|
|
1353
|
+
expression = expression.replace(/\*(?!\))/g, "(.*)");
|
|
1354
|
+
expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
|
|
1355
|
+
x.from = expression;
|
|
1356
1356
|
});
|
|
1357
1357
|
const firstMatch = redirects.find((x) => href.match(x.from));
|
|
1358
1358
|
if (firstMatch) {
|
package/dist/index.mjs
CHANGED
|
@@ -190,8 +190,7 @@ var COLLECTIONS = [...ENV_COLLECTIONS, ...KNOWN_COLLECTIONS];
|
|
|
190
190
|
import { isDevelopment } from "@websolutespa/bom-core";
|
|
191
191
|
|
|
192
192
|
// src/fs/fs.service.ts
|
|
193
|
-
|
|
194
|
-
var fs = __require("fs");
|
|
193
|
+
import * as fs from "fs";
|
|
195
194
|
async function fsRead(pathname, option) {
|
|
196
195
|
try {
|
|
197
196
|
const data = await fs.promises.readFile(pathname, option?.encoding || "utf8");
|
|
@@ -892,8 +891,8 @@ function getMockStoreFromData_(data) {
|
|
|
892
891
|
}
|
|
893
892
|
async function getStoreData_() {
|
|
894
893
|
if (isDevelopment) {
|
|
895
|
-
const
|
|
896
|
-
const pathname =
|
|
894
|
+
const path = __require("path");
|
|
895
|
+
const pathname = path.join(process.cwd(), ".mixer", "store.json");
|
|
897
896
|
return await fsReadJson(pathname) || {};
|
|
898
897
|
} else {
|
|
899
898
|
const store = process.env.STORE_ || {};
|
|
@@ -1271,9 +1270,10 @@ async function routePost(store, request, response) {
|
|
|
1271
1270
|
}
|
|
1272
1271
|
};
|
|
1273
1272
|
redirects.forEach((x) => {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
}
|
|
1273
|
+
let expression = x.from;
|
|
1274
|
+
expression = expression.replace(/\*(?!\))/g, "(.*)");
|
|
1275
|
+
expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
|
|
1276
|
+
x.from = expression;
|
|
1277
1277
|
});
|
|
1278
1278
|
const firstMatch = redirects.find((x) => href.match(x.from));
|
|
1279
1279
|
if (firstMatch) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websolutespa/bom-mixer-store",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Mixer Store module of the BOM Repository",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bom",
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@websolutespa/bom-core": "*",
|
|
30
30
|
"iron-session": ">= 6.2.1",
|
|
31
|
-
"next": ">=
|
|
31
|
+
"next": ">= 13.4.19"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/mime": "^3.0.1",
|
|
35
35
|
"@websolutespa/bom-cli": "*",
|
|
36
36
|
"@websolutespa/test": "*",
|
|
37
37
|
"@websolutespa/tsconfig": "*",
|
|
38
|
-
"eslint": "^8.
|
|
38
|
+
"eslint": "^8.46.0",
|
|
39
39
|
"eslint-config-websolute": "*",
|
|
40
40
|
"npm-run-all": "^4.1.5",
|
|
41
41
|
"ts-node": "^10.9.1",
|
|
42
42
|
"tsup": "^6.7.0",
|
|
43
|
-
"typescript": "^
|
|
43
|
+
"typescript": "^5.1.6"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
package/src/fs/fs.service.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Json } from '@websolutespa/bom-core';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
|
|
7
|
-
export type TFsReadOption = {
|
|
5
|
+
export type fsReadOptions = {
|
|
8
6
|
encoding?: null | undefined;
|
|
9
7
|
flag?: number | string | undefined;
|
|
10
8
|
signal?: AbortSignal | undefined;
|
|
11
9
|
};
|
|
12
10
|
|
|
11
|
+
export type fsWatchOptions = (fs.WatchOptions & { encoding: 'buffer' }) | 'buffer';
|
|
12
|
+
export type fsWatchFileOptions = (fs.WatchFileOptions & { bigint?: false });
|
|
13
|
+
export type fsWriteFileOptions = (fs.ObjectEncodingOptions & { mode?: fs.Mode; flag?: fs.OpenMode }) | BufferEncoding | null;
|
|
14
|
+
|
|
13
15
|
export async function fsExists(pathname: string): Promise<boolean> {
|
|
14
16
|
try {
|
|
15
17
|
await fs.promises.access(pathname);
|
|
@@ -19,7 +21,7 @@ export async function fsExists(pathname: string): Promise<boolean> {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
export async function fsRead(pathname: string, option?:
|
|
24
|
+
export async function fsRead(pathname: string, option?: fsReadOptions): Promise<string | undefined> {
|
|
23
25
|
try {
|
|
24
26
|
const data = await fs.promises.readFile(pathname, option?.encoding || 'utf8');
|
|
25
27
|
return data || undefined;
|
|
@@ -45,7 +47,7 @@ export async function fsReadJson<T = Json>(pathname: string): Promise<T | undefi
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
export async function fsWrite(pathname: string, data: string, encoding = 'utf8'): Promise<void> {
|
|
50
|
+
export async function fsWrite(pathname: string, data: string, encoding: fsWriteFileOptions = 'utf8'): Promise<void> {
|
|
49
51
|
try {
|
|
50
52
|
await fs.promises.mkdir(path.dirname(pathname), { recursive: true });
|
|
51
53
|
await fs.promises.writeFile(pathname, data, encoding);
|
|
@@ -54,7 +56,7 @@ export async function fsWrite(pathname: string, data: string, encoding = 'utf8')
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
export async function fsWriteJson(pathname: string, data:
|
|
59
|
+
export async function fsWriteJson(pathname: string, data: Json): Promise<void> {
|
|
58
60
|
try {
|
|
59
61
|
await fsWrite(pathname, JSON.stringify(data, null, 2));
|
|
60
62
|
} catch (error) {
|
|
@@ -111,12 +113,12 @@ export async function fsReadJsonDirectory(pathname: string): Promise<{ name: str
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
export function fsWatch(pathname: string, callback: (eventType:
|
|
116
|
+
export function fsWatch(pathname: string, callback: (eventType: fs.WatchEventType, fileName: string) => void, options: fsWatchOptions) {
|
|
115
117
|
const debounced = debounce(callback);
|
|
116
118
|
return fs.watch(pathname, options, debounced);
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
export function fsWatchFile(pathname: string, callback: (eventType:
|
|
121
|
+
export function fsWatchFile(pathname: string, callback: (eventType: fs.WatchEventType, fileName: string) => void, options?: fsWatchFileOptions) {
|
|
120
122
|
const debounced = debounce(callback);
|
|
121
123
|
return fs.watchFile(pathname, options, debounced);
|
|
122
124
|
}
|
|
@@ -235,9 +235,12 @@ export async function routePost(store: IStore, request: NextApiRequest, response
|
|
|
235
235
|
};
|
|
236
236
|
// check redirects by pattern
|
|
237
237
|
redirects.forEach(x => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
let expression = x.from;
|
|
239
|
+
// wrapping catchall in (.*)
|
|
240
|
+
expression = expression.replace(/\*(?!\))/g, '(.*)');
|
|
241
|
+
// wrapping expression in ^...$
|
|
242
|
+
expression = `^${expression.replace(/(^\^)|(\$$)/g, '')}$`;
|
|
243
|
+
x.from = expression;
|
|
241
244
|
});
|
|
242
245
|
// check if a regex pattern redirect does match
|
|
243
246
|
const firstMatch = redirects.find(x => href.match(x.from));
|