entropic-bond 1.49.0 → 1.50.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.
Files changed (141) hide show
  1. package/.github/workflows/release.yml +26 -0
  2. package/CHANGELOG.md +1151 -0
  3. package/docs/.nojekyll +1 -0
  4. package/docs/README.md +94 -0
  5. package/docs/classes/Auth.md +391 -0
  6. package/docs/classes/AuthMock.md +278 -0
  7. package/docs/classes/AuthService.md +188 -0
  8. package/docs/classes/CloudFunctions.md +123 -0
  9. package/docs/classes/CloudFunctionsMock.md +97 -0
  10. package/docs/classes/CloudStorage.md +215 -0
  11. package/docs/classes/DataSource.md +248 -0
  12. package/docs/classes/EntropicComponent.md +666 -0
  13. package/docs/classes/JsonDataSource.md +328 -0
  14. package/docs/classes/MockCloudStorage.md +279 -0
  15. package/docs/classes/Model.md +274 -0
  16. package/docs/classes/Observable.md +120 -0
  17. package/docs/classes/Persistent.md +420 -0
  18. package/docs/classes/ServerAuth.md +211 -0
  19. package/docs/classes/ServerAuthMock.md +176 -0
  20. package/docs/classes/ServerAuthService.md +130 -0
  21. package/docs/classes/Store.md +218 -0
  22. package/docs/classes/StoredFile.md +636 -0
  23. package/docs/enums/StoredFileEvent.md +41 -0
  24. package/docs/interfaces/AuthError.md +30 -0
  25. package/docs/interfaces/CloudFunctionsService.md +69 -0
  26. package/docs/interfaces/Collection.md +13 -0
  27. package/docs/interfaces/CustomCredentials.md +7 -0
  28. package/docs/interfaces/DocumentReference.md +49 -0
  29. package/docs/interfaces/JsonRawData.md +7 -0
  30. package/docs/interfaces/SignData.md +63 -0
  31. package/docs/interfaces/StoreParams.md +52 -0
  32. package/docs/interfaces/StoredFileChange.md +41 -0
  33. package/docs/interfaces/UploadControl.md +90 -0
  34. package/docs/interfaces/UserCredentials.md +113 -0
  35. package/docs/interfaces/Values.md +17 -0
  36. package/docs/modules.md +1273 -0
  37. package/package.json +23 -19
  38. package/src/auth/auth-mock.spec.ts +168 -0
  39. package/src/auth/auth-mock.ts +129 -0
  40. package/src/auth/auth.ts +185 -0
  41. package/src/auth/user-auth-types.ts +21 -0
  42. package/src/cloud-functions/cloud-functions-mock.spec.ts +136 -0
  43. package/src/cloud-functions/cloud-functions-mock.ts +23 -0
  44. package/src/cloud-functions/cloud-functions.ts +83 -0
  45. package/src/cloud-storage/cloud-storage.spec.ts +207 -0
  46. package/src/cloud-storage/cloud-storage.ts +60 -0
  47. package/src/cloud-storage/mock-cloud-storage.ts +72 -0
  48. package/src/cloud-storage/stored-file.ts +102 -0
  49. package/src/index.ts +19 -0
  50. package/src/observable/observable.spec.ts +105 -0
  51. package/src/observable/observable.ts +67 -0
  52. package/src/persistent/entropic-component.spec.ts +143 -0
  53. package/src/persistent/entropic-component.ts +135 -0
  54. package/src/persistent/persistent.spec.ts +828 -0
  55. package/src/persistent/persistent.ts +650 -0
  56. package/src/server-auth/server-auth-mock.spec.ts +53 -0
  57. package/src/server-auth/server-auth-mock.ts +45 -0
  58. package/src/server-auth/server-auth.ts +49 -0
  59. package/src/store/data-source.ts +186 -0
  60. package/src/store/json-data-source.spec.ts +100 -0
  61. package/src/store/json-data-source.ts +256 -0
  62. package/src/store/mocks/mock-data.json +155 -0
  63. package/src/store/mocks/test-user.ts +122 -0
  64. package/src/store/model.spec.ts +659 -0
  65. package/src/store/model.ts +462 -0
  66. package/src/store/store.spec.ts +30 -0
  67. package/src/store/store.ts +113 -0
  68. package/src/types/utility-types.spec.ts +117 -0
  69. package/src/types/utility-types.ts +116 -0
  70. package/src/utils/test-utils/test-person.ts +44 -0
  71. package/src/utils/utils.spec.ts +95 -0
  72. package/{lib/utils/utils.d.ts → src/utils/utils.ts} +34 -10
  73. package/tsconfig-build.json +7 -0
  74. package/tsconfig-cjs.json +9 -0
  75. package/tsconfig.json +33 -0
  76. package/vite.config.ts +22 -0
  77. package/lib/auth/auth-mock.d.ts +0 -22
  78. package/lib/auth/auth-mock.js +0 -111
  79. package/lib/auth/auth-mock.js.map +0 -1
  80. package/lib/auth/auth.d.ts +0 -131
  81. package/lib/auth/auth.js +0 -149
  82. package/lib/auth/auth.js.map +0 -1
  83. package/lib/auth/user-auth-types.d.ts +0 -19
  84. package/lib/auth/user-auth-types.js +0 -3
  85. package/lib/auth/user-auth-types.js.map +0 -1
  86. package/lib/cloud-functions/cloud-functions-mock.d.ts +0 -11
  87. package/lib/cloud-functions/cloud-functions-mock.js +0 -19
  88. package/lib/cloud-functions/cloud-functions-mock.js.map +0 -1
  89. package/lib/cloud-functions/cloud-functions.d.ts +0 -19
  90. package/lib/cloud-functions/cloud-functions.js +0 -64
  91. package/lib/cloud-functions/cloud-functions.js.map +0 -1
  92. package/lib/cloud-storage/cloud-storage.d.ts +0 -24
  93. package/lib/cloud-storage/cloud-storage.js +0 -37
  94. package/lib/cloud-storage/cloud-storage.js.map +0 -1
  95. package/lib/cloud-storage/mock-cloud-storage.d.ts +0 -20
  96. package/lib/cloud-storage/mock-cloud-storage.js +0 -68
  97. package/lib/cloud-storage/mock-cloud-storage.js.map +0 -1
  98. package/lib/cloud-storage/stored-file.d.ts +0 -39
  99. package/lib/cloud-storage/stored-file.js +0 -106
  100. package/lib/cloud-storage/stored-file.js.map +0 -1
  101. package/lib/index.d.ts +0 -19
  102. package/lib/index.js +0 -36
  103. package/lib/index.js.map +0 -1
  104. package/lib/observable/observable.d.ts +0 -52
  105. package/lib/observable/observable.js +0 -66
  106. package/lib/observable/observable.js.map +0 -1
  107. package/lib/persistent/entropic-component.d.ts +0 -76
  108. package/lib/persistent/entropic-component.js +0 -109
  109. package/lib/persistent/entropic-component.js.map +0 -1
  110. package/lib/persistent/persistent.d.ts +0 -281
  111. package/lib/persistent/persistent.js +0 -539
  112. package/lib/persistent/persistent.js.map +0 -1
  113. package/lib/server-auth/server-auth-mock.d.ts +0 -12
  114. package/lib/server-auth/server-auth-mock.js +0 -39
  115. package/lib/server-auth/server-auth-mock.js.map +0 -1
  116. package/lib/server-auth/server-auth.d.ts +0 -24
  117. package/lib/server-auth/server-auth.js +0 -36
  118. package/lib/server-auth/server-auth.js.map +0 -1
  119. package/lib/store/data-source.d.ts +0 -137
  120. package/lib/store/data-source.js +0 -62
  121. package/lib/store/data-source.js.map +0 -1
  122. package/lib/store/json-data-source.d.ts +0 -68
  123. package/lib/store/json-data-source.js +0 -199
  124. package/lib/store/json-data-source.js.map +0 -1
  125. package/lib/store/mocks/test-user.d.ts +0 -49
  126. package/lib/store/mocks/test-user.js +0 -135
  127. package/lib/store/mocks/test-user.js.map +0 -1
  128. package/lib/store/model.d.ts +0 -238
  129. package/lib/store/model.js +0 -417
  130. package/lib/store/model.js.map +0 -1
  131. package/lib/store/store.d.ts +0 -62
  132. package/lib/store/store.js +0 -102
  133. package/lib/store/store.js.map +0 -1
  134. package/lib/types/utility-types.d.ts +0 -45
  135. package/lib/types/utility-types.js +0 -3
  136. package/lib/types/utility-types.js.map +0 -1
  137. package/lib/utils/test-utils/test-person.d.ts +0 -33
  138. package/lib/utils/test-utils/test-person.js +0 -25
  139. package/lib/utils/test-utils/test-person.js.map +0 -1
  140. package/lib/utils/utils.js +0 -76
  141. package/lib/utils/utils.js.map +0 -1
