@k3000/store 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -45,7 +45,6 @@ import upgrade, {
45
45
  bigintSerialize,
46
46
  BigUint,
47
47
  Buffer,
48
- Byte,
49
48
  Float,
50
49
  Id,
51
50
  Int,
@@ -84,7 +83,7 @@ Id()
84
83
  .remark('备注') // 可缺省
85
84
 
86
85
  // Uint 用法
87
- Uint()
86
+ Uint(4)
88
87
  .index(false) // 是否索引,此类型默认为 false
89
88
  .value(2) // 默认值,此类型没有缺省值
90
89
  .step(2) // 缺省自增值,此类型没有缺省值
@@ -95,6 +94,7 @@ Int()
95
94
  .index(false) // 是否索引,此类型默认为 false
96
95
  .value(2) // 默认值,此类型没有缺省值
97
96
  .step(2) // 缺省自增值,此类型没有缺省值
97
+ .length(4) // 长度,此类型默认为 4
98
98
  .remark('备注') // 可缺省
99
99
 
100
100
  // Bool 用法
package/architect.mjs CHANGED
@@ -1054,19 +1054,27 @@ export class Storage {
1054
1054
  }
1055
1055
 
1056
1056
  item.value = value
1057
+
1058
+ return true
1057
1059
  }
1058
1060
 
1061
+ return false
1062
+
1059
1063
  } else {
1060
1064
 
1061
1065
  const val = Buffer.alloc(length)
1062
1066
 
1063
1067
  readSync(this.#fd_data, val, 0, length, position)
1064
1068
 
1069
+ const needsSave = !val.equals(value)
1070
+
1065
1071
  this.#values.set(position, {
1066
1072
  value,
1067
1073
  expired: true,
1068
- needsSave: value !== val,
1074
+ needsSave,
1069
1075
  })
1076
+
1077
+ return needsSave
1070
1078
  }
1071
1079
  }
1072
1080
 
package/generator.mjs CHANGED
@@ -2,8 +2,8 @@ import {copyFileSync, existsSync, mkdirSync, readdirSync, statSync, writeFileSyn
2
2
  import {buffer, string, Storage, TypeLen} from './architect.mjs'
3
3
  import {resolve} from 'node:path'
4
4
 
5
- const modulePath = import.meta.url.endsWith('?test=true') ? '../../architect.mjs' : 'dmb3/architect.mjs'
6
- const modulePath2 = import.meta.url.endsWith('?test=true') ? '../../generator.mjs' : 'dmb3'
5
+ const modulePath = import.meta.url.endsWith('?test=true') ? '../../architect.mjs' : '@k3000/store/architect.mjs'
6
+ const modulePath2 = import.meta.url.endsWith('?test=true') ? '../../generator.mjs' : '@k3000/store'
7
7
 
8
8
  class Enum {
9
9
 
@@ -744,11 +744,22 @@ const index = import.meta.url.indexOf('?')
744
744
 
745
745
  const url = \`./${version}/index.mjs\${index > -1 ? import.meta.url.substring(index) : ''}\`
746
746
 
747
+ let remark0, close0, getStruct0
748
+
747
749
  /**
748
750
  * @type {import('./${version}/type').Storage}
749
751
  */
750
752
  const storage = await new Promise((resolve, reject) => import(url)
751
- .then(modules => resolve(modules.default)).catch(error => reject(error)))
753
+ .then(modules => {
754
+ remark0 = modules.remark
755
+ close0 = modules.close
756
+ getStruct0 = modules.getStruct
757
+ resolve(modules.default)
758
+ }).catch(error => reject(error)))
759
+
760
+ export const remark = remark0
761
+ export const close = close0
762
+ export const getStruct = getStruct0
752
763
 
753
764
  export default storage
754
765
  `)
@@ -809,16 +820,12 @@ const storage = new Storage(import.meta.url)
809
820
 
810
821
  export const remark = Symbol('remark')
811
822
 
812
- export function getStruct() {
823
+ export const close = () => storage.close()
813
824
 
814
- return struct(storage, remark)
815
- }
825
+ export const getStruct = () => struct(storage, remark)
816
826
 
817
827
  export default new class extends Store {
818
828
 
819
- close() {
820
- storage.close()
821
- }
822
829
  }`)
823
830
  }
824
831
 
@@ -1170,8 +1177,7 @@ interface ${key}Set extends Array<${key}> {
1170
1177
  }
1171
1178
  ).join('')}
1172
1179
 
1173
- export interface Storage {
1174
- close(): void${Object.keys(struct.base).map(key => {
1180
+ export interface Storage {${Object.keys(struct.base).map(key => {
1175
1181
  const Key = key[0].toUpperCase() + key.substring(1)
1176
1182
  return `
1177
1183
  ${key}: ${Key}Set`
@@ -1191,18 +1197,14 @@ ${Object.entries(struct.base).map(clipEntity).join('')}
1191
1197
  ${Object.entries(struct.base).map(clipEntities).join('')}
1192
1198
  export const remark = Symbol('remark')
1193
1199
 
1194
- export function getStruct() {
1200
+ export const close = () => storage.close()
1195
1201
 
1196
- return struct(storage, remark)
1197
- }
1202
+ export const getStruct = () => struct(storage, remark)
1198
1203
 
1199
1204
  /**
1200
1205
  * @type {import('./type').Storage}
1201
1206
  */
1202
- const store = Object.freeze({
1203
- close() {
1204
- storage.close()
1205
- },${Object.keys(struct.base).map(key => {
1207
+ const store = Object.freeze({${Object.keys(struct.base).map(key => {
1206
1208
  const Key = key[0].toUpperCase() + key.substring(1)
1207
1209
  return `
1208
1210
  ${key}: new Proxy([], {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@k3000/store",
3
- "version": "0.1.0",
4
- "description": "storage dmb3",
3
+ "version": "0.1.2",
4
+ "description": "storage",
5
5
  "main": "generator.mjs",
6
6
  "scripts": {
7
7
  "test": "node test.mjs"
package/test.mjs CHANGED
@@ -13,7 +13,7 @@ import upgrade, {
13
13
  Time,
14
14
  Uint
15
15
  } from './generator.mjs?test=true'
16
- // } from 'dmb3/generator.mjs'
16
+ // } from '@k3000/store/generator.mjs'
17
17
  import {existsSync, readdirSync, rmdirSync, statSync, unlinkSync} from "node:fs";
18
18
  import {json} from "node:stream/consumers";
19
19