Skip to content

Commit

Permalink
full 1st lvl support
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne Moureton committed Apr 4, 2023
1 parent 6b521a4 commit a0f34e3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
34 changes: 31 additions & 3 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create, emit, DeclarationFlags } from 'dts-dom';
import { create, emit, DeclarationFlags, type } from 'dts-dom';
import { createWriteStream, existsSync, mkdirSync } from 'fs';
import findType from './utils/findType.js';
import { databasesClient } from './utils/firebase.js';
Expand Down Expand Up @@ -28,12 +28,40 @@ const fetchNewTypes = async ({ outDir = './types' } = {}) => {
const docData = (await doc.get()).data();
for (const key in docData) {
const value = docData[key];
result.set(key, value);
if (!result.has(key)) {
result.set(key, [findType(value)
]);
}
else {
const r = result.get(key);
const t = findType(value);
if (!JSON.stringify(r).includes(JSON.stringify(t))) {
result.set(key, r.concat([t]));
}
}
}
}
result.forEach((value, key) => {
// Push attribute to interface
intf.members.push(create.property(key, findType(value)));
if (value.length === 1) {
let t = undefined;
if (value[0].kind) {
t = type.array(type[value[0].type]);
}
else {
t = type[value[0]];
}
intf.members.push(create.property(key, t));
}
else {
const unionArray = value.map(v => {
if (v.kind) {
return type.array(type[v.type]);
}
return type[v];
});
intf.members.push(create.property(key, create.union(unionArray)));
}
});
// Write interface to file
const writeStream = createWriteStream(`${outDir}/firestore.ts`, { flags: 'a' });
Expand Down
33 changes: 30 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create, emit, DeclarationFlags } from 'dts-dom';
import { create, emit, DeclarationFlags, type } from 'dts-dom';
import { createWriteStream, existsSync, mkdirSync } from 'fs';
import findType from './utils/findType.js';
import { databasesClient } from './utils/firebase.js';
Expand Down Expand Up @@ -40,13 +40,40 @@ const fetchNewTypes = async ({ outDir = './types' }: fetchParameters = {}) => {

for (const key in docData) {
const value = docData[key];
result.set(key, value);

if (!result.has(key)) {
result.set(key, [findType(value)
]);
} else {
const r = result.get(key);
const t = findType(value);

if (!JSON.stringify(r).includes(JSON.stringify(t))) {
result.set(key, r.concat([t]));
}
}
}
}

result.forEach((value, key) => {
// Push attribute to interface
intf.members.push(create.property(key, findType(value)));
if (value.length === 1) {
let t = undefined;
if (value[0].kind) {
t = type.array(type[value[0].type]);
} else {
t = type[value[0]];
}
intf.members.push(create.property(key, t));
} else {
const unionArray = value.map(v => {
if (v.kind) {
return type.array(type[v.type]);
}
return type[v];
});
intf.members.push(create.property(key, create.union(unionArray)));
}
});

// Write interface to file
Expand Down

0 comments on commit a0f34e3

Please sign in to comment.