@@ -0,0 +1,117 @@
1
+ import type { Equal, Expect } from '@type-challenges/utils'
2
+ import { TestPerson, Name, Coordinates, samplePerson } from '../utils/test-utils/test-person'
3
+ import { getDeepValue } from '../utils/utils'
4
+ import { PropPath, PropPathType, Require } from './utility-types'
5
+
6
+ const person = samplePerson()
7
+
8
+
9
+ /*******************************************************************************
10
+ *
11
+ * SUB-PROPERTIES
12
+ *
13
+ *******************************************************************************/
14
+
15
+ //@ts-expect-error
16
+ const a: PropPath<TestPerson> = 'nothing'
17
+
18
+ //@ts-expect-error
19
+ const b: PropPath<TestPerson> = 'name.nothing'
20
+
21
+ //@ts-expect-error
22
+ const c: PropPath<TestPerson> = 'address.nothing'
23
+
24
+ //@ts-expect-error
25
+ const d: PropPath<TestPerson> = 'address.coordinates.nothing'
26
+
27
+ //@ts-expect-error
28
+ const e: PropPath<TestPerson> = 'address.nothing.x'
29
+
30
+ //@ts-expect-error
31
+ const f: PropPath<TestPerson> = 'nothing.coordinates'
32
+
33
+ //@ts-expect-error
34
+ const g0: PropPath<TestPerson> = 'testMethod'
35
+
36
+ //@ts-expect-error
37
+ const g1: PropPath<TestPerson> = 'address.senderMethod'
38
+
39
+ const h: PropPath<TestPerson, any, 5>[] = [
40
+ 'name',
41
+ 'name.firstName',
42
+ 'name.secondName',
43
+ 'address',
44
+ 'address.coordinates',
45
+ 'address.coordinates.x',
46
+ 'address.coordinates.y',
47
+ 'address.postalAddress',
48
+ 'age',
49
+ 'id',
50
+ 'deepProp.l1.l2.l3.l4.l5'
51
+ ]
52
+
53
+ //@ts-expect-error
54
+ const i: PropPath<TestPerson, number> = 'id'
55
+
56
+ const j: PropPath<TestPerson, number>[] = [
57
+ 'age'
58
+ ]
59
+
60
+ type cases0 = [
61
+ Expect<Equal< PropPathType<TestPerson, 'id'>, string>>,
62
+ Expect<Equal< PropPathType<TestPerson, 'age'>, number>>,
63
+ Expect<Equal< PropPathType<TestPerson, 'name'>, Name>>,
64
+ Expect<Equal< PropPathType<TestPerson, 'name.firstName'>, string>>,
65
+ Expect<Equal< PropPathType<TestPerson, 'name.secondName'>, string>>,
66
+ Expect<Equal< PropPathType<TestPerson, 'address'>, typeof person.address>>,
67
+ Expect<Equal< PropPathType<TestPerson, 'address.coordinates'>, Coordinates>>,
68
+ Expect<Equal< PropPathType<TestPerson, 'address.coordinates.x'>, number>>,
69
+ Expect<Equal< PropPathType<TestPerson, 'address.postalAddress'>, string>>,
70
+ ]
71
+
72
+ const id = getDeepValue( person, 'id' )
73
+ const age = getDeepValue( person, 'age' )
74
+ const name = getDeepValue( person, 'name' )
75
+ const nameFirstName = getDeepValue( person, 'name.firstName' )
76
+ const nameSecondName = getDeepValue( person, 'name.secondName' )
77
+ const address = getDeepValue( person, 'address' )
78
+ const addressCoordinates = getDeepValue( person, 'address.coordinates' )
79
+ const addressCoordinatesX = getDeepValue( person, 'address.coordinates.x' )
80
+ const addressCoordinatesY = getDeepValue( person, 'address.coordinates.y' )
81
+ const addressPostalAddress = getDeepValue( person, 'address.postalAddress' )
82
+
83
+ type cases = [
84
+ Expect<Equal< typeof id, string >>,
85
+ Expect<Equal< typeof age, number >>,
86
+ Expect<Equal< typeof name, Name >>,
87
+ Expect<Equal< typeof nameFirstName, string >>,
88
+ Expect<Equal< typeof nameSecondName, string >>,
89
+ Expect<Equal< typeof address, typeof person.address >>,
90
+ Expect<Equal< typeof addressCoordinates, Coordinates >>,
91
+ Expect<Equal< typeof addressCoordinatesX, number >>,
92
+ Expect<Equal< typeof addressCoordinatesY, number >>,
93
+ Expect<Equal< typeof addressPostalAddress, string >>,
94
+ ]
95
+
96
+ /*******************************************************************************
97
+ * Require
98
+ *******************************************************************************/
99
+ type Tr = { a?: number, b?: string, c?: boolean, d: number }
100
+ type Ra = { a: number, b?: string, c?: boolean, d: number }
101
+ type Sr = Require<Tr, 'a'>
102
+
103
+ const require1: Tr = { d: 3 }
104
+ const require2: Require<Tr, 'a'> = { a: 2, d: 3 }
105
+ const require3: Require<Tr, 'a' | 'b'> = { a: 2, b: 'b', d: 3 }
106
+ // @ts-expect-error
107
+ const require4: Require<Tr, 'a'> = { d: 3 }
108
+ // @ts-expect-error
109
+ const require5: Require<Tr, 'a' | 'b'> = { a: 2, d: 3 }
110
+
111
+
112
+
113
+
114
+
115
+ it('should compile everything above',()=>{
116
+ expect( true ).toBeTruthy()
117
+ })
@@ -0,0 +1,116 @@
1
+ export type ClassMethodNames<T> = {
2
+ [ K in keyof T]: T[K] extends Function? K : never
3
+ }[keyof T]
4
+
5
+ export type ClassMethods<T> = Pick<T, ClassMethodNames<T>>
6
+
7
+ export type ClassPropNames<T> = {
8
+ [ K in keyof T]: T[K] extends Function? never : K
9
+ }[keyof T]
10
+
11
+ export type ClassProps<T> = Pick<T, ClassPropNames<T>>
12
+
13
+ export type SomeClassProps<T> = Partial< ClassProps< T > >
14
+
15
+ export type SomeClassPropNames<T> = Partial< ClassPropNames< T > >
16
+
17
+ export type ClassArrayPropNames<T> = {
18
+ [ K in keyof T]: T[K] extends unknown[] | Readonly<unknown[]>? K : never
19
+ }[keyof T]
20
+
21
+ export type ClassArrayProps<T> = Pick<T, ClassArrayPropNames<T>>
22
+
23
+ export type Elements<
24
+ T extends ReadonlyArray<any> | ArrayLike<any> | Record<any, any> | any
25
+ > = T extends ReadonlyArray<any>
26
+ ? T[number]
27
+ : T extends ArrayLike<any>
28
+ ? T[number]
29
+ : T extends object
30
+ ? T[keyof T]
31
+ : never;
32
+
33
+ export type UnderscoredProp<T> = `_${ T & string }`
34
+
35
+ /*
36
+ // How to use
37
+
38
+ class A {
39
+ name: string
40
+ age: number
41
+
42
+ saySomething() {}
43
+ }
44
+
45
+ const obj: ClassProps<A> = {
46
+ name: '9',
47
+ age: 4,
48
+ saySomething: ()=>{}
49
+ }
50
+
51
+ const funcs: ClassMethods<A> = {
52
+ saySomething: ()=>{},
53
+ name: 'hola'
54
+ }
55
+
56
+ type ClassProps2<T> = {
57
+ [ K in keyof T]: T[K] extends Function? never : T[K]
58
+ }
59
+
60
+ const obj2: ClassProps2<A> = {
61
+ name: '5656',
62
+ saySomething: ()=>{}
63
+ }
64
+ */
65
+
66
+ export interface Collection<T> {
67
+ [ key: string | symbol ]: T
68
+ }
69
+
70
+ export declare type ClassPropNamesOfType<T, U> = {
71
+ [K in keyof T]: T[K] extends Function? never : T[K] extends U? K : never
72
+ }[keyof T];
73
+
74
+ /**
75
+ * Makes K properties of T required and keeps the rest untouched
76
+ * @example
77
+ * type T = { a?: number, b?: string, c?: boolean, d: number }
78
+ * type R = Require<T, 'a' | 'b'>
79
+ * // R = { a: number, b: string, c?: boolean, d: number }
80
+ */
81
+ export type Require<T, K extends keyof T> = T & { [P in K]-?: T[P] }
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ /*******************************************************************************
91
+ *
92
+ * SUB-PROPERTIES
93
+ *
94
+ *******************************************************************************/
95
+
96
+ export type Primitive = string | number | bigint | boolean | undefined | symbol
97
+
98
+ type Decr = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // add to a reasonable amount
99
+
100
+ type Concat<T, U> = `${ string & T }${ string & U }`
101
+
102
+ export type PropPath<T extends {}, AllowedTypes=any, MaxDepth extends number = 3, Prefix = ''> = MaxDepth extends number? {
103
+ [ P in keyof T ]: T[P] extends Function? never : T[P] extends AllowedTypes? T[P] extends Primitive | ArrayLike<any>
104
+ ? Concat<Prefix, P>
105
+ : Concat<Prefix, P> | PropPath <T[P] & {}, AllowedTypes, Decr[MaxDepth], `${ Concat<Prefix, P> }.`> : never
106
+ }[ keyof T ] & string: never
107
+
108
+ export type PropPathType<T, Path, MaxDepth extends number = 2> = MaxDepth extends number
109
+ ? Path extends keyof T
110
+ ? T[ Path ]
111
+ : Path extends `${ infer PropName}.${ infer SubPropName }`
112
+ ? PropName extends keyof T
113
+ ? PropPathType<T[PropName], SubPropName, Decr[MaxDepth]>
114
+ : never
115
+ : never
116
+ : never
@@ -0,0 +1,44 @@
1
+ export interface Name {
2
+ firstName: string
3
+ secondName: string
4
+ }
5
+
6
+ export interface Coordinates {
7
+ x: number
8
+ y: number
9
+ }
10
+
11
+ export interface TestPerson {
12
+ id: string
13
+ name: Name
14
+ age: number
15
+ address: {
16
+ coordinates: Coordinates
17
+ postalAddress: string
18
+ senderMethod: ()=>void
19
+ },
20
+ testMethod: ()=>void
21
+ deepProp: { l1: { l2: { l3: { l4: { l5: { l6: {}}}}}}}
22
+ }
23
+
24
+ export function samplePerson(): TestPerson {
25
+ return ({
26
+ id: 'testPersonId',
27
+ age: 34,
28
+ name: {
29
+ firstName: 'Joe',
30
+ secondName: 'Manteca'
31
+ },
32
+ address: {
33
+ coordinates: {
34
+ x: 10,
35
+ y: 20
36
+ },
37
+ postalAddress: 'Madison Av.',
38
+ senderMethod(){}
39
+ },
40
+ testMethod(){},
41
+ deepProp: { l1: { l2: { l3: { l4: { l5: { l6: {}}}}}}}
42
+ })
43
+ }
44
+
@@ -0,0 +1,95 @@
1
+ import { samplePerson, TestPerson } from './test-utils/test-person'
2
+ import { camelCase, getDeepValue, replaceValue, snakeCase } from './utils'
3
+
4
+ describe( 'Utils', ()=>{
5
+ describe( 'replaceValues', ()=>{
6
+ const text = 'The population of ${country} is ${ people} million \
7
+ and the GDP is $${ gdpValue } million'
8
+ const expected = 'The population of U.S.A. is 100 million \
9
+ and the GDP is $1000 million'
10
+ const vars = {
11
+ country: 'U.S.A.',
12
+ people: '100',
13
+ gdpValue: '1000'
14
+ }
15
+
16
+ it( 'should replace vars as a template literal', ()=>{
17
+ expect( replaceValue( text, vars ) ).toEqual( expected )
18
+ })
19
+
20
+ it( 'should replace vars with empty value', ()=>{
21
+ vars.country = ''
22
+ vars.people = undefined as any
23
+
24
+ expect(
25
+ replaceValue(
26
+ 'The population of ${country} is ${ people} million',
27
+ vars
28
+ )
29
+ ).toEqual( 'The population of is million' )
30
+ })
31
+
32
+ it( 'should resturn empty string on falsy', ()=>{
33
+ expect( replaceValue( undefined, vars ) ).toEqual( '' )
34
+ expect( replaceValue( null, vars ) ).toEqual( '' )
35
+ expect( replaceValue( '', vars ) ).toEqual( '' )
36
+ })
37
+
38
+ })
39
+
40
+ describe( 'Camel/Snake case', ()=>{
41
+
42
+ it( 'should convert to camel case', ()=>{
43
+ expect( camelCase( 'snake_case' ) ).toEqual( 'snakeCase' )
44
+ expect( camelCase( 'snake-case' ) ).toEqual( 'snakeCase' )
45
+ expect( camelCase( 'snake case' ) ).toEqual( 'snakeCase' )
46
+ expect( camelCase( 'snake-Case' ) ).toEqual( 'snakeCase' )
47
+ expect( camelCase( 'snake_Case' ) ).toEqual( 'snakeCase' )
48
+ expect( camelCase( 'snake Case' ) ).toEqual( 'snakeCase' )
49
+ expect( camelCase( 'Snake-Case' ) ).toEqual( 'SnakeCase' )
50
+ expect( camelCase( 'Snake_Case' ) ).toEqual( 'SnakeCase' )
51
+ expect( camelCase( 'Snake Case' ) ).toEqual( 'SnakeCase' )
52
+ })
53
+
54
+ it( 'should return empty string on invalid original string for camel case', ()=>{
55
+ expect( camelCase( undefined ) ).toEqual( '' )
56
+ expect( camelCase( null ) ).toEqual( '' )
57
+ expect( camelCase( '' ) ).toEqual( '' )
58
+ })
59
+
60
+ it( 'should convert to snake case', ()=>{
61
+ expect( snakeCase( 'snakeCase', '_' ) ).toEqual( 'snake_case' )
62
+ expect( snakeCase( 'SnakeCase' ) ).toEqual( 'snake-case' )
63
+ expect( snakeCase( 'SnakeCase', '_' ) ).toEqual( 'snake_case' )
64
+ expect( snakeCase( 'snake case' ) ).toEqual( 'snake-case' )
65
+ expect( snakeCase( 'snake Case' ) ).toEqual( 'snake-case' )
66
+ expect( snakeCase( 'Snake Case' ) ).toEqual( 'snake-case' )
67
+ })
68
+
69
+ it( 'should return empty string on invalid original string for snake case', ()=>{
70
+ expect( snakeCase( undefined ) ).toEqual( '' )
71
+ expect( snakeCase( null ) ).toEqual( '' )
72
+ expect( snakeCase( '' ) ).toEqual( '' )
73
+ })
74
+
75
+ })
76
+
77
+ describe( 'Get subProp value', ()=>{
78
+ let person: TestPerson
79
+ beforeEach(()=>{
80
+ person = JSON.parse( JSON.stringify( samplePerson() ) )
81
+ })
82
+
83
+ it( 'should get swallow value', ()=>{
84
+ expect( getDeepValue( person, 'age' ) ).toEqual( person.age )
85
+ })
86
+
87
+ it( 'should get 1 level value', ()=>{
88
+ expect( getDeepValue( person, 'name.firstName' ) ).toEqual( person.name.firstName )
89
+ })
90
+
91
+ it( 'should get 2 level value', ()=>{
92
+ expect( getDeepValue( person, 'address.coordinates.x' ) ).toEqual( person.address.coordinates.x )
93
+ })
94
+ })
95
+ })
@@ -1,14 +1,16 @@
1
- import { PropPath, PropPathType } from '../types/utility-types';
1
+ import { PropPath, PropPathType } from '../types/utility-types'
2
+
2
3
  /**
3
4
  * A map of key-value pairs
4
5
  * @param varName the name of the variable
5
6
  * @param value the value of the variable
6
7
  */
