sliftutils 0.87.0 → 0.88.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/builders/setup.ts
CHANGED
|
@@ -78,7 +78,7 @@ async function main() {
|
|
|
78
78
|
let packageJsonPath = path.join(targetDir, "package.json");
|
|
79
79
|
if (fs.existsSync(packageJsonPath)) {
|
|
80
80
|
console.log("\nUpdating package.json scripts...");
|
|
81
|
-
updatePackageJson(packageJsonPath);
|
|
81
|
+
await updatePackageJson(packageJsonPath);
|
|
82
82
|
} else {
|
|
83
83
|
console.warn("\nNo package.json found in target directory");
|
|
84
84
|
}
|
|
@@ -136,7 +136,7 @@ function replaceImports(content: string, importMappings: { [key: string]: string
|
|
|
136
136
|
return processedLines.join("\n");
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
function updatePackageJson(packageJsonPath: string) {
|
|
139
|
+
async function updatePackageJson(packageJsonPath: string) {
|
|
140
140
|
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
141
141
|
|
|
142
142
|
// Read our current package.json to get the type script
|
|
@@ -191,8 +191,22 @@ function updatePackageJson(packageJsonPath: string) {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
let needsYarnInstall = false;
|
|
195
|
+
|
|
196
|
+
// ALSO, add socket-function, if it doesn't have it already. This fixes intelliSense, for socket-function, which has a lot of useful utilities related to caching.
|
|
197
|
+
if (!packageJson.dependencies?.["socket-function"]) {
|
|
198
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
199
|
+
packageJson.dependencies["socket-function"] = "*";
|
|
200
|
+
needsYarnInstall = true;
|
|
201
|
+
}
|
|
202
|
+
|
|
194
203
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, undefined, 4) + "\n", "utf8");
|
|
195
204
|
console.log(" package.json updated");
|
|
205
|
+
|
|
206
|
+
if (needsYarnInstall) {
|
|
207
|
+
console.log(" Needs yarn install");
|
|
208
|
+
await execSync("yarn install", { cwd: path.dirname(packageJsonPath), stdio: "inherit" });
|
|
209
|
+
}
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
main().catch(error => {
|
package/index.d.ts
CHANGED
|
@@ -661,7 +661,11 @@ declare module "sliftutils/storage/DiskCollection" {
|
|
|
661
661
|
cbor?: boolean | undefined;
|
|
662
662
|
noPrompt?: boolean | undefined;
|
|
663
663
|
freeze?: "deep" | "shallow" | undefined;
|
|
664
|
-
beforeWrite?: ((
|
|
664
|
+
beforeWrite?: ((update: {
|
|
665
|
+
newValue: T;
|
|
666
|
+
key: string;
|
|
667
|
+
collection: DiskCollection<T>;
|
|
668
|
+
}) => void) | undefined;
|
|
665
669
|
} | undefined);
|
|
666
670
|
transactionStorage: TransactionStorage | undefined;
|
|
667
671
|
initStorage(): Promise<IStorage<T>>;
|
|
@@ -985,7 +989,11 @@ declare module "sliftutils/storage/StorageObservable" {
|
|
|
985
989
|
};
|
|
986
990
|
constructor(storage: IStorage<T>, config?: {
|
|
987
991
|
freeze?: "deep" | "shallow" | undefined;
|
|
988
|
-
beforeWrite?: ((
|
|
992
|
+
beforeWrite?: ((update: {
|
|
993
|
+
newValue: T;
|
|
994
|
+
key: string;
|
|
995
|
+
collection: StorageSync<T>;
|
|
996
|
+
}) => void) | undefined;
|
|
989
997
|
} | undefined);
|
|
990
998
|
get(key: string): T | undefined;
|
|
991
999
|
set(key: string, value: T): void;
|
package/package.json
CHANGED
|
@@ -11,7 +11,11 @@ export declare class DiskCollection<T> implements IStorageSync<T> {
|
|
|
11
11
|
cbor?: boolean | undefined;
|
|
12
12
|
noPrompt?: boolean | undefined;
|
|
13
13
|
freeze?: "deep" | "shallow" | undefined;
|
|
14
|
-
beforeWrite?: ((
|
|
14
|
+
beforeWrite?: ((update: {
|
|
15
|
+
newValue: T;
|
|
16
|
+
key: string;
|
|
17
|
+
collection: DiskCollection<T>;
|
|
18
|
+
}) => void) | undefined;
|
|
15
19
|
} | undefined);
|
|
16
20
|
transactionStorage: TransactionStorage | undefined;
|
|
17
21
|
initStorage(): Promise<IStorage<T>>;
|
|
@@ -20,7 +20,7 @@ export class DiskCollection<T> implements IStorageSync<T> {
|
|
|
20
20
|
noPrompt?: boolean;
|
|
21
21
|
freeze?: "shallow" | "deep";
|
|
22
22
|
// May mutate newValue in order to change what will be written
|
|
23
|
-
beforeWrite?: (newValue: T) => void;
|
|
23
|
+
beforeWrite?: (update: { newValue: T; key: string; collection: DiskCollection<T> }) => void;
|
|
24
24
|
}
|
|
25
25
|
) {
|
|
26
26
|
}
|
|
@@ -45,7 +45,10 @@ export class DiskCollection<T> implements IStorageSync<T> {
|
|
|
45
45
|
new PendingStorage(`Collection (${this.collectionName})`,
|
|
46
46
|
new DelayedStorage<T>(this.baseStorage)
|
|
47
47
|
),
|
|
48
|
-
|
|
48
|
+
{
|
|
49
|
+
freeze: this.config?.freeze,
|
|
50
|
+
beforeWrite: this.config?.beforeWrite && ((update) => this.config!.beforeWrite!({ ...update, collection: this })),
|
|
51
|
+
}
|
|
49
52
|
);
|
|
50
53
|
|
|
51
54
|
public get(key: string): T | undefined {
|
|
@@ -13,7 +13,11 @@ export declare class StorageSync<T> implements IStorageSync<T> {
|
|
|
13
13
|
};
|
|
14
14
|
constructor(storage: IStorage<T>, config?: {
|
|
15
15
|
freeze?: "deep" | "shallow" | undefined;
|
|
16
|
-
beforeWrite?: ((
|
|
16
|
+
beforeWrite?: ((update: {
|
|
17
|
+
newValue: T;
|
|
18
|
+
key: string;
|
|
19
|
+
collection: StorageSync<T>;
|
|
20
|
+
}) => void) | undefined;
|
|
17
21
|
} | undefined);
|
|
18
22
|
get(key: string): T | undefined;
|
|
19
23
|
set(key: string, value: T): void;
|
|
@@ -14,7 +14,7 @@ export class StorageSync<T> implements IStorageSync<T> {
|
|
|
14
14
|
constructor(public storage: IStorage<T>, private config?: {
|
|
15
15
|
freeze?: "shallow" | "deep";
|
|
16
16
|
// May mutate newValue in order to change what will be written
|
|
17
|
-
beforeWrite?: (newValue: T) => void;
|
|
17
|
+
beforeWrite?: (update: { newValue: T; key: string; collection: StorageSync<T> }) => void;
|
|
18
18
|
}) {
|
|
19
19
|
storage.watchResync?.(async () => {
|
|
20
20
|
// NOTE: If there's multiple tabs open, this'll trigger a lot, so we can't just clear all the values, as that'll cause a render where nothing's loaded.
|
|
@@ -38,7 +38,7 @@ export class StorageSync<T> implements IStorageSync<T> {
|
|
|
38
38
|
}
|
|
39
39
|
public set(key: string, value: T): void {
|
|
40
40
|
if (this.config?.beforeWrite) {
|
|
41
|
-
this.config.beforeWrite(value);
|
|
41
|
+
this.config.beforeWrite({ newValue: value, key, collection: this });
|
|
42
42
|
}
|
|
43
43
|
if (!this.keys.has(key)) {
|
|
44
44
|
this.keys.add(key);
|