Skip to content

Commit

Permalink
fix: fixed issue with transactions in firestoreCollectionQueryFactory
Browse files Browse the repository at this point in the history
- fixed issue where the transaction was not passed to documents within firestoreCollectionQueryFactory properly when a transaction was present
- added improvements to make-env.js
  • Loading branch information
dereekb committed Dec 24, 2022
1 parent 44baeed commit 79a1456
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
14 changes: 9 additions & 5 deletions make-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ const env = {}; // this is the object that is parsed
const keysToIgnoreFromTemplate = ['PUT_YOUR_REAL_SECRETS_INTO_ENV_SECRET', 'THIS_FILE_IS_COMMITTED_TO_GITHUB']; // these keys are ignored
const keysToIgnore = new Set(keysToIgnoreFromTemplate);

const envSpecifierType = new String(process.argv[2] || 'test').toUpperCase(); // Also use this to find variables. Always lowercase
const envSpecifierSeparator = '__';
const envSpecifierTypeLower = envSpecifierType.toLowerCase();
const envSpecifierSeparator = '_';

Object.keys(template)
.filter((x) => !keysToIgnore.has(x))
.forEach((key) => (env[key] = ''));

function copyToEnvFromProcessEnv(key, defaultValue = '') {
const envSpecificKey = `${key}${envSpecifierSeparator}${envSpecifierType}`; // MY_ENV_VARIABLE.test
env[key] = process.env[envSpecificKey] || process.env[key] || defaultValue;
const envSpecificKey = `${key}${envSpecifierSeparator}${envSpecifierType}`; // MY_ENV_VARIABLE_TEST
const envSpecificKeyLower = `${key}${envSpecifierSeparator}${envSpecifierTypeLower}`; // MY_ENV_VARIABLE_test

env[key] = process.env[envSpecificKey] || process.env[envSpecificKeyLower] || process.env[key] || defaultValue;
}

function initWithProcessEnv(defaultValue, keysSource = env) {
Expand All @@ -63,7 +65,9 @@ const defaultPlaceholderValue = 'placeholder'; // This is the default value to u
initWithProcessEnv(defaultPlaceholderValue); // Init with process.env, copying values from process.env onto the existing keys of our env variable

// Check there are no placeholder values remaining
assertHasNoPlaceholderValues(defaultPlaceholderValue);
if (envSpecifierTypeLower === 'staging' || envSpecifierTypeLower === 'prod') {
assertHasNoPlaceholderValues(defaultPlaceholderValue);
}

// Explicit Declaration
copyToEnvFromProcessEnv('MAILGUN_DOMAIN');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export interface DbxFirebaseCollectionStoreContextState<T, D extends FirestoreDo
readonly constraints?: Maybe<ArrayOrValue<FirestoreQueryConstraint>>;
}

/**
* Used for storing the state of a Person and related email threads.
*/
@Injectable()
export class AbstractDbxFirebaseCollectionStore<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, C extends DbxFirebaseCollectionStoreContextState<T, D> = DbxFirebaseCollectionStoreContextState<T, D>> extends LockSetComponentStore<C> implements DbxFirebaseCollectionStore<T, D> {
// MARK: Effects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ export interface DbxFirebaseDocumentStoreContextState<T, D extends FirestoreDocu
readonly ref?: Maybe<DocumentReference<T>>;
}

/**
* Used for storing the state of a Person and related email threads.
*/
@Injectable()
export class AbstractDbxFirebaseDocumentStore<T, D extends FirestoreDocument<T> = FirestoreDocument<T>, C extends DbxFirebaseDocumentStoreContextState<T, D> = DbxFirebaseDocumentStoreContextState<T, D>> extends LockSetComponentStore<C> implements DbxFirebaseDocumentStore<T, D> {
// MARK: Effects
Expand Down
2 changes: 1 addition & 1 deletion packages/dbx-web/src/lib/layout/section/_section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $header-left-reserved-space-small-screen: 120px;
}

.dbx-section-header-padded {
padding: 0 2px;
padding: 0 4px;
}

.dbx-section-hint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function firestoreCollectionQueryFactory<T, D extends FirestoreDocument<T
const result = await baseQuery.getFirstDoc(transaction);
return result ? documentLoader([result.ref])[0] : undefined;
},
getDocs: (transaction?: Transaction) => baseQuery.getDocs(transaction).then((x) => documentLoader(documentReferencesFromSnapshot(x))),
getDocs: (transaction?: Transaction) => baseQuery.getDocs(transaction).then((x) => documentLoader(documentReferencesFromSnapshot(x), transaction)),
streamDocs: () => baseQuery.streamDocs().pipe(map((x) => documentLoader(documentReferencesFromSnapshot(x)))),
filter: (...queryConstraints: ArrayOrValue<FirestoreQueryConstraint>[]) => wrapQuery(baseQuery.filter(...queryConstraints))
};
Expand Down

0 comments on commit 79a1456

Please sign in to comment.