7
8
  export interface Values {
8
- [varName: string]: string;
9
+ [ varName: string ]: string;
9
10
  }
11
+
10
12
  /**
11
- * Replaces keys found in a string for its values. The keys should be inserted
13
+ * Replaces keys found in a string for its values. The keys should be inserted
12
14
  * inside brackets ${ key } as is done in the string template literals substitutions
13
15
  * @param text the string template
14
16
  * @param values an object with key-value pairs
@@ -19,10 +21,17 @@ export interface Values {
19
21
  * const result = replaceValue( text, values )
20
22
  * // result = 'Hello John, how are you today?'
21
23
  */
22
- export declare function replaceValue(text: string | undefined | null, values: Values): string;
24
+ export function replaceValue( text: string | undefined | null, values: Values ): string {
25
+ if ( !text ) return ''
26
+
27
+ return text.replace(/\${\s*(\w*)\s*}/g, function( _match , group){
28
+ return values[ group ] || '';
29
+ });
30
+ }
31
+
23
32
  /**
24
33
  * Transforms a string to a camel case format (camelCaseFormat)
25
- * @param str the string to transform. It can be a string with spaces or a
34
+ * @param str the string to transform. It can be a string with spaces or a
26
35
  * snake case format
27
36
  * @returns the camel case transformed string
28
37
  * @example
@@ -30,7 +39,15 @@ export declare function replaceValue(text: string | undefined | null, values: Va
30
39
  * const result = camelCase( str )
31
40
  * // result = 'snakeCaseFormat'
32
41
  */
33
- export declare function camelCase(str: string | undefined | null): string;
42
+ export function camelCase( str: string | undefined | null ) {
43
+ if ( !str ) return ''
44
+
45
+ return str.replace(
46
+ /([-_ ][\w])/g,
47
+ group => group.toUpperCase().replace('-', '').replace('_', '').replace(' ', '')
48
+ )
49
+ }
50
+
34
51
  /**
35
52
  * Transforms a string in to a snake case format (snake-case-format)
36
53
  * @param str the string to transform. It can be a string with spaces or a camel
@@ -44,11 +61,16 @@ export declare function camelCase(str: string | undefined | null): string;
44
61
  * const result = snakeCase( str )
45
62
  * // result = 'camel-case-format'
46
63
  */
47
- export declare function snakeCase(str: string | undefined | null, snakeChar?: string): string;
64
+ export function snakeCase( str: string | undefined | null, snakeChar: string = '-' ) {
65
+ if ( !str ) return ''
66
+ const replaced = str.slice(1).replace(/( |[A-Z])/g, g => g===' '? '-' : snakeChar + g[0]!.toLowerCase() )
67
+ return str[0]!.toLocaleLowerCase() + replaced.replace(/--/g, '-')
68
+ }
69
+
48
70
  /**
49
71
  * Gets the value of the supproperty in the passed object
50
- *
51
- * @param obj the object containing the subproperty
72
+ *
73
+ * @param obj the object containing the subproperty
52
74
  * @param path a string containing the subproperty path in dotted notation
53
75
  * @returns the value of the supproperty in the passed object
54
76
  * @example
@@ -57,4 +79,6 @@ export declare function snakeCase(str: string | undefined | null, snakeChar?: st
57
79
  * const result = getDeepValue( obj, path )
58
80
  * // result = 1
59
81
  */
60
- export declare function getDeepValue<T extends {}, P extends PropPath<T>>(obj: T, path: P): PropPathType<T, P>;
82
+ export function getDeepValue<T extends {}, P extends PropPath<T>>( obj: T, path: P ): PropPathType<T, P> {
83
+ return path.split('.').reduce(( acc: {}, prop: string ) => acc[ prop ], obj )
84
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": []
5
+ },
6
+ "exclude": [ "**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx" ]
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "CommonJS",
5
+ "outDir": "./lib",
6
+ "types": []
7
+ },
8
+ "exclude": [ "**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx" ]
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "compileOnSave": false,
3
+ "compilerOptions": {
4
+ "target": "ES2020",
5
+ "module": "ESNext",
6
+ "esModuleInterop": true,
7
+ "moduleResolution": "Bundler",
8
+ "sourceMap": true,
9
+ "outDir": "lib",
10
+ "rootDir": "src/",
11
+ "resolveJsonModule": true,
12
+ "lib": [
13
+ "esnext", "DOM"
14
+ ],
15
+ "declaration": true,
16
+ "experimentalDecorators": true,
17
+ "allowJs": true,
18
+ "isolatedModules": true,
19
+ "strictNullChecks": true, // should be enabled progressively to end having all code base compliant with this rule
20
+ "strictPropertyInitialization": true, // should be enabled progressively to end having all code base compliant with this rule
21
+ "noUncheckedIndexedAccess": true, // this causes errors when accessing arrays elements without checking if they exist
22
+ "noImplicitOverride": true, // this causes errors when overriding methods of base classes. Annoying for React components
23
+ "forceConsistentCasingInFileNames": true,
24
+ "noImplicitThis": true,
25
+ // "noImplicitAny": true, // this causes errors when accessing properties of objects with index signatures
26
+ // "noPropertyAccessFromIndexSignature": true, // annoying when accessing properties of objects with index signatures
27
+ // "strict": true,
28
+ "types": [
29
+ "vitest/globals",
30
+ ]
31
+ },
32
+ "include": ["src"]
33
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { resolve } from 'path'
2
+ import { defineConfig } from 'vitest/config'
3
+ import dts from 'vite-plugin-dts'
4
+
5
+ export default defineConfig({
6
+ test: {
7
+ globals: true,
8
+ exclude: ['**/node_modules', '**/dist', '.idea', '.git', '.cache','**/lib', '**/out'],
9
+ },
10
+ build: {
11
+ lib: {
12
+ entry: resolve( __dirname, 'src/index.ts' ),
13
+ name: 'entropic-bond',
14
+ fileName: 'entropic-bond'
15
+
16
+ },
17
+ "outDir": "lib",
18
+ },
19
+ plugins: [
20
+ dts()
21
+ ]
22
+ })
@@ -1,22 +0,0 @@
1
- import { Collection } from '../types/utility-types';
2
- import { AuthService } from "./auth";
3
- import { UserCredentials, SignData, AuthProvider } from "./user-auth-types";
4
- export declare class AuthMock extends AuthService {
5
- signUp<T extends {}>(signData: SignData): Promise<UserCredentials<T>>;
6
- login<T extends {}>(signData: SignData): Promise<UserCredentials<T>>;
7
- onAuthStateChange<T extends {}>(onChange: (userCredentials: UserCredentials<T>) => void): void;
8
- logout(): Promise<void>;
9
- resetEmailPassword(email: string): Promise<void>;
10
- resendVerificationEmail(email: string, _password: string, _verificationLink: string): Promise<void>;
11
- refreshToken(): Promise<void>;
12
- linkAdditionalProvider(provider: AuthProvider): Promise<unknown>;
13
- unlinkProvider(provider: AuthProvider): Promise<unknown>;
14
- flush(): Promise<void>;
15
- fakeRegisteredUser<T extends {}>(userCredentials: UserCredentials<T>): this;
16
- get fakeRegisteredUsers(): Collection<UserCredentials<{}>>;
17
- private userCredentials;
18
- private pendingPromises;
19
- private _loggedUser;
20
- private notifyChange;
21
- private _fakeRegisteredUsers;
22
- }
@@ -1,111 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthMock = void 0;
4
- const auth_1 = require("./auth");
5
- class AuthMock extends auth_1.AuthService {
6
- constructor() {
7
- super(...arguments);
8
- this.pendingPromises = [];
9
- this._fakeRegisteredUsers = {};
10
- }
11
- signUp(signData) {
12
- const { verificationLink, email, password, authProvider } = signData;
13
- const promise = new Promise(async (resolve, reject) => {
14
- if (authProvider === 'email') {
15
- if (!email)
16
- reject({ code: 'missingEmail', message: 'missingEmail' });
17
- if (!password)
18
- reject({ code: 'missingPassword', message: 'missingPassword' });
19
- }
20
- if (password !== 'fail' && email !== 'fail') {
21
- this._loggedUser = this.userCredentials(signData);
22
- this._fakeRegisteredUsers[this._loggedUser.id] = this._loggedUser;
23
- resolve(this._loggedUser);
24
- this.notifyChange?.(this._loggedUser);
25
- }
26
- else {
27
- reject({ code: 'userNotFound', message: verificationLink || 'Test auth error' });
28
- this.notifyChange?.(undefined);
29
- }
30
- });
31
- this.pendingPromises.push(promise);
32
- return promise;
33
- }
34
- login(signData) {
35
- const fakeUser = Object.values(this._fakeRegisteredUsers).find(user => user.email === signData.email);
36
- if (signData.authProvider === 'email' && !fakeUser && signData.email) {
37
- signData.email = 'fail';
38
- }
39
- return this.signUp(signData);
40
- }
41
- onAuthStateChange(onChange) {
42
- this.notifyChange = onChange;
43
- this.notifyChange(this._loggedUser);
44
- }
45
- async logout() {
46
- const promise = new Promise(resolve => {
47
- this._loggedUser = undefined;
48
- resolve();
49
- this.notifyChange?.(undefined);
50
- });
51
- this.pendingPromises.push(promise);
52
- return promise;
53
- }
54
- resetEmailPassword(email) {
55
- const fakeUserExists = Object.values(this._fakeRegisteredUsers).find(user => user.email === email);
56
- if (fakeUserExists)
57
- return Promise.resolve();
58
- else
59
- return Promise.reject({ code: 'userNotFound', message: 'Test auth error' });
60
- }
61
- resendVerificationEmail(email, _password, _verificationLink) {
62
- const fakeUserExists = Object.values(this._fakeRegisteredUsers).find(user => user.email === email);
63
- if (fakeUserExists)
64
- return Promise.resolve();
65
- else
66
- return Promise.reject({ code: 'userNotFound', message: 'Test auth error' });
67
- }
68
- refreshToken() {
69
- return Promise.resolve();
70
- }
71
- linkAdditionalProvider(provider) {
72
- throw new Error('Not implemented.');
73
- }
74
- unlinkProvider(provider) {
75
- throw new Error('Not implemented.');
76
- }
77
- async flush() {
78
- await Promise.all(this.pendingPromises);
79
- this.pendingPromises = [];
80
- }
81
- fakeRegisteredUser(userCredentials) {
82
- if (this._fakeRegisteredUsers[userCredentials.id])
83
- throw new Error(`User with id ${userCredentials.id} already exists in fake user list`);
84
- this._fakeRegisteredUsers[userCredentials.id] = userCredentials;
85
- return this;
86
- }
87
- get fakeRegisteredUsers() {
88
- return this._fakeRegisteredUsers;
89
- }
90
- userCredentials(signData) {
91
- const fakeUser = Object.values(this._fakeRegisteredUsers).find(user => user.email === signData.email);
92
- if (fakeUser) {
93
- return { ...fakeUser };
94
- }
95
- else {
96
- return {
97
- id: signData.authProvider || `testUID${signData.email ? '-' + signData.email : ''}`,
98
- email: signData.email || 'testEmail',
99
- name: signData.authProvider || `testName${signData.email ? ' ' + signData.email : ''}`,
100
- phoneNumber: 'testPhone',
101
- customData: {
102
- role: 'test'
103
- },
104
- lastLogin: 0,
105
- creationDate: 0
106
- };
107
- }
108
- }
109
- }
110
- exports.AuthMock = AuthMock;
111
- //# sourceMappingURL=auth-mock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-mock.js","sourceRoot":"","sources":["../../src/auth/auth-mock.ts"],"names":[],"mappings":";;;AACA,iCAAuE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